From 79b8274db6aa3123d7781b0069d4db6bb2bffd18 Mon Sep 17 00:00:00 2001 From: wtt <1985833171@qq.com> Date: 星期五, 21 六月 2024 15:15:35 +0800 Subject: [PATCH] 添加导入功能 --- WebAPI/Controllers/基础资料/基础资料/Gy_RepairCheckBillController.cs | 256 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 256 insertions(+), 0 deletions(-) diff --git "a/WebAPI/Controllers/\345\237\272\347\241\200\350\265\204\346\226\231/\345\237\272\347\241\200\350\265\204\346\226\231/Gy_RepairCheckBillController.cs" "b/WebAPI/Controllers/\345\237\272\347\241\200\350\265\204\346\226\231/\345\237\272\347\241\200\350\265\204\346\226\231/Gy_RepairCheckBillController.cs" index 91afe47..7e67c9c 100644 --- "a/WebAPI/Controllers/\345\237\272\347\241\200\350\265\204\346\226\231/\345\237\272\347\241\200\350\265\204\346\226\231/Gy_RepairCheckBillController.cs" +++ "b/WebAPI/Controllers/\345\237\272\347\241\200\350\265\204\346\226\231/\345\237\272\347\241\200\350\265\204\346\226\231/Gy_RepairCheckBillController.cs" @@ -9,6 +9,9 @@ using System.Net.Http; using System.Web.Http; using WebAPI.Models; +using System.Web; +using WebAPI.Controllers.SCGL.鏃ヨ鍒掔鐞�; +using System.IO; namespace WebAPI.Controllers.鍩虹璧勬枡.鍩虹璧勬枡 { @@ -317,5 +320,258 @@ } } #endregion + + #region 缁翠慨楠屾敹鏂囦欢涓婁紶 + [Route("Gy_RepairCheck/Gy_RepairCheck_Excel")] + [HttpPost] + public object Gy_RepairCheck_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()); + } + + //妯℃澘缂哄皯鍒� 浣嗛渶瑕佷粠鏁版嵁搴撲腑鏌ヨ鍑烘潵鏄剧ず鍦ㄩ〉闈㈢殑瀛楁 + tb2.Columns.Add("HOrgID", 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 HORGNumber = ""; + string HORGName = ""; + string HRepairCheckNum = ""; + string HRepairCheckName = ""; + + HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐浠g爜"].ToString()); + HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁勭粐鍚嶇О"].ToString()); + HRepairCheckNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁翠慨楠屾敹椤圭洰浠g爜"].ToString()); + HRepairCheckName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["缁翠慨楠屾敹椤圭洰鍚嶇О"].ToString()); + + //妫�鏌ョ粍缁� + int index = i + 1; + + if (HORGNumber != "") + { + + + //鏌ヨ缁勭粐 + ds = oCN.RunProcReturn("select * from Xt_ORGANIZATIONS where HNumber='" + HORGNumber + "' and Hname='" + HORGName + "'", "Xt_ORGANIZATIONS"); + + if (ds.Tables[0].Rows.Count == 0) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + index + "琛�,缁勭粐涓嶅瓨鍦紒"; + objJsonResult.data = null; + return objJsonResult; + } + else + { + tb2.Rows[i]["HOrgID"] = ds.Tables[0].Rows[0]["HItemID"].ToString(); + } + string HORGid = ds.Tables[0].Rows[0]["HItemID"].ToString(); + + //缁翠慨楠屾敹鍚嶇О + if (HRepairCheckName == "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "绗�" + index + "琛�,缁翠慨楠屾敹鍚嶇О涓嶈兘涓虹┖锛�"; + objJsonResult.data = null; + return objJsonResult; + } + + //缁翠慨楠屾敹浠g爜 + if (HRepairCheckNum == "") + { + 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; + } + } + #endregion + + #region 缁翠慨楠屾敹 瀵煎叆(淇濆瓨) + [Route("Gy_RepairCheck/Gy_RepairCheck_btnSave")] + [HttpPost] + public object Gy_RepairCheck_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_RepairCheck_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 HOrgID = item["HOrgID"].ToString();//缁勭粐ID + string HRepairCheckName = item["缁翠慨楠屾敹椤圭洰鍚嶇О"].ToString(); + string HRepairCheckNum = item["缁翠慨楠屾敹椤圭洰浠g爜"].ToString(); + string sShortNumber; + sShortNumber = DBUtility.ClsPub.GetShortNumber(HRepairCheckNum);//鐭唬鐮� + if (sShortNumber.Trim() == "") + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛佺煭浠g爜涓虹┖锛�"; + objJsonResult.data = 1; + return objJsonResult; + } + int HEndFlag = 1;//鏈骇鏍囧織 + int HLevel = DBUtility.ClsPub.GetLevel(HRepairCheckNum); //绛夌骇 + + + if (!DBUtility.ClsPub.AllowNumber(HRepairCheckNum.Trim())) + { + objJsonResult.code = "0"; + objJsonResult.count = 0; + objJsonResult.Message = "淇濆瓨澶辫触锛佷唬鐮佷腑涓嶈兘鍑虹幇杩炵画鈥�.鈥欏苟涓旈浣嶆湯浣嶄笉鑳戒负鈥�.鈥欙紒"; + objJsonResult.data = 1; + return objJsonResult; + } + + ds = oCN.RunProcReturn("select * from Gy_RepairCheck where HNumber='" + HRepairCheckNum + "'", "Gy_RepairCheck"); + + if (ds.Tables[0].Rows.Count == 0) + { + + string sql = "insert into Gy_RepairCheck(HName,HNumber,HUSEORGID,HCREATEORGID,HShortNumber,HEndFlag,HLevel,HParentID,HStopflag,HRemark,HHelpCode)" + + $"values('{HRepairCheckName}', '{HRepairCheckNum}',{HOrgID},{HOrgID}, '{sShortNumber}', {HEndFlag},{HLevel},0,0,'','')"; + oCN.RunProc(sql); + } + else + { + oCN.RunProc(" update Gy_RepairCheck set HName='" + HRepairCheckName + "' where HNumber='" + HRepairCheckNum + "'"); + } + + 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