From dbf3e7077ff5af84e27b6b94705484d4c1567058 Mon Sep 17 00:00:00 2001
From: zrg <z18737863051@163.com>
Date: 星期五, 29 十二月 2023 17:18:46 +0800
Subject: [PATCH] 添加了后端用户关联职业,用户关联供应商,用户关联工序的Excel导入保存功能

---
 WebAPI/Controllers/BLL/Xt_UserController.cs |  802 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 795 insertions(+), 7 deletions(-)

diff --git a/WebAPI/Controllers/BLL/Xt_UserController.cs b/WebAPI/Controllers/BLL/Xt_UserController.cs
index 853a083..d98f506 100644
--- a/WebAPI/Controllers/BLL/Xt_UserController.cs
+++ b/WebAPI/Controllers/BLL/Xt_UserController.cs
@@ -6,7 +6,10 @@
 using System.Collections.Generic;
 using System.Data;
 using System.Data.SqlClient;
+using System.IO;
+using System.Web;
 using System.Web.Http;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
 using WebAPI.Models;
 namespace WebAPI.Controllers
 {
@@ -202,13 +205,15 @@
                     ",HSellManID,HSellMan,HDeptID,HDept " +
                     ",HWhID,HWHName,HSupID,HSupName " +
                     ",HSCWHID,HSCWHName " +
-                    ",HCloudUserName,HCloudUserPsd,HUSEORGID) " +
+                    ",HCloudUserName,HCloudUserPsd,HUSEORGID,HProcID" +
+                    ",HGroupID,HSourceID) " +
                     "values ('" + lsmain[0].Czybm.ToString() + "','" + lsmain[0].Czymc.ToString() + "','" + ClsPub.StrToPsd(lsmain[0].Czmm.ToString()) + "','" + lsmain[0].Explain.ToString() + "','" + lsmain[0].HEmpID.ToString() + "',"+ lsmain[0].HK3UserID.ToString() + "" +
                     ","+ lsmain[0].HKeeperID.ToString() + ",'"+ lsmain[0].HKeeper.ToString() + "',"+ lsmain[0].HSecManagerID.ToString() + ",'"+ lsmain[0].HSecManager.ToString() + "'" +
                     "," + lsmain[0].HSellManID.ToString() + ",'" + lsmain[0].HSellMan.ToString() + "'," + lsmain[0].HDeptID.ToString() + ",'" + lsmain[0].HDept.ToString() + "'" +
                     "," + lsmain[0].HWhID.ToString() + ",'" + lsmain[0].HWHName.ToString() + "'," + lsmain[0].HSupID.ToString() + ",'" + lsmain[0].HSupName.ToString() + "'" +
                     "," + lsmain[0].HSCWHID.ToString() + ",'" + lsmain[0].HSCWHName.ToString() + "'" + 
-                    ",'" + lsmain[0].HCloudUserName.ToString() + "','" + lsmain[0].HCloudUserPsd.ToString() + "',"+ lsmain[0].HOrgID.ToString() + ")");
+                    ",'" + lsmain[0].HCloudUserName.ToString() + "','" + lsmain[0].HCloudUserPsd.ToString() + "',"+ lsmain[0].HOrgID.ToString() + "," + lsmain[0].HProcID.ToString() + "" +
+                    ","+ lsmain[0].HGroupID.ToString() + ","+ lsmain[0].HSourceID.ToString() + ")");
 
                     //鏂板鍚庢煡璇�  纭繚鏁版嵁娣诲姞鎴愬姛
                     ds = oCN.RunProcReturn("Select * from  Gy_Czygl where Czybm='" + lsmain[0].Czybm.ToString() + "'", "Gy_Czygl");
@@ -255,6 +260,9 @@
                         ",HSCWHID=" + lsmain[0].HSCWHID.ToString() +
                         ",HSCWHName='" + lsmain[0].HSCWHName.ToString() + "'" +
                         ",HSupID=" + lsmain[0].HSupID.ToString() +
+                        ",HProcID=" + lsmain[0].HProcID.ToString() +
+                        ",HSourceID=" + lsmain[0].HSourceID.ToString() +
+                        ",HGroupID=" + lsmain[0].HGroupID.ToString() +
                         ",HSupName='" + lsmain[0].HSupName.ToString() + "'" +
                         ",HCloudUserName='" + lsmain[0].HCloudUserName.ToString() + "'" +
                         ",HCloudUserPsd='" + lsmain[0].HCloudUserPsd.ToString() + "'" +
@@ -280,6 +288,9 @@
                            ",HSCWHID=" + lsmain[0].HSCWHID.ToString() +
                            ",HSCWHName='" + lsmain[0].HSCWHName.ToString() + "'" +
                            ",HSupID=" + lsmain[0].HSupID.ToString() +
+                            ",HProcID=" + lsmain[0].HProcID.ToString() +
+                           ",HSourceID=" + lsmain[0].HSourceID.ToString() +
+                           ",HGroupID=" + lsmain[0].HGroupID.ToString() +
                            ",HSupName='" + lsmain[0].HSupName.ToString() + "'" +
                            ",HCloudUserName='" + lsmain[0].HCloudUserName.ToString() + "'" +
                            ",HCloudUserPsd='" + lsmain[0].HCloudUserPsd.ToString() + "'" +
@@ -358,7 +369,7 @@
         }
         #endregion
 
-        #region 鐢ㄦ埛鍏宠仈渚涘簲鍟嗕繚瀛�
+        #region 鐢ㄦ埛鍏宠仈渚涘簲鍟嗕繚瀛� Excel瀵煎叆
         [Route("Xt_User/SaveUserSupper")]
         [HttpPost]
         public object SaveUserSupper([FromBody] JObject msg)
@@ -402,6 +413,237 @@
                 return objJsonResult;
             }
         }
+
+        /// 鏂囦欢涓婁紶 Gy_Supplier
+        [Route("Xt_User/UserSupperBill_Excel")]
+        [HttpPost]
+        public object UserSupperBill_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("HSupID", typeof(Int32));//渚涘簲鍟咺D
+
+                //娣诲姞鏁版嵁
+                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("渚涘簲鍟嗕唬鐮�"))
+                    error += "娌℃湁鎵惧埌銆愪緵搴斿晢浠g爜銆戠殑鏍囬,";
+
+                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]["渚涘簲鍟嗕唬鐮�"].ToString());
+                    HName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["渚涘簲鍟嗗悕绉�"].ToString());
+                   
+                    int index = i + 1;
+                    //妫�鏌ョ敤鎴蜂笌渚涘簲鍟嗕唬鐮佹槸鍚﹂兘涓虹┖
+                    if (czybm != "" || HNumber != "")
+                    {
+                        //鏌ヨ渚涘簲鍟�
+                        ds = oCN.RunProcReturn("select * from Gy_Supplier where  HNumber='" + HNumber + "'", "Gy_Supplier");
+
+                        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]["HSupID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); //渚涘簲鍟咺D
+                        }
+                        //鏌ヨ鐢ㄦ埛
+                        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;
+            }
+        }
+  
+
+        #region  瀵煎叆(淇濆瓨)
+        [Route("Xt_User/UserSupperBill_btnSave")]
+        [HttpPost]
+        public object UserSupperBill_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 HSupID = item["HSupID"].ToString();//渚涘簲鍟咺D
+                    string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//鐢ㄦ埛浠g爜
+                    string czymc = item["鐢ㄦ埛鍚嶇О"].ToString();//鐢ㄦ埛鍚嶇О
+                    string HNumber = item["渚涘簲鍟嗕唬鐮�"].ToString();//渚涘簲鍟嗕唬鐮�
+                    string HName = item["渚涘簲鍟嗗悕绉�"].ToString();//渚涘簲鍟嗗悕绉�
+
+                    var ds = oCN.RunProcReturn("select * from Gy_UserSupplierRelation where  HSupID='" + HSupID + "'and HUserID='" + HUserID + "'", "Gy_UserSupplierRelation");
+
+
+                    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_UserSupplierRelation (HSupID,HUserID) values ('" + HSupID + "','" + 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
         #endregion
 
         #region  鏍规嵁鐢ㄦ埛缂栫爜鏌ユ壘宸插垎閰嶇粍缁囧垪琛�
@@ -933,7 +1175,7 @@
         }
         #endregion
 
-        #region 鐢ㄦ埛鍏宠仈鑱屽憳淇濆瓨
+        #region 鐢ㄦ埛鍏宠仈鑱屽憳淇濆瓨 Excel瀵煎叆
         [Route("Xt_User/SaveUserEmployee")]
         [HttpPost]
         public object SaveUserEmployee([FromBody] JObject msg)
@@ -973,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;
             }
         }
@@ -1147,12 +1626,73 @@
         #region  鏍规嵁鐢ㄦ埛缂栫爜鏌ユ壘宸插垎閰嶅鎴峰垪琛�
         [Route("Xt_User/CustomerPlaylist")]
         [HttpGet]
-        public object CustomerPlaylist(string HUserID)
+        public object CustomerPlaylist(string HUserID, string CurUserName)
         {
             try
             {
+                //鏌ヨ鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_UserRelationCustomer_Query", 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡璇㈡潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                ds = oCN.RunProcReturn("select HCusID,瀹㈡埛浠g爜 HCustomerNumber,瀹㈡埛鍚嶇О HCustomerName from h_v_Gy_UserCustomerList where HUserID='" + HUserID + "' order by HCusID", "h_v_Gy_UserCustomerList");
+                if (ds == null || ds.Tables[0].Rows.Count == 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犲鎴蜂俊鎭紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+                else
+                {
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "Sucess锛�";
+                    objJsonResult.data = ds.Tables[0];
+                    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/CustomerPlaylistFromUserCustomerList")]
+        [HttpGet]
+        public object CustomerPlaylistFromUserCustomerList(string HUserID, string HCusNumber, string HCusName, string CurUserName)
+        {
+            try
+            {
+                //鏌ヨ鏉冮檺
+                if (!DBUtility.ClsPub.Security_Log_second("Gy_UserRelationCustomer_Query", 1, false, CurUserName))
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = "鏃犳煡璇㈡潈闄愶紒";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
 
-                ds = oCN.RunProcReturn("select HCusID,瀹㈡埛浠g爜 HCustomerNumber,瀹㈡埛鍚嶇О HCustomerName from h_v_Gy_UserCustomerList where HUserID='" + HUserID + "' ", "h_v_Gy_UserCustomerList");
+                string sql = "select HCusID,瀹㈡埛浠g爜 HCustomerNumber,瀹㈡埛鍚嶇О HCustomerName " +
+                    "from h_v_Gy_UserCustomerList " +
+                    "where HUserID='" + HUserID + "' " +
+                    "and 瀹㈡埛浠g爜 like '%" + HCusNumber + "%' " +
+                    "and 瀹㈡埛鍚嶇О like '%" + HCusName + "%' " +
+                    " order by 瀹㈡埛浠g爜";
+
+
+                ds = oCN.RunProcReturn(sql, "h_v_Gy_UserCustomerList");
                 if (ds == null || ds.Tables[0].Rows.Count == 0)
                 {
                     objJsonResult.code = "0";
@@ -1191,6 +1731,17 @@
             string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
             string msg2 = sArray[0].ToString();
             string msg3 = sArray[1].ToString();
+            string msg4 = sArray[2].ToString();
+
+            //鏌ヨ鏉冮檺
+            if (!DBUtility.ClsPub.Security_Log_second("Gy_UserRelationCustomer_Edit", 1, false, msg4))
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鏃犵紪杈戞潈闄愶紒";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
 
             ListModels oListModels = new ListModels();
             try
@@ -1264,7 +1815,7 @@
         }
         #endregion
 
-        #region 鐢ㄦ埛鍏宠仈宸ュ簭淇濆瓨
+        #region 鐢ㄦ埛鍏宠仈宸ュ簭淇濆瓨  Excel瀵煎叆
         [Route("Xt_User/SaveUserProcess")]
         [HttpPost]
         public object SaveUserProcess([FromBody] JObject msg)
@@ -1308,6 +1859,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