From 80e1af24248a6b94951cef2910065c2f6ac0033c Mon Sep 17 00:00:00 2001
From: llj <132905093+newwwwwwtree@users.noreply.github.com>
Date: 星期一, 09 二月 2026 14:36:12 +0800
Subject: [PATCH] wip导入

---
 WebAPI/Controllers/成本管理/CB_WipProcessTableController.cs |  287 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 WebAPI/WebAPI.csproj                                    |    2 
 2 files changed, 289 insertions(+), 0 deletions(-)

diff --git "a/WebAPI/Controllers/\346\210\220\346\234\254\347\256\241\347\220\206/CB_WipProcessTableController.cs" "b/WebAPI/Controllers/\346\210\220\346\234\254\347\256\241\347\220\206/CB_WipProcessTableController.cs"
new file mode 100644
index 0000000..71da11a
--- /dev/null
+++ "b/WebAPI/Controllers/\346\210\220\346\234\254\347\256\241\347\220\206/CB_WipProcessTableController.cs"
@@ -0,0 +1,287 @@
+锘縰sing Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using Pub_Class;
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SqlClient;
+using System.Web;
+using System.Web.Http;
+using WebAPI.Models;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace WebAPI.Controllers.鎴愭湰绠$悊
+{
+    public class CB_WipProcessTableController : ApiController
+    {
+        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
+        public DAL.ClsCB_ItemMoneyBillMain BillOld = new DAL.ClsCB_ItemMoneyBillMain();
+        public DAL.ClsCB_ItemMoneyBillMain BillNew0 = new DAL.ClsCB_ItemMoneyBillMain();
+
+        private json objJsonResult = new json();
+        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
+        DataSet ds;
+
+
+        #region 鏂囦欢涓婁紶
+        [Route("CB_WipProcessTableController/CB_WipProcessTable_Excel")]
+        [HttpPost]
+        public json CB_WipProcessTable_Excel()
+        {
+            json res = new json();
+            try
+            {
+                //鑾峰彇鏂囦欢鍚嶇О
+                var file = HttpContext.Current.Request.Files[0];
+                //鑾峰彇鏂囦欢鐗╃悊璺緞
+                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+                //淇濆瓨鏂囦欢
+                file.SaveAs(ExcelPath);
+
+                SCGL.鏃ヨ鍒掔鐞�.NpoiHelper np = new NpoiHelper();
+                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable provisional = new DataTable("dt2");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+                {
+                    provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+                //provisional.Columns.Add("鍗曟嵁鍙�", typeof(string));
+
+                //娣诲姞鏁版嵁
+                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+                {
+                    DataRow row = provisional.NewRow();
+                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+                    {
+                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+                    }
+                    provisional.Rows.Add(row);
+                }
+
+                //鍒ゆ柇鍒�
+                string error = JudgmentColumns(provisional);
+                if (error.Length > 0)
+                {
+                    res.code = "0";
+                    res.count = 0;
+                    res.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+                    res.data = null;
+                    return res;
+                }
+
+                for (int i = 0; i <= provisional.Rows.Count - 1; i++)
+                {
+
+                    string HProcName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["浜у嚭宸ュ簭"].ToString());
+                    string HCusName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["瀹㈡埛"].ToString());
+
+                    string HPartNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鎴愬搧鏂欏彿"].ToString());
+                    string HWIPQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["WIP鏁伴噺"].ToString());
+
+                    string HInProcessWIPQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍦ㄥ埗WIP鏁伴噺"].ToString());
+
+                    string HPanelQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鎷肩増鏁�"].ToString());
+                    string HLot = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["LOT"].ToString());
+
+                    string HOrderTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["涓嬪崟鏃堕棿"].ToString());
+
+                    string HStartTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鎶曚骇鏃堕棿"].ToString());
+                    string HOutputTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["浜у嚭鏃堕棿"].ToString());
+
+                    string HProductionTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鐢熶骇鏃堕棿"].ToString());
+                    string HStatus = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鐘舵��"].ToString());
+
+                    string HStayTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["鍋滅暀鏃堕棿(鍒嗛挓)"].ToString());
+
+                    //string remark = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["澶囨敞"].ToString());
+
+                    //鑾峰彇鐪熷疄琛屾暟
+                    int line = i + 1;
+                }
+
+                res.code = "1";
+                res.count = 1;
+                res.Message = error;
+                res.data = provisional;
+                return res;
+            }
+            catch (Exception e)
+            {
+                res.code = "0";
+                res.count = 0;
+                res.Message = "Exception锛�" + e.ToString();
+                res.data = null;
+                return res;
+            }
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇鍒�
+        /// </summary>
+        /// <param name="provisional"></param>
+        /// <returns></returns>
+        private static string JudgmentColumns(DataTable provisional)
+        {
+            var error = "";
+
+            //鏌ヨ娌℃湁鐨勫垪
+            if (!provisional.Columns.Contains("瀹㈡埛"))
+                error += "娌℃湁鎵惧埌銆愬鎴枫�戠殑鏍囬,";
+
+            if (!provisional.Columns.Contains("鎴愬搧鏂欏彿"))
+                error += "娌℃湁鎵惧埌銆愭垚鍝佹枡鍙枫�戠殑鏍囬,";
+            return error;
+        }
+        #endregion
+
+        #region 涓婁紶淇濆瓨
+        [Route("CB_WipProcessTableController/Excel_btnSave")]
+        [HttpPost]
+        public object Excel_btnSave([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            string organ = sArray[2].ToString();
+            json res = new json();
+
+            try
+            {
+                oCN.BeginTran();
+                List<object> Excel = Newtonsoft.Json.JsonConvert.DeserializeObject<List<object>>(msg2);
+                List<Dictionary<string, string>> list = new List<Dictionary<string, string>>();
+
+                foreach (JObject item in Excel)
+                {
+                    Dictionary<string, string> dic = new Dictionary<string, string>();
+                    foreach (var itm in item.Properties())
+                    {
+                        dic.Add(itm.Name, itm.Value.ToString());
+                    }
+                    list.Add(dic);
+                }
+
+                // 4. 鏌ヨ鐢ㄦ埛淇℃伅
+                DataSet emp = oCN.RunProcReturn($"SELECT Czybm FROM Gy_Czygl WHERE Czymc = '{user.Replace("'", "''")}'", "Gy_Czygl");
+                if (emp.Tables[0].Rows.Count == 0)
+                {
+                    res.code = "0";
+                    res.count = 0;
+                    res.Message = "鐢ㄦ埛涓嶅瓨鍦紒";
+                    res.data = null;
+                    return res;
+                }
+                string HUserID = emp.Tables[0].Rows[0]["Czybm"].ToString();
+
+                StringBuilder errorMessage = new StringBuilder();
+                StringBuilder insertSql = new StringBuilder();
+                StringBuilder updateSql = new StringBuilder();
+                string currentDate = DateTime.Today.ToString("yyyy-MM-dd");
+                int HEntryID = 1;
+
+                // 閬嶅巻鏁版嵁骞堕獙璇�
+                for (int i = 0; i < list.Count; i++)
+                {
+                    var item = list[i];
+
+                    List<string> intFields = new List<string>
+                    {
+                        "WIP鏁伴噺", "鍦ㄥ埗WIP鏁伴噺", "鎷肩増鏁�", "鍋滅暀鏃堕棿(鍒嗛挓)"
+                    };
+
+                    bool hasError = false;
+                    foreach (var field in intFields)
+                    {
+                        if (item.ContainsKey(field))
+                        {
+                            string value = item[field];
+                            // 妫�鏌ユ槸鍚︿负鏁存暟
+                            if (!string.IsNullOrWhiteSpace(value))
+                            {
+                                if (!int.TryParse(value, out _))
+                                {
+                                    errorMessage.AppendLine($"绗瑊i + 1}琛屾暟鎹敊璇細瀛楁 '{field}' 鐨勫�� '{value}' 涓嶆槸鏈夋晥鐨勬暣鏁�");
+                                    hasError = true;
+                                }
+                            }
+                        }
+                    }
+
+                    // 濡傛灉鏈夐敊璇紝璺宠繃鎻掑叆
+                    if (hasError)
+                    {
+                        continue;
+                    }
+
+
+                    insertSql.AppendLine($"INSERT INTO CB_WipProcessTable  ([HYear], [HPeriod], [HDay], [HProcName], [HCusName], [HPartNumber], [HWIPQty], [HInProcessWIPQty], [HPanelQty], [HLot], [HOrderTime], [HStartTime], [HOutputTime], [HProductionTime], [HStatus], [HStayTime], [HChecker], [HCheckDate], [HMaker], [HMakeDate], [HUpDater], [HUpDateDate], [HCloseMan], [HCloseDate], [HCloseType], [HDeleteMan], [HDeleteDate], [HReamrk]) VALUES (");
+                    insertSql.AppendLine($" {DateTime.Now.Year}, {DateTime.Now.Month}, {DateTime.Now.Day}, '{item["浜у嚭宸ュ簭"]}', '{item["瀹㈡埛"]}',  '{item["鎴愬搧鏂欏彿"]}', '{item["WIP鏁伴噺"]}', '{item["鍦ㄥ埗WIP鏁伴噺"]}', '{item["鎷肩増鏁�"]}', '{item["LOT"]}', '{item["涓嬪崟鏃堕棿"]}', '{item["鎶曚骇鏃堕棿"]}', '{item["浜у嚭鏃堕棿"]}', '{item["鐢熶骇鏃堕棿"]}', '{item["鐘舵��"]}', '{item["鍋滅暀鏃堕棿(鍒嗛挓)"]}', '{""}', '{""}', '{user}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{""}', '{"0"}', '{""}', '{""}', '{"excel瀵煎叆"}');");
+                }
+
+                if (errorMessage.Length > 0)
+                {
+                    //oCN.Rollback();
+                    res.code = "0";
+                    res.count = 0;
+                    res.Message = "鏁版嵁楠岃瘉澶辫触锛歕n" + errorMessage.ToString();
+                    res.data = null;
+                    return res;
+                }
+
+                if (insertSql.Length == 0)
+                {
+                    // oCN.Rollback();
+                    res.code = "0";
+                    res.count = 0;
+                    res.Message = "娌℃湁鏈夋晥鐨勬暣鏁版暟鎹彲浠ュ鍏�";
+                    res.data = null;
+                    return res;
+                }
+
+                // 鎵ц鎵归噺鎿嶄綔
+                if (insertSql.Length > 0)
+                {
+                    oCN.RunProc(insertSql.ToString());
+                }
+
+                //if (updateSql.Length > 0)
+                //{
+                //    oCN.RunProc(updateSql.ToString());
+                //    oCN.RunProc(updateSql_sub.ToString());
+                //}
+
+                oCN.Commit();
+
+                res.code = "1";
+                res.count = 1;
+                res.Message = "瀵煎叆鎴愬姛!";
+                res.data = null;
+                return res;
+            }
+            catch (Exception e)
+            {
+                //oCN.Rollback();
+                LogService.Write(e);
+                res.code = "0";
+                res.count = 0;
+                res.Message = "Exception锛�" + e.ToString();
+                res.data = null;
+                return res;
+            }
+        }
+        #endregion 
+    }
+}
\ No newline at end of file
diff --git a/WebAPI/WebAPI.csproj b/WebAPI/WebAPI.csproj
index 6fa47da..e095697 100644
--- a/WebAPI/WebAPI.csproj
+++ b/WebAPI/WebAPI.csproj
@@ -706,6 +706,7 @@
     <Compile Include="Controllers\鍩虹璧勬枡\鍩虹璧勬枡\Gy_CostItemFixRateController.cs" />
     <Compile Include="Controllers\鍩虹璧勬枡\鍩虹璧勬枡\Gy_CostItemAverageTypeController.cs" />
     <Compile Include="Controllers\鎴愭湰绠$悊\CB_ItemMoneyBillController.cs" />
+    <Compile Include="Controllers\鎴愭湰绠$悊\CB_WipProcessTableController.cs" />
     <Compile Include="Controllers\妫�楠岀敵璇峰崟\QC_RequestCheckBillController.cs" />
     <Compile Include="Controllers\鐗╂祦绠$悊\鍏朵粬缁撶畻鍗昞YF_PayMentOtherBillTranController.cs" />
     <Compile Include="Controllers\鐗╂祦绠$悊\鍑鸿繍鍗昞WLYayBillController.cs" />
@@ -1294,6 +1295,7 @@
     <Folder Include="bin\" />
     <Folder Include="Controllers\椤圭洰绠$悊\鍩虹寤烘ā\" />
     <Folder Include="obj\x86\Debug\" />
+    <Folder Include="Views\CB_WipProcessTable\" />
     <Folder Include="Views\Cg_ContractTransportBillList\" />
     <Folder Include="Views\Cg_PODemandPlanBill\" />
     <Folder Include="Views\Cg_PurchaseReturn\" />

--
Gitblit v1.9.1