| | |
| | | using System.Net.Http; |
| | | using System.Web.Http; |
| | | using WebAPI.Models; |
| | | using System.Web; |
| | | using WebAPI.Controllers.SCGL.æ¥è®¡å管ç; |
| | | using System.IO; |
| | | |
| | | namespace WebAPI.Controllers.åºç¡èµæ.åºç¡èµæ |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region ç»´ä¿®é¡¹ç®æä»¶ä¸ä¼ |
| | | [Route("Gy_Repair/Gy_Repair_Excel")] |
| | | [HttpPost] |
| | | public object Gy_Repair_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("ç»ç»ä»£ç ")) |
| | | error += "æ²¡ææ¾å°ãç»ç»ä»£ç ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("ç»ç»åç§°")) |
| | | error += "æ²¡ææ¾å°ãç»ç»åç§°ãçæ é¢,"; |
| | | |
| | | if (!tb2.Columns.Contains("维修项ç®ä»£ç ")) |
| | | 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 HRepairNum = ""; |
| | | string HRepairName = ""; |
| | | |
| | | HORGNumber = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç»ç»ä»£ç "].ToString()); |
| | | HORGName = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["ç»ç»åç§°"].ToString()); |
| | | HRepairNum = DBUtility.ClsPub.isStrNull(tb2.Rows[i]["维修项ç®ä»£ç "].ToString()); |
| | | HRepairName = 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 (HRepairName == "") |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "è¡,维修项ç®åç§°ä¸è½ä¸ºç©ºï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | //维修项ç®ä»£ç |
| | | if (HRepairNum == "") |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "第" + index + "è¡,维修项ç®ä»£ç ä¸è½ä¸ºç©ºï¼"; |
| | | objJsonResult.data = null; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "第" + index + "è¡,ç»ç»ä»£ç 为空"; |
| | | 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_Repair/Gy_Repair_btnSave")] |
| | | [HttpPost] |
| | | public object Gy_Repair_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_Repair_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 HRepairName = item["维修项ç®åç§°"].ToString(); |
| | | string HRepairNum = item["维修项ç®ä»£ç "].ToString(); |
| | | string sShortNumber; |
| | | sShortNumber = DBUtility.ClsPub.GetShortNumber(HRepairNum);//ç代ç |
| | | if (sShortNumber.Trim() == "") |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "ä¿å失败ï¼ç代ç 为空ï¼"; |
| | | objJsonResult.data = 1; |
| | | return objJsonResult; |
| | | } |
| | | int HEndFlag = 1;//æ«çº§æ å¿ |
| | | int HLevel = DBUtility.ClsPub.GetLevel(HRepairNum); //ç级 |
| | | |
| | | |
| | | if (!DBUtility.ClsPub.AllowNumber(HRepairNum.Trim())) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "ä¿å失败ï¼ä»£ç ä¸ä¸è½åºç°è¿ç»â.âå¹¶ä¸é¦ä½æ«ä½ä¸è½ä¸ºâ.âï¼"; |
| | | objJsonResult.data = 1; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | ds = oCN.RunProcReturn("select * from Gy_Repair where HNumber='" + HRepairNum + "'", "Gy_Repair"); |
| | | |
| | | if (ds.Tables[0].Rows.Count == 0) |
| | | { |
| | | |
| | | string sql = "insert into Gy_Repair(HName,HNumber,HUSEORGID,HCREATEORGID,HShortNumber,HEndFlag,HLevel,HParentID,HStopflag,HRemark,HHelpCode)" + |
| | | $"values('{HRepairName}', '{HRepairNum}',{HOrgID},{HOrgID}, '{sShortNumber}', {HEndFlag},{HLevel},0,0,'','')"; |
| | | oCN.RunProc(sql); |
| | | } |
| | | else |
| | | { |
| | | oCN.RunProc(" update Gy_Repair set HName='" + HRepairName + "' where HNumber='" + HRepairNum + "'"); |
| | | } |
| | | |
| | | 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 |
| | | |
| | | } |
| | | } |