| New file |
| | |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using Pub_Class; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using System.Web; |
| | | using System.Web.Http; |
| | | using WebAPI.Models; |
| | | using WebAPI.Controllers.SCGL.æ¥è®¡å管ç; |
| | | using System.IO; |
| | | using System.Linq; |
| | | using System.Text; |
| | | |
| | | namespace WebAPI.Controllers.ææ¬ç®¡ç |
| | | { |
| | | public class CB_WipProcessTableController : ApiController |
| | | { |
| | | public DBUtility.ClsPub.Enum_BillStatus BillStatus; |
| | | public DAL.ClsCB_ItemMoneyBillMain BillOld = new DAL.ClsCB_ItemMoneyBillMain(); |
| | | public DAL.ClsCB_ItemMoneyBillMain BillNew0 = new DAL.ClsCB_ItemMoneyBillMain(); |
| | | |
| | | private json objJsonResult = new json(); |
| | | SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); |
| | | DataSet ds; |
| | | |
| | | |
| | | #region æä»¶ä¸ä¼ |
| | | [Route("CB_WipProcessTableController/CB_WipProcessTable_Excel")] |
| | | [HttpPost] |
| | | public json CB_WipProcessTable_Excel() |
| | | { |
| | | json res = new json(); |
| | | try |
| | | { |
| | | //è·åæä»¶åç§° |
| | | var file = HttpContext.Current.Request.Files[0]; |
| | | //è·åæä»¶ç©çè·¯å¾ |
| | | string ExcelPath = HttpContext.Current.Server.MapPath("~/" + file.FileName); |
| | | //ä¿åæä»¶ |
| | | file.SaveAs(ExcelPath); |
| | | |
| | | SCGL.æ¥è®¡å管ç.NpoiHelper np = new NpoiHelper(); |
| | | DataSet ExcelDs = np.ReadExcel(ExcelPath, 1, 1, "0"); |
| | | |
| | | //å 餿件 |
| | | File.Delete(ExcelPath); |
| | | |
| | | //å建临æ¶è¡¨ |
| | | DataTable provisional = new DataTable("dt2"); |
| | | |
| | | //æ·»å åå |
| | | for (int i = 0; i < ExcelDs.Tables[0].Columns.Count; i++) |
| | | { |
| | | provisional.Columns.Add(ExcelDs.Tables[0].Rows[0][i].ToString()); |
| | | } |
| | | //provisional.Columns.Add("åæ®å·", typeof(string)); |
| | | |
| | | //æ·»å æ°æ® |
| | | for (int i = 1; i < ExcelDs.Tables[0].Rows.Count; i++) |
| | | { |
| | | DataRow row = provisional.NewRow(); |
| | | for (int j = 0; j < ExcelDs.Tables[0].Columns.Count; j++) |
| | | { |
| | | row[j] = ExcelDs.Tables[0].Rows[i][j].ToString(); |
| | | } |
| | | provisional.Rows.Add(row); |
| | | } |
| | | |
| | | //夿å |
| | | string error = JudgmentColumns(provisional); |
| | | if (error.Length > 0) |
| | | { |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = $"Excel模æ¿åå¨é误,{error}\r\n"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | for (int i = 0; i <= provisional.Rows.Count - 1; i++) |
| | | { |
| | | |
| | | string HProcName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["产åºå·¥åº"].ToString()); |
| | | string HCusName = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["客æ·"].ToString()); |
| | | |
| | | string HPartNumber = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æåæå·"].ToString()); |
| | | string HWIPQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["WIPæ°é"].ToString()); |
| | | |
| | | string HInProcessWIPQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["å¨å¶WIPæ°é"].ToString()); |
| | | |
| | | string HPanelQty = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æ¼çæ°"].ToString()); |
| | | string HLot = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["LOT"].ToString()); |
| | | |
| | | string HOrderTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ä¸åæ¶é´"].ToString()); |
| | | |
| | | string HStartTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["æäº§æ¶é´"].ToString()); |
| | | string HOutputTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["äº§åºæ¶é´"].ToString()); |
| | | |
| | | string HProductionTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç产æ¶é´"].ToString()); |
| | | string HStatus = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["ç¶æ"].ToString()); |
| | | |
| | | string HStayTime = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["åçæ¶é´(åé)"].ToString()); |
| | | |
| | | //string remark = DBUtility.ClsPub.isStrNull(provisional.Rows[i]["夿³¨"].ToString()); |
| | | |
| | | //è·åçå®è¡æ° |
| | | int line = i + 1; |
| | | } |
| | | |
| | | res.code = "1"; |
| | | res.count = 1; |
| | | res.Message = error; |
| | | res.data = provisional; |
| | | return res; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "Exceptionï¼" + e.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿å |
| | | /// </summary> |
| | | /// <param name="provisional"></param> |
| | | /// <returns></returns> |
| | | private static string JudgmentColumns(DataTable provisional) |
| | | { |
| | | var error = ""; |
| | | |
| | | //æ¥è¯¢æ²¡æçå |
| | | if (!provisional.Columns.Contains("客æ·")) |
| | | error += "æ²¡ææ¾å°ã客æ·ãçæ é¢,"; |
| | | |
| | | if (!provisional.Columns.Contains("æåæå·")) |
| | | error += "æ²¡ææ¾å°ãæåæå·ãçæ é¢,"; |
| | | return error; |
| | | } |
| | | #endregion |
| | | |
| | | #region ä¸ä¼ ä¿å |
| | | [Route("CB_WipProcessTableController/Excel_btnSave")] |
| | | [HttpPost] |
| | | public object Excel_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(); |
| | | string organ = sArray[2].ToString(); |
| | | json res = new json(); |
| | | |
| | | try |
| | | { |
| | | oCN.BeginTran(); |
| | | 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); |
| | | } |
| | | |
| | | // 4. æ¥è¯¢ç¨æ·ä¿¡æ¯ |
| | | DataSet emp = oCN.RunProcReturn($"SELECT Czybm FROM Gy_Czygl WHERE Czymc = '{user.Replace("'", "''")}'", "Gy_Czygl"); |
| | | if (emp.Tables[0].Rows.Count == 0) |
| | | { |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "ç¨æ·ä¸åå¨ï¼"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | string HUserID = emp.Tables[0].Rows[0]["Czybm"].ToString(); |
| | | |
| | | StringBuilder errorMessage = new StringBuilder(); |
| | | StringBuilder insertSql = new StringBuilder(); |
| | | StringBuilder updateSql = new StringBuilder(); |
| | | string currentDate = DateTime.Today.ToString("yyyy-MM-dd"); |
| | | int HEntryID = 1; |
| | | |
| | | // éåæ°æ®å¹¶éªè¯ |
| | | for (int i = 0; i < list.Count; i++) |
| | | { |
| | | var item = list[i]; |
| | | |
| | | List<string> intFields = new List<string> |
| | | { |
| | | "WIPæ°é", "å¨å¶WIPæ°é", "æ¼çæ°", "åçæ¶é´(åé)" |
| | | }; |
| | | |
| | | bool hasError = false; |
| | | foreach (var field in intFields) |
| | | { |
| | | if (item.ContainsKey(field)) |
| | | { |
| | | string value = item[field]; |
| | | // æ£æ¥æ¯å¦ä¸ºæ´æ° |
| | | if (!string.IsNullOrWhiteSpace(value)) |
| | | { |
| | | if (!int.TryParse(value, out _)) |
| | | { |
| | | errorMessage.AppendLine($"第{i + 1}è¡æ°æ®é误ï¼å段 '{field}' çå¼ '{value}' 䏿¯ææçæ´æ°"); |
| | | hasError = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 妿æé误ï¼è·³è¿æå
¥ |
| | | if (hasError) |
| | | { |
| | | continue; |
| | | } |
| | | |
| | | |
| | | insertSql.AppendLine($"INSERT INTO CB_WipProcessTable ([HYear], [HPeriod], [HDay], [HProcName], [HCusName], [HPartNumber], [HWIPQty], [HInProcessWIPQty], [HPanelQty], [HLot], [HOrderTime], [HStartTime], [HOutputTime], [HProductionTime], [HStatus], [HStayTime], [HChecker], [HCheckDate], [HMaker], [HMakeDate], [HUpDater], [HUpDateDate], [HCloseMan], [HCloseDate], [HCloseType], [HDeleteMan], [HDeleteDate], [HReamrk]) VALUES ("); |
| | | insertSql.AppendLine($" {DateTime.Now.Year}, {DateTime.Now.Month}, {DateTime.Now.Day}, '{item["产åºå·¥åº"]}', '{item["客æ·"]}', '{item["æåæå·"]}', '{item["WIPæ°é"]}', '{item["å¨å¶WIPæ°é"]}', '{item["æ¼çæ°"]}', '{item["LOT"]}', '{item["ä¸åæ¶é´"]}', '{item["æäº§æ¶é´"]}', '{item["äº§åºæ¶é´"]}', '{item["ç产æ¶é´"]}', '{item["ç¶æ"]}', '{item["åçæ¶é´(åé)"]}', '{""}', '{""}', '{user}', '{DateTime.Now}', '{""}', '{DateTime.Now}', '{""}', '{""}', '{"0"}', '{""}', '{""}', '{"excel导å
¥"}');"); |
| | | } |
| | | |
| | | if (errorMessage.Length > 0) |
| | | { |
| | | //oCN.Rollback(); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "æ°æ®éªè¯å¤±è´¥ï¼\n" + errorMessage.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | if (insertSql.Length == 0) |
| | | { |
| | | // oCN.Rollback(); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "æ²¡æææçæ´æ°æ°æ®å¯ä»¥å¯¼å
¥"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | |
| | | // æ§è¡æ¹éæä½ |
| | | if (insertSql.Length > 0) |
| | | { |
| | | oCN.RunProc(insertSql.ToString()); |
| | | } |
| | | |
| | | //if (updateSql.Length > 0) |
| | | //{ |
| | | // oCN.RunProc(updateSql.ToString()); |
| | | // oCN.RunProc(updateSql_sub.ToString()); |
| | | //} |
| | | |
| | | oCN.Commit(); |
| | | |
| | | res.code = "1"; |
| | | res.count = 1; |
| | | res.Message = "导å
¥æå!"; |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | //oCN.Rollback(); |
| | | LogService.Write(e); |
| | | res.code = "0"; |
| | | res.count = 0; |
| | | res.Message = "Exceptionï¼" + e.ToString(); |
| | | res.data = null; |
| | | return res; |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | } |