From 5ef4a489b3739a670796810dd484376dcc7534c6 Mon Sep 17 00:00:00 2001
From: yangle <admin@YINMOU>
Date: 星期三, 10 五月 2023 13:36:13 +0800
Subject: [PATCH] 乔一 添加字段白坯发布

---
 WebAPI/Controllers/BaseSet/Gy_CustomerController.cs |  233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 227 insertions(+), 6 deletions(-)

diff --git a/WebAPI/Controllers/BaseSet/Gy_CustomerController.cs b/WebAPI/Controllers/BaseSet/Gy_CustomerController.cs
index 83bade0..f362ec6 100644
--- a/WebAPI/Controllers/BaseSet/Gy_CustomerController.cs
+++ b/WebAPI/Controllers/BaseSet/Gy_CustomerController.cs
@@ -12,6 +12,8 @@
 {
     public class Gy_CustomerController : ApiController
     {
+        //鑾峰彇绯荤粺鍙傛暟
+        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
         public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
         private json objJsonResult = new json();
@@ -40,7 +42,22 @@
                     objJsonResult.data = null;
                     return objJsonResult;
                 }
-                string sql1 = string.Format(@"select * from h_v_Gy_CustomerList where 缁勭粐鍚嶇О='" + Organization + "'");
+                string sql1 = "";
+                //瀹㈡埛鍒跺畾
+                string sErr = "";
+                if (oSystemParameter.ShowBill(ref sErr))
+                {
+                    if (oSystemParameter.omodel.WMS_CampanyName == "涔斾竴")
+                    {
+                         sql1 = string.Format(@"select * from h_v_Gy_CustomerList where 1=1");
+                    }
+                    else
+                    {
+                         sql1 = string.Format(@"select * from h_v_Gy_CustomerList where 缁勭粐鍚嶇О='" + Organization + "'");
+                    }
+                }
+
+             
                 if (sWhere == null || sWhere.Equals(""))
                 {
                     ds = oCN.RunProcReturn(sql1 + sWhere + " order by 瀹㈡埛浠g爜 ", "h_v_Gy_CustomerList");
@@ -283,7 +300,7 @@
                     ",HEmpID,HCreditDate,HCreditRatingDate,HMaxCreditRatingDate" +
                     ",HMonthUseQty,HForecastCreditRating,HCreditLevelID,HCountAccrualRating" +
                     ",HSubsidyAccrualRating,HCreditRating,HMaxCreditRating" +
-                    ",HCusTypeID) " +
+                    ",HCusTypeID,HCREATEORGID,HUSEORGID) " +
                     " Values('" + HNumber + "','" + HName + "','" + HHelpCode + "','" + HShortNumber + "'," + HParentID +
                     ", " + HLevel + ",0,'" + HStopflag + "','" + HRemark + "'" +
                     ",'" + HShortName + "','" + HAddress + "','" + HLinkMan + "','" + HLinkPhone + "','" + HMobilePhone + "'" +
@@ -293,7 +310,7 @@
                     "," + HEmpID + "," + HCreditDate + "," + HCreditRatingDate + "," + HMaxCredRatingDate +
                     "," + HMonthUseQty + "," + HForecastCreditRating + "," + HCreditLevelID + "," + HCountAccrualRating +
                     "," + HSubsidyAccrualRating + "," + HCreditRating + "," + HMaxCreditRating +
-                    ", " + HCusTypeID + ")");
+                    ", " + HCusTypeID + ","+ HCreateOrgID + ","+ HUseOrgID + ")");
                 //淇敼涓婄骇涓洪潪鏈骇浠g爜
                 oCN.RunProc("Update Gy_Customer set HEndflag=0 where HItemID=" + HParentID, ref DBUtility.ClsPub.sExeReturnInfo);
                 oCN.Commit();
@@ -323,16 +340,20 @@
             try
             {
                 var model = oMain["model"].ToString();
+                var custLocationModel = oMain["model"]["HCustLocationEntry"].ToString();
+                var custContactModel = oMain["model"]["HCustContactEntry"].ToString();
                 //鍙嶅簭鍒楀寲
                 model = "[" + model + "]";
                 List<Customer> lsmain = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Customer>>(model);
+                List<Model.ClsGy_CustLocation_Model> custLocationls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_CustLocation_Model>>(custLocationModel);
+                List<Model.ClsGy_COMMONCONTACT_Model> custContactls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Model.ClsGy_COMMONCONTACT_Model>>(custContactModel);
                 string sql = string.Empty;
                 oCN.BeginTran();
                 sql = $"delete gy_Customer where HItemID = {lsmain[0].HItemID}";
                 oCN.RunProc(sql);
                 sql = "set identity_insert gy_Customer on";
                 oCN.RunProc(sql);
-                //涓昏〃
+                //涓昏〃_瀹㈡埛
                 oCN.RunProc("Insert into Gy_Customer " +
                     " (HItemID,HNumber,HName,HHelpCode,HShortNumber,HParentID" +
                     ",HLevel,HEndFlag,HStopflag,HRemark" +
@@ -356,10 +377,49 @@
                     ", " + lsmain[0].HCusTypeID + ")");
                 sql = "set identity_insert gy_Customer off";
                 oCN.RunProc(sql);
+                //瀹㈡埛_浜よ揣鍦扮偣
+                sql = $"delete Gy_CustLocation where HItemID = {lsmain[0].HItemID}";
+                oCN.RunProc(sql);
+                sql = "set identity_insert Gy_CustLocation on";
+                oCN.RunProc(sql);
+                foreach (var item in custLocationls)
+                {
+                    sql = $@"insert into Gy_CustLocation(HItemID,HEntryID,HNumber,HName ,HShortNumber,HParentID ,HLevel 
+                                ,HEndFlag,HStopflag,HRemark ,HHelpCode ,HUseFlag
+                                 ,HMakeTime ,HMakeEmp ,HCheckEmp ,HCheckTime ,HModifyEmp 
+                                 ,HModifyTime ,HStopEmp ,HStopTime ,HUSEORGID,HCREATEORGID)
+                  values({item.HItemID},{item.HENTRYID},'{item.HNumber}','{item.HName}','{item.HShortNumber}',{item.HParentID},{item.HLevel}
+           ,{Convert.ToString(item.HEndFlag ? 1 : 0)},{Convert.ToString(item.HStopflag ? 1 : 0) },'{item.HRemark}','{item.HHelpCode}','{item.HUseFlag}'
+            ,'{item.HMakeTime}','{item.HMakeEmp}','{item.HCheckEmp}','{item.HCheckTime}','{item.HModifyEmp}'
+            ,'{item.HModifyTime}','{item.HStopEmp}',null,{item.HUSEORGID},{item.HCREATEORGID})";
+                    oCN.RunProc(sql);
+                }
+                sql = "set identity_insert Gy_CustLocation off";
+                oCN.RunProc(sql);
+
+                //瀹㈡埛_鏀惰揣鏂硅仈绯讳汉
+                sql = $"delete Gy_COMMONCONTACT where HCUSTID = {lsmain[0].HItemID}";
+                oCN.RunProc(sql);
+                sql = "set identity_insert Gy_COMMONCONTACT on";
+                oCN.RunProc(sql);
+                foreach (var item in custContactls)
+                {
+                    sql = $@"insert into Gy_COMMONCONTACT(HItemID,HCUSTID,HNumber,HName,HShortNumber,HParentID,HLevel,HEndFlag,HStopflag,
+                    HRemark,HHelpCode,HUseFlag,HMakeTime,HMakeEmp,HCheckEmp,HCheckTime,HModifyEmp,HModifyTime,HStopEmp,HStopTime,
+                    HUSEORGID,HCREATEORGID)
+                  values({item.HItemID},{item.HCUSTID},'{item.HNumber}','{item.HName}','{item.HShortNumber}',{item.HParentID},{item.HLevel}
+           ,{Convert.ToString(item.HEndFlag ? 1 : 0)},{Convert.ToString(item.HStopflag ? 1 : 0) },'{item.HRemark}','{item.HHelpCode}','{item.HUseFlag}'
+            ,'{item.HMakeTime}','{item.HMakeEmp}','{item.HCheckEmp}','{item.HCheckTime}','{item.HModifyEmp}'
+            ,'{item.HModifyTime}','{item.HStopEmp}','{item.HStopTime}',{item.HUSEORGID},{item.HCREATEORGID})";
+                    oCN.RunProc(sql);
+                }
+                sql = "set identity_insert Gy_COMMONCONTACT off";
+                oCN.RunProc(sql);
+
                 oCN.Commit();
                 objJsonResult.code = "1";
                 objJsonResult.count = 1;
-                objJsonResult.Message = "鏂板鍗曟嵁鎴愬姛锛�";
+                objJsonResult.Message = "鏂板鍩虹璧勬枡鎴愬姛锛�";
                 //objJsonResult.data = null;
                 return objJsonResult;
             }
@@ -612,6 +672,167 @@
             }
         }
 
-        //
+        #region [鍚屾鍩虹璧勬枡]
+        [Route("Gy_Customer/Gy_CustomerViewApi")]
+        [HttpGet]
+        public json Gy_CustomerViewApi(string Number, string Type)
+        {
+            string sql = string.Empty;
+            string sReturn = "";
+            if (oSystemParameter.ShowBill(ref sReturn) == true)
+            {
+                //绯荤粺鍙傛暟鏄惁涓虹鏈変簯妯″紡,N涓哄叕鏈変簯妯″紡锛孻涓虹鏈変簯妯″紡
+                if (oSystemParameter.omodel.WMS_CloudMode == "Y")
+                {
+                    #region [绉佹湁浜戞ā寮忥紝鐩存帴璋冪敤鏁版嵁搴撳瓨鍌ㄨ繃绋嬫洿鏂癩
+                    try
+                    {
+                        oCN.BeginTran();
+                        SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
+                        DataSet DS = oCn.RunProcReturn("exec h_p_WMS_ERPBasicInfoToLocal '" + Number + "','" + Type + "'", "h_p_WMS_ERPBasicInfoToLocal");
+                        if (DS == null)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "鍩虹璧勬枡鍚屾澶辫触";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            if (DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HBack"]) == "2")
+                            {
+                                objJsonResult.code = "0";
+                                objJsonResult.count = 0;
+                                objJsonResult.Message = "ERP涓笉瀛樺湪璇ヤ唬鐮�";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+                            else
+                            {
+                                objJsonResult.code = "1";
+                                objJsonResult.count = 1;
+                                objJsonResult.Message = "鍩虹璧勬枡鍚屾鎴愬姛";
+                                objJsonResult.data = null;
+                                return objJsonResult;
+                            }
+                        }
+
+                    }
+                    catch (Exception e)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "Exception锛�" + e.ToString();
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    #endregion
+                }
+                else
+                {
+                    #region [鍏湁浜戞ā寮忥紝璋冪敤WEBAPI鐨勬柟寮忚繘琛屾洿鏂癩
+                    var json = new
+                    {
+                        CreateOrgId = 0,
+                        Number = Number,
+                        Id = ""
+                    };
+                    #region [閲戣澏閮ㄥ垎]
+                    //鐧诲綍閲戣澏
+                    var loginRet = InvokeHelper.Login();
+                    var isSuccess = JObject.Parse(loginRet)["LoginResultType"].Value<int>();
+                    //鍒ゆ柇鏄惁鐧诲綍鎴愬姛
+                    if (isSuccess < 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = loginRet;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    //鏌ョ湅 鑾峰彇鏁版嵁                    
+                    var _result = InvokeHelper.View("BD_Customer", JsonConvert.SerializeObject(json));
+                    var _saveObj = JObject.Parse(_result);
+                    //鍒ゆ柇鏁版嵁鏄惁鑾峰彇鎴愬姛
+                    if (_saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper() != "TRUE")
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "閲戣澏瀹㈡埛鍚屾澶辫触jsonRoot锛�" + _result;
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    #endregion
+                    //鑾峰彇鏁版嵁
+                    DataSet Ds;
+                    Ds = oCN.RunProcReturn("select * from Gy_Customer where HNumber = '" + Number + "'", "Gy_Customer");
+                    if (Ds.Tables[0].Rows.Count != 0 && ClsPub.isLong(Ds.Tables[0].Rows[0]["HItemID"].ToString()) != 0)
+                    {
+
+                    }
+
+                    #region [琛ㄦ暟鎹祴鍊糫
+                    var jsonData = new
+                    {
+                        HItemID = _saveObj["Result"]["Result"]["Id"],
+                        HERPItemID = _saveObj["Result"]["Result"]["Id"],
+                        HNumber = _saveObj["Result"]["Result"]["Number"],
+                        HName         = _saveObj["Result"]["Result"]["Name"][0]["Value"],
+                        HShortNumber  = _saveObj["Result"]["Result"]["Number"],
+                        HParentID     = 0,
+                        HLevel        = 1,
+                        HEndFlag      = 1,
+                        HStopflag     = _saveObj["Result"]["Result"]["ForbidStatus"].ToString() == "A" ? 0 : 1,
+                        HRemark       = "CLD-ERP瀵煎叆",
+                        HUseFlag      = "宸蹭娇鐢�",
+                        HMakeTime     = _saveObj["Result"]["Result"]["CreateDate"],
+                        HCREATEORGID  = _saveObj["Result"]["Result"]["CreateOrgId_Id"],
+                        HUSEORGID = _saveObj["Result"]["Result"]["UseOrgId_Id"],
+                    };
+                    #endregion
+                    // 鍒犻櫎涓昏〃瀵瑰簲鏁版嵁
+                    sql = $"delete from Gy_Customer where HItemID = " + jsonData.HItemID + " and HNumber = '" + Number + "'";
+                    oCN.RunProc(sql);
+
+                    sql = "set identity_insert Gy_Customer on";
+                    oCN.RunProc(sql);
+
+                    //鎻掑叆琛�
+                    sql = $@"
+                insert into Gy_Customer
+                (HItemID,HERPItemID,HNumber,HName,HShortNumber,HParentID
+	            ,HLevel,HEndFlag,HStopflag,HRemark,HUseFlag,HMakeTime,HCREATEORGID,HUSEORGID
+                 )
+                values
+                ({jsonData.HItemID},{jsonData.HERPItemID},'{jsonData.HNumber}','{jsonData.HName}',
+                '{jsonData.HShortNumber}',{jsonData.HParentID},{jsonData.HLevel},{jsonData.HEndFlag},{jsonData.HStopflag},'{jsonData.HRemark}','{jsonData.HUseFlag}','{jsonData.HMakeTime}',{jsonData.HCREATEORGID},{jsonData.HUSEORGID})";
+
+                    oCN.RunProc(sql);
+
+                    sql = "set identity_insert Gy_Customer off";
+                    oCN.RunProc(sql);
+
+                    objJsonResult.code = "1";
+                    objJsonResult.count = 1;
+                    objJsonResult.Message = "瀹㈡埛鍚屾鎴愬姛锛�";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+
+                    #endregion
+                }
+            }
+            else
+            {
+                objJsonResult.code = "0";
+                objJsonResult.count = 0;
+                objJsonResult.Message = "鍩虹璧勬枡璇诲彇澶辫触锛�";
+                objJsonResult.data = null;
+                return objJsonResult;
+            }
+        }
+        #endregion
+
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1