From 4709166614ea10ba442400992cade48c4c9ef00d Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期五, 09 六月 2023 17:18:06 +0800
Subject: [PATCH] 提料计划信息导入

---
 WebAPI/Controllers/SCGL/日计划管理/Sc_JIT_ComplementGoodBillController.cs |  401 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 401 insertions(+), 0 deletions(-)

diff --git "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/Sc_JIT_ComplementGoodBillController.cs" "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/Sc_JIT_ComplementGoodBillController.cs"
index 87870f3..d00e673 100644
--- "a/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/Sc_JIT_ComplementGoodBillController.cs"
+++ "b/WebAPI/Controllers/SCGL/\346\227\245\350\256\241\345\210\222\347\256\241\347\220\206/Sc_JIT_ComplementGoodBillController.cs"
@@ -3,9 +3,11 @@
 using System;
 using System.Collections.Generic;
 using System.Data;
+using System.IO;
 using System.Linq;
 using System.Web;
 using System.Web.Http;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
 using WebAPI.Models;
 
 namespace WebAPI.Controllers.SCGL
@@ -554,6 +556,405 @@
         }
         #endregion
 
+        #region 鎻愭枡璁″垝淇℃伅 鏂囦欢涓婁紶
+        [Route("Cg_PODemandPlanConfigBill/Cg_PODemandPlanConfigBill_Excel")]
+        [HttpPost]
+        public object Cg_PODemandPlanConfigBill_Excel()
+        {
+            try
+            {
+                //var WorkBookName = HttpContext.Current.Request["WorkBookName"];
+                //DBUtility.ClsPub.HOrgID = long.Parse(HttpContext.Current.Request["HOrgID"]);
+                //鑾峰彇鏂囦欢鍚嶇О
+                var file = HttpContext.Current.Request.Files[0];
+                //鑾峰彇鏂囦欢鐗╃悊璺緞
+                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+                //淇濆瓨鏂囦欢
+                file.SaveAs(ExcelPath);
+
+                NpoiHelper np = new NpoiHelper();
+                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable tb2 = new DataTable("dt2");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+                {
+                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+
+                //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("HOrgID", typeof(Int32));//缁勭粐ID
+                tb2.Columns.Add("HSupID", typeof(Int32));//渚涘簲鍟�
+                tb2.Columns.Add("HMaterID", typeof(Int32));//鐗╂枡ID
+                tb2.Columns.Add("HUnitID", typeof(Int32));//璁¢噺鍗曚綅
+
+                //娣诲姞鏁版嵁
+                for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
+                {
+                    DataRow row = tb2.NewRow();
+                    for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++)
+                    {
+                        row[j] = ExcelDs.Tables[0].Rows[i][j].ToString();
+                    }
+                    tb2.Rows.Add(row);
+                }
+
+
+                var error = "";
+
+                //鏌ヨ宸ヨ壓璺嚎娌℃湁鐨勫垪
+                if (!tb2.Columns.Contains("缁勭粐缂栫爜"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囩紪鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("缁勭粐"))
+                    error += "娌℃湁鎵惧埌銆愮粍缁囥�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("渚涘簲鍟嗕唬鐮�"))
+                    error += "娌℃湁鎵惧埌銆愪緵搴斿晢浠g爜銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("渚涘簲鍟�"))
+                    error += "娌℃湁鎵惧埌銆愪緵搴斿晢銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗╂枡浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮墿鏂欎唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐗╂枡鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮墿鏂欏悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("瑙勬牸鍨嬪彿"))
+                    error += "娌℃湁鎵惧埌銆愯鏍煎瀷鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("璁¢噺鍗曚綅"))
+                    error += "娌℃湁鎵惧埌銆愯閲忓崟浣嶃�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鐗╂枡鍒嗙被"))
+                    error += "娌℃湁鎵惧埌銆怞IT鐗╂枡鍒嗙被銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鎷夊姩瀹夊叏搴撳瓨閲�"))
+                    error += "娌℃湁鎵惧埌銆怞IT鎷夊姩瀹夊叏搴撳瓨閲忋�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鐗╂枡闇�姹備緵璐у懆鏈�"))
+                    error += "娌℃湁鎵惧埌銆怞IT鐗╂枡闇�姹備緵璐у懆鏈熴�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鎻愯揣缁忔祹鎵归噺"))
+                    error += "娌℃湁鎵惧埌銆怞IT鎻愯揣缁忔祹鎵归噺銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鎻愯揣鎵归噺瀵瑰簲鍛ㄦ湡锛堝ぉ锛�"))
+                    error += "娌℃湁鎵惧埌銆怞IT鎻愯揣鎵归噺瀵瑰簲鍛ㄦ湡锛堝ぉ锛夈�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT渚涜揣鎻愬墠鏈燂紙澶╋級"))
+                    error += "娌℃湁鎵惧埌銆怞IT渚涜揣鎻愬墠鏈燂紙澶╋級銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鍒拌揣鍓嶇疆鏈燂紙澶╋級"))
+                    error += "娌℃湁鎵惧埌銆怞IT鍒拌揣鍓嶇疆鏈燂紙澶╋級銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT閫佽揣鎺у埗澶╂暟"))
+                    error += "娌℃湁鎵惧埌銆怞IT閫佽揣鎺у埗澶╂暟銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("JIT鏈�灏忚捣閫侀噺"))
+                    error += "娌℃湁鎵惧埌銆怞IT鏈�灏忚捣閫侀噺銆戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("澶囨敞"))
+                    error += "娌℃湁鎵惧埌銆愬娉ㄣ�戠殑鏍囬,";
+
+                if (error.Length > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+                {
+                    string HORGNumber = "";
+                    string HORGName = "";
+                    string HSupNumer = "";
+                    string HSupName = "";
+                    string HMaterNumer = "";
+                    string HMaterName = "";
+                    string HMaterModel = "";
+                    string HUntilName = "";
+
+                    string JITType = "";//JIT鐗╂枡鍒嗙被
+                    string JIPEB = ""; //JIT鎻愯揣缁忔祹鎵归噺
+                    string JISLT = ""; //JIT渚涜揣鎻愬墠鏈燂紙澶╋級
+                    string JIDLT = ""; //JIT鍒拌揣鍓嶇疆鏈燂紙澶╋級
+                    string JIMLC = ""; //JIT鏈�灏忚捣閫侀噺
+
+                    HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐缂栫爜"].ToString());
+                    HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐"].ToString());
+                    HSupNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟嗕唬鐮�"].ToString());
+                    HSupName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟�"].ToString());
+                    HMaterNumer = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡浠g爜"].ToString());
+                    HMaterName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐗╂枡鍚嶇О"].ToString());
+                    HMaterModel = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瑙勬牸鍨嬪彿"].ToString());
+                    HUntilName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["璁¢噺鍗曚綅"].ToString());
+
+                    JITType = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT鐗╂枡鍒嗙被"].ToString());
+                    JIPEB = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT鎻愯揣缁忔祹鎵归噺"].ToString());
+                    JISLT = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT渚涜揣鎻愬墠鏈燂紙澶╋級"].ToString());
+                    JIDLT = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT鍒拌揣鍓嶇疆鏈燂紙澶╋級"].ToString());
+                    JIMLC = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["JIT鏈�灏忚捣閫侀噺"].ToString());
+
+                    //妫�鏌ョ墿鏂�
+                    int index = i + 1;
+
+                    if (HORGNumber != "")
+                    {
+
+
+                        //鏌ヨ缁勭粐
+                        ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where  HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,缁勭粐涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+                        string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString();
+
+
+                        //鏌ヨ渚涘簲鍟�
+                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HNumber='" + HSupNumer + "' and HName='" + HSupName + "'  and HUSEORGID=" + HORGid + "", "Gy_Supplier");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,渚涘簲鍟嗕笉瀛樺湪锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+
+                        //鏌ヨ鐗╂枡
+                        ds = oCN.RunProcReturn("select * from Gy_Material where  HNumber='" + HMaterNumer + "' and HName='" + HMaterName + "' and HModel='" + HMaterModel + "'  and HUSEORGID=" + HORGid + "", "Gy_Material");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,鐗╂枡涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HMaterID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+
+                        //鏌ヨ璁¢噺鍗曚綅
+                        ds = oCN.RunProcReturn("select * from Gy_Unit where  HName='" + HUntilName + "' ", "Gy_Unit"); //and HUSEORGID=" + HORGid + "
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,璇�" + HORGName + "缁勭粐,璁¢噺鍗曚綅涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HUnitID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+
+                        //JIT鐗╂枡鍒嗙被
+                        if (JITType == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,JIT鐗╂枡鍒嗙被涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //JIT鎻愯揣缁忔祹鎵归噺
+                        if (JIPEB == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,JIT鎻愯揣缁忔祹鎵归噺涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //JIT渚涜揣鎻愬墠鏈燂紙澶╋級
+                        if (JISLT == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,JIT渚涜揣鎻愬墠鏈燂紙澶╋級涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //JIT鍒拌揣鍓嶇疆鏈燂紙澶╋級
+                        if (JIDLT == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,IT鍒拌揣鍓嶇疆鏈燂紙澶╋級涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //JIT鏈�灏忚捣閫侀噺
+                        if (JIMLC == "")
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,JIT鏈�灏忚捣閫侀噺涓虹┖锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //瀹℃牳浠g爜鏄惁鍚堢悊
+                        if (!DBUtility.ClsPub.AllowNumber(HMaterNumer))
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐗╂枡浠g爜涓笉鑳藉嚭鐜拌繛缁��.鈥欏苟涓旈浣嶆湯浣嶄笉鑳戒负鈥�.鈥欙紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                    }
+                    else
+                    {
+                        objJsonResult.code = "1";
+                        objJsonResult.count = 1;
+                        objJsonResult.Message = "绗�" + index + "琛�,缁勭粐浠g爜涓虹┖";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = error;
+                objJsonResult.data = tb2;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+        #region 鎻愭枡璁″垝淇℃伅 瀵煎叆(淇濆瓨)
+        [Route("Cg_PODemandPlanConfigBill/Cg_PODemandPlanConfigBill_btnSave")]
+        [HttpPost]
+        public object Cg_PODemandPlanConfigBill_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();
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Cg_PODemandPlanConfigBill_Edit", 1, false, user))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犱繚瀛樻潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                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);
+                }
+
+                oCN.BeginTran();
+
+                foreach (Dictionary<string, string> item in list)
+                {
+                    long HInterID = DBUtility.ClsPub.CreateBillID_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo);//鑾峰緱涓�涓柊鐨刬d
+                    string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("4611", ref DBUtility.ClsPub.sExeReturnInfo, true);//鑾峰緱涓�涓柊鐨勫崟鎹彿
+                    string HOrgID = item["HOrgID"].ToString();//缁勭粐ID
+                    string HSupID = item["HSupID"].ToString();//渚涘簲鍟�
+                    string HSupplierName = item["渚涘簲鍟�"].ToString();
+                    string HMaterID = item["HMaterID"].ToString();//鐗╂枡ID
+                    string HMaterName = item["鐗╂枡鍚嶇О"].ToString();
+                    string HMaterModel = item["瑙勬牸鍨嬪彿"].ToString();
+                    string HUnitID = item["HUnitID"].ToString();//璁¢噺鍗曚綅
+                    string JITType = item["JIT鐗╂枡鍒嗙被"].ToString();
+                    string JITPSL = item["JIT鎷夊姩瀹夊叏搴撳瓨閲�"].ToString();
+                    string JITMDSC = item["JIT鐗╂枡闇�姹備緵璐у懆鏈�"].ToString();
+                    string JIPEB = item["JIT鎻愯揣缁忔祹鎵归噺"].ToString();
+                    string JITPBCC = item["JIT鎻愯揣鎵归噺瀵瑰簲鍛ㄦ湡锛堝ぉ锛�"].ToString();
+                    string JISLT = item["JIT渚涜揣鎻愬墠鏈燂紙澶╋級"].ToString();
+                    string JIDLT = item["JIT鍒拌揣鍓嶇疆鏈燂紙澶╋級"].ToString();
+                    string JITDCD = item["JIT閫佽揣鎺у埗澶╂暟"].ToString();
+                    string JIMLC = item["JIT鏈�灏忚捣閫侀噺"].ToString();
+                    string HRemark = item["澶囨敞"].ToString();
+
+                    int i = 1;
+                    //涓昏〃
+                    oCN.RunProc("insert into Cg_PODemandPlanConfigBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType,HBillSubType,HDate,HBillStatus,HMaker,HMakeDate,HOrgId)" +
+                        $"values({HInterID}, '{HBillNo}',{DateTime.Now.Year}, {DateTime.Now.Month}, '4611', '4611', GETDATE(), 1, '{user}', GETDATE(), {HOrgID})");
+                    //瀛愯〃
+                    oCN.RunProc("insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
+                   "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
+                   "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl)values" +
+                   $"({HInterID}, {i}, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
+                   $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},0,{(JITPBCC == "" ? "0" : JITPBCC)}," +
+                   $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)}) ");
+                }
+              
+                oCN.Commit();
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
         #endregion
 
         #region 鏃ヨ鍒掑钩鍙板熀纭�璧勬枡 瑕佹枡璁″垝淇℃伅

--
Gitblit v1.9.1