From 64b3893b55020b994d5f3a9dd6035592c1602596 Mon Sep 17 00:00:00 2001
From: zrg <z18737863051@163.com>
Date: 星期三, 03 一月 2024 14:00:44 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/BLL/Xt_UserController.cs |  404 ++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 309 insertions(+), 95 deletions(-)

diff --git a/WebAPI/Controllers/BLL/Xt_UserController.cs b/WebAPI/Controllers/BLL/Xt_UserController.cs
index 20463ed..c40192f 100644
--- a/WebAPI/Controllers/BLL/Xt_UserController.cs
+++ b/WebAPI/Controllers/BLL/Xt_UserController.cs
@@ -1752,8 +1752,8 @@
                 }
 
                 //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
-                tb2.Columns.Add("HCusID", typeof(Int32));//缁勭粐ID
-                tb2.Columns.Add("HUserID", typeof(Int32));//渚涘簲鍟�
+                tb2.Columns.Add("瀹㈡埛鍐呯爜", typeof(string));//瀹㈡埛鍐呯爜
+                tb2.Columns.Add("鍒ゅ畾缁撴灉", typeof(string));//鍒ゅ畾缁撴灉
 
                 //娣诲姞鏁版嵁
                 for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++)
@@ -1768,6 +1768,14 @@
 
                 //鏌ヨExcel鏂囦欢涓病鏈夌殑鍒�
                 var error = "";
+                if (!tb2.Columns.Contains("鐢ㄦ埛浠g爜"))
+                {
+                    error += "娌℃湁鎵惧埌銆愮敤鎴蜂唬鐮併�戠殑鏍囬,";
+                }
+                if (!tb2.Columns.Contains("鐢ㄦ埛鍚嶇О"))
+                {
+                    error += "娌℃湁鎵惧埌銆愮敤鎴峰悕绉般�戠殑鏍囬,";
+                }
                 if (!tb2.Columns.Contains("瀹㈡埛浠g爜"))
                 {
                     error += "娌℃湁鎵惧埌銆愬鎴蜂唬鐮併�戠殑鏍囬,";
@@ -1776,9 +1784,13 @@
                 {
                     error += "娌℃湁鎵惧埌銆愬鎴峰悕绉般�戠殑鏍囬,";
                 }
-                if (!tb2.Columns.Contains("鐢ㄦ埛鍚嶇О"))
+                if (!tb2.Columns.Contains("缁勭粐浠g爜"))
                 {
-                    error += "娌℃湁鎵惧埌銆愮敤鎴峰悕绉般�戠殑鏍囬,";
+                    error += "娌℃湁鎵惧埌銆愮粍缁囦唬鐮併�戠殑鏍囬,";
+                }
+                if (!tb2.Columns.Contains("缁勭粐鍚嶇О"))
+                {
+                    error += "娌℃湁鎵惧埌銆愮粍缁囧悕绉般�戠殑鏍囬,";
                 }
                 if (error.Length > 0)
                 {
@@ -1790,68 +1802,66 @@
                 }
 
                 //鏌ヨ鏁版嵁璧嬬粰鏁版嵁琛�
-                string err = "";
                 for (int i = 0; i <= tb2.Rows.Count - 1; i++)
                 {
+                    string HUserID = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛浠g爜"].ToString());
+                    string HUserName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鐢ㄦ埛鍚嶇О"].ToString());
                     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());
+                    string HOrgNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString());
+                    string HOrgName = 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();
-                        }
+                    //string sql = "";
 
-                        //鑾峰彇鐢ㄦ埛鍐呯爜
-                        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_Czygl where Czybm = '" + HUserID + "'";
+                    //ds = oCN.RunProcReturn(sql, "Gy_Czygl");
+                    //if (ds.Tables[0].Rows.Count > 0)
+                    //{
+                    //    tb2.Rows[i]["鐢ㄦ埛鍚嶇О"] = ds.Tables[0].Rows[0]["Czymc"];
+                    //}
+                    //else
+                    //{
+                    //    sql = "select * from Gy_Czygl where Czymc = '" + HUserName + "'";
+                    //    ds = oCN.RunProcReturn(sql, "Gy_Czygl");
+                    //    if (ds.Tables[0].Rows.Count > 0)
+                    //    {
+                    //        tb2.Rows[i]["鐢ㄦ埛浠g爜"] = ds.Tables[0].Rows[0]["Czybm"];
+                    //    }
+                    //}
 
-                        //鍒ゆ柇琛ㄤ腑鏄惁宸茬粡瀛樺湪璇ョ敤鎴峰叧鑱斿鎴�
-                        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;
+                    ////鍒ゅ畾瀹㈡埛鏄惁瀛樺湪骞惰缃暟鎹�
+                    //sql = "select c.HItemID 瀹㈡埛鍐呯爜,c.HNumber 瀹㈡埛浠g爜,c.HName 瀹㈡埛鍚嶇О,isnull(c.HUSEORGID,0) 缁勭粐鍐呯爜,isnull(o.HNumber,'') 缁勭粐浠g爜,isnull(o.Hname,'') 缁勭粐鍚嶇О from " +
+                    //    "Gy_Customer as c " +
+                    //    "left join Xt_ORGANIZATIONS o on c.HUSEORGID = o.HItemID " +
+                    //    "where " +
+                    //        "c.HNumber = '" + HCusNumber + "' " +
+                    //        "and isnull(o.HNumber,'')<>'' and isnull(o.HNumber,'') = '" + HOrgNumber + "'";
+                    //ds = oCN.RunProcReturn(sql, "Gy_Customer");
+                    //if(ds.Tables[0].Rows.Count > 0)
+                    //{
+                    //    tb2.Rows[i]["瀹㈡埛鍐呯爜"] = ds.Tables[0].Rows[0]["瀹㈡埛鍐呯爜"];
+                    //    tb2.Rows[i]["瀹㈡埛鍚嶇О"] = ds.Tables[0].Rows[0]["瀹㈡埛鍚嶇О"];
+                    //    tb2.Rows[i]["缁勭粐鍚嶇О"] = ds.Tables[0].Rows[0]["缁勭粐鍚嶇О"];
+                    //}
+                    //else
+                    //{
+                    //    sql = "select c.HItemID 瀹㈡埛鍐呯爜,c.HNumber 瀹㈡埛浠g爜,c.HName 瀹㈡埛鍚嶇О,isnull(c.HUSEORGID,0) 缁勭粐鍐呯爜,isnull(o.HNumber,'') 缁勭粐浠g爜,isnull(o.Hname,'') 缁勭粐鍚嶇О from " +
+                    //    "Gy_Customer as c " +
+                    //    "left join Xt_ORGANIZATIONS o on c.HUSEORGID = o.HItemID " +
+                    //    "where " +
+                    //        "c.HNumber = '" + HCusNumber + "' " +
+                    //        "and isnull(o.HName,'')<>'' and isnull(o.HName,'') = '" + HOrgName + "'";
+                    //    ds = oCN.RunProcReturn(sql, "Gy_Customer");
+                    //    if (ds.Tables[0].Rows.Count > 0)
+                    //    {
+                    //        tb2.Rows[i]["瀹㈡埛鍐呯爜"] = ds.Tables[0].Rows[0]["瀹㈡埛鍐呯爜"];
+                    //        tb2.Rows[i]["瀹㈡埛鍚嶇О"] = ds.Tables[0].Rows[0]["瀹㈡埛鍚嶇О"];
+                    //        tb2.Rows[i]["缁勭粐浠g爜"] = ds.Tables[0].Rows[0]["缁勭粐浠g爜"];
+                    //    }
+                    //}
+
+                    tb2.Rows[i]["鍒ゅ畾缁撴灉"] = "";
                 }
 
                 objJsonResult.code = "1";
@@ -1870,6 +1880,172 @@
             }
         }
         #endregion
+        #region 鐢ㄦ埛鍏宠仈瀹㈡埛 瀵煎叆(鏁版嵁楠岃瘉)
+        [Route("Xt_User/Gy_UserCustomer_ImportByExcel_Confirm")]
+        [HttpPost]
+        public object Gy_UserCustomer_ImportByExcel_Confirm([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            string[] importFieldList = sArray[2].ToString().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
+            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);
+                }
+
+                //鍒涘缓涓存椂琛ㄥ苟璁剧疆鍒楀悕
+                DataTable tb2 = new DataTable("dt2");
+                tb2.Columns.Add("鐢ㄦ埛浠g爜", typeof(string));
+                tb2.Columns.Add("鐢ㄦ埛鍚嶇О", typeof(string));
+                tb2.Columns.Add("瀹㈡埛鍐呯爜", typeof(string));
+                tb2.Columns.Add("瀹㈡埛浠g爜", typeof(string));
+                tb2.Columns.Add("瀹㈡埛鍚嶇О", typeof(string));
+                tb2.Columns.Add("缁勭粐浠g爜", typeof(string));
+                tb2.Columns.Add("缁勭粐鍚嶇О", typeof(string));
+                tb2.Columns.Add("鍒ゅ畾缁撴灉", typeof(string));
+
+                string error = "";
+                int i = 1;
+                string sql = "";
+                foreach (Dictionary<string, string> item in list)
+                {
+                    //璁板綍鍒ゅ畾缁撴灉
+                    string err = "";
+
+                    DataRow row = tb2.NewRow();
+                    tb2.Rows.Add(row);
+                    string HUserID = item["鐢ㄦ埛浠g爜"].ToString();
+                    string HUserName = item["鐢ㄦ埛鍚嶇О"].ToString();
+                    string HCusID = item["瀹㈡埛鍐呯爜"].ToString();
+                    string HCusNumber = item["瀹㈡埛浠g爜"].ToString();
+                    string HCusName = item["瀹㈡埛鍚嶇О"].ToString();
+                    string HOrgNumber = item["缁勭粐浠g爜"].ToString();
+                    string HOrgName = item["缁勭粐鍚嶇О"].ToString();
+
+                    tb2.Rows[i - 1]["鐢ㄦ埛浠g爜"] = HUserID;
+                    tb2.Rows[i - 1]["鐢ㄦ埛鍚嶇О"] = HUserName;
+                    tb2.Rows[i - 1]["瀹㈡埛鍐呯爜"] = HCusID;
+                    tb2.Rows[i - 1]["瀹㈡埛浠g爜"] = HCusNumber;
+                    tb2.Rows[i - 1]["瀹㈡埛鍚嶇О"] = HCusName;
+                    tb2.Rows[i - 1]["缁勭粐浠g爜"] = HOrgNumber;
+                    tb2.Rows[i - 1]["缁勭粐鍚嶇О"] = HOrgName;
+                    tb2.Rows[i - 1]["鍒ゅ畾缁撴灉"] = "";
+
+                    //鏍规嵁瀵煎叆瀛楁鑾峰彇鐢ㄦ埛鐩稿叧鏁版嵁锛屽苟杩涜鏍¢獙
+                    sql = "";
+                    if (importFieldList[0] == "HUserID")
+                    {
+                        sql = "select * from Gy_Czygl where Czybm = '" + HUserID + "'";
+                    }
+                    else if(importFieldList[0] == "HUserName")
+                    {
+                        sql = "select * from Gy_Czygl where Czymc = '" + HUserName + "'";
+                    }
+                    ds = oCN.RunProcReturn(sql, "Gy_Czygl");
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        err += "鐢ㄦ埛涓嶅瓨鍦紱";
+                    }
+                    else
+                    {
+                        tb2.Rows[i - 1]["鐢ㄦ埛浠g爜"] = ds.Tables[0].Rows[0]["Czybm"];
+                        tb2.Rows[i - 1]["鐢ㄦ埛鍚嶇О"] = ds.Tables[0].Rows[0]["Czymc"];
+
+                        HUserID = ds.Tables[0].Rows[0]["Czybm"].ToString();
+                        HUserName = ds.Tables[0].Rows[0]["Czymc"].ToString();
+                    }
+
+                    //鏍规嵁瀵煎叆瀛楁鑾峰彇瀹㈡埛鐩稿叧鏁版嵁锛屽苟杩涜鏍¢獙
+                    sql = "";
+                    if (importFieldList[1] == "HOrgNumber")
+                    {
+                        sql = "select * from Xt_ORGANIZATIONS where HNumber = '" + HOrgNumber + "'";
+                    }
+                    else if (importFieldList[1] == "HOrgName")
+                    {
+                        sql = "select * from Xt_ORGANIZATIONS where HName = '" + HOrgName + "'";
+                    }
+                    ds = oCN.RunProcReturn(sql, "Xt_ORGANIZATIONS");
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        err += "缁勭粐涓嶅瓨鍦紱";
+
+                        HCusID = "0";
+                        tb2.Rows[i - 1]["瀹㈡埛鍐呯爜"] = "0";
+                    }
+                    else
+                    {
+                        tb2.Rows[i - 1]["缁勭粐浠g爜"] = ds.Tables[0].Rows[0]["HNumber"];
+                        tb2.Rows[i - 1]["缁勭粐鍚嶇О"] = ds.Tables[0].Rows[0]["HName"];
+
+                        sql = "select c.* from " +
+                        "Gy_Customer as c " +
+                        "left join Xt_ORGANIZATIONS o on c.HUSEORGID = o.HItemID " +
+                        "where c.HNumber = '" + HCusNumber + "' " +
+                        "and o.HNumber = '" + ds.Tables[0].Rows[0]["HNumber"] + "' " +
+                        "and o.HName = '" + ds.Tables[0].Rows[0]["HName"] + "'";
+                        ds = oCN.RunProcReturn(sql, "Gy_Customer");
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            err += "璇ョ粍缁囦笅瀹㈡埛涓嶅瓨鍦紱";
+                            HCusID = "0";
+                            tb2.Rows[i - 1]["瀹㈡埛鍐呯爜"] = "0";
+                        }
+                        else
+                        {
+                            tb2.Rows[i - 1]["瀹㈡埛鍐呯爜"] = ds.Tables[0].Rows[0]["HItemID"];
+                            tb2.Rows[i - 1]["瀹㈡埛浠g爜"] = ds.Tables[0].Rows[0]["HNumber"];
+                            tb2.Rows[i - 1]["瀹㈡埛鍚嶇О"] = ds.Tables[0].Rows[0]["HName"];
+
+                            HCusID = ds.Tables[0].Rows[0]["HItemID"].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)
+                    {
+                        err += "鐢ㄦ埛宸茬粡鍏宠仈璇ュ鎴凤紱";
+                    }
+
+                    tb2.Rows[i - 1]["鍒ゅ畾缁撴灉"] = err;
+                    error += err;
+
+                    i++;
+                }
+
+                objJsonResult.code = "1";
+                objJsonResult.count = 1;
+                objJsonResult.Message = (error.Length>0?"0":"1");
+                objJsonResult.data = tb2;
+                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/Gy_UserCustomer_ImportByExcel_Save")]
         [HttpPost]
@@ -1880,6 +2056,7 @@
             string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
             string msg2 = sArray[0].ToString();
             string user = sArray[1].ToString();
+            string saveType = sArray[2].ToString();
             try
             {
                 if (!DBUtility.ClsPub.Security_Log("Gy_UserRelationCustomer_Edit", 1, false, user))
@@ -1904,46 +2081,84 @@
                     list.Add(dic);
                 }
 
-                oCN.BeginTran();
-                string err = "";
-                int i = 1;
-                string sql = "";
-                foreach (Dictionary<string, string> item in list)
+                if(saveType == "1")
                 {
-                    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();
+                    oCN.BeginTran();
+                    string err = "";
+                    int i = 1;
+                    string sql = "";
+                    foreach (Dictionary<string, string> item in list)
+                    {
+                        string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//渚涘簲鍟�
+                        string HUserName = item["鐢ㄦ埛鍚嶇О"].ToString();//鐗╂枡ID
+                        string HCusID = item["瀹㈡埛鍐呯爜"].ToString();//缁勭粐ID
+                        string HCusNumber = item["瀹㈡埛浠g爜"].ToString();
+                        string HCusName = item["瀹㈡埛鍚嶇О"].ToString();
+                        string HOrgNumber = item["缁勭粐浠g爜"].ToString();
+                        string HOrgName = 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);
+                        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
+                        {
+                            
+                        }
+                        i++;
                     }
-                    else
-                    {
-                        err += "绗�" + i + "琛岋細鐢ㄦ埛宸茬粡鍏宠仈璇ュ鎴�!";
-                    }
-                    i++;
-                }
-                //鍒ゆ柇鏄惁瀛樺湪閿欒
-                if (err.Length > 0)
+                }else if(saveType == "2")
                 {
-                    oCN.RollBack();
-                    objJsonResult.code = "0";
-                    objJsonResult.count = 0;
-                    objJsonResult.Message = "瀵煎叆閿欒锛�"+ err;
-                    objJsonResult.data = null;
-                    return objJsonResult;
-                }
+                    oCN.BeginTran();
+                    string err = "";
+                    int i = 1;
+                    string sql = "";
+                    foreach (Dictionary<string, string> item in list)
+                    {
+                        string HUserID = item["鐢ㄦ埛浠g爜"].ToString();//渚涘簲鍟�
+                        string HUserName = item["鐢ㄦ埛鍚嶇О"].ToString();//鐗╂枡ID
+                        string HCusID = item["瀹㈡埛鍐呯爜"].ToString();//缁勭粐ID
+                        string HCusNumber = item["瀹㈡埛浠g爜"].ToString();
+                        string HCusName = item["瀹㈡埛鍚嶇О"].ToString();
+                        string HOrgNumber = item["缁勭粐浠g爜"].ToString();
+                        string HOrgName = 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;
@@ -1963,7 +2178,6 @@
             }
         }
         #endregion
-
 
         #region 鐢ㄦ埛鍏宠仈瀹㈡埛淇濆瓨
         [Route("Xt_User/SaveUserCustomer")]

--
Gitblit v1.9.1