From d00b4284626da680659b4f013e5c17d5dbe4ccf7 Mon Sep 17 00:00:00 2001
From: chenhaozhe <cgz@hz-kingdee.com>
Date: 星期一, 01 九月 2025 17:01:19 +0800
Subject: [PATCH] 合并分支

---
 WebAPI/Controllers/华远datamapping/Gy_PNLInfoController.cs |  345 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 345 insertions(+), 0 deletions(-)

diff --git "a/WebAPI/Controllers/\345\215\216\350\277\234datamapping/Gy_PNLInfoController.cs" "b/WebAPI/Controllers/\345\215\216\350\277\234datamapping/Gy_PNLInfoController.cs"
index bf9b150..dc7581d 100644
--- "a/WebAPI/Controllers/\345\215\216\350\277\234datamapping/Gy_PNLInfoController.cs"
+++ "b/WebAPI/Controllers/\345\215\216\350\277\234datamapping/Gy_PNLInfoController.cs"
@@ -11,6 +11,10 @@
 using SyntacticSugar.constant;
 using DBUtility;
 using System.Text;
+using System.Web;
+using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�;
+using System.IO;
+using System.Text.RegularExpressions;
 
 namespace WebAPI.Controllers.鍩虹璧勬枡.鍩虹璧勬枡
 {
@@ -1084,5 +1088,346 @@
             }
         }
         #endregion
+
+        #region PNL甯冨眬淇℃伅 鏂囦欢涓婁紶
+        [Route("Gy_PNLInfo/Gy_PNLInfo_Excel")]
+        [HttpPost]
+        public object Gy_PNLInfo_Excel()
+        {
+            try
+            {
+                //var WorkBookName = HttpContext.Current.Request["WorkBookName"];
+                //DBUtility.ClsPub.HOrgID = long.Parse(HttpContext.Current.Request["HOrgID"]);
+                //鑾峰彇鏂囦欢鍚嶇О
+                var file = HttpContext.Current.Request.Files[0];
+                //鑾峰彇鏂囦欢鐗╃悊璺緞
+                string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName);
+                //淇濆瓨鏂囦欢
+                file.SaveAs(ExcelPath);
+
+                NpoiHelper np = new NpoiHelper();
+                DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0");
+
+                //鍒犻櫎鏂囦欢
+                File.Delete(ExcelPath);
+
+                //鍒涘缓涓存椂琛�
+                DataTable tb2 = new DataTable("dt2");
+
+                //娣诲姞鍒楀悕
+                for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++)
+                {
+                    tb2.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString());
+                }
+
+                //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁
+                tb2.Columns.Add("Set鍙�", typeof(string));
+                tb2.Columns.Add("琛岀储寮�", typeof(Int32));
+                tb2.Columns.Add("鍒楃储寮�", typeof(Int32));
+                tb2.Columns.Add("HPNLInfoTypeID", 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
+                    if (ExcelDs.Tables[0].Rows[i][0].ToString() == "")
+                    {
+                        continue;
+                    }
+                    else
+                    {
+                        tb2.Rows.Add(row);
+                    }
+                }
+
+
+                var error = "";
+
+                //鏌ヨ瀵煎叆妯℃澘娌℃湁鐨勫垪
+                if (!tb2.Columns.Contains("鏂欏彿"))
+                    error += "涓婁紶鏂囦欢涓病鏈夋壘鍒般�愭枡鍙枫�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("鍒嗙被"))
+                    error += "涓婁紶鏂囦欢涓病鏈夋壘鍒般�愬垎绫汇�戠殑鏍囬,";
+
+                if (!tb2.Columns.Contains("PCS鍙�"))
+                    error += "涓婁紶鏂囦欢涓病鏈夋壘鍒般�怭CS鍙枫�戠殑鏍囬,";
+
+
+                if (error.Length > 0)
+                {
+                    objJsonResult.code = "0";
+                    objJsonResult.count = 0;
+                    objJsonResult.Message = $"Excel妯℃澘瀛樺湪閿欒,{error}\r\n";
+                    objJsonResult.data = null;
+                    return objJsonResult;
+                }
+
+                string HLayOutName_temp = "";
+                string HPNLInfoTypeName_temp = "";
+                List<string> HPCSNo_Array = new List<string>();
+                if (tb2.Rows.Count > 0)
+                {
+                    HLayOutName_temp = DBUtility.ClsPub.isStrNull(tb2.Rows[0]["鏂欏彿"].ToString());
+                    HPNLInfoTypeName_temp = DBUtility.ClsPub.isStrNull(tb2.Rows[0]["鍒嗙被"].ToString());
+                }
+
+                for (int i = 0; i <= tb2.Rows.Count - 1; i++)
+                {
+                    string HLayOutName = "";                //鏂欏彿
+                    string HPNLInfoTypeName = "";           //鍒嗙被
+                    string HPCSNo = "";                     //PCS鍙�
+
+                    HLayOutName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鏂欏彿"].ToString());
+                    HPNLInfoTypeName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["鍒嗙被"].ToString());
+                    HPCSNo = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["PCS鍙�"].ToString());
+                    
+                    //妫�鏌ユ暟鎹槸鍚﹀畬鏁�
+                    int index = i + 2;
+
+                    if (HLayOutName != "")
+                    {
+                        if (HLayOutName != HLayOutName_temp)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,銆愭枡鍙枫�戜笌棣栬鏁版嵁涓�愭枡鍙枫�戜笉涓�鑷达紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        if (HPNLInfoTypeName != HPNLInfoTypeName_temp)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,銆愬垎绫汇�戜笌棣栬鏁版嵁涓�愬垎绫汇�戜笉涓�鑷达紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        if (HPCSNo_Array.Contains(HPCSNo))
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,銆怭CS鍙枫�戝瓨鍦ㄩ噸澶嶏紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            HPCSNo_Array.Add(HPCSNo);
+                        }
+
+
+                        //鏌ヨ鏂欏彿璧勬枡鏄惁宸茬粡瀛樺湪
+                        ds = oCN.RunProcReturn("select * from Gy_PNLInfo where HLayOutName = '" + HLayOutName + "' ", "Gy_PNLInfo");
+
+                        if (ds.Tables[0].Rows.Count > 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鏂欏彿銆�" + HLayOutName + "銆戣祫鏂欏凡缁忓瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        //鏌ヨ 鍒嗙被
+                        ds = oCN.RunProcReturn("select * from Gy_PNLInfoType where HName = '" + HPNLInfoTypeName + "' ", "Gy_PNLInfoType");
+                        if (ds.Tables[0].Rows.Count == 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鍒嗙被銆�" + HPNLInfoTypeName + "銆戜笉瀛樺湪锛�";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["HPNLInfoTypeID"] = ds.Tables[0].Rows[0]["HInterID"];
+                        }
+
+                        //鍒ゆ柇PCS鍙锋牸寮忔槸鍚︽纭�
+                        if (!Regex.IsMatch(HPCSNo, @"^\d{6}$"))
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,PCS鍙枫��" + HPCSNo + "銆戞牸寮忛敊璇紝搴旇缃负鐢�6浣嶆暟瀛楃粍鎴愶紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+                        else
+                        {
+                            tb2.Rows[i]["Set鍙�"] = HPCSNo.Substring(0, 2);
+                            tb2.Rows[i]["琛岀储寮�"] = int.Parse(HPCSNo.Substring(2, 2));
+                            tb2.Rows[i]["鍒楃储寮�"] = int.Parse(HPCSNo.Substring(4, 2));
+                        }
+                    }
+                }
+
+                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 PNL甯冨眬淇℃伅 瀵煎叆(淇濆瓨)
+        [Route("Gy_PNLInfo/Gy_PNLInfo_btnSave")]
+        [HttpPost]
+        public object Gy_PNLInfo_btnSave([FromBody] JObject sMainSub)
+        {
+            var _value = sMainSub["sMainSub"].ToString();
+            string msg1 = _value.ToString();
+            string[] sArray = msg1.Split(new string[] { "&鍜�" }, StringSplitOptions.RemoveEmptyEntries);
+            string msg2 = sArray[0].ToString();
+            string user = sArray[1].ToString();
+            try
+            {
+                if (!DBUtility.ClsPub.Security_Log("Gy_PNLInfo_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();
+                int i = 1;
+                foreach (Dictionary<string, string> item in list)
+                {
+                    string HInterID = "0";
+                    string HLayOutName = item["鏂欏彿"].ToString();                //鏂欏彿
+                    string HPNLInfoTypeID = item["HPNLInfoTypeID"].ToString();   //鍒嗙被ID
+                    string HPNLInfoTypeName = item["鍒嗙被"].ToString();           //鍒嗙被
+                    string HSetNo = item["Set鍙�"].ToString();                    //Set鍙�
+                    string HPCSNo = item["PCS鍙�"].ToString();                    //PCS鍙�
+                    string HPosition_x = item["琛岀储寮�"].ToString();              //琛岀储寮�
+                    string HPosition_y = item["鍒楃储寮�"].ToString();              //鍒楃储寮�
+
+                    //妫�鏌ユ暟鎹槸鍚﹀畬鏁�
+                    int index = i;
+
+                    if (i == 1)
+                    {
+                        //鏌ヨ鏂欏彿璧勬枡鏄惁宸茬粡瀛樺湪
+                        ds = oCN.RunProcReturn("select * from Gy_PNLInfo where HLayOutName = '" + HLayOutName + "' ", "Gy_PNLInfo");
+                        if (ds.Tables[0].Rows.Count > 0)
+                        {
+                            objJsonResult.code = "0";
+                            objJsonResult.count = 0;
+                            objJsonResult.Message = "绗�" + index + "琛�,鏂欏彿銆�+ " + HLayOutName + "銆戣祫鏂欏凡缁忓瓨鍦紒";
+                            objJsonResult.data = null;
+                            return objJsonResult;
+                        }
+
+                        string HIcon = "/img/鏅鸿兘鑺墖锛�.png";
+                        string HMaker = user;
+
+                        string sql_main = "insert into Gy_PNLInfo(HLayOutName,HIcon,HMaker,HMakeDate,HPNLInfoTypeID) " +
+                            "values(" +
+                            "'" + HLayOutName + "'" +
+                            ",'" + HIcon + "'" +
+                            ",'" + HMaker + "'" +
+                            ",getdate()" +
+                            "," + HPNLInfoTypeID + "" +
+                            ")";
+                        oCN.RunProc(sql_main);
+                    }
+
+                    string sql_getInterID = "select * from Gy_PNLInfo where HLayOutName = '" + HLayOutName + "'";
+                    ds = oCN.RunProcReturn(sql_getInterID, "Gy_PNLInfo");
+                    if (ds == null || ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "PNL甯冨眬淇℃伅瀵煎叆澶辫触锛侊紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+                    else
+                    {
+                        HInterID = DBUtility.ClsPub.isStrNull(ds.Tables[0].Rows[0]["HInterID"]);
+                    }
+
+                    //鏌ヨ 鍒嗙被
+                    ds = oCN.RunProcReturn("select * from Gy_PNLInfoType where HName = '" + HPNLInfoTypeName + "' ", "Gy_PNLInfoType");
+                    if (ds.Tables[0].Rows.Count == 0)
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + index + "琛�,鍒嗙被銆�+ " + HPNLInfoTypeName + "銆戜笉瀛樺湪锛�";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    //鍒ゆ柇PCS鍙锋牸寮忔槸鍚︽纭�
+                    if (!Regex.IsMatch(HPCSNo, @"^\d{6}$"))
+                    {
+                        objJsonResult.code = "0";
+                        objJsonResult.count = 0;
+                        objJsonResult.Message = "绗�" + index + "琛�,PCS鍙枫��" + HPCSNo + "銆戞牸寮忛敊璇紝搴旇缃负鐢�6浣嶆暟瀛楃粍鎴愶紒";
+                        objJsonResult.data = null;
+                        return objJsonResult;
+                    }
+
+                    string sql_sub = "insert into Gy_PNLInfoSub(HInterID,HLayOutName,HSetNo,HPCSNo,HPosition_x,HPosition_y) " +
+                        "values(" +
+                        "" + HInterID + "" +
+                        ",'" + HLayOutName + "'" +
+                        ",'" + HSetNo + "'" +
+                        ",'" + HPCSNo + "'" +
+                        "," + HPosition_x + "" +
+                        "," + HPosition_y + "" +
+                        ")";
+                    oCN.RunProc(sql_sub);
+                    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
     }
 }

--
Gitblit v1.9.1