using System; using System.Collections.Generic; using System.Linq; using System.Text; using Stone.Common; using System.IO; using System.Data; using Stone.Entity; using Stone.WinForm.F_Common; using System.Threading; using Gm_WMS.DataAccess.DataService; using System.Runtime.InteropServices; namespace Stone.WinService { public class F_EDI_BJ { #region 构造函数 public static bool IsRun = false; public static string Path_Receive_YZ = string.Empty; public static string Path_Error_YZ = string.Empty; public static string Path_Bak_YZ = string.Empty; public static string Path_Receive_SY = string.Empty; public static string Path_Error_SY = string.Empty; public static string Path_Bak_SY = string.Empty; static F_EDI_BJ() { Path_Receive_YZ = MyAppconfig.ReadValue("亦庄接收路径"); Path_Error_YZ = MyAppconfig.ReadValue("亦庄错误路径"); Path_Bak_YZ = MyAppconfig.ReadValue("亦庄备份路径"); Path_Receive_SY = MyAppconfig.ReadValue("顺义接收路径"); Path_Error_SY = MyAppconfig.ReadValue("顺义错误路径"); Path_Bak_SY = MyAppconfig.ReadValue("顺义备份路径"); } #endregion #region 数据解析 public static void Run() { int UpdateTime = Convert.ToInt32(MyAppconfig.ReadValue("BJEDI解析刷新时间")) * 1000; while (IsRun) { //亦庄数据处理 也叫大兴 try { ProcessData_YZ(); } catch (Exception ex) { MyLogger.Write(ex.Message); } //顺义数据处理 try { ProcessData_SY(); } catch (Exception ex) { MyLogger.Write(ex.Message); } System.Threading.Thread.Sleep(UpdateTime); } } public static void ProcessData_YZ() { DirectoryInfo dir = new DirectoryInfo(Path_Receive_YZ); FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly); Array.Sort(files, new MyFileSort(FileOrder.Length)); //按修改日期升序排列 Entity_t_JIS_Log t_JIS_Log = new Entity_t_JIS_Log(); foreach (FileInfo file in files) { DataRow drJIS_Log = t_JIS_Log.Table.NewRow(); StreamReader sr = null; string filetype = ""; try { drJIS_Log["FileName"] = file.Name; drJIS_Log["StartTime"] = DateTime.Now; drJIS_Log["FileType"] = filetype; drJIS_Log["ModificationTime"] = file.LastWriteTime; drJIS_Log = t_JIS_Log.Add(drJIS_Log); if (IsUseFile(file.FullName)) { drJIS_Log["EndTime"] = MyDateTime.GetServerDateTime(); drJIS_Log["ProcessState"] = "Failed"; drJIS_Log["Memo"] = file.FullName + " 文件被占用,30秒后再试..."; t_JIS_Log.Edit(drJIS_Log); Thread.Sleep(30 * 1000); } sr = file.OpenText(); string text = sr.ReadToEnd(); sr.Close(); string[] sp_text = text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "").Split('\''); //判断文件格式是否正式 filetype = IsFileOK(sp_text, file.Name); //if (filetype != "307-JSA" && filetype != "241-DELFOR") continue; //跳过JSP的文件 //判断是否是亦庄文件 如果是顺义文件,转移到顺义的 Receive目录下 亦庄(大兴)= 104;顺义 = 1046 var facCode = sp_text[1].Split('+')[2].Split(':')[0]; if (facCode == "1046") { //顺义的文件,转移到顺义文件夹下 MoveFile(file, Path_Receive_SY, ""); continue; } string NewName = ""; string Path_Bak_New = Path_Bak_YZ + "\\" + MyDateTime.Format(DateTime.Now, MyDateTimeType.Date); if (!Directory.Exists(Path_Bak_New)) { Directory.CreateDirectory(Path_Bak_New); } switch (filetype) { case "307-JSA": if (file.Name.Substring(0, 4) != "YZA_") { NewName = "YZA_"; } ProcessDataAJIS(sp_text, file.Name); //解析Actual break; case "241-DELFOR": if (file.Name.Substring(0, 4) != "YZD_") { NewName = "YZD_"; } ProcessDELFOR(sp_text, file.Name); //解析DELFOR break; case "307-JSP": if (file.Name.Substring(0, 4) != "YZP_") { NewName = "YZP_"; } ProcessDataPJIS(sp_text, Path_Bak_New + "\\" + NewName + file.Name); //解析Planned break; default: throw new Exception("文件格式不正确"); } MyLogger.Write(file.Name + " 处理成功"); MoveFile(file, Path_Bak_New, NewName); drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Success"; t_JIS_Log.Edit(drJIS_Log); } catch (Exception ex) { if (sr != null) sr.Close(); MyLogger.Write(file.Name + " 处理失败,原因为:" + ex.Message); string Path_Error_New = Path_Error_YZ + "\\" + MyDateTime.Format(DateTime.Now, MyDateTimeType.Date); if (!Directory.Exists(Path_Error_New)) { Directory.CreateDirectory(Path_Error_New); } //MoveFile(file, Path_Error_New); drJIS_Log["FileType"] = filetype; drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Failed"; drJIS_Log["Memo"] = MyStrings.GetString(ex.Message); t_JIS_Log.Edit(drJIS_Log); F_Mail.SendMail(file.Name, "安通林EDI邮件报警(亦庄)", ex.Message); } } } public static void ProcessData_SY() { DirectoryInfo dir = new DirectoryInfo(Path_Receive_SY); FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly); Array.Sort(files, new MyFileSort(FileOrder.Length)); //按修改日期升序排列 Entity_t_JIS_Log t_JIS_Log = new Entity_t_JIS_Log(); foreach (FileInfo file in files) { DataRow drJIS_Log = t_JIS_Log.Table.NewRow(); StreamReader sr = null; string filetype = ""; try { drJIS_Log["FileName"] = file.Name; drJIS_Log["StartTime"] = DateTime.Now; drJIS_Log["FileType"] = filetype; drJIS_Log["ModificationTime"] = file.LastWriteTime; drJIS_Log = t_JIS_Log.Add(drJIS_Log); if (IsUseFile(file.FullName)) { drJIS_Log["EndTime"] = MyDateTime.GetServerDateTime(); drJIS_Log["ProcessState"] = "Failed"; drJIS_Log["Memo"] = file.FullName + " 文件被占用,30秒后再试..."; t_JIS_Log.Edit(drJIS_Log); Thread.Sleep(30 * 1000); } sr = file.OpenText(); string text = sr.ReadToEnd(); sr.Close(); string[] sp_text = text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "").Split('\''); //判断文件格式是否正式 filetype = IsFileOK(sp_text, file.Name); //if (filetype != "307-JSA" && filetype != "241-DELFOR") continue; //跳过JSP的文件 string NewName = ""; string Path_Bak_New = Path_Bak_SY + "\\" + MyDateTime.Format(DateTime.Now, MyDateTimeType.Date); if (!Directory.Exists(Path_Bak_New)) { Directory.CreateDirectory(Path_Bak_New); } switch (filetype) { case "307-JSA": if (file.Name.Substring(0, 4) != "SYA_") { NewName = "SYA_"; } ProcessDataAJIS(sp_text, file.Name); //解析Actual break; case "241-DELFOR": if (file.Name.Substring(0, 4) != "SYD_") { NewName = "SYD_"; } ProcessDELFOR(sp_text, file.Name); //解析DELFOR break; case "307-JSP": if (file.Name.Substring(0, 4) != "SYP_") { NewName = "SYP_"; } ProcessDataPJIS(sp_text, Path_Bak_New + "\\" + NewName + file.Name); //解析Planned break; } MyLogger.Write(file.Name + " 处理成功"); MoveFile(file, Path_Bak_New, NewName); drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Success"; t_JIS_Log.Edit(drJIS_Log); } catch (Exception ex) { if (sr != null) sr.Close(); MyLogger.Write(file.Name + " 处理失败,原因为:" + ex.Message); string Path_Error_New = Path_Error_SY + "\\" + MyDateTime.Format(DateTime.Now, MyDateTimeType.Date); if (!Directory.Exists(Path_Error_New)) { Directory.CreateDirectory(Path_Error_New); } //MoveFile(file, Path_Error_New); drJIS_Log["FileType"] = filetype; drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Failed"; drJIS_Log["Memo"] = MyStrings.GetString(ex.Message); t_JIS_Log.Edit(drJIS_Log); F_Mail.SendMail(file.Name, "安通林EDI邮件报警(顺义)", ex.Message); } } } #region old /* public static void ProcessDataJSP() { DirectoryInfo dir = new DirectoryInfo(Path_Receive); FileInfo[] files = dir.GetFiles("*.*", SearchOption.TopDirectoryOnly); Array.Sort(files, new MyFileSort(FileOrder.LastWriteTime)); //按修改日期升序排列 Entity_t_JIS_Log t_JIS_Log = new Entity_t_JIS_Log(); int n = 0; //JSP一次处理 foreach (FileInfo file in files) { DataRow drJIS_Log = t_JIS_Log.Table.NewRow(); StreamReader sr = null; string filetype = ""; try { sr = file.OpenText(); string text = sr.ReadToEnd(); sr.Close(); string[] sp_text = text.Replace("\r\n", "").Replace("\r", "").Replace("\n", "").Split('\''); //判断文件格式是否正式 filetype = IsFileOK(sp_text, file.Name); if (filetype != "307-JSP") continue; //跳过不是JSP的文件 if (n >= 1) break; //一次处理一个JSP文件,这样可防止大堆来JSP文件的时候一直在处理JSP文件 n++; drJIS_Log["FileName"] = file.Name; drJIS_Log["StartTime"] = DateTime.Now; drJIS_Log = t_JIS_Log.Add(drJIS_Log); switch (filetype) { case "307-JSP": ProcessDataPJIS(sp_text, file.Name); //解析Planned break; } MyLogger.Write(file.Name + " 处理成功"); string Path_Bak_New = Path_Bak + "\\" + MyDateTime.Format(DateTime.Now, MyDateTimeType.Date); if (!Directory.Exists(Path_Bak_New)) { Directory.CreateDirectory(Path_Bak_New); } MoveFile(file, Path_Bak_New); drJIS_Log["FileType"] = filetype; drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Success"; t_JIS_Log.Edit(drJIS_Log); } catch (Exception ex) { if (sr != null) sr.Close(); MyLogger.Write(file.Name + " 处理失败,原因为:" + ex.Message); MoveFile(file, Path_Error); drJIS_Log["FileType"] = filetype; drJIS_Log["EndTime"] = DateTime.Now; drJIS_Log["ProcessState"] = "Failed"; drJIS_Log["Memo"] = MyStrings.GetString(ex.Message); t_JIS_Log.Edit(drJIS_Log); } } } */ #endregion //处理PJIS数据 private static string sss = ""; public static void ProcessDataPJIS(string[] sp_text, string filename) { LocalDBService db = new LocalDBService(); Entity_t_OptionBOM t_OptionBOM = new Entity_t_OptionBOM(); Entity_t_ProdnoRule1 t_ProdnoRule1 = new Entity_t_ProdnoRule1(); Entity_t_ProdnoRule2 t_ProdnoRule2 = new Entity_t_ProdnoRule2(); Entity_t_ModunoABase t_ModunoABase = new Entity_t_ModunoABase(); Entity_t_ProdnoBase t_ProdnoBase = new Entity_t_ProdnoBase(); Entity_t_TTZ_Rule t_TTZ_Rule = new Entity_t_TTZ_Rule(); //增加 总成特殊零件 add by JinH 2023-03-28 var strsql = "select * from t_FGPartStuffix"; var dtPartStuffix = new DataTable(); try { dtPartStuffix = db.Exec_DataSet(strsql).Tables[0]; } catch (Exception e) { throw new Exception("系统中未定义-总成特殊零件"); } //获取基础数据_颜色 用于243、247的具体车型指定 strsql = "select * from t_Color"; var dtAGColorCarType = new DataTable(); try { dtAGColorCarType = db.Exec_DataSet(strsql).Tables[0]; } catch (Exception e) { throw new Exception("系统中未定义-颜色"); } //获取基础数据_特殊零件 用于243、247的具体车型指定 strsql = "select * from t_ColorPart"; var dtAGColorPart = new DataTable(); try { dtAGColorPart = db.Exec_DataSet(strsql).Tables[0]; } catch (Exception e) { throw new Exception("系统中未定义-特殊零件"); } DataTable dtOptionBOM = t_OptionBOM.GetData("", "1=1", "[Code] asc").Tables[0]; DataTable dtProdnoRule1 = t_ProdnoRule1.GetData("", "1=1", "[Code] asc").Tables[0]; DataTable dtProdnoRule2 = t_ProdnoRule2.GetData("", "1=1", "[Sort] asc").Tables[0]; DataTable dtModunoABase = t_ModunoABase.GetData("", "1=1", "[moduno] asc").Tables[0]; DataTable dtProdnoBase = t_ProdnoBase.GetData("", "1=1", "[prodno] asc").Tables[0]; DataTable dtTTZRule = t_TTZ_Rule.GetData("", "1=1", "[Code] asc").Tables[0]; #region 解析文本 var lists = new List(); var lst = new List(); var Lines = new List(); //门板PJIS var LinesCarpet = new List(); //地毯PJIS string MessageDateTime = ""; string UNH = ""; string ProductionNumber = ""; string SequenceNumber = ""; string AssemblyLine = ""; string itemNumber = ""; string quantity = "0"; string Location = ""; string DeliveryDateTime = ""; string Baumuster = ""; string DemandDate = ""; string Address = ""; string AgColor = ""; List lst_plannedLineCode = new List(); List lst_PlanedItems = new List(); List lst_PlanedItemsSegment = new List(); List lst_PlanedProductionNo = new List(); List lst_ModunoABase = new List(); DataRow[] drs_ModunoABase = null; List lstKey = MyAppconfig.ReadValue("地毯A零件").Split(',').ToList(); List lstProductionNumber = new List(); //bool IsReadCode = false; //int IsReadLine = 0; foreach (string line_text in sp_text) { if (line_text.Trim() == "") continue; string[] sp_line = line_text.Split('+'); #region 解析字段 if (sp_line[0] == "UNB") { MessageDateTime = sp_line[4].Trim(); } if(sp_line[0] == "UNH") { UNH = sp_line[1].Trim(); } if(sp_line[0] == "DTM") { DemandDate = sp_line[1].Split(':')[1].Trim(); } if (sp_line[0] == "NAD") { if (sp_line[1] == "BY") Address = sp_line[2].Split(':')[0]; } if (sp_line[0] == "GIR") { if (sp_line[1] == "1") { if (sp_line[2].Split(':')[1] == "AN") { ProductionNumber = sp_line[2].Split(':')[0]; //生产号=当前日期+生产号(防止生产号重复) if(ProductionNumber == "3746552") { string s = ""; } lst.Add(ProductionNumber); } } if (sp_line[1] == "4") { if(Address == "104") { if (sp_line[2].Split(':')[1] == "AB") { SequenceNumber = sp_line[2].Split(':')[0]; } } if (Address == "1046") { if (sp_line[2].Split(':')[1] == "XO") { SequenceNumber = sp_line[2].Split(':')[0]; } } } if (sp_line[1] == "4") { if (sp_line[2].Split(':')[1] == "AC") { AssemblyLine = sp_line[2].Split(':')[0].Trim(); Baumuster = AssemblyLine; if (AssemblyLine.Length > 3) AssemblyLine = AssemblyLine.Substring(0, 3); //Modify By Jinh 2023.04.12 243 247的具体车型通过 基础数据_颜色 和基础数据_特殊零件来指定 if (AssemblyLine == "177") AssemblyLine = "Z177"; // if (AssemblyLine == "247") AssemblyLine = "X247"; if (AssemblyLine == "247") AssemblyLine = "247"; //if (AssemblyLine == "243") AssemblyLine = "X243"; if (AssemblyLine == "243") AssemblyLine = "243"; } foreach (string ss in sp_line) { string[] ss_sp = ss.Split(':'); if (ss_sp.Length == 2) { if (ss_sp[1] == "AG") { AgColor = ss_sp[0]; // if (AssemblyLine == "X247") // { // // if (AgColor == "111" || AgColor == "115") // { // AssemblyLine = "H247"; // } // } } } } // if (AssemblyLine == "X247") // { // // if (AgColor == "111" || AgColor == "115") // { // AssemblyLine = "H247"; // } // } } if (sp_line[1] == "4") { for (int j = 2; j < sp_line.Length; j++) { string[] sp_line_code = sp_line[j].Split(':'); PlannedLineCode plannedLineCode = new PlannedLineCode(); plannedLineCode.Code = sp_line_code[1]; plannedLineCode.Value = sp_line_code[0]; lst_plannedLineCode.Add(plannedLineCode); } } } if(sp_line[0] == "UNT") { // if (AssemblyLine == "243") // { // if (AgColor == "211") // { // var query = lst_PlanedItemsSegment.Where(t => // t.PartNumber.Contains("A2477208005") || // t.PartNumber.Contains("A2477301503") // ).ToList(); // // if (query.Count > 0) // { // AssemblyLine = "H243"; // // foreach (var _query in query) // { // _query.CarType = AssemblyLine; // } // } // // query = lst_PlanedItemsSegment.Where(t => // t.PartNumber.Contains("A2477209604") || // t.PartNumber.Contains("A2477306502") // ).ToList(); // // if (query.Count > 0) // { // AssemblyLine = "X243"; // foreach (var _query in query) // { // _query.CarType = AssemblyLine; // } // // } // // } // else if (AgColor == "101" || // AgColor == "105" || // AgColor == "608" || // AgColor == "688") // { // AssemblyLine = "X243"; // } // else if (AgColor == "111" || // AgColor == "115" || // AgColor == "618" || // AgColor == "698") // { // AssemblyLine = "H243"; // } // // } if (AssemblyLine == "243" || AssemblyLine == "247") { var rowAGColorCarType = dtAGColorCarType.Select($"[Code] = '{AgColor}' and CarType like '%{AssemblyLine}'"); if (rowAGColorCarType.Length == 0) { throw new Exception("系统中未定义-颜色 " + AgColor + " 对应的车型!"); } //有唯一的对应关系,直接取车型 if (rowAGColorCarType.Length == 1) { AssemblyLine = rowAGColorCarType[0]["CarType"].ToString(); } //有多个对应关系时,根据指定的子零件来校验车型 if (rowAGColorCarType.Length > 1) { //从特殊零件表中进行判断 var rowColorPart = dtAGColorPart.Select($"[Color] = '{AgColor}'"); if (rowColorPart.Length == 0) { throw new Exception("系统中未定义-颜色 " + AgColor + " 对应的特殊零件信息!"); } var isFind = false; foreach (var row in rowColorPart) { if (isFind) { break; } var parts = row["PartNumber"].ToString().Split(','); foreach (var part in parts) { if (lst_PlanedItemsSegment.Count(p => p.PartNumber == part) > 0) { AssemblyLine = row["CarType"].ToString(); isFind = true; break; } } } } } foreach (var _item in lst_PlanedItemsSegment) { drs_ModunoABase = dtModunoABase.Select($"[moduno]='{_item.PartNumber}' and [cartype]='{AssemblyLine}'"); if (drs_ModunoABase.Length == 0) { var querylist = lst_ModunoABase.Where(x => x.moduno == _item.PartNumber && x.cartype == AssemblyLine).ToList(); if (querylist.Count == 0) { ModunoABase modunoABase = new ModunoABase(); modunoABase.cartype = AssemblyLine; modunoABase.moduno = _item.PartNumber; lst_ModunoABase.Add(modunoABase); DataRow drModunoABase = t_ModunoABase.Table.NewRow(); drModunoABase["cartype"] = AssemblyLine; drModunoABase["moduno"] = _item.PartNumber; t_ModunoABase.Add(drModunoABase); } } } PlannedLine line = new PlannedLine(); line.MessageDateTime = MessageDateTime; line.UNH = UNH; line.ProductionNo = ProductionNumber; line.SequenceNo = SequenceNumber; line.AssemblyLine = AssemblyLine; line.Location = Location; line.DeliveryDateTime = DeliveryDateTime; line.lst_plannedLineCode = lst_plannedLineCode; line.Baumuster = Baumuster; line.DemandDate = DemandDate; line.Address = Address; PlannedLine planned = null; if (AssemblyLine == "156") { planned = GetOptionBOM(dtOptionBOM, lst_plannedLineCode); } if (AssemblyLine == "Z177" || AssemblyLine == "X247" || AssemblyLine == "H247" || AssemblyLine == "X243" || AssemblyLine == "H243") { planned = GetZ177BOM(dtProdnoRule1, dtProdnoRule2, lst_plannedLineCode, AssemblyLine, dtProdnoBase, Address, dtTTZRule, ProductionNumber); } if (planned == null) { throw new Exception(ProductionNumber + " 解析到需要车型之外的数据"); } line.drOptionBOM = planned.drOptionBOM; line.AdColor = planned.AdColor; line.AgColor = planned.AgColor; line.ErrorMessage = planned.ErrorMessage; Lines.Add(line); foreach(var ItemsSegment in lst_PlanedItemsSegment) { PlanedItem item = new PlanedItem(); item.Address = ItemsSegment.Address; item.CarType = AssemblyLine; item.ProductionNo = ItemsSegment.ProductionNo; item.SequenceNo = ItemsSegment.SequenceNo; item.PartNumber = ItemsSegment.PartNumber; item.Qty = ItemsSegment.Qty; item.DelveryDate = ItemsSegment.DelveryDate; lst_PlanedItems.Add(item); PlannedLine lineCarpet = new PlannedLine(); lineCarpet.MessageDateTime = MessageDateTime; lineCarpet.UNH = UNH; lineCarpet.ProductionNo = ItemsSegment.ProductionNo; lineCarpet.SequenceNo = ItemsSegment.SequenceNo; lineCarpet.AssemblyLine = AssemblyLine; lineCarpet.Location = Location; lineCarpet.DeliveryDateTime = ItemsSegment.DelveryDate; lineCarpet.lst_plannedLineCode = lst_plannedLineCode; lineCarpet.Baumuster = Baumuster; lineCarpet.DemandDate = DemandDate; lineCarpet.moduno = ItemsSegment.PartNumber; lineCarpet.Address = ItemsSegment.Address; lineCarpet.IsCarpet = lstKey.IndexOf(ItemsSegment.PartNumber) >= 0 ? true : false; //判断是否地毯 LinesCarpet.Add(lineCarpet); if (lstProductionNumber.IndexOf(ItemsSegment.ProductionNo) == -1) lstProductionNumber.Add(ItemsSegment.ProductionNo); var q = lst_PlanedProductionNo.Where(x => x.Address == Address && x.ProductionNo == ItemsSegment.ProductionNo).ToArray(); if (q.Length == 0) { PlanedProductionNo p = new PlanedProductionNo(); p.Address = ItemsSegment.Address; p.ProductionNo = ItemsSegment.ProductionNo; lst_PlanedProductionNo.Add(p); } } lst_plannedLineCode = new List(); lst_PlanedItemsSegment = new List(); } if (sp_line[0] == "LIN") { itemNumber = sp_line[3].Split(':')[0]; //drs_ModunoABase = dtModunoABase.Select($"[moduno]='{itemNumber}' and [cartype]='{AssemblyLine}'"); //if (drs_ModunoABase.Length == 0) //{ // var querylist = lst_ModunoABase.Where(x => x.moduno == itemNumber && x.cartype == AssemblyLine).ToList(); // if (querylist.Count == 0) // { // ModunoABase modunoABase = new ModunoABase(); // modunoABase.cartype = AssemblyLine; // modunoABase.moduno = itemNumber; // lst_ModunoABase.Add(modunoABase); // DataRow drModunoABase = t_ModunoABase.Table.NewRow(); // drModunoABase["cartype"] = AssemblyLine; // drModunoABase["moduno"] = itemNumber; // t_ModunoABase.Add(drModunoABase); // } //} } if (sp_line[0] == "LOC") { if (sp_line[1] == "159") { Location = sp_line[2].Split(':')[0]; } } if (sp_line[0] == "QTY") { string[] sp_qty = sp_line[1].Split(':'); if (sp_qty[0] == "113") { quantity = sp_qty[1].Trim(); } } if (sp_line[0] == "DTM") { string[] sp_time = sp_line[1].Split(':'); if (sp_time[0] == "2") { DeliveryDateTime = sp_time[1]; PlanedItem item = new PlanedItem(); item.Address = Address; item.CarType = ""; item.ProductionNo = ProductionNumber; item.SequenceNo = SequenceNumber; item.PartNumber = itemNumber; item.Qty = quantity; //item.DelveryDate = GetDateTime(DeliveryDateTime, ServerDateTimeType.DateTime); item.DelveryDate = DeliveryDateTime; lst_PlanedItemsSegment.Add(item); } } #endregion } #endregion #region 写门板PJIS数据 StringBuilder sb = new StringBuilder(); foreach(PlannedLine line in Lines) { string sql = @" delete from t_PJIS where [ProductionNo]='{ProductionNo}'; INSERT INTO [t_PJIS] ([MessageDateTime] ,[ProductionNo] ,[SequenceNo] ,[type] ,[code] ,[FLProdNo] ,[FRProdNo] ,[RLProdNo] ,[RRProdNo] ,[isalter] ,[LOCATION] ,[Address] ,[DeliveryDateTime] ,[Baumuster] ,[AssemblyLine] ,[sysdtm] ,[filename] ,[UNH] ,[DemandDate] ,[adColor] ,[agColor] ,[UpdateMessage]) VALUES ('{MessageDateTime}' ,'{ProductionNo}' ,'{SequenceNo}' ,'{type}' ,'{code}' ,'{FLProdNo}' ,'{FRProdNo}' ,'{RLProdNo}' ,'{RRProdNo}' , {isalter} ,'{LOCATION}' ,'{Address}' ,'{DeliveryDateTime}' ,'{Baumuster}' ,'{AssemblyLine}' , {sysdtm} ,'{filename}' ,'{UNH}' ,'{DemandDate}' ,'{adColor}' ,'{agColor}' ,'{UpdateMessage}'); "; sql = sql.Replace("{MessageDateTime}", line.MessageDateTime); sql = sql.Replace("{ProductionNo}", line.ProductionNo); sql = sql.Replace("{SequenceNo}", line.SequenceNo); if (line.drOptionBOM != null) { //计算总成特殊零件号 //通过关键件进行判断 string FL = "", FR = "", RL = "", RR = ""; if (dtPartStuffix.Rows.Count > 0) { foreach (PlanedItem item in lst_PlanedItems.Where(p => p.ProductionNo == line.ProductionNo)) { //如果都找到,则跳出不再计算 if (FL != "" && FR != "" && RL != "" && RR != "") { break; } var partNumber = item.PartNumber; var carType = item.CarType; var partRow = dtPartStuffix.Select("PartCode like '%" + partNumber + "%' and CarType = '" + carType + "'"); if (partRow.Length > 0) { for (int i = 0; i < partRow.Length; i++) { if (partRow[i]["Site"].ToString().ToUpper() == "FL") { FL = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "FR") { FR = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "RL") { RL = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "RR") { RR = partRow[i]["Stiffix"].ToString(); continue; } } } } } sql = sql.Replace("{type}", line.drOptionBOM["Type"].ToString()); sql = sql.Replace("{code}", line.drOptionBOM["Code"].ToString()); sql = sql.Replace("{FLProdNo}", line.drOptionBOM["FLProd"].ToString() + FL); sql = sql.Replace("{FRProdNo}", line.drOptionBOM["FRProd"].ToString()+FR); sql = sql.Replace("{RLProdNo}", line.drOptionBOM["RLProd"].ToString()+RL); sql = sql.Replace("{RRProdNo}", line.drOptionBOM["RRProd"].ToString() + RR); if(line.drOptionBOM.Table.Columns.IndexOf("UpdateMessage") >= 0) { sql = sql.Replace("{UpdateMessage}", line.drOptionBOM["UpdateMessage"].ToString()); } else { sql = sql.Replace("{UpdateMessage}", ""); } } else { sql = sql.Replace("{type}", ""); sql = sql.Replace("{code}", ""); sql = sql.Replace("{FLProdNo}", ""); sql = sql.Replace("{FRProdNo}", ""); sql = sql.Replace("{RLProdNo}", ""); sql = sql.Replace("{RRProdNo}", ""); sql = sql.Replace("{UpdateMessage}", ""); } sql = sql.Replace("{isalter}", line.isalter.ToString()); sql = sql.Replace("{LOCATION}", line.Location); sql = sql.Replace("{DeliveryDateTime}", line.DeliveryDateTime); sql = sql.Replace("{Baumuster}", line.Baumuster); sql = sql.Replace("{AssemblyLine}", line.AssemblyLine); sql = sql.Replace("{sysdtm}", "getdate()"); sql = sql.Replace("{filename}", filename); sql = sql.Replace("{UNH}", line.UNH); sql = sql.Replace("{DemandDate}", line.DemandDate); sql = sql.Replace("{adColor}", line.AdColor); sql = sql.Replace("{agColor}", line.AgColor); sql = sql.Replace("{Address}", line.Address); sb.AppendLine(sql); if(sb.Length > 20000) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } } if(sb.Length > 0) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } #endregion #region 写地毯PJIS数据 //判断生产号中有没有未找到地毯零件的记录,如果有就将该订单的第一个零件做为地毯的主零件 foreach(string p in lstProductionNumber) { var q = LinesCarpet.Where(x => x.ProductionNo == p && x.IsCarpet == true).ToArray(); if(q.Length == 0) { q = LinesCarpet.Where(x => x.ProductionNo == p).ToArray(); if(q.Length > 0) { q[0].moduno = ""; q[0].IsCarpet = true; q[0].ErrorMessage = $"PJIS地毯{p}没有主零件,请检查"; F_Mail.SendMail($"{filename}地毯{p}没有主零件,请检查"); } else { F_Mail.SendMail($"{filename}地毯{p}没有零件,请检查PJIS文件"); } } } sb = new StringBuilder(); LinesCarpet = LinesCarpet.Where(x => x.IsCarpet == true).ToList(); foreach (PlannedLine line in LinesCarpet) { string sql = @" delete from t_PJISCarpet where [ProductionNo]='{ProductionNo}'; INSERT INTO [t_PJISCarpet] ([MessageDateTime] ,[ProductionNo] ,[SequenceNo] ,[type] ,[code] ,[FLProdNo] ,[FRProdNo] ,[RLProdNo] ,[RRProdNo] ,[isalter] ,[LOCATION] ,[Address] ,[DeliveryDateTime] ,[Baumuster] ,[AssemblyLine] ,[sysdtm] ,[filename] ,[UNH] ,[DemandDate] ,[moduno] ,[IsError] ,[ErrorMsg]) VALUES ('{MessageDateTime}' ,'{ProductionNo}' ,'{SequenceNo}' ,'{type}' ,'{code}' ,'{FLProdNo}' ,'{FRProdNo}' ,'{RLProdNo}' ,'{RRProdNo}' , {isalter} ,'{LOCATION}' ,'{Address}' ,'{DeliveryDateTime}' ,'{Baumuster}' ,'{AssemblyLine}' , {sysdtm} ,'{filename}' ,'{UNH}' ,'{DemandDate}' ,'{moduno}' , {IsError} ,'{ErrorMsg}'); "; DataRow[] drsModunoABase = dtModunoABase.Select($"[moduno]='{line.moduno}'"); sql = sql.Replace("{type}", ""); sql = sql.Replace("{code}", ""); sql = sql.Replace("{FLProdNo}", ""); sql = sql.Replace("{FRProdNo}", ""); sql = sql.Replace("{RLProdNo}", ""); sql = sql.Replace("{RRProdNo}", ""); sql = sql.Replace("{MessageDateTime}", line.MessageDateTime); sql = sql.Replace("{ProductionNo}", line.ProductionNo); sql = sql.Replace("{SequenceNo}", line.SequenceNo); sql = sql.Replace("{isalter}", line.isalter.ToString()); sql = sql.Replace("{LOCATION}", line.Location); sql = sql.Replace("{DeliveryDateTime}", line.DeliveryDateTime); sql = sql.Replace("{Baumuster}", line.Baumuster); sql = sql.Replace("{AssemblyLine}", line.AssemblyLine); sql = sql.Replace("{sysdtm}", "getdate()"); sql = sql.Replace("{filename}", filename); sql = sql.Replace("{UNH}", line.UNH); sql = sql.Replace("{DemandDate}", line.DemandDate); if(drsModunoABase.Length > 0) { sql = sql.Replace("{moduno}", drsModunoABase[0]["prodno"].ToString()); if(drsModunoABase[0]["prodno"].ToString() == "") { line.ErrorMessage += line.moduno + " 在A零件基础表中未设置对应的总成号\r\n"; } } else { sql = sql.Replace("{moduno}", ""); line.ErrorMessage += line.moduno + " 在A零件基础表中不存在\r\n"; } sql = sql.Replace("{Address}", line.Address); sql = sql.Replace("{IsError}", line.ErrorMessage == "" ? "0" : "1"); sql = sql.Replace("{ErrorMsg}", line.ErrorMessage); sb.AppendLine(sql); if (sb.Length > 20000) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } } if (sb.Length > 0) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } #endregion #region 写A零件明细数据 sb = new StringBuilder(); foreach(PlanedProductionNo p in lst_PlanedProductionNo) { string sql = $"delete from [t_PJISItem] where [Address]='{p.Address}' and [ProductionNo]='{p.ProductionNo}';"; sb.AppendLine(sql); if (sb.Length > 20000) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } } if (sb.Length > 0) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } foreach (PlanedItem item in lst_PlanedItems) { string k = item.Address + "-" + item.ProductionNo + "-" + item.PartNumber; string sql = $@" --delete from [t_PJISItem] where [k]='{k}'; INSERT INTO [t_PJISItem] ([Address] ,[CarType] ,[ProductionNo] ,[SequenceNo] ,[PartNumber] ,[Qty] ,[DelveryDate] ,[filename] ,[k]) VALUES ('{item.Address}' ,'{item.CarType}' ,'{item.ProductionNo}' ,'{item.SequenceNo}' ,'{item.PartNumber}' ,'{item.Qty}' ,'{GetDateTime(item.DelveryDate, ServerDateTimeType.DateTime)}' ,'{filename}' ,'{k}'); "; sb.AppendLine(sql); if (sb.Length > 20000) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } } if (sb.Length > 0) { db.Exec_NonQuery(sb.ToString()); sb = new StringBuilder(); } #endregion #region 匹配门板PJIS的所有零件(为了保证速度,在新的线程中去处理) MatchObject matchobj = new MatchObject(); matchobj.lines = Lines; matchobj.items = lst_PlanedItems; Thread t1 = new Thread(MatchItem); t1.Start(matchobj); #endregion } //按零件号匹配PJIS零件 public static void MatchItem(object obj) { try { Entity_t_PJIS t_PJIS = new Entity_t_PJIS(); Entity_t_Bom t_Bom = new Entity_t_Bom(); List lst = MyAppconfig.ReadValue("地毯A零件").Split(',').ToList(); MatchObject matchobj = (MatchObject)obj; var strsql = "select * from t_FGPartStuffix"; LocalDBService db = new LocalDBService(); var dtPartStuffix = new DataTable(); try { dtPartStuffix = db.Exec_DataSet(strsql).Tables[0]; } catch (Exception e) { throw new Exception("系统中未定义-总成特殊零件"); } foreach (PlannedLine line in matchobj.lines) { if( line.ProductionNo == "3276164") { string s = "abc"; } /* if (line.AssemblyLine != "177" && line.AssemblyLine != "247") { if (line.ErrorMessage != "") { t_PJIS.Edit($"[IsError]=1, [ErrorMsg]='{line.ErrorMessage}'", $"[ProductionNo]='{line.ProductionNo}'"); string mail_body = $"生产号 {line.ProductionNo} 总成零件匹配异常,原因为:
"; mail_body += line.ErrorMessage.Replace("\r\n", "
"); F_Mail.SendMail(mail_body); } continue; } */ string ErrorMsg = ""; try { var querylist = matchobj.items.Where(x => x.ProductionNo == line.ProductionNo && x.CarType == line.AssemblyLine).ToList(); string FLProdNo = line.drOptionBOM["FLProd"].ToString(); string FRProdNo = line.drOptionBOM["FRProd"].ToString(); string RLProdNo = line.drOptionBOM["RLProd"].ToString(); string RRProdNo = line.drOptionBOM["RRProd"].ToString(); //更新OptionBom里的数据 如果是特殊总成 //计算总成特殊零件号 //通过关键件进行判断 string FL = "", FR = "", RL = "", RR = ""; if (dtPartStuffix.Rows.Count > 0) { var lstPartNum = querylist.Select(p=>p.PartNumber).Distinct().ToList(); var parts = ""; foreach (var partNum in lstPartNum) { parts += "'" + partNum + "',"; } if (parts.Length > 0) parts = parts.Substring(0, parts.Length - 1); var partRow = dtPartStuffix.Select("PartCode in (" + parts + ") and CarType = '" + line.AssemblyLine + "'"); if (partRow.Length > 0) { for (int i = 0; i < partRow.Length; i++) { if (partRow[i]["Site"].ToString().ToUpper() == "FL") { FL = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "FR") { FR = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "RL") { RL = partRow[i]["Stiffix"].ToString(); continue; } if (partRow[i]["Site"].ToString().ToUpper() == "RR") { RR = partRow[i]["Stiffix"].ToString(); continue; } } } } FLProdNo += FL; FRProdNo += FR; RLProdNo += RL; RRProdNo += RR; // DataTable dtBom = t_Bom.GetData("[PartNumber], isnull( Sum(Qty), 0) as Qty", $"[CarType]='{line.AssemblyLine}' and ([Code]='{FLProdNo}' or [Code]='{FRProdNo}' or [Code]='{RLProdNo}' or [Code]='{RRProdNo}') group by [PartNumber]", "[PartNumber] asc").Tables[0]; DataTable dtBom = t_Bom.GetData("[PartNumber], isnull( Sum(Qty), 0) as Qty", $" ([Code]='{FLProdNo}' or [Code]='{FRProdNo}' or [Code]='{RLProdNo}' or [Code]='{RRProdNo}') group by [PartNumber]", "[PartNumber] asc").Tables[0]; foreach (DataRow drBom in dtBom.Rows) { if (lst.IndexOf(drBom["PartNumber"].ToString()) >= 0) //跳过地毯的零件 { continue; } var list = querylist.Where(x => x.PartNumber == drBom["PartNumber"].ToString()).ToList(); if (list.Count == 0) { ErrorMsg += $"{drBom["PartNumber"] } 零件在PJIS中不存在\r\n"; } else { if (Convert.ToInt32(drBom["Qty"]) != Convert.ToInt32(list[0].Qty)) { ErrorMsg += $"{drBom["PartNumber"] } 零件数量和PJIS中数量不相等\r\n"; } } } foreach (PlanedItem item in querylist) { if (lst.IndexOf(item.PartNumber) >= 0) //跳过地毯的零件 { continue; } DataRow[] drs = dtBom.Select($"[PartNumber]='{item.PartNumber}'"); if (drs.Length == 0) { ErrorMsg += $"{item.PartNumber} 零件在BOM中不存在\r\n"; } else { if (Convert.ToInt32(item.Qty) != Convert.ToInt32(drs[0]["Qty"])) { ErrorMsg += $"{item.PartNumber} 零件数量和BOM中数量不相等\r\n"; } } } } catch (Exception e) { ErrorMsg += e.Message; } if(ErrorMsg != "" || line.ErrorMessage != "") { ErrorMsg = line.ErrorMessage + ErrorMsg; t_PJIS.Edit($"[IsError]=1, [ErrorMsg]='{ErrorMsg}'", $"[ProductionNo]='{line.ProductionNo}'"); string mail_body = $"生产号 {line.ProductionNo} PJIS和BOM零件匹配异常,原因为:
"; mail_body += ErrorMsg.Replace("\r\n", "
"); F_Mail.SendMail(mail_body); } } } catch (Exception ex) { MyLogger.Write(ex.Message); F_Mail.SendMail(ex.Message); } } //取156的OptionBOM private static PlannedLine GetOptionBOM(DataTable dtOptionBOM, List lineCodes) { //新:编码规则顺序:890-500-U62-877-810-242-808-149-896-X3-X4-X5-X6-X7-X8 剩余6位 PlannedLine ret = new PlannedLine(); string code = ""; List querylist = null; string AdColor = ""; string AgColor = ""; querylist = lineCodes.Where(x => x.Code == "AG").ToList(); if (querylist.Count > 0) { AgColor = querylist[0].Value; if (AgColor == "175") AgColor = "165"; //特殊 if (AgColor == "855") AgColor = "165"; //特殊 } querylist = lineCodes.Where(x => x.Value == "890" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "500" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "U62" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "877" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "810" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "242" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => (x.Value == "808" || x.Value == "809") && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; if(AgColor == "161" || AgColor == "801") { querylist = lineCodes.Where(x => x.Value == "149" && x.Code == "AD").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "896" && x.Code == "AD").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; } else { code += "00"; } querylist = lineCodes.Where(x => x.Value == "X3" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "X4" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "X5" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "X6" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "X7" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; querylist = lineCodes.Where(x => x.Value == "X8" && x.Code == "AE").ToList(); if (querylist.Count > 0) { code += "1"; } else { code += "0"; }; code += AgColor; querylist = lineCodes.Where(x => x.Code == "AD").ToList(); if (querylist.Count > 0) { AdColor = querylist[0].Value; } DataRow[] drsBom = dtOptionBOM.Select($"[Code]='{code}'"); ret.ErrorMessage = ""; if (drsBom.Length > 0) { ret.drOptionBOM = drsBom[0]; } else { ret.ErrorMessage += $"OptionBOM {code} 在系统中不存在\r\n"; } ret.AdColor = AdColor; ret.AgColor = AgColor; ret.Code = code; return ret; } //取177的OptionBOM private static PlannedLine GetZ177BOM(DataTable dtProdnoRule1, DataTable dtProdnoRule2, List lineCodes, string CarType, DataTable dtProdnoBase, string Address, DataTable dtTTZRule, string ProductionNumber) { Entity_t_TTZ_Data t_TTZ_Data = new Entity_t_TTZ_Data(); DataRow[] drsBaseCode = dtProdnoRule1.Select($"[cartype]='{CarType}'", "[Sort] asc"); DataRow[] drsRule = dtProdnoRule2.Select($"[cartype]='{CarType}'", "[Sort] asc"); string BaseCode = ""; // if (Address == "104") // { // BaseCode = "AE"; // } // if (Address == "1046") // { // BaseCode = "AH"; // } BaseCode = "AH"; DataTable dtData = new DataTable(); dtData.Columns.Add("Type"); dtData.Columns.Add("Code"); dtData.Columns.Add("FLProd"); dtData.Columns.Add("FRProd"); dtData.Columns.Add("RLProd"); dtData.Columns.Add("RRProd"); dtData.Columns.Add("UpdateMessage"); DataRow drData = dtData.NewRow(); drData["Type"] = ""; drData["Code"] = CarType; dtData.Rows.Add(drData); if(ProductionNumber == "3501754") { string a = "abc"; } string Code = ""; string FLProd = ""; string FRProd = ""; string RLProd = ""; string RRProd = ""; Code += "M"; if (CarType == "Z177") Code += "Z"; if (CarType == "X247") Code += "X"; if (CarType == "H247") Code += "H"; if (CarType == "X243") Code += "X"; if (CarType == "H243") Code += "H"; FLProd = Code + "FL"; FRProd = Code + "FR"; RLProd = Code + "RL"; RRProd = Code + "RR"; Code = ""; PlannedLine ret = new PlannedLine(); List querylist = null; string AdColor = ""; //外漆颜色 string AgColor = ""; //内饰颜色 querylist = lineCodes.Where(x => x.Code == "AD").ToList(); if (querylist.Count > 0) { AdColor = querylist[0].Value; } querylist = lineCodes.Where(x => x.Code == "AG").ToList(); if (querylist.Count > 0) { AgColor = querylist[0].Value; } #region 计算TTZ规则 /* 1.对于 Z177车型,阶段为19/2的,如果内饰颜色code是267或者是258时,并且生产号下边有853 code,也就是总成号里由字母E时,那么总成号结尾加 -2 2.对于Z177车型,阶段为19/2的,如果内饰颜色code不是267,也不是258时,并且生产号下边有853 code, 那么pjis报错,按当前总成号组成规则,总成号里不带入字母E。 */ string FLProd_Purpose = ""; string FRProd_Purpose = ""; string RLProd_Purpose = ""; string RRProd_Purpose = ""; if(ProductionNumber == "3386516") { string a = ""; } if (CarType == "Z177") { if (AgColor == "267" || AgColor == "258") { //判断有没有853 var s = lineCodes.Where(x => x.Code == "AE" & x.Value == "853").ToList(); if (s.Count > 0) { DataTable dtTTZ_Data = t_TTZ_Data.GetData("top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; if (dtTTZ_Data.Rows.Count > 0) { string Purpose = dtTTZ_Data.Rows[0]["Purpose"].ToString(); if (CarType != dtTTZ_Data.Rows[0]["CarType"].ToString()) { ret.ErrorMessage = $"{ProductionNumber}生产号PJIS车型与TTZ车型不一致"; } if (Purpose != "" && Purpose != "#N/A") { // // DataRow[] drTTZ_Rule = dtTTZRule.Select($"[cartype]='{CarType}' and [Code]='{Purpose}'"); // DataRow[] drTTZ_Rule = dtTTZRule.Select($"[cartype]='{CarType}'"); // if (drTTZ_Rule.Length > 0) // { // //if (Convert.ToBoolean(drTTZ_Rule[0]["FL"])) FLProd_Purpose = "-" + drTTZ_Rule[0]["Value"].ToString(); // //if (Convert.ToBoolean(drTTZ_Rule[0]["FR"])) FRProd_Purpose = "-" + drTTZ_Rule[0]["Value"].ToString(); // if (Convert.ToBoolean(drTTZ_Rule[0]["RL"])) RLProd_Purpose = "-" + drTTZ_Rule[0]["Value"].ToString(); // if (Convert.ToBoolean(drTTZ_Rule[0]["RR"])) RRProd_Purpose = "-" + drTTZ_Rule[0]["Value"].ToString(); // // } } else { //支持阶段号是空的 Purpose = ""; } FLProd_Purpose = GetPurpose(CarType, "FL", dtTTZRule, Purpose); FRProd_Purpose = GetPurpose(CarType, "FR", dtTTZRule, Purpose); RLProd_Purpose = GetPurpose(CarType, "RL", dtTTZRule, Purpose); RRProd_Purpose = GetPurpose(CarType, "RR", dtTTZRule, Purpose); } else { //code1 = 不为空的 // 并且ttzdata没有数据 FLProd_Purpose = GetPurposeTTZNull(CarType, "FL", dtTTZRule); FRProd_Purpose = GetPurposeTTZNull(CarType, "FR", dtTTZRule); RLProd_Purpose = GetPurposeTTZNull(CarType, "RL", dtTTZRule); RRProd_Purpose = GetPurposeTTZNull(CarType, "RR", dtTTZRule); } } } else { //判断有没有853 var s = lineCodes.Where(x => x.Code == "AE" & x.Value == "853").ToList(); if (s.Count > 0) { DataTable dtTTZ_Data = t_TTZ_Data.GetData("top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; if (dtTTZ_Data.Rows.Count > 0) { string Purpose = dtTTZ_Data.Rows[0]["Purpose"].ToString(); if (Purpose != "" && Purpose != "#N/A") { DataRow[] drTTZ_Rule = dtTTZRule.Select($"[cartype]='{CarType}' and [Code]='{Purpose}'"); if (drTTZ_Rule.Length > 0) { ret.ErrorMessage += $"{ProductionNumber} 内饰风格 {AgColor} 但是存在853 Code"; } } } } } DataTable dtTTZ_Data1 = t_TTZ_Data.GetData("top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; if (dtTTZ_Data1.Rows.Count > 0) { string Purpose = dtTTZ_Data1.Rows[0]["Purpose"].ToString(); if (CarType != dtTTZ_Data1.Rows[0]["CarType"].ToString()) { ret.ErrorMessage = $"{ProductionNumber}生产号PJIS车型与TTZ车型不一致"; } if (Purpose != "" && Purpose != "#N/A") { // if(Purpose.IndexOf("21") >= 0) FLProd_Purpose = "-2"; } else { Purpose = ""; } FLProd_Purpose = GetPurpose(CarType, "FL", dtTTZRule, Purpose); } else { //code1 = 不为空的 // 并且ttzdata没有数据 FLProd_Purpose = GetPurposeTTZNull(CarType, "FL", dtTTZRule); } } else if (CarType == "X243" || CarType == "H243") { // FLProd_Purpose = "-2"; //243的不进行t_TTZ_Data导入,认为阶段号是"" string Purpose = ""; DataTable dtTTZ_Data = t_TTZ_Data.GetData("top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; if (dtTTZ_Data.Rows.Count > 0) { Purpose = dtTTZ_Data.Rows[0]["Purpose"].ToString(); if (CarType != dtTTZ_Data.Rows[0]["CarType"].ToString()) { ret.ErrorMessage = $"{ProductionNumber}生产号PJIS车型与TTZ车型不一致"; } if (Purpose != "" && Purpose != "#N/A") { // if (Purpose.IndexOf("21") >= 0) FLProd_Purpose = "-2"; } else { Purpose = ""; } FLProd_Purpose = GetPurpose(CarType, "FL", dtTTZRule, Purpose); } else { //code1 = 不为空的 // 并且ttzdata没有数据 FLProd_Purpose = GetPurposeTTZNull(CarType, "FL", dtTTZRule); } // FLProd_Purpose = GetPurpose(CarType, "FL", dtTTZRule, Purpose); } else if (CarType == "X247" || CarType == "H247") { DataTable dtTTZ_Data = t_TTZ_Data.GetData("top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; if (dtTTZ_Data.Rows.Count > 0) { string Purpose = dtTTZ_Data.Rows[0]["Purpose"].ToString(); if (CarType != dtTTZ_Data.Rows[0]["CarType"].ToString()) { ret.ErrorMessage = $"{ProductionNumber}生产号PJIS车型与TTZ车型不一致"; } if (Purpose != "" && Purpose != "#N/A") { // if (Purpose.IndexOf("21") >= 0) FLProd_Purpose = "-2"; } else { Purpose = ""; } FLProd_Purpose = GetPurpose(CarType, "FL", dtTTZRule, Purpose); } else { //code1 = 不为空的 // 并且ttzdata没有数据 FLProd_Purpose = GetPurposeTTZNull(CarType, "FL", dtTTZRule); } } #endregion //(三位),内饰颜色代码,取后源代码的数字部分, 101A-101 105A-105 104A-104 //程序把颜色代码的字母去掉 Code += MyStrings.GetNumber(AgColor); FLProd += Code; FRProd += Code; RLProd += Code; RRProd += Code; Code = ""; //(两位),装饰板,取源代码数字部分,H15=15 H44=44 H45=45 H55=55 H59=59 H95=95 foreach (DataRow drBaseCode in drsBaseCode) { // querylist = lineCodes.Where(x => x.Value == drBaseCode["Code"].ToString() && x.Code == BaseCode).ToList(); querylist = lineCodes.Where(x => x.Value == drBaseCode["Code"].ToString() && (x.Code == "AE"|| x.Code == "AH")).ToList(); if (querylist.Count > 0) { Code += drBaseCode["Value"].ToString().Trim().ToUpper(); } } FLProd += Code; FRProd += Code; //(选配区)表示选配,221-A 222-B 500-C 810-D 853-E 873-F 877-G U62-H //其中:A和C仅适用左前门,B仅适用右前门, // D和E不同时存在, // G和H不同时存在 DataTable dtGroups = new DataTable(); dtGroups.Columns.Add("groups", typeof(Int32)); foreach (DataRow drRule in drsRule) { int groups = Convert.ToInt32(drRule["groups"]); if (dtGroups.Select($"[groups]='{groups}'").Length == 0) { //querylist = lineCodes.Where(x => x.Value == drRule["code"].ToString() && x.Code == BaseCode).ToList(); querylist = lineCodes.Where(x => x.Value == drRule["code"].ToString() && (x.Code == "AE"|| x.Code == "AH")).ToList(); if (querylist.Count > 0) { // if (drRule["code"].ToString() == "U62") // { // DataTable dtTTZ_Data = t_TTZ_Data.GetData($"top 1 *", $"[ProductionNo]='{ProductionNumber}'", "[ID] desc").Tables[0]; // if (dtTTZ_Data.Rows.Count > 0) // { // string Purpose = dtTTZ_Data.Rows[0]["Purpose"].ToString().Trim(); // if(Purpose != "") // { // //todo // if (Purpose.IndexOf("20/1") >= 0 || // Purpose.IndexOf("20/2") >= 0 || // Purpose.IndexOf("20-1") >= 0 || // Purpose.IndexOf("20-2") >= 0 || // Purpose.IndexOf("21/1") >= 0 || // Purpose.IndexOf("21-1") >= 0 || // Purpose == "X247 PT3 C3" || // Purpose == "H247 C2 PT3" || // Purpose == "X247 C3 PT3" || // // Purpose == "X247 C5 PT2" || // Purpose == "X247 PT2 C5" || // // Purpose == "X247 PT2 C2" || // Purpose == "X247 C2 PT2" // ) // { // continue; // } // // } // } // } if (Convert.ToBoolean(drRule["FL"])) FLProd += drRule["Value"].ToString(); if (Convert.ToBoolean(drRule["FR"])) FRProd += drRule["Value"].ToString(); if (Convert.ToBoolean(drRule["RL"])) RLProd += drRule["Value"].ToString(); if (Convert.ToBoolean(drRule["RR"])) RRProd += drRule["Value"].ToString(); DataRow drGroups = dtGroups.NewRow(); drGroups["groups"] = groups; dtGroups.Rows.Add(drGroups); } } } if(CarType == "X247" || CarType == "H247") { //querylist = lineCodes.Where(x => x.Value == "853" && x.Code == BaseCode).ToList(); querylist = lineCodes.Where(x => x.Value == "853" && (x.Code == "AE" || x.Code == "AH")).ToList(); if (querylist.Count > 0) { ret.ErrorMessage += $"853code后台监控:出现853,"; } } drData["FLProd"] = FLProd + FLProd_Purpose; drData["FRProd"] = FRProd + FRProd_Purpose; drData["RLProd"] = RLProd + RLProd_Purpose; drData["RRProd"] = RRProd + RRProd_Purpose; //ret.ErrorMessage = ""; if (dtProdnoBase.Select($"[prodno]='{drData["FLProd"]}'").Length == 0) ret.ErrorMessage += $"总成零件号 {drData["FLProd"]} 在系统中不存在\r\n"; if (dtProdnoBase.Select($"[prodno]='{drData["FRProd"]}'").Length == 0) ret.ErrorMessage += $"总成零件号 {drData["FRProd"]} 在系统中不存在\r\n"; if (dtProdnoBase.Select($"[prodno]='{drData["RLProd"]}'").Length == 0) ret.ErrorMessage += $"总成零件号 {drData["RLProd"]} 在系统中不存在\r\n"; if (dtProdnoBase.Select($"[prodno]='{drData["RRProd"]}'").Length == 0) ret.ErrorMessage += $"总成零件号 {drData["RRProd"]} 在系统中不存在\r\n"; ret.drOptionBOM = drData; ret.AdColor = AdColor; ret.AgColor = AgColor; return ret; } private static string GetPurpose(string CarType, string position ,DataTable dtTTZRule, string Purpose) { string Prod_Purpose = ""; DataRow[] drTTZ_Rule_RR = dtTTZRule.Select($"[cartype]='{CarType}' and [position] = '{position}'"); if (drTTZ_Rule_RR.Length > 0) { for (int i = 0; i < drTTZ_Rule_RR.Length; i++) { var strCode1 = drTTZ_Rule_RR[i]["code"].ToString(); if(strCode1 == "不包含") { strCode1 = ""; } if (Purpose.Contains(strCode1) && !Purpose.Contains(drTTZ_Rule_RR[i]["code2"].ToString())) { Prod_Purpose = drTTZ_Rule_RR[i]["Value"].ToString(); break; } } } return Prod_Purpose; } /// /// TTZ没有数据时,获取Purpose /// /// /// /// /// private static string GetPurposeTTZNull(string CarType, string position, DataTable dtTTZRule) { string Prod_Purpose = ""; DataRow[] drTTZ_Rule_RR = dtTTZRule.Select($"[cartype]='{CarType}' and [position] = '{position}'"); if (drTTZ_Rule_RR.Length > 0) { for (int i = 0; i < drTTZ_Rule_RR.Length; i++) { var strCode1 = drTTZ_Rule_RR[i]["code"].ToString(); if (strCode1 == "不包含") { Prod_Purpose = drTTZ_Rule_RR[i]["Value"].ToString(); break; } } } return Prod_Purpose; } //处理AJIS数据 public static void ProcessDataAJIS(string[] sp_text, string filename) { string MessageDateTime = ""; string UNH = ""; string ProductionNo = ""; string ArrivalDateTime = ""; string SequenceNo = ""; string Address = ""; foreach (string line_text in sp_text) { if (line_text.Trim() == "") continue; string[] sp_line = line_text.Split('+'); if (sp_line[0] == "UNB") { MessageDateTime = sp_line[4].Trim(); } if (sp_line[0] == "UNH") { UNH = sp_line[1].Trim(); } if (sp_line[0] == "DTM") { string[] sp = sp_line[1].Split(':'); if (sp[0] == "132") { ArrivalDateTime = sp[1]; } } if (sp_line[0] == "NAD") { if (sp_line[1] == "BY") Address = sp_line[2].Split(':')[0]; } if (sp_line[0] == "GIR") { if (sp_line[1] == "1") { if (sp_line[2].Split(':')[1] == "AN") { ProductionNo = sp_line[2].Split(':')[0]; } } if (sp_line[1] == "4") { SequenceNo = sp_line[2].Split(':')[0]; string ErrorMsg = ""; string ErrorMsgCarpet = ""; LocalDBService db = null; try { db = new LocalDBService(); db.BeginTrans(); Entity_t_AJIS t_AJIS = new Entity_t_AJIS(db); Entity_t_AJISCarpet t_AJISCarpet = new Entity_t_AJISCarpet(db); Entity_t_PJIS t_PJIS = new Entity_t_PJIS(); Entity_t_PJISCarpet t_PJISCarpet = new Entity_t_PJISCarpet(); DataTable dtPJIS = t_PJIS.GetData($"[ProductionNo]='{ProductionNo}'").Tables[0]; if (dtPJIS.Rows.Count == 0) { ErrorMsg += $"{ProductionNo} 未找到门板PJIS,请检查数据\r\n"; } else { if (Convert.ToBoolean(dtPJIS.Rows[0]["IsError"])) { ErrorMsg += $"{ProductionNo} 门板PJIS有错误未处理,请检查并处理"; } } DataTable dtPJISCarpet = t_PJISCarpet.GetData($"[ProductionNo]='{ProductionNo}'").Tables[0]; if (dtPJISCarpet.Rows.Count == 0) { ErrorMsgCarpet += $"{ProductionNo} 未找到地毯PJIS,请检查数据\r\n"; } else { if (Convert.ToBoolean(dtPJISCarpet.Rows[0]["IsError"])) { ErrorMsgCarpet += $"{ProductionNo} 地毯PJIS有错误未处理,请检查并处理\r\n"; } } DataTable dtAJIS = t_AJIS.GetData($"[ProductionNo]='{ProductionNo}'").Tables[0]; if (dtAJIS.Rows.Count > 0) { if( Convert.ToDateTime( GetDateTime( dtAJIS.Rows[0]["MessageDateTime"].ToString().Replace(":", ""), ServerDateTimeType.DateTime)) < Convert.ToDateTime(GetDateTime( MessageDateTime.Replace(":", ""), ServerDateTimeType.DateTime))) { if (Convert.ToBoolean(dtAJIS.Rows[0]["IsPost"])) throw new Exception($"{ProductionNo}已经打印序列单,不能覆盖"); t_AJIS.Del(dtAJIS.Rows[0]); } else { return; } } DataTable dtAJISCarpet = t_AJISCarpet.GetData($"[ProductionNo]='{ProductionNo}'").Tables[0]; if (dtAJISCarpet.Rows.Count > 0) { if (Convert.ToDateTime(GetDateTime(dtAJISCarpet.Rows[0]["MessageDateTime"].ToString().Replace(":", ""), ServerDateTimeType.DateTime)) < Convert.ToDateTime(GetDateTime(MessageDateTime.Replace(":", ""), ServerDateTimeType.DateTime))) { if (Convert.ToBoolean(dtAJISCarpet.Rows[0]["IsPost"])) throw new Exception($"{SequenceNo}已经打印序列单,不能覆盖"); t_AJISCarpet.Del(dtAJISCarpet.Rows[0]); } } DataRow drAJIS = t_AJIS.Table.NewRow(); drAJIS["MessageDateTime"] = MessageDateTime; drAJIS["ProductionNo"] = ProductionNo; drAJIS["SequenceNo"] = SequenceNo; drAJIS["ArrivalDateTime"] = ArrivalDateTime; drAJIS["FileName"] = filename; drAJIS["UNH"] = UNH; drAJIS["type"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["type"].ToString() : ""; drAJIS["code"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["code"].ToString() : ""; drAJIS["FLProdNo"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["FLProdNo"].ToString() : ""; drAJIS["FRProdNo"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["FRProdNo"].ToString() : ""; drAJIS["RLProdNo"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["RLProdNo"].ToString() : ""; drAJIS["RRProdNo"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["RRProdNo"].ToString() : ""; drAJIS["AssemblyLine"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["AssemblyLine"].ToString() : ""; drAJIS["Baumuster"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["Baumuster"].ToString() : ""; drAJIS["Location"] = dtPJIS.Rows.Count > 0 ? dtPJIS.Rows[0]["Location"].ToString() : ""; drAJIS["Address"] = Address; if (ErrorMsg != "") { drAJIS["IsError"] = true; drAJIS["ErrorMsg"] = ErrorMsg; } t_AJIS.Add(drAJIS); DataRow drAJISCarpet = t_AJISCarpet.Table.NewRow(); drAJISCarpet["MessageDateTime"] = MessageDateTime; drAJISCarpet["ProductionNo"] = ProductionNo; drAJISCarpet["SequenceNo"] = SequenceNo; drAJISCarpet["ArrivalDateTime"] = ArrivalDateTime; drAJISCarpet["FileName"] = filename; drAJISCarpet["UNH"] = UNH; drAJISCarpet["moduno"] = dtPJISCarpet.Rows.Count > 0 ? dtPJISCarpet.Rows[0]["moduno"].ToString() : ""; drAJISCarpet["AssemblyLine"] = dtPJISCarpet.Rows.Count > 0 ? dtPJISCarpet.Rows[0]["AssemblyLine"].ToString() : ""; drAJISCarpet["Baumuster"] = dtPJISCarpet.Rows.Count > 0 ? dtPJISCarpet.Rows[0]["Baumuster"].ToString() : ""; drAJISCarpet["Location"] = dtPJISCarpet.Rows.Count > 0 ? dtPJISCarpet.Rows[0]["Location"].ToString() : ""; drAJISCarpet["Address"] = Address; if (ErrorMsg != "") { drAJISCarpet["IsError"] = true; drAJISCarpet["ErrorMsg"] = ErrorMsgCarpet; } t_AJISCarpet.Add(drAJISCarpet); //写接口 if (ErrorMsg == "") { Entity_byAJISToMES byAJISToMES = new Entity_byAJISToMES(); DataRow drbyAJISToMES = byAJISToMES.Table.NewRow(); drbyAJISToMES["ProductionNo"] = ProductionNo; drbyAJISToMES["SequenceNo"] = SequenceNo; drbyAJISToMES["FLProdNo"] = dtPJIS.Rows[0]["FLProdNo"].ToString(); drbyAJISToMES["FRProdNo"] = dtPJIS.Rows[0]["FRProdNo"].ToString(); drbyAJISToMES["RLProdNo"] = dtPJIS.Rows[0]["RLProdNo"].ToString(); drbyAJISToMES["RRProdNo"] = dtPJIS.Rows[0]["RRProdNo"].ToString(); byAJISToMES.Add(drbyAJISToMES); } db.Commit(); } catch (Exception ex) { if (db != null) db.Rollback(); throw ex; } finally { if (db != null) db.EndTrans(); } } } } } //处理预测Delfor public static void ProcessDELFOR(string[] sp_text, string filename) { Entity_t_DELFOR t_DELFOR = new Entity_t_DELFOR(); Entity_t_DELFOR_All t_DELFOR_All = new Entity_t_DELFOR_All(); Entity_t_ModunoABase t_ModunoABase = new Entity_t_ModunoABase(); string SupplierID = ""; string Address = ""; string CalloffNumber = ""; string CalloffDate = ""; string CalloffNumberOld = ""; string CalloffDateOld = ""; string OrderNumber = ""; string LastDeliveryNoteNumber = ""; string LastDeliveryNoteDate = ""; string LastDeliveryNoteQuantity = "0"; string CumQtyReceive = "0"; string TransmissionNumber = ""; string Storage = ""; string Plant = ""; string Dock = ""; string PartNumber = ""; string PartDescription = ""; string Status = ""; string Rate = ""; string Quantity = "0"; string StartDate = ""; string EndDate = ""; bool IsGetCallOffOld = false; #region 解析数据字段 foreach (string line_text in sp_text) { if (line_text.Trim() == "") continue; string[] sp_line = line_text.Split('+'); if (sp_line[0] == "UNH") { TransmissionNumber = sp_line[1]; } if (sp_line[0] == "NAD") { if (sp_line[1] == "SE") SupplierID = sp_line[2].Split(':')[0]; } if (sp_line[0] == "NAD") { if (sp_line[1] == "BY") Address = sp_line[2].Split(':')[0]; } if (sp_line[0] == "RFF") { if (sp_line[1].Split(':')[0] == "AAN") CalloffNumber = sp_line[1].Split(':')[1]; } if (sp_line[0] == "UNB") { CalloffDate = sp_line[4].Split(':')[0]; } if (sp_line[0] == "RFF") { if (sp_line[1].Split(':')[0] == "AIF") { CalloffNumberOld = ""; if (sp_line[1].Split(':').Length >= 2) { CalloffNumberOld = sp_line[1].Split(':')[1]; } } } if (sp_line[0] == "RFF") { if (sp_line[1].Split(':')[0] == "ON") { OrderNumber = sp_line[1].Split(':')[1]; //删除原来的数据 t_DELFOR.Del($"[Address]='{Address}' and [Plant]='{Plant}' and [PartNumber]='{PartNumber}' and [Dock]='{Dock}'"); } } if (sp_line[0] == "RFF") { if (sp_line[1].Split(':')[0] == "AAK") LastDeliveryNoteNumber = sp_line[1].Split(':')[1]; } if (sp_line[0] == "DTM") { if (sp_line[1].Split(':')[0] == "11") LastDeliveryNoteDate = sp_line[1].Split(':')[1]; } if (sp_line[0] == "QTY") { if (sp_line[1].Split(':')[0] == "12") LastDeliveryNoteQuantity = sp_line[1].Split(':')[1]; } if (sp_line[0] == "QTY") { if (sp_line[1].Split(':')[0] == "70") CumQtyReceive = sp_line[1].Split(':')[1]; } if (sp_line[0] == "LOC") { if (sp_line[1] == "159") { Storage = sp_line[2].Split(':')[0]; } } if (sp_line[0] == "NAD") { if (sp_line[1] == "ST") Plant = sp_line[2].Split(':')[0]; } if (sp_line[0] == "LOC") { if (sp_line[1] == "11") { Dock = sp_line[2].Split(':')[0]; } } if (sp_line[0] == "LIN") { PartNumber = sp_line[3].Split(':')[0]; PartDescription = ""; //取描述 DataTable dt = t_ModunoABase.GetData($"[moduno]='{PartNumber}'").Tables[0]; if (dt.Rows.Count > 0) PartDescription = dt.Rows[0]["Description"].ToString(); } if (sp_line[0] == "QTY") { string[] sp_qty = sp_line[1].Split(':'); if (sp_qty[0] == "113") Quantity = sp_qty[1]; } if (sp_line[0] == "SCC") { //inforamtion = (sp_line.Length >= 2 ? sp_line[1] : "") + " " + (sp_line.Length >= 4 ? sp_line[3] : ""); Status = ""; Rate = ""; if (sp_line.Length >= 2) Status = sp_line[1]; if (sp_line.Length >= 4) Rate = sp_line[3]; } if (sp_line[0] == "DTM") { string[] sp_time = sp_line[1].Split(':'); if (sp_time[0] == "2") StartDate = sp_time[1]; //单独要货日期 if (sp_time[0] == "191") StartDate = sp_time[1]; //单独要货日期 if (sp_time[0] == "158") StartDate = sp_time[1]; //按时间段要货 if (sp_time[0] == "159") EndDate = sp_time[1]; //按时间段要货 if (sp_time[0] == "194") StartDate = sp_time[1]; //按时间段要货 if (sp_time[0] == "206") EndDate = sp_time[1]; //按时间段要货 //DTM + 2 '要货日期 //DTM + 158 '开始日期 //DTM + 159 '结束日期 //DTM + 191 '要货日期 //DTM + 194 '开始日期 //DTM + 206 '结束日期 //DTM + 323 '从第多少周到多少周 201905-201915 //2019第05周到2019第15周 先不用 if (sp_time[0] == "2" || sp_time[0] == "191" || sp_time[0] == "159" || sp_time[0] == "206") { if (sp_time[0] == "2") EndDate = ""; if (sp_time[0] == "191") EndDate = ""; if (StartDate.Trim() == "") continue; if (!IsGetCallOffOld) { //取上一个版本的日期 DataTable dtLast = t_DELFOR_All.GetData("top 1 CalloffDate", $"[Address]='{Address}' and [Plant]='{Plant}' and [PartNumber]='{PartNumber}' and [Dock]='{Dock}' and [CalloffNumber]<='{CalloffNumber}'", "[CalloffNumber] desc").Tables[0]; if (dtLast.Rows.Count > 0) { if (dtLast.Rows[0]["CalloffDate"] != DBNull.Value) { CalloffDateOld = Convert.ToDateTime(dtLast.Rows[0]["CalloffDate"]).ToString("yyyy-MM-dd"); } } IsGetCallOffOld = true; } DataRow drNew = t_DELFOR.Table.NewRow(); drNew["SupplierID"] = SupplierID; drNew["Address"] = Address; drNew["CalloffNumber"] = CalloffNumber; drNew["CalloffDate"] = GetDateTime(CalloffDate, ServerDateTimeType.Date); drNew["CalloffNumberOld"] = CalloffNumberOld; if(CalloffDateOld != "") drNew["CalloffDateOld"] = CalloffDateOld; drNew["OrderNumber"] = OrderNumber; drNew["LastDeliveryNoteNumber"] = LastDeliveryNoteNumber; if(LastDeliveryNoteDate != "") drNew["LastDeliveryNoteDate"] = GetDateTime(LastDeliveryNoteDate, ServerDateTimeType.Date); drNew["LastDeliveryNoteQuantity"] = LastDeliveryNoteQuantity; drNew["CumQtyReceive"] = CumQtyReceive; drNew["TransmissionNumber"] = TransmissionNumber; drNew["Storage"] = Storage; drNew["Plant"] = Plant; drNew["Dock"] = Dock; drNew["PartNumber"] = PartNumber; drNew["PartDescription"] = PartDescription; drNew["Quantity"] = Quantity; drNew["StartDate"] = GetDateTime(StartDate, ServerDateTimeType.Date); if (EndDate != "") drNew["EndDate"] = GetDateTime(EndDate, ServerDateTimeType.Date); drNew["Status"] = Status; drNew["Rate"] = Rate; drNew["filename"] = filename; t_DELFOR.Add(drNew); DataRow drNewAll = t_DELFOR_All.Table.NewRow(); drNewAll["SupplierID"] = SupplierID; drNewAll["Address"] = Address; drNewAll["CalloffNumber"] = CalloffNumber; drNewAll["CalloffDate"] = GetDateTime(CalloffDate, ServerDateTimeType.Date); drNewAll["CalloffNumberOld"] = CalloffNumberOld; if (CalloffDateOld != "") drNewAll["CalloffDateOld"] = CalloffDateOld; drNewAll["OrderNumber"] = OrderNumber; drNewAll["LastDeliveryNoteNumber"] = LastDeliveryNoteNumber; if (LastDeliveryNoteDate != "") drNewAll["LastDeliveryNoteDate"] = GetDateTime(LastDeliveryNoteDate, ServerDateTimeType.Date); drNewAll["LastDeliveryNoteQuantity"] = LastDeliveryNoteQuantity; drNewAll["CumQtyReceive"] = CumQtyReceive; drNewAll["TransmissionNumber"] = TransmissionNumber; drNewAll["Storage"] = Storage; drNewAll["Plant"] = Plant; drNewAll["Dock"] = Dock; drNewAll["PartNumber"] = PartNumber; drNewAll["PartDescription"] = PartDescription; drNewAll["Quantity"] = Quantity; drNewAll["StartDate"] = GetDateTime(StartDate, ServerDateTimeType.Date); if (EndDate != "") drNewAll["EndDate"] = GetDateTime(EndDate, ServerDateTimeType.Date); drNewAll["Status"] = Status; drNewAll["Rate"] = Rate; drNew["filename"] = filename; t_DELFOR_All.Add(drNewAll); } } } #endregion } #endregion #region 私有函数 private static void MoveFile(FileInfo file, string MovePath) { //string filename1 = Path_Receive_YZ + "\\" + file.Name; string filename1 = file.FullName; string filename2 = MovePath + "\\" + file.Name; try { if (File.Exists(filename2)) File.Delete(filename2); File.Move(filename1, filename2); } catch (Exception ex) { MyLogger.Write("移动文件错误 " + filename1 + "->" + filename2 + ",原因为:" + ex.Message); } } private static void MoveFile(FileInfo file, string MovePath, string NewName) { //string filename1 = Path_Receive_YZ + "\\" + file.Name; string filename1 = file.FullName; string filename2 = MovePath + "\\" + NewName + file.Name; try { if (File.Exists(filename2)) File.Delete(filename2); File.Move(filename1, filename2); } catch (Exception ex) { MyLogger.Write("移动文件错误 " + filename1 + "->" + filename2 + ",原因为:" + ex.Message); } } private static string IsFileOK(string[] sp_text, string filename) { if (sp_text[0].Substring(0, 3) != "UNA") throw new Exception(filename + " 不以UNA开头"); if (sp_text[sp_text.Length - 2].Substring(0, 3) != "UNZ") throw new Exception(filename + " 不以UNZ结尾"); if (sp_text[sp_text.Length - 3].Substring(0, 3) != "UNT") throw new Exception(filename + " 未找到UNT"); //int segment_count = Convert.ToInt32(sp_text[sp_text.Length - 3].Split('+')[1]); //if (segment_count != sp_text.Length - 4) throw new Exception(filename + " 段数不正确"); string BGM = sp_text[3]; if (BGM.Substring(0, 3) != "BGM") throw new Exception(filename + " 未找到BGM"); if (BGM.IndexOf("+241+") >= 0) return "241-DELFOR"; if (BGM.IndexOf("+307:") >= 0) { if (BGM.IndexOf("JSP") >= 0) return "307-JSP"; if (BGM.IndexOf("JSA") >= 0) return "307-JSA"; } return ""; } private static string GetDateTime(string sDateTime, ServerDateTimeType dType) { if (sDateTime.Length != 6 && sDateTime.Length != 8 && sDateTime.Length != 10 && sDateTime.Length != 12 && sDateTime.Length != 14) throw new Exception("[" + sDateTime + "]日期时间格式错误!"); string Result = ""; string year = ""; string month = ""; string day = ""; string h = ""; string m = ""; string s = ""; string mi = "0"; if (sDateTime.Length == 6) { year = "20" + sDateTime.Substring(0, 2); month = sDateTime.Substring(2, 2); day = sDateTime.Substring(4, 2); h = "0"; m = "0"; s = "0"; mi = "0"; } else { if (sDateTime.Length == 10) { year = "20" + sDateTime.Substring(0, 2); month = sDateTime.Substring(2, 2); day = sDateTime.Substring(4, 2); h = sDateTime.Substring(6, 2); m = sDateTime.Substring(8, 2); s = "0"; } else { year = sDateTime.Substring(0, 4); month = sDateTime.Substring(4, 2); day = sDateTime.Substring(6, 2); h = sDateTime.Length != 8 ? sDateTime.Substring(8, 2) : "0"; m = sDateTime.Length != 8 ? sDateTime.Substring(10, 2) : "0"; s = sDateTime.Length != 8 ? (sDateTime.Length == 14 ? sDateTime.Substring(12, 2) : "0") : "0"; mi = "0"; } } if (month.Length == 1) month = "0" + month; if (day.Length == 1) day = "0" + day; if (h.Length == 1) h = "0" + h; if (m.Length == 1) m = "0" + m; if (s.Length == 1) s = "0" + s; if (mi.Length == 1) mi = "00" + mi; if (mi.Length == 2) mi = "0" + mi; if (dType == ServerDateTimeType.DateTime) { Result = year + "-" + month + "-" + day + " " + h + ":" + m + ":" + s; } if (dType == ServerDateTimeType.Date) { Result = year + "-" + month + "-" + day; } if (dType == ServerDateTimeType.Time) { Result = h + ":" + m + ":" + s; } if (dType == ServerDateTimeType.Batch) { Result = year.Substring(2, 2) + month + day; } if (dType == ServerDateTimeType.BillNo) { Result = year + month + day + h + m + s + mi; } return Result; } #endregion #region 判断文件是否被占用 [DllImport("kernel32.dll")] private static extern IntPtr _lopen(string lpPathName, int iReadWrite); [DllImport("kernel32.dll")] private static extern bool CloseHandle(IntPtr hObject); private static bool IsUseFile(string filename) { const int OF_READWRITE = 2; const int OF_SHARE_DENY_NONE = 0x40; IntPtr HFILE_ERROR = new IntPtr(-1); if (!File.Exists(filename)) throw new Exception(filename + " 文件不存在"); IntPtr vHandle = _lopen(filename, OF_READWRITE | OF_SHARE_DENY_NONE); if (vHandle == HFILE_ERROR) { return true; } CloseHandle(vHandle); return false; } #endregion } #region 其他类 public enum ServerDateTimeType { DateTime = 1, Date = 2, Date2 = 6, Date3 = 13, Time = 3, Time1 = 10, Time2 = 11, Time3 = 12, //10:02 Batch = 4, BillNo = 5, DateTime1 = 6, //01.02.2014 DateTime2 = 7, //01.02.2014 06.07s DateTime3 = 9, //2014-01-20 18:50 YearMonth = 8, } public class PlannedLine { public string MessageDateTime = ""; public string ProductionNo = ""; public string SequenceNo = ""; public string AssemblyLine = ""; public string Location = ""; public string DeliveryDateTime = ""; public List lst_plannedLineCode; public DataRow drOptionBOM; public string AdColor; public string AgColor; public int isalter = 0; public string Baumuster; public string UNH; public string DemandDate; public string Code; public string moduno; public string Address; public string ErrorMessage = ""; public bool IsCarpet = false; //是否地毯 } public class PlannedLineCode { public string Code; public string Value; } public class ModunoABase { public string cartype; public string moduno; } public class PlanedItem { public string Address; public string CarType; public string ProductionNo; public string SequenceNo; public string PartNumber; public string Qty; public string DelveryDate; } public class MatchObject { public List lines; public List items; } public class PlanedProductionNo { public string Address; public string ProductionNo; } #endregion }