using Cksoft.Data; using Cksoft.Unity; using DllEapDal.OFILM.MES; using DllEapEntity; using DllEapEntity.Rms; using DllHsms; using DllHsmsWeb; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Xml; using ZipFileHelper; namespace DllEapDal { public class StripMapDal { private IDatabase CurrDb = null; public StripMapDal(IDatabase db) { CurrDb = db; } private OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval, ref string errorinfo) { //读取机台信息 string condition = $" and a.macid={macid}"; List macs = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (macs == null) return null; if (macs.Count <= 0) { errorinfo = $"未找到机台ID【{macid}】的机台指令信息。"; return null; } condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval}"; List details = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (details == null) return null; if (details.Count <= 0) { errorinfo = "未找到您要的指令。"; return null; } return details[0]; } private OrderDetail ReadMachineOrderDetailByName(int macid, string fname, int sval, int fval, ref string errorinfo) { //读取机台信息 string condition = $" and a.macid={macid}"; List macs = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (macs == null) return null; if (macs.Count <= 0) { errorinfo = $"未找到机台ID【{macid}】的机台指令信息。"; return null; } condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval} and a.fname='{fname}'"; List details = CurrDb.FindListForCondition(condition, ref errorinfo).ToList(); if (details == null) return null; if (details.Count <= 0) { errorinfo = "未找到您要的指令。"; return null; } return details[0]; } public int RequestStripmap(OrderBlock entitys, ref string errorinfo) { try { Machine mac = CurrDb.FindListForCondition($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault(); if (mac == null) { errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。"; return -1; } //获取strip id string stripid = GetStripMapId(entitys.Datalists, ref errorinfo); if (stripid == "") return -1; OrderDetail order = ReadMachineOrderDetail(mac.ID, 14, 2, ref errorinfo); if (order == null) { errorinfo = $"读取指令S14F2发生异常:{errorinfo}"; return -1; } //strip map数据 var content = $"11111111\n11111111\n11111111"; var stripInfo = new StripMapInfo { LotId = "LOT0001", StripDetail = content, SubstrateId = stripid }; string stripmap = StripMapFileGenerator.CreateStripMapXmlV4(stripInfo, ref errorinfo); //string stripmap = StripMapFileGenerator.CreateStripMapXmlV2(stripInfo, ref errorinfo); //string stripmap = StripMapFileGenerator.CreateStripMapXmlV3(stripInfo, ref errorinfo); List datas = GetS14F2Datas(order, stripid, stripmap, ref errorinfo); if (datas == null) { errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}"; return -1; } HsmsWeb accessmac = new HsmsWeb(); int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo); if (result <= 0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } public int RequestStripmapE142(OrderBlock entitys, ref string errorinfo) { try { Machine mac = CurrDb.FindListForCondition($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault(); if (mac == null) { errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。"; return -1; } //macsecv = GetOrderS6F11Dt(details, repostdetails, ref errorinfo); //if (macsecv == null) //{ // errorinfo = "GetOrderS6F11Dt函数错误:" + errorinfo; // return null; //} //获取strip id string stripid = GetStripMapId(entitys.Datalists, ref errorinfo); if (stripid == "") return -1; OrderDetail order = ReadMachineOrderDetailByName(mac.ID, "s14f2e142", 14, 2, ref errorinfo); if (order == null) { errorinfo = $"读取指令S14F2发生异常:{errorinfo}"; return -1; } //strip map数据 int rows = 4; int columns = 9; int orginloc = 1; string stripmap = StripMapFileGenerator.CreateStripMapXmlV301(stripid, rows, columns, ref errorinfo); List datas = GetS14F2Datas(order, stripid, stripmap, ref errorinfo); if (datas == null) { errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}"; return -1; } HsmsWeb accessmac = new HsmsWeb(); int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo); if (result <= 0) return -1; // 进站 var ofTrackDal = new OfTrackMstDal(CurrDb); if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", 1, ref errorinfo) < 0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } public int RequestStripmapG84(OrderBlock entitys, ref string errorinfo) { try { Machine mac = CurrDb.FindListForCondition($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault(); if (mac == null) { errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。"; return -1; } //获取strip id string stripid = GetStripMapId(entitys.Datalists, ref errorinfo); if (stripid == "") return -1; OrderDetail order = ReadMachineOrderDetailByName(mac.ID, "s14f2G84", 14, 2, ref errorinfo); if (order == null) { errorinfo = $"读取指令S14F2发生异常:{errorinfo}"; return -1; } //strip map数据 int rows = 4; int columns = 9; int orginloc = 1; List datas = GetS14F2DatasG84(order, stripid, rows, columns, orginloc, ref errorinfo); if (datas == null) { errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}"; return -1; } HsmsWeb accessmac = new HsmsWeb(); int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo); if (result <= 0) return -1; // 进站 var ofTrackDal = new OfTrackMstDal(CurrDb); if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", 1, ref errorinfo) < 0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } /// /// 接收到机台上传的StripMap后解析出StripId出站 /// /// /// /// /// public int RequestUploadStripMap(OrderBlock entitys, List reportDetails, ref string errorinfo) { try { Machine mac = CurrDb.FindListForCondition($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault(); if (mac == null) { errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。"; return -1; } //获取strip id string stripid = GetStripId(entitys.Datalists, reportDetails, ref errorinfo); if (stripid == "") return -1; // 出站 var ofTrackDal = new OfTrackMstDal(CurrDb); if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", -1, ref errorinfo) < 0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } public int RequestUploadStripMapE142(OrderBlock entitys, List reportDetails, ref string errorinfo) { try { Machine mac = CurrDb.FindListForCondition($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault(); if (mac == null) { errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。"; return -1; } //获取strip id string stripid = GetStripMapIdFromE142(entitys.Datalists, ref errorinfo); if (stripid == "") return -1; // 出站 var ofTrackDal = new OfTrackMstDal(CurrDb); if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", -1, ref errorinfo) < 0) return -1; return 1; } catch (Exception ex) { errorinfo = ex.ToString(); return -1; } } private List GetS14F2DatasG84(OrderDetail order, string stripid, int rows, int columns, int originloc, ref string errorinfo) { try { // < L[2] //< L[1] // < L[2] // < A[10] 1190523619 > // < L[5] // < L[2] // < A[14] OriginLocation > // < U4[1] 1 > // > // < L[2] // < A[4] Rows > // < U4[1] 3 > // > // < L[2] // < A[7] Columns > // < U4[1] 8 > // > // < L[2] // < A[10] CellStatus > // < U4[24] 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 > // > // < L[2] // < A[11] DefectCodes > // < U4[24] 200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200,200 > // > // > // > // > // < L[1] // < L[2] // < U1[1] 0 > // < L[0] // > // > // > // > List datas = CurrDb.FindListForCondition($" and a.preid={order.ID}", ref errorinfo).ToList(); List tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第二个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L的子节点 0位置为stripid,1位置为第四个L tempdatas[0].FContent = stripid; List fourels = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();// 第4个L的子节点 tempdatas = datas.Where(t => t.ParentID == fourels[0].ID).ToList();// tempdatas[1].FContent = originloc.ToString(); tempdatas = datas.Where(t => t.ParentID == fourels[1].ID).ToList();// tempdatas[1].FContent = rows.ToString(); tempdatas = datas.Where(t => t.ParentID == fourels[2].ID).ToList();// tempdatas[1].FContent = columns.ToString(); int vcount = rows * columns; string cellstr = ""; string defstr = ""; for (int i = 0; i < vcount; i++) { if (i == 0) { cellstr = "0"; defstr = "200"; } else { cellstr += ",0"; defstr += ",200"; } } tempdatas = datas.Where(t => t.ParentID == fourels[3].ID).ToList();// tempdatas[1].FContent = cellstr; tempdatas = datas.Where(t => t.ParentID == fourels[4].ID).ToList();// tempdatas[1].FContent = defstr; return datas; } catch (Exception ex) { errorinfo = ex.ToString(); return null; } } private List GetS14F2Datas(OrderDetail order, string stripid, string stripmap, ref string errorinfo) { try { // < L[2] 第一个L //< L[1] 第二个L //< L[2] 第三个L //< A "1003175743" > // < L[1] 第四个L // < L[2] 第五个L // < A "MapData" > // < A " List datas = CurrDb.FindListForCondition($" and a.preid={order.ID}", ref errorinfo).ToList(); List tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第二个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L的子节点 0位置为stripid,1位置为第四个L tempdatas[0].FContent = stripid; tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取第五个L 0位置 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第五个L的子节点 0位置为< A "MapData" >,1位置为< A " tempdatas[1].FContent = stripmap; tempdatas[1].FLen = stripmap.Length; return datas; } catch (Exception ex) { errorinfo = ex.ToString(); return null; } } private string GetStripMapId(List datas, ref string errorinfo) { try { //< L[3] 1 //< U4[1] 9087 > 2 // < U4[1] 251 > 3 // < L[1] 4 // < L[2] 5 // < U4[1] 21 > 6 // < L[1] 7 // < A[10] 1190717625 > 8 // > // > // > // > List tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 1 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第一个L下面的节点 2,3,4 tempdatas = datas.Where(t => t.ParentID == tempdatas[2].ID).ToList();//获取条号节点 < L[1] 5 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取条号节点 < L[2] 6,7 tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取条号节点 < L[2] 的子节点 8 return tempdatas[0].FContent; } catch (Exception ex) { errorinfo = $"解析获取载板编号发生异常:{ex.ToString()}"; return ""; } } private string GetStripMapIdFromE142(List datas, ref string errorinfo) { try { List tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第一个L下面的节点 tempdatas = datas.Where(t => t.ParentID == tempdatas[2].ID).ToList();//获取条号节点 tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取条号节点 < L[2] 6,7 tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取条号节点 < L[2] 的子节点 8 return StripMapFileGenerator.GetStripIdFromE142(tempdatas[0].FContent); } catch (Exception ex) { errorinfo = $"解析获取载板编号发生异常:{ex.ToString()}"; return ""; } } /// /// 从XML文件中解析stripid /// /// /// private string GetStripIDFromXml(string xml) { DataSet ds = new DataSet(); StringReader stream = new StringReader(xml);//读取字符串为数据量 XmlTextReader reader = new XmlTextReader(stream);//对XML的数据流的只进只读访问 ds.ReadXml(reader);//吧数据读入DataSet //DataTable dt = ds.Tables["createOrderReturn"]; while(reader.Read()) { // 处理一个元素节点的起始。 if (reader.NodeType == XmlNodeType.Element) { return reader.Value; } } return ""; } /// /// 获取StripID /// /// /// /// /// private string GetStripId(List details, List reportDetails, ref string errorinfo) { List mcaSecVDetails = HsmsUnity.GetOrderS6F11Dt(details, reportDetails, ref errorinfo); if (mcaSecVDetails == null || mcaSecVDetails.Count <= 0) { return null; } var tempdata = mcaSecVDetails.FirstOrDefault(t => t.FCode == "S00161"); if (tempdata == null) { errorinfo = $"从指令数据中未找到指令【S00161】数值"; return null; } return tempdata.FVal; } } }