StripMapDal.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapDal.OFILM.MES;
  4. using DllEapEntity;
  5. using DllEapEntity.Rms;
  6. using DllHsms;
  7. using DllHsmsWeb;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Xml;
  16. using ZipFileHelper;
  17. namespace DllEapDal
  18. {
  19. public class StripMapDal
  20. {
  21. private IDatabase CurrDb = null;
  22. public StripMapDal(IDatabase db)
  23. {
  24. CurrDb = db;
  25. }
  26. private OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval, ref string errorinfo)
  27. {
  28. //读取机台信息
  29. string condition = $" and a.macid={macid}";
  30. List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  31. if (macs == null)
  32. return null;
  33. if (macs.Count <= 0)
  34. {
  35. errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
  36. return null;
  37. }
  38. condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval}";
  39. List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  40. if (details == null)
  41. return null;
  42. if (details.Count <= 0)
  43. {
  44. errorinfo = "未找到您要的指令。";
  45. return null;
  46. }
  47. return details[0];
  48. }
  49. private OrderDetail ReadMachineOrderDetailByName(int macid, string fname, int sval, int fval, ref string errorinfo)
  50. {
  51. //读取机台信息
  52. string condition = $" and a.macid={macid}";
  53. List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  54. if (macs == null)
  55. return null;
  56. if (macs.Count <= 0)
  57. {
  58. errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
  59. return null;
  60. }
  61. condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval} and a.fname='{fname}'";
  62. List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  63. if (details == null)
  64. return null;
  65. if (details.Count <= 0)
  66. {
  67. errorinfo = "未找到您要的指令。";
  68. return null;
  69. }
  70. return details[0];
  71. }
  72. public int RequestStripmap(OrderBlock entitys, ref string errorinfo)
  73. {
  74. try
  75. {
  76. Machine mac = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault();
  77. if (mac == null)
  78. {
  79. errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。";
  80. return -1;
  81. }
  82. //获取strip id
  83. string stripid = GetStripMapId(entitys.Datalists, ref errorinfo);
  84. if (stripid == "")
  85. return -1;
  86. OrderDetail order = ReadMachineOrderDetail(mac.ID, 14, 2, ref errorinfo);
  87. if (order == null)
  88. {
  89. errorinfo = $"读取指令S14F2发生异常:{errorinfo}";
  90. return -1;
  91. }
  92. //strip map数据
  93. var content = $"11111111\n11111111\n11111111";
  94. var stripInfo = new StripMapInfo
  95. {
  96. LotId = "LOT0001",
  97. StripDetail = content,
  98. SubstrateId = stripid
  99. };
  100. string stripmap = StripMapFileGenerator.CreateStripMapXmlV4(stripInfo, ref errorinfo);
  101. //string stripmap = StripMapFileGenerator.CreateStripMapXmlV2(stripInfo, ref errorinfo);
  102. //string stripmap = StripMapFileGenerator.CreateStripMapXmlV3(stripInfo, ref errorinfo);
  103. List<OrderData> datas = GetS14F2Datas(order, stripid, stripmap, ref errorinfo);
  104. if (datas == null)
  105. {
  106. errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}";
  107. return -1;
  108. }
  109. HsmsWeb accessmac = new HsmsWeb();
  110. int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo);
  111. if (result <= 0)
  112. return -1;
  113. return 1;
  114. }
  115. catch (Exception ex)
  116. {
  117. errorinfo = ex.ToString();
  118. return -1;
  119. }
  120. }
  121. public int RequestStripmapE142(OrderBlock entitys, ref string errorinfo)
  122. {
  123. try
  124. {
  125. Machine mac = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault();
  126. if (mac == null)
  127. {
  128. errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。";
  129. return -1;
  130. }
  131. //macsecv = GetOrderS6F11Dt(details, repostdetails, ref errorinfo);
  132. //if (macsecv == null)
  133. //{
  134. // errorinfo = "GetOrderS6F11Dt函数错误:" + errorinfo;
  135. // return null;
  136. //}
  137. //获取strip id
  138. string stripid = GetStripMapId(entitys.Datalists, ref errorinfo);
  139. if (stripid == "")
  140. return -1;
  141. OrderDetail order = ReadMachineOrderDetailByName(mac.ID, "s14f2e142", 14, 2, ref errorinfo);
  142. if (order == null)
  143. {
  144. errorinfo = $"读取指令S14F2发生异常:{errorinfo}";
  145. return -1;
  146. }
  147. //strip map数据
  148. int rows = 4;
  149. int columns = 9;
  150. int orginloc = 1;
  151. string stripmap = StripMapFileGenerator.CreateStripMapXmlV301(stripid, rows, columns, ref errorinfo);
  152. List<OrderData> datas = GetS14F2Datas(order, stripid, stripmap, ref errorinfo);
  153. if (datas == null)
  154. {
  155. errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}";
  156. return -1;
  157. }
  158. HsmsWeb accessmac = new HsmsWeb();
  159. int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo);
  160. if (result <= 0)
  161. return -1;
  162. // 进站
  163. var ofTrackDal = new OfTrackMstDal(CurrDb);
  164. if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", 1, ref errorinfo) < 0)
  165. return -1;
  166. return 1;
  167. }
  168. catch (Exception ex)
  169. {
  170. errorinfo = ex.ToString();
  171. return -1;
  172. }
  173. }
  174. public int RequestStripmapG84(OrderBlock entitys, ref string errorinfo)
  175. {
  176. try
  177. {
  178. Machine mac = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault();
  179. if (mac == null)
  180. {
  181. errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。";
  182. return -1;
  183. }
  184. //获取strip id
  185. string stripid = GetStripMapId(entitys.Datalists, ref errorinfo);
  186. if (stripid == "")
  187. return -1;
  188. OrderDetail order = ReadMachineOrderDetailByName(mac.ID, "s14f2G84", 14, 2, ref errorinfo);
  189. if (order == null)
  190. {
  191. errorinfo = $"读取指令S14F2发生异常:{errorinfo}";
  192. return -1;
  193. }
  194. //strip map数据
  195. int rows = 4;
  196. int columns = 9;
  197. int orginloc = 1;
  198. List<OrderData> datas = GetS14F2DatasG84(order, stripid, rows, columns, orginloc, ref errorinfo);
  199. if (datas == null)
  200. {
  201. errorinfo = $"读取指令S14F2数据发生异常:{errorinfo}";
  202. return -1;
  203. }
  204. HsmsWeb accessmac = new HsmsWeb();
  205. int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, entitys.GID, ref errorinfo);
  206. if (result <= 0)
  207. return -1;
  208. // 进站
  209. var ofTrackDal = new OfTrackMstDal(CurrDb);
  210. if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", 1, ref errorinfo) < 0)
  211. return -1;
  212. return 1;
  213. }
  214. catch (Exception ex)
  215. {
  216. errorinfo = ex.ToString();
  217. return -1;
  218. }
  219. }
  220. /// <summary>
  221. /// 接收到机台上传的StripMap后解析出StripId出站
  222. /// </summary>
  223. /// <param name="entitys"></param>
  224. /// <param name="reportDetails"></param>
  225. /// <param name="errorinfo"></param>
  226. /// <returns></returns>
  227. public int RequestUploadStripMap(OrderBlock entitys, List<ReportDetail> reportDetails, ref string errorinfo)
  228. {
  229. try
  230. {
  231. Machine mac = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault();
  232. if (mac == null)
  233. {
  234. errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。";
  235. return -1;
  236. }
  237. //获取strip id
  238. string stripid = GetStripId(entitys.Datalists, reportDetails, ref errorinfo);
  239. if (stripid == "")
  240. return -1;
  241. // 出站
  242. var ofTrackDal = new OfTrackMstDal(CurrDb);
  243. if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", -1, ref errorinfo) < 0)
  244. return -1;
  245. return 1;
  246. }
  247. catch (Exception ex)
  248. {
  249. errorinfo = ex.ToString();
  250. return -1;
  251. }
  252. }
  253. public int RequestUploadStripMapE142(OrderBlock entitys, List<ReportDetail> reportDetails, ref string errorinfo)
  254. {
  255. try
  256. {
  257. Machine mac = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entitys.MainMsg.McaCode}'", ref errorinfo).FirstOrDefault();
  258. if (mac == null)
  259. {
  260. errorinfo = $"未找到机台编号=【{entitys.MainMsg.McaCode}】的机台信息。";
  261. return -1;
  262. }
  263. //获取strip id
  264. string stripid = GetStripMapIdFromE142(entitys.Datalists, ref errorinfo);
  265. if (stripid == "")
  266. return -1;
  267. // 出站
  268. var ofTrackDal = new OfTrackMstDal(CurrDb);
  269. if (ofTrackDal.TrackInOut(mac.FCode, stripid, "机台自动", -1, ref errorinfo) < 0)
  270. return -1;
  271. return 1;
  272. }
  273. catch (Exception ex)
  274. {
  275. errorinfo = ex.ToString();
  276. return -1;
  277. }
  278. }
  279. private List<OrderData> GetS14F2DatasG84(OrderDetail order, string stripid, int rows, int columns, int originloc, ref string errorinfo)
  280. {
  281. try
  282. {
  283. // < L[2]
  284. //< L[1]
  285. // < L[2]
  286. // < A[10] 1190523619 >
  287. // < L[5]
  288. // < L[2]
  289. // < A[14] OriginLocation >
  290. // < U4[1] 1 >
  291. // >
  292. // < L[2]
  293. // < A[4] Rows >
  294. // < U4[1] 3 >
  295. // >
  296. // < L[2]
  297. // < A[7] Columns >
  298. // < U4[1] 8 >
  299. // >
  300. // < L[2]
  301. // < A[10] CellStatus >
  302. // < 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 >
  303. // >
  304. // < L[2]
  305. // < A[11] DefectCodes >
  306. // < 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 >
  307. // >
  308. // >
  309. // >
  310. // >
  311. // < L[1]
  312. // < L[2]
  313. // < U1[1] 0 >
  314. // < L[0]
  315. // >
  316. // >
  317. // >
  318. // >
  319. List<OrderData> datas = CurrDb.FindListForCondition<OrderData>($" and a.preid={order.ID}", ref errorinfo).ToList();
  320. List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 0位置
  321. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第二个L 0位置
  322. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L 0位置
  323. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L的子节点 0位置为stripid,1位置为第四个L
  324. tempdatas[0].FContent = stripid;
  325. List<OrderData> fourels = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();// 第4个L的子节点
  326. tempdatas = datas.Where(t => t.ParentID == fourels[0].ID).ToList();//
  327. tempdatas[1].FContent = originloc.ToString();
  328. tempdatas = datas.Where(t => t.ParentID == fourels[1].ID).ToList();//
  329. tempdatas[1].FContent = rows.ToString();
  330. tempdatas = datas.Where(t => t.ParentID == fourels[2].ID).ToList();//
  331. tempdatas[1].FContent = columns.ToString();
  332. int vcount = rows * columns;
  333. string cellstr = "";
  334. string defstr = "";
  335. for (int i = 0; i < vcount; i++)
  336. {
  337. if (i == 0)
  338. {
  339. cellstr = "0";
  340. defstr = "200";
  341. }
  342. else
  343. {
  344. cellstr += ",0";
  345. defstr += ",200";
  346. }
  347. }
  348. tempdatas = datas.Where(t => t.ParentID == fourels[3].ID).ToList();//
  349. tempdatas[1].FContent = cellstr;
  350. tempdatas = datas.Where(t => t.ParentID == fourels[4].ID).ToList();//
  351. tempdatas[1].FContent = defstr;
  352. return datas;
  353. }
  354. catch (Exception ex)
  355. {
  356. errorinfo = ex.ToString();
  357. return null;
  358. }
  359. }
  360. private List<OrderData> GetS14F2Datas(OrderDetail order, string stripid, string stripmap, ref string errorinfo)
  361. {
  362. try
  363. {
  364. // < L[2] 第一个L
  365. //< L[1] 第二个L
  366. //< L[2] 第三个L
  367. //< A "1003175743" >
  368. // < L[1] 第四个L
  369. // < L[2] 第五个L
  370. // < A "MapData" >
  371. // < A "<?xml version="1.0" encoding="utf - 8"?>
  372. List<OrderData> datas = CurrDb.FindListForCondition<OrderData>($" and a.preid={order.ID}", ref errorinfo).ToList();
  373. List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 0位置
  374. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第二个L 0位置
  375. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L 0位置
  376. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第三个L的子节点 0位置为stripid,1位置为第四个L
  377. tempdatas[0].FContent = stripid;
  378. tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取第五个L 0位置
  379. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第五个L的子节点 0位置为< A "MapData" >,1位置为< A "<?xml version="1.0" encoding="utf - 8"?>
  380. tempdatas[1].FContent = stripmap;
  381. tempdatas[1].FLen = stripmap.Length;
  382. return datas;
  383. }
  384. catch (Exception ex)
  385. {
  386. errorinfo = ex.ToString();
  387. return null;
  388. }
  389. }
  390. private string GetStripMapId(List<OrderData> datas, ref string errorinfo)
  391. {
  392. try
  393. {
  394. //< L[3] 1
  395. //< U4[1] 9087 > 2
  396. // < U4[1] 251 > 3
  397. // < L[1] 4
  398. // < L[2] 5
  399. // < U4[1] 21 > 6
  400. // < L[1] 7
  401. // < A[10] 1190717625 > 8
  402. // >
  403. // >
  404. // >
  405. // >
  406. List <OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L 1
  407. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第一个L下面的节点 2,3,4
  408. tempdatas = datas.Where(t => t.ParentID == tempdatas[2].ID).ToList();//获取条号节点 < L[1] 5
  409. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取条号节点 < L[2] 6,7
  410. tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取条号节点 < L[2] 的子节点 8
  411. return tempdatas[0].FContent;
  412. }
  413. catch (Exception ex)
  414. {
  415. errorinfo = $"解析获取载板编号发生异常:{ex.ToString()}";
  416. return "";
  417. }
  418. }
  419. private string GetStripMapIdFromE142(List<OrderData> datas, ref string errorinfo)
  420. {
  421. try
  422. {
  423. List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();//获取第一个L
  424. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取第一个L下面的节点
  425. tempdatas = datas.Where(t => t.ParentID == tempdatas[2].ID).ToList();//获取条号节点
  426. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).ToList();//获取条号节点 < L[2] 6,7
  427. tempdatas = datas.Where(t => t.ParentID == tempdatas[1].ID).ToList();//获取条号节点 < L[2] 的子节点 8
  428. return StripMapFileGenerator.GetStripIdFromE142(tempdatas[0].FContent);
  429. }
  430. catch (Exception ex)
  431. {
  432. errorinfo = $"解析获取载板编号发生异常:{ex.ToString()}";
  433. return "";
  434. }
  435. }
  436. /// <summary>
  437. /// 从XML文件中解析stripid
  438. /// </summary>
  439. /// <param name="xml"></param>
  440. /// <returns></returns>
  441. private string GetStripIDFromXml(string xml)
  442. {
  443. DataSet ds = new DataSet();
  444. StringReader stream = new StringReader(xml);//读取字符串为数据量
  445. XmlTextReader reader = new XmlTextReader(stream);//对XML的数据流的只进只读访问
  446. ds.ReadXml(reader);//吧数据读入DataSet
  447. //DataTable dt = ds.Tables["createOrderReturn"];
  448. while(reader.Read())
  449. {
  450. // 处理一个元素节点的起始。
  451. if (reader.NodeType == XmlNodeType.Element)
  452. {
  453. return reader.Value;
  454. }
  455. }
  456. return "";
  457. }
  458. /// <summary>
  459. /// 获取StripID
  460. /// </summary>
  461. /// <param name="details"></param>
  462. /// <param name="reportDetails"></param>
  463. /// <param name="errorinfo"></param>
  464. /// <returns></returns>
  465. private string GetStripId(List<OrderData> details, List<ReportDetail> reportDetails, ref
  466. string errorinfo)
  467. {
  468. List<McaSecVDetail> mcaSecVDetails = HsmsUnity.GetOrderS6F11Dt(details, reportDetails,
  469. ref errorinfo);
  470. if (mcaSecVDetails == null || mcaSecVDetails.Count <= 0)
  471. {
  472. return null;
  473. }
  474. var tempdata = mcaSecVDetails.FirstOrDefault(t => t.FCode == "S00161");
  475. if (tempdata == null)
  476. {
  477. errorinfo = $"从指令数据中未找到指令【S00161】数值";
  478. return null;
  479. }
  480. return tempdata.FVal;
  481. }
  482. }
  483. }