123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503 |
- 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<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(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<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(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<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(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<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(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<Machine>($" 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<OrderData> 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<Machine>($" 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<OrderData> 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<Machine>($" 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<OrderData> 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;
- }
- }
- /// <summary>
- /// 接收到机台上传的StripMap后解析出StripId出站
- /// </summary>
- /// <param name="entitys"></param>
- /// <param name="reportDetails"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- public int RequestUploadStripMap(OrderBlock entitys, List<ReportDetail> reportDetails, ref string errorinfo)
- {
- try
- {
- Machine mac = CurrDb.FindListForCondition<Machine>($" 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<ReportDetail> reportDetails, ref string errorinfo)
- {
- try
- {
- Machine mac = CurrDb.FindListForCondition<Machine>($" 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<OrderData> 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<OrderData> datas = CurrDb.FindListForCondition<OrderData>($" and a.preid={order.ID}", ref errorinfo).ToList();
- List<OrderData> 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<OrderData> 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<OrderData> 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 "<?xml version="1.0" encoding="utf - 8"?>
- List<OrderData> datas = CurrDb.FindListForCondition<OrderData>($" and a.preid={order.ID}", ref errorinfo).ToList();
- List<OrderData> 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 "<?xml version="1.0" encoding="utf - 8"?>
- tempdatas[1].FContent = stripmap;
- tempdatas[1].FLen = stripmap.Length;
- return datas;
- }
- catch (Exception ex)
- {
- errorinfo = ex.ToString();
- return null;
- }
- }
- private string GetStripMapId(List<OrderData> 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 <OrderData> 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<OrderData> datas, ref string errorinfo)
- {
- try
- {
- List<OrderData> 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 "";
- }
- }
- /// <summary>
- /// 从XML文件中解析stripid
- /// </summary>
- /// <param name="xml"></param>
- /// <returns></returns>
- 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 "";
- }
- /// <summary>
- /// 获取StripID
- /// </summary>
- /// <param name="details"></param>
- /// <param name="reportDetails"></param>
- /// <param name="errorinfo"></param>
- /// <returns></returns>
- private string GetStripId(List<OrderData> details, List<ReportDetail> reportDetails, ref
- string errorinfo)
- {
- List<McaSecVDetail> 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;
- }
- }
- }
|