From 223760311c950654d96909b0b245ebec6d53b026 Mon Sep 17 00:00:00 2001
From: zrg <z18737863051@163.com>
Date: 星期二, 02 一月 2024 17:30:23 +0800
Subject: [PATCH] 首件检验单维护,巡检单维护,工序检验单维护,审核反审核,关闭,反关闭,作废,反作废

---
 WebAPI/Controllers/BLL/Xt_UserController.cs |  786 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 741 insertions(+), 45 deletions(-)

diff --git a/WebAPI/Controllers/BLL/Xt_UserController.cs b/WebAPI/Controllers/BLL/Xt_UserController.cs
index 706ab8f..d305603 100644
--- a/WebAPI/Controllers/BLL/Xt_UserController.cs
+++ b/WebAPI/Controllers/BLL/Xt_UserController.cs
@@ -444,7 +444,7 @@
                 }
 
                 ////Excel妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
-                tb2.Columns.Add("HItemId", typeof(Int32));//渚涘簲鍟咺D
+                tb2.Columns.Add("HSupID", typeof(Int32));//渚涘簲鍟咺D
 
                 //娣诲姞鏁版嵁
                 for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
@@ -513,10 +513,10 @@
                         }
                         else
                         {
-                            tb2.Rows[i]["HItemID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); //渚涘簲鍟咺D
+                            tb2.Rows[i]["HSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); //渚涘簲鍟咺D
                         }
                         //鏌ヨ鐢ㄦ埛
-                        ds = oCN.RunProcReturn("select * from h_v_Gy_UserList where  czybm='" + czybm + "'", "h_v_Gy_UserList");
+                        ds = oCN.RunProcReturn("select * from Gy_Czygl where  czybm='" + czybm + "'", "Gy_Czygl");
 
                         if (ds.Tables[0].Rows.Count == 0)
                         {
@@ -528,7 +528,7 @@
                         }
                         else
                         {
-                            tb2.Rows[i]["HItemID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                            //tb2.Rows[i]["czybm"] = ds.Tables[0].Rows[0]["czybm"].ToString();
                         }
 
                         //瀹℃牳浠g爜鏄惁鍚堢悊
@@ -569,7 +569,7 @@
         }
   
 
-        #region 鎻愭枡璁″垝淇℃伅 瀵煎叆(淇濆瓨)
+        #region  瀵煎叆(淇濆瓨)
         [Route("Xt_User/UserSupperBill_btnSave")]
         [HttpPost]
         public object UserSupperBill_btnSave([FromBody] JObject sMainSub)
@@ -599,49 +599,27 @@
                 int i = 1;
                 foreach (Dictionary<string, string> item in list)
                 {
-                    string HSupID = item["HSupID"].ToString();//渚涘簲鍟�
-                    string HMaterID = item["HMaterID"].ToString();//鐗╂枡ID
-                    string HOrgID = item["HOrgID"].ToString();//缁勭粐ID
-                    string HSupplierName = item["渚涘簲鍟�"].ToString();
-                    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();
+                    string HSupID = item["HSupID"].ToString();//渚涘簲鍟咺D
+                    string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//鐢ㄦ埛浠g爜
+                    string czymc = item["鐢ㄦ埛鍚嶇О"].ToString();//鐢ㄦ埛鍚嶇О
+                    string HNumber = item["渚涘簲鍟嗕唬鐮�"].ToString();//渚涘簲鍟嗕唬鐮�
+                    string HName = item["渚涘簲鍟嗗悕绉�"].ToString();//渚涘簲鍟嗗悕绉�
 
-                    ds = oCN.RunProcReturn("select * from Cg_PODemandPlanConfigBillSub where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID, "Cg_PODemandPlanConfigBillSub");
+                    var ds = oCN.RunProcReturn("select * from Gy_UserSupplierRelation where  HSupID='" + HSupID + "'and HUserID='" + HUserID + "'", "Gy_UserSupplierRelation");
 
-                    if (ds.Tables[0].Rows.Count == 0)
+
+                    if (ds.Tables[0].Rows.Count >0)
                     {
-
-                        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 sql = "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})";
-                        string sql1 = "insert into Cg_PODemandPlanConfigBillSub(HInterID,HEntryID,HRemark,HSupplierID,HSupplierName,HMaterID," +
-                       "HMaterName, HMaterModel, HJITMaterGroup, HJITSafeStock, HJITMaterDemand, HJITBatchQty, HDeliveryPeriod, " +
-                       "HLeadTime, HLeadTime_Sec, HDeliveryMode, HDeliveryDaysCtrl,HUnitID,HJITMinDeliveryQty)values" +
-                       $"({HInterID}, 1, '{HRemark}', {(HSupID == "" ? "0" : HSupID)}, '{HSupplierName}', {(HMaterID == "" ? "0" : HMaterID)}," +
-                       $" '{HMaterName}', '{HMaterModel}', '{JITType}', {(JITPSL == "" ? "0" : JITPSL)}, {(JITMDSC == "" ? "0" : JITMDSC)},{(JIPEB == "" ? "0" : JIPEB)},{(JITPBCC == "" ? "0" : JITPBCC)}," +
-                       $" {(JISLT == "" ? "0" : JISLT)}, {(JIDLT == "" ? "0" : JIDLT)}, '', {(JITDCD == "" ? "0" : JITDCD)} ,{HUnitID},{JIMLC})";
-                        //涓昏〃
-                        oCN.RunProc(sql);
-                        //瀛愯〃
-                        oCN.RunProc(sql1);
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + i + "琛�, 鐢ㄦ埛: " + czymc + " 涓� 渚涘簲鍟�: "+ HName + ",宸插瓨鍦�,鎴�,鎻掑叆琛ㄦ牸鏈夐噸澶嶄俊鎭�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
                     }
                     else
                     {
-                        oCN.RunProc("	update  Cg_PODemandPlanConfigBillSub set HLeadTime=" + JISLT + "  where HMaterID=" + HMaterID + " and HSupplierID=" + HSupID);
+                        oCN.RunProc("insert into Gy_UserSupplierRelation (HSupID,HUserID) values ('" + HSupID + "','" + HUserID + "')");
                     }
 
                     i++;
@@ -1197,7 +1175,7 @@
         }
         #endregion
 
-        #region 鐢ㄦ埛鍏宠仈鑱屽憳淇濆瓨
+        #region 鐢ㄦ埛鍏宠仈鑱屽憳淇濆瓨 Excel瀵煎叆
         [Route("Xt_User/SaveUserEmployee")]
         [HttpPost]
         public object SaveUserEmployee([FromBody] JObject msg)
@@ -1237,6 +1215,243 @@
                 objJsonResult.count = 0;
                 objJsonResult.Message = "淇濆瓨澶辫触锛�" + e.ToString();
                 objJsonResult.data = 1;
+                return objJsonResult;
+            }
+        }
+
+        /// <summary>
+        /// 鏂囦欢涓婁紶瑙f瀽鍥炴樉
+        /// </summary>
+        /// <returns></returns>
+        [Route("Xt_User/UserEmployeeBill_Excel")]
+        [HttpPost]
+        public object UserEmployeeBill_Excel()
+        {
+            try
+            {
+                //鑾峰彇鏂囦欢鍚嶇О
+                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());
+                }
+
+                ////Excel妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("HEmployeeID", typeof(Int32));//宸ュ簭ID
+
+                //娣诲姞鏁版嵁
+                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("鐢ㄦ埛浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮敤鎴蜂唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐢ㄦ埛鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮敤鎴峰悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鑱屽憳浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愯亴鍛樹唬鐮併�戠殑鏍囬,";
+
+                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 czybm = "";
+                    string czymc = "";
+                    string HNumber = "";
+                    string HName = "";
+
+                    //HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐缂栫爜"].ToString());
+                    //HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐"].ToString());
+                    czybm = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛浠g爜"].ToString());
+                    czymc = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛鍚嶇О"].ToString());
+                    HNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鑱屽憳浠g爜"].ToString());
+                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鑱屽憳鍚嶇О"].ToString());
+
+                    int index = i + 1;
+                    //妫�鏌ョ敤鎴蜂笌宸ュ簭浠g爜鏄惁閮戒负绌�
+                    if (czybm != "" || HNumber != "")
+                    {
+                        //鏌ヨ宸ュ簭
+                        ds = oCN.RunProcReturn("select * from Gy_Employee where  HNumber='" + HNumber + "'", "Gy_Employee");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鑱屽憳鍚嶇О:" + HName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HEmployeeID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); //鑱屽憳ID
+                        }
+                        //鏌ヨ鐢ㄦ埛
+                        ds = oCN.RunProcReturn("select * from Gy_Czygl where  czybm='" + czybm + "'", "Gy_Czygl");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐢ㄦ埛: " + czymc + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            //tb2.Rows[i]["czybm"] = ds.Tables[0].Rows[0]["czybm"].ToString();
+                        }
+
+                        //瀹℃牳浠g爜鏄惁鍚堢悊
+                        if (!DBUtility.ClsPub.AllowNumber(czybm))
+                        {
+                            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;
+            }
+        }
+
+
+        /// <summary>
+        /// 瀵煎叆淇濆瓨
+        /// </summary>
+        /// <param name="sMainSub"></param>
+        /// <returns></returns>
+        [Route("Xt_User/UserEmployeeBill_btnSave")]
+        [HttpPost]
+        public object UserEmployeeBill_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
+            {
+
+                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();
+                int i = 1;
+                foreach (Dictionary<string, string> item in list)
+                {
+                    string HEmployeeID = item["HEmployeeID"].ToString();//鑱屽憳ID
+                    string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//鐢ㄦ埛浠g爜
+                    string czymc = item["鐢ㄦ埛鍚嶇О"].ToString();//鐢ㄦ埛鍚嶇О
+                    string HNumber = item["鑱屽憳浠g爜"].ToString();//鑱屽憳浠g爜
+                    string HName = item["鑱屽憳鍚嶇О"].ToString();//鑱屽憳鍚嶇О
+
+                    var ds = oCN.RunProcReturn("select * from Gy_UserEmployeeRelation where  HEmployeeID='" + HEmployeeID + "'and HUserID='" + HUserID + "'", "Gy_UserEmployeeRelation");
+
+
+                    if (ds.Tables[0].Rows.Count > 0)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + i + "琛�, 鐢ㄦ埛: " + czymc + " 涓� 宸ュ簭鍚�: " + HName + ",宸插瓨鍦�,鎴�,鎻掑叆琛ㄦ牸鏈夐噸澶嶄俊鎭�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        oCN.RunProc("insert into Gy_UserEmployeeRelation (HEmployeeID,HUserID) values ('" + HEmployeeID + "','" + HUserID + "')");
+                    }
+
+                    i++;
+                }
+
+                oCN.Commit();
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write(e);
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
                 return objJsonResult;
             }
         }
@@ -1505,8 +1720,252 @@
             }
         }
         #endregion
+        #region 鐢ㄦ埛鍏宠仈瀹㈡埛 鏂囦欢涓婁紶
+        [Route("Xt_User/Gy_UserCustomer_ImportByExcel")]
+        [HttpPost]
+        public object Gy_UserCustomer_ImportByExcel()
+        {
+            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);
 
-        #region 鐢ㄦ埛鍏宠仈鐗╂枡淇濆瓨
+                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("HCusID", typeof(Int32));//缁勭粐ID
+                tb2.Columns.Add("HUserID", 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);
+                }
+
+                //鏌ヨExcel鏂囦欢涓病鏈夌殑鍒�
+                var error = "";
+                if (!tb2.Columns.Contains("瀹㈡埛浠g爜"))
+                {
+                    error += "娌℃湁鎵惧埌銆愬鎴蜂唬鐮併�戠殑鏍囬,";
+                }
+                if (!tb2.Columns.Contains("瀹㈡埛鍚嶇О"))
+                {
+                    error += "娌℃湁鎵惧埌銆愬鎴峰悕绉般�戠殑鏍囬,";
+                }
+                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;
+                }
+
+                //鏌ヨ鏁版嵁璧嬬粰鏁版嵁琛�
+                string err = "";
+                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+                {
+                    string HCusNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瀹㈡埛浠g爜"].ToString());
+                    string HCusName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["瀹㈡埛鍚嶇О"].ToString());
+                    string HUserName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛鍚嶇О"].ToString());
+                    int index = i + 1;
+                    string sql = "";
+                    if (HCusNumber != "" && HUserName != "")
+                    {
+                        //鑾峰彇瀹㈡埛鍐呯爜
+                        sql = "select * from Gy_Customer where HNumber = '" + HCusNumber + "'";
+                        string HCusID = "0";
+                        ds = oCN.RunProcReturn(sql, "Gy_Customer");
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            err += "绗�" + index + "琛�,瀹㈡埛涓嶅瓨鍦�!";
+                            continue;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HCusID"] = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                            HCusID = ds.Tables[0].Rows[0]["HItemID"].ToString();
+                        }
+
+                        //鑾峰彇鐢ㄦ埛鍐呯爜
+                        sql = "select * from Gy_Czygl where Czymc = '" + HUserName + "'";
+                        string HUserID = "";
+                        ds = oCN.RunProcReturn(sql, "Gy_Czygl");
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            err += "绗�" + index + "琛�,鐢ㄦ埛涓嶅瓨鍦�!";
+                            continue;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HUserID"] = ds.Tables[0].Rows[0]["Czybm"].ToString();
+                            HUserID = ds.Tables[0].Rows[0]["Czybm"].ToString();
+                        }
+
+                        //鍒ゆ柇琛ㄤ腑鏄惁宸茬粡瀛樺湪璇ョ敤鎴峰叧鑱斿鎴�
+                        sql = "select * from Gy_UserCustomerRelation where HCusID = " + HCusID + " and HUserID = '" + HUserID + "'";
+                        ds = oCN.RunProcReturn(sql, "Gy_UserCustomerRelation");
+                        if (ds.Tables[0].Rows.Count > 0)
+                        {
+                            err += "绗�" + index + "琛岋紝璇ョ敤鎴蜂笌瀹㈡埛宸茬粡鍏宠仈!";
+                            continue;
+                        }
+                    }
+                    else
+                    {
+                        err += "绗�" + index + "琛�,瀹㈡埛浠g爜鎴栫敤鎴峰悕绉颁负绌�!";
+                        continue;
+                    }
+                }
+                if (err.Length > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "瀵煎叆閿欒锛�" + err;
+                    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("Xt_User/Gy_UserCustomer_ImportByExcel_Save")]
+        [HttpPost]
+        public object Gy_UserCustomer_ImportByExcel_Save([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("Gy_UserRelationCustomer_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();
+                string err = "";
+                int i = 1;
+                string sql = "";
+                foreach (Dictionary<string, string> item in list)
+                {
+                    string HUserID = item["HUserID"].ToString();//渚涘簲鍟�
+                    string HUserName = item["鐢ㄦ埛鍚嶇О"].ToString();//鐗╂枡ID
+                    string HCusID = item["HCusID"].ToString();//缁勭粐ID
+                    string HCusNumber = item["瀹㈡埛浠g爜"].ToString();
+                    string HCusName = item["瀹㈡埛鍚嶇О"].ToString();
+
+                    sql = "select * from Gy_UserCustomerRelation where HUserID = '" + HUserID + "' and HCusID = " + HCusID;
+                    ds = oCN.RunProcReturn(sql, "Gy_UserCustomerRelation");
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        sql = "insert into Gy_UserCustomerRelation(HUserID,HCusID)" +
+                            "values(" +
+                            "'" + HUserID + "'" +
+                            "," + HCusID + "" +
+                            ")";
+                        oCN.RunProc(sql);
+                    }
+                    else
+                    {
+                        err += "绗�" + i + "琛岋細鐢ㄦ埛宸茬粡鍏宠仈璇ュ鎴�!";
+                    }
+                    i++;
+                }
+                //鍒ゆ柇鏄惁瀛樺湪閿欒
+                if (err.Length > 0)
+                {
+                    oCN.RollBack();
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "瀵煎叆閿欒锛�"+ err;
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                oCN.Commit();
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write(e);
+                oCN.RollBack();
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
+
+        #region 鐢ㄦ埛鍏宠仈瀹㈡埛淇濆瓨
         [Route("Xt_User/SaveUserCustomer")]
         [HttpPost]
         public object SaveUserCustomer([FromBody] JObject msg)
@@ -1600,7 +2059,7 @@
         }
         #endregion
 
-        #region 鐢ㄦ埛鍏宠仈宸ュ簭淇濆瓨
+        #region 鐢ㄦ埛鍏宠仈宸ュ簭淇濆瓨  Excel瀵煎叆
         [Route("Xt_User/SaveUserProcess")]
         [HttpPost]
         public object SaveUserProcess([FromBody] JObject msg)
@@ -1644,6 +2103,243 @@
                 return objJsonResult;
             }
         }
+
+        /// <summary>
+        /// 鏂囦欢涓婁紶瑙f瀽鍥炴樉
+        /// </summary>
+        /// <returns></returns>
+        [Route("Xt_User/UserProcessBill_Excel")]
+        [HttpPost]
+        public object UserProcessBill_Excel()
+        {
+            try
+            {
+                //鑾峰彇鏂囦欢鍚嶇О
+                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());
+                }
+
+                ////Excel妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("HProcID", typeof(Int32));//宸ュ簭ID
+
+                //娣诲姞鏁版嵁
+                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("鐢ㄦ埛浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愮敤鎴蜂唬鐮併�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鐢ㄦ埛鍚嶇О"))
+                    error += "娌℃湁鎵惧埌銆愮敤鎴峰悕绉般�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("宸ュ簭浠g爜"))
+                    error += "娌℃湁鎵惧埌銆愬伐搴忎唬鐮併�戠殑鏍囬,";
+
+                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 czybm = "";
+                    string czymc = "";
+                    string HNumber = "";
+                    string HName = "";
+
+                    //HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐缂栫爜"].ToString());
+                    //HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐"].ToString());
+                    czybm = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛浠g爜"].ToString());
+                    czymc = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛鍚嶇О"].ToString());
+                    HNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["宸ュ簭浠g爜"].ToString());
+                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["宸ュ簭鍚嶇О"].ToString());
+
+                    int index = i + 1;
+                    //妫�鏌ョ敤鎴蜂笌宸ュ簭浠g爜鏄惁閮戒负绌�
+                    if (czybm != "" || HNumber != "")
+                    {
+                        //鏌ヨ宸ュ簭
+                        ds = oCN.RunProcReturn("select * from Gy_Process where  HNumber='" + HNumber + "'", "Gy_Process");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,宸ュ簭鍚嶇О:" + HName + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HProcID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); //宸ュ簭ID
+                        }
+                        //鏌ヨ鐢ㄦ埛
+                        ds = oCN.RunProcReturn("select * from Gy_Czygl where  czybm='" + czybm + "'", "Gy_Czygl");
+
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鐢ㄦ埛: " + czymc + ",涓嶅瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            //tb2.Rows[i]["czybm"] = ds.Tables[0].Rows[0]["czybm"].ToString();
+                        }
+
+                        //瀹℃牳浠g爜鏄惁鍚堢悊
+                        if (!DBUtility.ClsPub.AllowNumber(czybm))
+                        {
+                            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;
+            }
+        }
+
+
+        /// <summary>
+        /// 瀵煎叆淇濆瓨
+        /// </summary>
+        /// <param name="sMainSub"></param>
+        /// <returns></returns>
+        [Route("Xt_User/UserProcessBill_btnSave")]
+        [HttpPost]
+        public object UserProcessBill_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
+            {
+
+                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();
+                int i = 1;
+                foreach (Dictionary<string, string> item in list)
+                {
+                    string HProcID = item["HProcID"].ToString();//宸ュ簭ID
+                    string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//鐢ㄦ埛浠g爜
+                    string czymc = item["鐢ㄦ埛鍚嶇О"].ToString();//鐢ㄦ埛鍚嶇О
+                    string HNumber = item["宸ュ簭浠g爜"].ToString();//渚涘簲鍟嗕唬鐮�
+                    string HName = item["宸ュ簭鍚嶇О"].ToString();//渚涘簲鍟嗗悕绉�
+
+                    var ds = oCN.RunProcReturn("select * from Gy_UserByProcess where  HProcID='" + HProcID + "'and HUserID='" + HUserID + "'", "Gy_UserByProcess");
+
+
+                    if (ds.Tables[0].Rows.Count > 0)
+                    {
+                        oCN.RollBack();
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + i + "琛�, 鐢ㄦ埛: " + czymc + " 涓� 宸ュ簭鍚�: " + HName + ",宸插瓨鍦�,鎴�,鎻掑叆琛ㄦ牸鏈夐噸澶嶄俊鎭�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        oCN.RunProc("insert into Gy_UserByProcess (HProcID,HUserID) values ('" + HProcID + "','" + HUserID + "')");
+                    }
+
+                    i++;
+                }
+
+                oCN.Commit();
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = "瀵煎叆鎴愬姛!";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+            catch (Exception e)
+            {
+                LogService.Write(e);
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "Exception锛�" + e.ToString();
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
         #endregion
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1