ParamsComMstDal.cs 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using DllEapEntity.Rms;
  5. using DllHsms;
  6. using DllHsmsWeb;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Net.Http;
  11. using System.Text;
  12. using System.Threading;
  13. namespace DllEapDal
  14. {
  15. /// <summary>
  16. /// 参数比对数据访问层
  17. /// </summary>
  18. public class ParamsComMstDal
  19. {
  20. private IDatabase CurrDb = null;
  21. public ParamsComMstDal(IDatabase db)
  22. {
  23. CurrDb = db;
  24. }
  25. public ParamsComMst IUParamsComMst(ParamsComMst mst,string usercode, ref string errorinfo)
  26. {
  27. try
  28. {
  29. int result = CurrDb.InsertFor(mst, usercode);
  30. if (result < 0)
  31. {
  32. return null;
  33. }
  34. object objid = CurrDb.FindObject("select @@IDENTITY");
  35. if (objid.ToString() == "")
  36. {
  37. return null;
  38. }
  39. int id = int.Parse(objid.ToString());
  40. foreach (var item in mst.CurrDetails)
  41. {
  42. item.PreID = id;
  43. item.EntityStatusID = 1;
  44. item.ID = 0;
  45. }
  46. List<PCSubDetail> pcsubdetails = null;
  47. foreach(var item in mst.CurrDetails)
  48. {
  49. result = CurrDb.InsertFor<ParamsComDetail>(item, usercode);
  50. if (result < 0)
  51. return null;
  52. objid = CurrDb.FindObject("select @@IDENTITY");
  53. if (objid.ToString() == "")
  54. {
  55. return null;
  56. }
  57. int subid = int.Parse(objid.ToString());
  58. pcsubdetails = item.pcsubdetails;
  59. foreach (var subitem in pcsubdetails)
  60. {
  61. subitem.PreID = subid;
  62. subitem.ID = 0;
  63. subitem.EntityStatusID = 1;
  64. }
  65. result = CurrDb.InsertFor<PCSubDetail>(pcsubdetails, usercode);
  66. if (result < 0)
  67. return null;
  68. }
  69. mst = CurrDb.FindEntityFor<ParamsComMst>(id);
  70. return mst;
  71. }
  72. catch (Exception e)
  73. {
  74. errorinfo = e.Message;
  75. return null;
  76. }
  77. }
  78. private string GetSecCode(int ftype, ref string errorinfo)
  79. {
  80. try
  81. {
  82. StringBuilder sqlstr = new StringBuilder(100);
  83. string code = "";
  84. switch (ftype)
  85. {
  86. case 1:
  87. code = "S";
  88. break;
  89. case 2:
  90. code = "E";
  91. break;
  92. case 3:
  93. code = "C";
  94. break;
  95. }
  96. sqlstr.AppendFormat("SELECT max(fcode) FROM sec where fcode like '{0}%'", code);
  97. object obj = CurrDb.FindObject(sqlstr.ToString());
  98. if (obj.ToString() == "")
  99. return code + "00001";
  100. int fnum = int.Parse(obj.ToString().Substring(1, 5));
  101. fnum++;
  102. return code + fnum.ToString().PadLeft(5, '0');
  103. }
  104. catch (Exception ex)
  105. {
  106. errorinfo = ex.Message.ToString();
  107. return "";
  108. }
  109. }
  110. public int CompareParamsForOthers(string maccode,string programname, string usercode, ref string errorinfo)
  111. {
  112. try
  113. {
  114. string condition = $" and a.FCode='{maccode}'";
  115. Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).FirstOrDefault();
  116. if(mac==null)
  117. {
  118. errorinfo = $"未找到机台编号={maccode}的机台信息......";
  119. return -1;
  120. }
  121. if (mac.IsControl == 1)
  122. {
  123. condition = $" and a.FName='{programname}' and a.ProcessCode='{mac.PCode}' and a.ModelID={mac.MModeID}";
  124. List<ProgramMst> programmsts = CurrDb.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  125. if (programmsts.Count <= 0)
  126. {
  127. errorinfo = $"未找到程序名称【{programname}】,制程代码【{mac.PCode}】,机型代码【{mac.MModeCode}】对应的信息。";
  128. return -1;
  129. }
  130. ProgramMst programmst = programmsts[0];
  131. ParamsComMst mst = null;
  132. //比对程序参数
  133. mst = CompareParams(mac, programmst, ref errorinfo);
  134. if (mst == null)
  135. {
  136. errorinfo = $"未找到机台【{mac.FCode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
  137. return -1;
  138. }
  139. //插入比对记录
  140. mst = IUParamsComMst(mst, usercode, ref errorinfo);
  141. if (mst == null)
  142. {
  143. errorinfo = $"插入比对结果发生错误:{errorinfo}";
  144. return -1;
  145. }
  146. //如果参数不对,就发送停机指令
  147. if (mst.IsPass <= 0)
  148. {
  149. return -100; //要提交到数据库
  150. }
  151. }
  152. return 1;
  153. }
  154. catch (Exception ex)
  155. {
  156. errorinfo = ex.Message.ToString();
  157. return -1;
  158. }
  159. }
  160. public ParamsComMst CompareParams(Machine mac, ProgramMst programmst, ref string errorinfo)
  161. {
  162. try
  163. {
  164. //读取机台信息
  165. //Machine mac = ReadMachine(maccode, ref errorinfo);
  166. //if (mac == null)
  167. // return null;
  168. //菲尼克斯专用函数
  169. List<ParamsComDetail> deslist = null;
  170. string client = AppConfigurtaionServices.Configuration["Client"];
  171. switch(client)
  172. {
  173. case "Onsemi":
  174. deslist = CompareParamsDetailForOnsemi(mac, programmst.ID, programmst.FName, ref errorinfo);
  175. if (deslist == null)
  176. return null;
  177. break;
  178. default:
  179. deslist = CompareParamsDetail(mac, programmst.ID, ref errorinfo);
  180. if (deslist == null)
  181. return null;
  182. break;
  183. }
  184. ParamsComMst mst = new ParamsComMst();
  185. mst.CurrDetails = deslist;
  186. List<ParamsComDetail> nopass = deslist.Where(t => t.IsPass <= 0).ToList();
  187. if (nopass.Count > 0)
  188. {
  189. mst.IsPass = -1;
  190. }
  191. else
  192. {
  193. mst.IsPass = 1;
  194. }
  195. mst.MacID = mac.ID;
  196. mst.ProgramID = programmst.ID;
  197. return mst;
  198. }
  199. catch (Exception ex)
  200. {
  201. errorinfo = ex.Message.ToString();
  202. return null;
  203. }
  204. }
  205. //public ParamsComMst CompareParams(string maccode, string programname, ref string errorinfo)
  206. //{
  207. // try
  208. // {
  209. // string condition = $" and a.fname='{programname}'";
  210. // List<ProgramMst> msts = CurrDb.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  211. // if (msts == null)
  212. // return null;
  213. // if(msts.Count<=0)
  214. // {
  215. // errorinfo = $"未找到程序名称【{programname}】的记录。";
  216. // return null;
  217. // }
  218. // return CompareParams(maccode,msts[0].ID,ref errorinfo);
  219. // }
  220. // catch (Exception ex)
  221. // {
  222. // errorinfo = ex.Message.ToString();
  223. // return null;
  224. // }
  225. //}
  226. /// <summary>
  227. /// 根据机台ID、程序ID,产生参数比较结果
  228. /// </summary>
  229. /// <param name="macid"></param>
  230. /// <param name="programid"></param>
  231. /// <param name="errorinfo"></param>
  232. /// <returns></returns>
  233. public List<ParamsComDetail> CompareParamsDetail(Machine mac,int programid,ref string errorinfo)
  234. {
  235. try
  236. {
  237. //读取程序参数
  238. //string condition = $" and a.preid={programid} and a.IsCompare=1";
  239. //读取程序所有参数,不比对也要抓数据保存,以便今后查找
  240. string condition = $" and a.preid={programid}";
  241. List<ProgramParamsDetail> programparams = CurrDb.FindListForCondition< ProgramParamsDetail>(condition, ref errorinfo).ToList();
  242. if (programparams == null)
  243. return null;
  244. //if(programparams.Count<=0)
  245. //读取程序参数子参数
  246. condition = $" and a.preid in(select id from ProgramParamsDetail where preid={programid} and IsCompare=1)";
  247. List<PPSubDetail> ppsubdetails = CurrDb.FindListForCondition<PPSubDetail>(condition, ref errorinfo).ToList();
  248. if (ppsubdetails == null)
  249. return null;
  250. List<ParamsComDetail> deslist = MadeParamsComDetail(programparams,ppsubdetails, ref errorinfo);
  251. if (deslist == null)
  252. return null;
  253. if (deslist.Count <= 0)//没有设置比对参数
  254. return deslist;
  255. #region 构造参数结构
  256. //List<ParamsComDetail> templist = deslist.Where(t => t.SecFType == SecType.SVID).OrderBy(t => t.FNum).ToList();
  257. //List<OrderData> datas = MadeOrderData(templist, ref errorinfo);
  258. //if (datas == null)
  259. // return null;
  260. //OrderDetail order= ReadMachineOrderDetail(mac.ID,1,3, ref errorinfo);
  261. //if (order == null)
  262. // return null;
  263. //HsmsWeb accessmac = new HsmsWeb();
  264. //OrderBlock rec= accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  265. //if (rec == null)
  266. // return null;
  267. ////将返回值填写到参数列表
  268. //int result = UpdateParamsComDetail(templist, rec.Datalists, ref errorinfo);
  269. //if (result <= 0)
  270. // return null;
  271. //order = ReadMachineOrderDetail(mac.ID, 2, 13, ref errorinfo);
  272. //if (order == null)
  273. // return null;
  274. ////构造参数结构
  275. //templist = deslist.Where(t => t.SecFType == SecType.ECID).OrderBy(t => t.FNum).ToList();
  276. //datas = MadeOrderData(templist, ref errorinfo);
  277. //if (datas == null)
  278. // return null;
  279. //rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  280. //if (rec == null)
  281. // return null;
  282. ////将返回值填写到参数列表
  283. //result = UpdateParamsComDetail(templist, rec.Datalists, ref errorinfo);
  284. //if (result <= 0)
  285. // return null;
  286. #endregion
  287. int result = CompareParamsDetail(deslist, mac, SecType.SVID, ref errorinfo);
  288. if (result <= 0)
  289. return null;
  290. result = CompareParamsDetail(deslist, mac, SecType.ECID, ref errorinfo);
  291. if (result <= 0)
  292. return null;
  293. //遍历参数明细,判断每条的比对结果
  294. foreach (var item in deslist)
  295. {
  296. result = CompareParamsComDetail(item);
  297. }
  298. return deslist;
  299. }
  300. catch(Exception ex)
  301. {
  302. errorinfo = ex.Message.ToString();
  303. return null;
  304. }
  305. }
  306. public List<ParamsComDetail> CompareParamsDetailForOnsemi(Machine mac, int programid,string orgpname, ref string errorinfo)
  307. {
  308. try
  309. {
  310. //读取程序参数
  311. //string condition = $" and a.preid={programid} and a.IsCompare=1";
  312. //读取程序所有参数,不比对也要抓数据保存,以便今后查找
  313. string programname = "0000000000";
  314. string condition = $" and a.FName='{programname}' and a.ProcessCode='{mac.PCode}' and a.ModelID={mac.MModeID}";
  315. List<ProgramMst> programmsts = CurrDb.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  316. if (programmsts.Count <= 0)
  317. {
  318. errorinfo = $"未找标准程序0000000000,制程代码【{mac.PCode}】,机型代码【{mac.MModeCode}】对应的信息。";
  319. return null;
  320. }
  321. programid = programmsts[0].ID;
  322. condition = $" and a.preid={programid}";
  323. List<ProgramParamsDetail> programparams = CurrDb.FindListForCondition<ProgramParamsDetail>(condition, ref errorinfo).OrderBy(t=>t.FNum).ToList();
  324. if (programparams == null)
  325. return null;
  326. //if(programparams.Count<=0)
  327. //根据机型和程序名称去中间表中读取刀片信息
  328. condition = $" and a.RecipeName='{orgpname}' and a.MCType='{mac.MModeCode}'";
  329. List<OnsemiProgram> onprograms = CurrDb.FindListForCondition<OnsemiProgram>(condition, ref errorinfo).ToList();
  330. if(onprograms==null)
  331. {
  332. errorinfo = $"从表OnsemiProgram中抓取刀片信息失败:{errorinfo};程序名称={orgpname},机型={mac.MModeCode}";
  333. return null;
  334. }
  335. if (onprograms.Count<=0)
  336. {
  337. errorinfo = $"在表OnsemiProgram中未找到刀片信息;程序名称={orgpname},机型={mac.MModeCode}";
  338. return null;
  339. }
  340. if(mac.MModeCode.ToLower()=="dad3350")
  341. {
  342. programparams[0].CL = onprograms[0].SawBlade.Trim();
  343. }
  344. else
  345. {
  346. string[] tempstrs = onprograms[0].SawBlade.Split('+');
  347. if(tempstrs.Length<2)
  348. {
  349. errorinfo = $"双刀机需要2个刀片信息,而OnsemiProgram表中指记录了一种:{onprograms[0].SawBlade.Trim()}";
  350. return null;
  351. }
  352. programparams[0].CL = tempstrs[0].Trim();
  353. programparams[1].CL = tempstrs[1].Trim();
  354. }
  355. //读取程序参数子参数
  356. condition = $" and a.preid in(select id from ProgramParamsDetail where preid={programid} and IsCompare=1)";
  357. List<PPSubDetail> ppsubdetails = CurrDb.FindListForCondition<PPSubDetail>(condition, ref errorinfo).ToList();
  358. if (ppsubdetails == null)
  359. return null;
  360. List<ParamsComDetail> deslist = MadeParamsComDetail(programparams, ppsubdetails, ref errorinfo);
  361. if (deslist == null)
  362. return null;
  363. if (deslist.Count <= 0)//没有设置比对参数
  364. return deslist;
  365. int result = CompareParamsDetail(deslist, mac, SecType.SVID, ref errorinfo);
  366. if (result <= 0)
  367. return null;
  368. result = CompareParamsDetail(deslist, mac, SecType.ECID, ref errorinfo);
  369. if (result <= 0)
  370. return null;
  371. //遍历参数明细,判断每条的比对结果
  372. foreach (var item in deslist)
  373. {
  374. result = CompareParamsComDetail(item);
  375. }
  376. return deslist;
  377. }
  378. catch (Exception ex)
  379. {
  380. errorinfo = ex.Message.ToString();
  381. return null;
  382. }
  383. }
  384. public int CompareParamsDetail(List<ParamsComDetail> deslist,Machine mac, int ftype, ref string errorinfo)
  385. {
  386. try
  387. {
  388. int sval = 1;
  389. int fval = 3;
  390. if(ftype== SecType.ECID)
  391. {
  392. sval = 2;
  393. fval = 13;
  394. }
  395. //构造参数结构
  396. List<ParamsComDetail> templist = deslist.Where(t => t.SecFType == ftype).OrderBy(t => t.FNum).ToList();
  397. if (templist.Count <= 0)
  398. return 1;//没有要比较的参数,直接返回
  399. List<OrderData> datas = MadeOrderData(templist, ref errorinfo);
  400. if (datas == null)
  401. return -1;
  402. OrderDetail order = ReadMachineOrderDetail(mac.ID, sval, fval, ref errorinfo);
  403. if (order == null)
  404. return -1;
  405. HsmsWeb accessmac = new HsmsWeb();
  406. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  407. if (rec == null)
  408. return -1;
  409. //将返回值填写到参数列表
  410. int result = UpdateParamsComDetail(templist, rec.Datalists, ref errorinfo);
  411. if (result <= 0)
  412. return -1;
  413. return 1;
  414. }
  415. catch (Exception ex)
  416. {
  417. errorinfo = ex.Message.ToString();
  418. return -1;
  419. }
  420. }
  421. //固定值是字符串,以逗号隔开的
  422. private void CompareConst(ParamsComDetail entity)
  423. {
  424. //转换中文逗号
  425. string fval = entity.CL.Replace(',', ',');
  426. List<string> templist = fval.Split(',').ToList();
  427. List<string> flist = templist.Where(t => t == entity.FVal).ToList();
  428. if (flist.Count > 0)
  429. entity.IsPass = 1;
  430. else
  431. entity.IsPass = -1;
  432. }
  433. private int CompareParamsComDetail(ParamsComDetail entity)
  434. {
  435. //如果此参数无需比对,则直接通过
  436. if(entity.IsCompare<=0)
  437. {
  438. entity.IsPass = 1;
  439. return 1;
  440. }
  441. if (entity.pcsubdetails.Count<=0)
  442. {
  443. if (!string.IsNullOrEmpty(entity.CL))
  444. {
  445. //说明是比较固定值
  446. //if (entity.CL == entity.FVal)
  447. //{
  448. // entity.IsPass = 1;
  449. //}
  450. //else
  451. //{
  452. // entity.IsPass = -1;
  453. //}
  454. CompareConst(entity);
  455. return 1;
  456. }
  457. if (decimal.Parse(entity.FVal) < decimal.Parse(entity.LCL))
  458. {
  459. entity.IsPass = -1;
  460. return 1;
  461. }
  462. if (decimal.Parse(entity.FVal) > decimal.Parse(entity.UCL))
  463. {
  464. entity.IsPass = -1;
  465. return 1;
  466. }
  467. entity.IsPass = 1;
  468. }
  469. else
  470. {
  471. foreach(var item in entity.pcsubdetails)
  472. {
  473. if(item.IsCompare<=0)
  474. {
  475. item.IsPass = 1;
  476. continue;
  477. }
  478. if(string.IsNullOrEmpty(item.FVal))
  479. {
  480. item.IsPass = -1;
  481. continue;
  482. }
  483. if (!string.IsNullOrEmpty(item.CL))
  484. {
  485. //说明是比较固定值
  486. //if (item.CL == item.FVal)
  487. //{
  488. // item.IsPass = 1;
  489. //}
  490. //else
  491. //{
  492. // item.IsPass = -1;
  493. //}
  494. CompareConst(entity);
  495. return 1;
  496. }
  497. if (decimal.Parse(item.FVal) < decimal.Parse(item.LCL))
  498. {
  499. item.IsPass = -1;
  500. return 1;
  501. }
  502. if (decimal.Parse(item.FVal) > decimal.Parse(item.UCL))
  503. {
  504. item.IsPass = -1;
  505. return 1;
  506. }
  507. item.IsPass = 1;
  508. }
  509. List<PCSubDetail> tempsub = entity.pcsubdetails.Where(t => t.IsCompare >= 0 && t.IsPass <= 0).ToList();
  510. if(tempsub.Count>0)
  511. {
  512. entity.IsPass = -1;
  513. }
  514. else
  515. {
  516. entity.IsPass = 1;
  517. }
  518. }
  519. return 1;
  520. }
  521. /// <summary>
  522. /// 根据机台ID读取机台信息
  523. /// </summary>
  524. /// <param name="macid"></param>
  525. /// <param name="errorinfo"></param>
  526. /// <returns></returns>
  527. private Machine ReadMachine(string maccode,ref string errorinfo)
  528. {
  529. //读取机台信息
  530. string condition = $" and a.fcode='{maccode}'";
  531. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  532. if (macs == null)
  533. return null;
  534. if (macs.Count <= 0)
  535. {
  536. errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
  537. return null;
  538. }
  539. return macs[0];
  540. }
  541. /// <summary>
  542. /// 读取机台S1F3指令
  543. /// </summary>
  544. /// <param name="macid"></param>
  545. /// <param name="errorinfo"></param>
  546. /// <returns></returns>
  547. private OrderDetail ReadMachineOrderDetail(int macid,int sval,int fval, ref string errorinfo)
  548. {
  549. //读取机台信息
  550. string condition = $" and a.macid={macid}";
  551. List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  552. if (macs == null)
  553. return null;
  554. if (macs.Count <= 0)
  555. {
  556. errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
  557. return null;
  558. }
  559. condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval}";
  560. List<OrderDetail> details= CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  561. if (details == null)
  562. return null;
  563. if(details.Count<=0)
  564. {
  565. errorinfo = "未找到您要的指令。";
  566. return null;
  567. }
  568. return details[0];
  569. }
  570. private OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval,string fname, ref string errorinfo)
  571. {
  572. //读取机台信息
  573. string condition = $" and a.macid={macid}";
  574. List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  575. if (macs == null)
  576. return null;
  577. if (macs.Count <= 0)
  578. {
  579. errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
  580. return null;
  581. }
  582. condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval} and lower(a.FName)='{fname.ToLower()}'";
  583. List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  584. if (details == null)
  585. return null;
  586. if (details.Count <= 0)
  587. {
  588. errorinfo = "未找到您要的指令。";
  589. return null;
  590. }
  591. return details[0];
  592. }
  593. /// <summary>
  594. /// 产生指令数据
  595. /// </summary>
  596. /// <param name="programparams"></param>
  597. /// <param name="errorinfo"></param>
  598. /// <returns></returns>
  599. private List<OrderData> MadeOrderData(List<ParamsComDetail> programparams, ref string errorinfo)
  600. {
  601. List<OrderData> datas = new List<OrderData>();
  602. OrderData preid = new OrderData();
  603. preid.ID = 1;
  604. preid.ParentID = 0;
  605. preid.PreID = 0;
  606. preid.FCode = "L";
  607. preid.FLen = programparams.Count;
  608. datas.Add(preid);
  609. OrderData tempentity = null;
  610. int id = 2;
  611. int fnum = 10;
  612. foreach(var item in programparams)
  613. {
  614. tempentity = new OrderData();
  615. tempentity.ID = id;
  616. tempentity.FNum = fnum;
  617. tempentity.FCode = item.DCode;
  618. tempentity.FContent = item.FVal;
  619. tempentity.ParentID = preid.ID;
  620. datas.Add(tempentity);
  621. id++;
  622. fnum += 10;
  623. }
  624. return datas;
  625. }
  626. /// <summary>
  627. /// 将程序参数列表转换成比对明细列表
  628. /// </summary>
  629. /// <param name="programparams"></param>
  630. /// <param name="errorinfo"></param>
  631. /// <returns></returns>
  632. private List<ParamsComDetail> MadeParamsComDetail(List<ProgramParamsDetail> programparams,List<PPSubDetail> subdetails, ref string errorinfo)
  633. {
  634. List<ParamsComDetail> datas = new List<ParamsComDetail>();
  635. ParamsComDetail tempentity = null;
  636. List<PCSubDetail> pcsubdetails = null;
  637. List<PPSubDetail> ppsubdetails = null;
  638. PCSubDetail subentity = null;
  639. foreach (var item in programparams)
  640. {
  641. tempentity = new ParamsComDetail();
  642. tempentity.ID = 0;
  643. tempentity.FNum = item.FNum.Value;
  644. tempentity.SecID = item.SecID;
  645. tempentity.DCode = item.DCode;
  646. tempentity.FVal = item.FVal;
  647. tempentity.UCL = item.UCL;
  648. tempentity.CL = item.CL;
  649. tempentity.LCL = item.LCL;
  650. tempentity.SVType = item.SVType.Value;
  651. tempentity.Module = item.Module.Value;
  652. tempentity.CTLType = item.CTLType.Value;
  653. tempentity.SecFType = item.SecFType;
  654. tempentity.IsCompare = item.IsCompare;
  655. datas.Add(tempentity);
  656. pcsubdetails = new List<PCSubDetail>();
  657. tempentity.pcsubdetails = pcsubdetails;
  658. ppsubdetails = subdetails.Where(t => t.PreID == item.ID).ToList();
  659. foreach(var subitem in ppsubdetails)
  660. {
  661. subentity = new PCSubDetail();
  662. subentity.ID = 0;
  663. subentity.FNum = subitem.FNum;
  664. subentity.FName = subitem.ParameFName;
  665. subentity.UCL = subitem.UCL;
  666. subentity.CL = subitem.CL;
  667. subentity.LCL = subitem.LCL;
  668. subentity.IsCompare = subitem.IsCompare;
  669. pcsubdetails.Add(subentity);
  670. }
  671. }
  672. return datas;
  673. }
  674. /// <summary>
  675. /// 根据返回的参数列表值,更新比对结果值
  676. /// </summary>
  677. /// <param name="deslist"></param>
  678. /// <param name="orglist"></param>
  679. /// <param name="errorinfo"></param>
  680. /// <returns></returns>
  681. private int UpdateParamsComDetail(List<ParamsComDetail> deslist,List<OrderData> orglist, ref string errorinfo)
  682. {
  683. List<OrderData> ldata = orglist.Where(t => t.ParentID == 0).ToList();
  684. int preid = ldata[0].ID;
  685. ldata = orglist.Where(t => t.ParentID == preid).OrderBy(t=>t.FNum).ToList();
  686. if(deslist.Count!=ldata.Count)
  687. {
  688. errorinfo = "获取到的参数与实际参数个数不一致。";
  689. return -1;
  690. }
  691. List<PCSubDetail> pcsubdetails = null;
  692. List<OrderData> subdata = null;
  693. for(int i=0;i<deslist.Count;i++)
  694. {
  695. deslist[i].FVal = ldata[i].FContent;
  696. //更新子列表值
  697. pcsubdetails = deslist[i].pcsubdetails;
  698. subdata = orglist.Where(t => t.ParentID == ldata[i].ID).ToList();
  699. for(int j=0;j<pcsubdetails.Count;j++)
  700. {
  701. pcsubdetails[j].FVal = subdata.Count > j ? subdata[j].FContent : "";
  702. }
  703. }
  704. return 1;
  705. }
  706. /// <summary>
  707. /// 根据机台编号、产品编号、制程代码等信息查找程序,返回程序ID
  708. /// </summary>
  709. /// <param name="maccode"></param>
  710. /// <param name="partcode"></param>
  711. /// <param name="pcode"></param>
  712. /// <param name="errorinfo"></param>
  713. /// <returns></returns>
  714. public ProgramMst FindProgram(string maccode, string partcode, string pcode, ref string errorinfo)
  715. {
  716. try
  717. {
  718. Machine mac = ReadMachine(maccode, ref errorinfo);
  719. if (mac == null)
  720. return null;
  721. string condition = $" and b.ModelID={mac.MModeID} and b.ProcessCode='{pcode}'";
  722. List<ProgramRule> rules = CurrDb.FindListForCondition<ProgramRule>(condition, ref errorinfo).ToList();
  723. if (rules == null)
  724. return null;
  725. if (rules.Count<=0)
  726. {
  727. errorinfo = "未找到对应的程序。";
  728. return null;
  729. }
  730. //先精确匹配产品编号
  731. List<ProgramRule> templist = rules.Where(t => t.PartCode == partcode).ToList();
  732. if (templist.Count > 0)
  733. return CurrDb.FindEntityFor<ProgramMst>(templist[0].ProgramMstID);
  734. //取模糊匹配的规则
  735. rules = rules.Where(t => t.PartCode.Contains("%")).ToList();
  736. if(rules.Count<=0)
  737. {
  738. errorinfo = "未找到对应的程序。";
  739. return null;
  740. }
  741. //去掉规则里产品编号的“%”符号
  742. foreach(var item in rules)
  743. {
  744. item.PartCode = item.PartCode.Replace("%", "");
  745. }
  746. //排序规则列表,按产品编号长度从大到小排列
  747. rules = rules.OrderByDescending(t => t.PartCode.Length).ToList();
  748. foreach(var item in rules)
  749. {
  750. if (partcode.Contains(item.PartCode))
  751. {
  752. return CurrDb.FindEntityFor<ProgramMst>(item.ProgramMstID);
  753. }
  754. }
  755. errorinfo = "未找到对应的程序。";
  756. return null;
  757. }
  758. catch (Exception ex)
  759. {
  760. errorinfo = ex.Message.ToString();
  761. return null;
  762. }
  763. }
  764. /// <summary>
  765. /// DP机台装载程序指令数据
  766. /// </summary>
  767. /// <param name="programname">要装载的程序名称</param>
  768. /// <param name="preid"></param>
  769. /// <param name="errorinfo"></param>
  770. /// <returns></returns>
  771. private List<OrderData> GetS2F41Data(string programname, int preid, ref string errorinfo)
  772. {
  773. string rcmd = "PP-SELECT";
  774. List<OrderData> ldata = new List<OrderData>();
  775. OrderData lentity = new OrderData();
  776. lentity.ID = 1;
  777. lentity.ParentID = 0;
  778. lentity.PreID = preid;
  779. lentity.FCode = "L";
  780. lentity.FLen = 2;
  781. ldata.Add(lentity);
  782. OrderData entity = new OrderData();
  783. entity.ID = 2;
  784. entity.ParentID = 1;
  785. entity.FNum = 10;
  786. entity.PreID = preid;
  787. entity.FCode = "A";
  788. entity.FContent = rcmd;
  789. entity.FLen = rcmd.Length;
  790. ldata.Add(entity);
  791. entity = new OrderData();//添加L节点
  792. entity.ID = 3;
  793. entity.ParentID = 1;
  794. entity.FNum = 20;
  795. entity.PreID = preid;
  796. entity.FCode = "L";
  797. entity.FLen = 1;
  798. ldata.Add(entity);
  799. entity = new OrderData();//添加L节点
  800. entity.ID = 4;
  801. entity.ParentID = 3;
  802. entity.FNum = 10;
  803. entity.PreID = preid;
  804. entity.FCode = "L";
  805. entity.FLen = 2;
  806. ldata.Add(entity);
  807. string cpname = "PPID";
  808. entity = new OrderData();
  809. entity.ID = 5;
  810. entity.ParentID = 4;
  811. entity.FNum = 10;
  812. entity.PreID = preid;
  813. entity.FCode = "A";
  814. entity.FContent = cpname;
  815. entity.FLen = cpname.Length;
  816. ldata.Add(entity);
  817. entity = new OrderData();
  818. entity.ID = 6;
  819. entity.ParentID = 4;
  820. entity.FNum = 20;
  821. entity.PreID = preid;
  822. entity.FCode = "A";
  823. entity.FContent = programname;
  824. entity.FLen = programname.Length;
  825. ldata.Add(entity);
  826. return ldata;
  827. }
  828. /// <summary>
  829. /// 构造S7F3数据
  830. /// </summary>
  831. /// <param name="programname"></param>
  832. /// <param name="filestr"></param>
  833. /// <param name="errorinfo"></param>
  834. /// <returns></returns>
  835. private List<OrderData> GetS7F3Data(string programname,int filelen, string filepath,int preid, ref string errorinfo)
  836. {
  837. List<OrderData> ldata = new List<OrderData>();
  838. OrderData lentity = new OrderData();
  839. lentity.ID = 1;
  840. lentity.ParentID = 0;
  841. lentity.PreID = preid;
  842. lentity.FCode = "L";
  843. lentity.FLen = 2;
  844. ldata.Add(lentity);
  845. OrderData entity = new OrderData();
  846. entity.ID = 2;
  847. entity.ParentID = 1;
  848. entity.FNum = 10;
  849. entity.PreID = preid;
  850. entity.FCode = "A";
  851. entity.FContent = programname;
  852. entity.FLen = programname.Length;
  853. ldata.Add(entity);
  854. entity = new OrderData();
  855. entity.ID = 2;
  856. entity.ParentID = 1;
  857. entity.FNum = 20;
  858. entity.PreID = preid;
  859. entity.FCode = "B";
  860. entity.FContent = filepath;
  861. entity.OrgDatas = null;
  862. entity.FLen = filelen;
  863. //entity.FLen = programname.Length;
  864. ldata.Add(entity);
  865. return ldata;
  866. }
  867. /// <summary>
  868. /// 构造S7F1数据
  869. /// </summary>
  870. /// <param name="programname"></param>
  871. /// <param name="filestr"></param>
  872. /// <param name="errorinfo"></param>
  873. /// <returns></returns>
  874. private List<OrderData> GetS7F1Data(string programname,int len, int preid, ref string errorinfo)
  875. {
  876. List<OrderData> ldata = new List<OrderData>();
  877. OrderData lentity = new OrderData();
  878. lentity.ID = 1;
  879. lentity.ParentID = 0;
  880. lentity.PreID = preid;
  881. lentity.FCode = "L";
  882. lentity.FLen = 2;
  883. ldata.Add(lentity);
  884. OrderData entity = new OrderData();
  885. entity.ID = 2;
  886. entity.ParentID = 1;
  887. entity.FNum = 10;
  888. entity.PreID = preid;
  889. entity.FCode = "A";
  890. entity.FContent = programname;
  891. entity.FLen = programname.Length;
  892. ldata.Add(entity);
  893. entity = new OrderData();
  894. entity.ID = 2;
  895. entity.ParentID = 1;
  896. entity.FNum = 20;
  897. entity.PreID = preid;
  898. entity.FCode = "U4";
  899. entity.FLen = 1;
  900. entity.FContent = len.ToString();
  901. //entity.OrgDatas = filedatas;
  902. //entity.FLen = programname.Length;
  903. ldata.Add(entity);
  904. return ldata;
  905. }
  906. /// <summary>
  907. /// 根据机台编号、产品编号、制程代码等信息,下发程序到机台
  908. /// </summary>
  909. /// <param name="maccode"></param>
  910. /// <param name="partcode"></param>
  911. /// <param name="pcode"></param>
  912. /// <param name="errorinfo"></param>
  913. /// <returns></returns>
  914. public ProgramMst DownloadProgram(string maccode, string partcode, string pcode, ref string errorinfo)
  915. {
  916. try
  917. {
  918. Machine mac = ReadMachine(maccode, ref errorinfo);
  919. if (mac == null)
  920. return null;
  921. //查找程序文件
  922. ProgramMst mst = FindProgram(maccode, partcode, pcode, ref errorinfo);
  923. if(mst==null)
  924. {
  925. return null;
  926. }
  927. OrderDetail order = ReadMachineOrderDetail(mac.ID, 7, 1, ref errorinfo);
  928. if (order == null)
  929. return null;
  930. string filedir = AppConfigurtaionServices.Configuration["ProgramDir"];
  931. filedir += "\\" + maccode;
  932. string filepath = filedir + "\\" + mst.FName;
  933. byte[] filedatas = UnityHelper.ReadFile(filepath, ref errorinfo);
  934. if (filedatas == null)
  935. {
  936. return null;
  937. }
  938. string condition = $" and a.preid={order.ID}";
  939. List<OrderData> datas = GetS7F1Data(mst.FName, filedatas.Length, order.ID, ref errorinfo);// CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
  940. if (datas == null)
  941. return null;
  942. HsmsWeb accessmac = new HsmsWeb();
  943. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  944. if (rec == null)
  945. return null;
  946. if(int.Parse(rec.Datalists[0].FContent)!=0)
  947. {
  948. errorinfo = "机台不接受程序。";
  949. return null;
  950. }
  951. order = ReadMachineOrderDetail(mac.ID, 7, 3, ref errorinfo);
  952. datas = GetS7F3Data(mst.FName, filedatas.Length,filepath, order.PreID, ref errorinfo);
  953. rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  954. if (rec == null)
  955. return null;
  956. if (int.Parse(rec.Datalists[0].FContent) != 0)
  957. {
  958. errorinfo = "机台没有正确接受程序。";
  959. return null;
  960. }
  961. //发送程序装载命令,暂时还不能执行
  962. order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
  963. datas = GetS2F41Data(mst.FName, order.PreID, ref errorinfo);
  964. rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  965. if (rec == null)
  966. return null;
  967. if (int.Parse(rec.Datalists[1].FContent) != 0)
  968. {
  969. errorinfo = $"装载程序不成功,错误代码为:{rec.Datalists[1].FContent}。";
  970. return null;
  971. }
  972. return mst;
  973. }
  974. catch (Exception ex)
  975. {
  976. errorinfo = ex.Message.ToString();
  977. return null;
  978. }
  979. }
  980. /// <summary>
  981. /// 构造获取机台程序名称的数据
  982. /// </summary>
  983. /// <param name="mmsec"></param>
  984. /// <param name="preid"></param>
  985. /// <param name="errorinfo"></param>
  986. /// <returns></returns>
  987. private List<OrderData> GetMacProgram(MMSecDetail mmsec, int preid, ref string errorinfo)
  988. {
  989. List<OrderData> ldata = new List<OrderData>();
  990. OrderData lentity = new OrderData();
  991. lentity.ID = 1;
  992. lentity.ParentID = 0;
  993. lentity.PreID = preid;
  994. lentity.FCode = "L";
  995. lentity.FLen = 1;
  996. ldata.Add(lentity);
  997. OrderData entity = new OrderData();
  998. entity.ID = 2;
  999. entity.ParentID = 1;
  1000. entity.FNum = 10;
  1001. entity.PreID = preid;
  1002. entity.FCode = mmsec.DCode;
  1003. entity.FContent = mmsec.FVal;
  1004. entity.FLen = mmsec.FVal.Length;
  1005. ldata.Add(entity);
  1006. return ldata;
  1007. }
  1008. /// <summary>
  1009. /// 根据机台编号,读取机台当前正在使用的程序名称
  1010. /// </summary>
  1011. /// <param name="maccode"></param>
  1012. /// <param name="errorinfo"></param>
  1013. /// <returns></returns>
  1014. public string GetMacProgram(string maccode, ref string errorinfo)
  1015. {
  1016. try
  1017. {
  1018. Machine mac = ReadMachine(maccode, ref errorinfo);
  1019. if (mac == null)
  1020. return "";
  1021. OrderDetail order = ReadMachineOrderDetail(mac.ID,1, 3, ref errorinfo);
  1022. if (order == null)
  1023. return "";
  1024. //从机型参数中读取程序参数信息
  1025. string condition = $" and a.preid={mac.MModeID} and b.FCode='{StandardCode.SVID_ProgramName}'";
  1026. List<MMSecDetail> mmsecs = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
  1027. if (mmsecs == null)
  1028. return "";
  1029. if(mmsecs.Count<=0)
  1030. {
  1031. errorinfo = "未找到此机台对应的程序参数说明。";
  1032. return "";
  1033. }
  1034. List<OrderData> datas = GetMacProgram(mmsecs[0], order.ID, ref errorinfo);
  1035. if (datas == null)
  1036. return "";
  1037. HsmsWeb accessmac = new HsmsWeb();
  1038. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  1039. if (rec == null)
  1040. return "";
  1041. return rec.Datalists[1].FContent;
  1042. }
  1043. catch (Exception ex)
  1044. {
  1045. errorinfo = ex.Message.ToString();
  1046. return "";
  1047. }
  1048. }
  1049. /// <summary>
  1050. /// 根据机台查找机台使用的程序
  1051. /// </summary>
  1052. /// <param name="mac"></param>
  1053. /// <param name="errorinfo"></param>
  1054. /// <returns></returns>
  1055. public ProgramMst GetMacProgram(Machine mac, ref string errorinfo)
  1056. {
  1057. try
  1058. {
  1059. OrderDetail order = ReadMachineOrderDetail(mac.ID, 1, 3, ref errorinfo);
  1060. if (order == null)
  1061. return null;
  1062. //从机型参数中读取程序参数信息
  1063. string condition = $" and a.preid={mac.MModeID} and b.FCode='{StandardCode.SVID_ProgramName}'";
  1064. List<MMSecDetail> mmsecs = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
  1065. if (mmsecs == null)
  1066. return null;
  1067. if (mmsecs.Count <= 0)
  1068. {
  1069. errorinfo = "未找到此机台对应的程序参数说明。";
  1070. return null;
  1071. }
  1072. List<OrderData> datas = GetMacProgram(mmsecs[0], order.ID, ref errorinfo);
  1073. if (datas == null)
  1074. return null;
  1075. HsmsWeb accessmac = new HsmsWeb();
  1076. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  1077. if (rec == null)
  1078. return null;
  1079. string programname= rec.Datalists[1].FContent;
  1080. condition = $" and a.fname='{programname}'";
  1081. List<ProgramMst> msts = CurrDb.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  1082. if (msts == null)
  1083. return null;
  1084. if (msts.Count <= 0)
  1085. {
  1086. errorinfo = $"未找到程序名称【{programname}】的记录。";
  1087. return null;
  1088. }
  1089. return msts[0];
  1090. }
  1091. catch (Exception ex)
  1092. {
  1093. errorinfo = ex.Message.ToString();
  1094. return null;
  1095. }
  1096. }
  1097. public string GetMacProgramName(Machine mac, ref string errorinfo)
  1098. {
  1099. try
  1100. {
  1101. OrderDetail order = ReadMachineOrderDetail(mac.ID, 1, 3, ref errorinfo);
  1102. if (order == null)
  1103. return null;
  1104. //从机型参数中读取程序参数信息
  1105. string condition = $" and a.preid={mac.MModeID} and b.FCode='{StandardCode.SVID_ProgramName}'";
  1106. List<MMSecDetail> mmsecs = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
  1107. if (mmsecs == null)
  1108. return null;
  1109. if (mmsecs.Count <= 0)
  1110. {
  1111. errorinfo = "未找到此机台对应的程序参数说明。";
  1112. return null;
  1113. }
  1114. List<OrderData> datas = GetMacProgram(mmsecs[0], order.ID, ref errorinfo);
  1115. if (datas == null)
  1116. return null;
  1117. HsmsWeb accessmac = new HsmsWeb();
  1118. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  1119. if (rec == null)
  1120. return null;
  1121. string programname = rec.Datalists[1].FContent;
  1122. return programname;
  1123. }
  1124. catch (Exception ex)
  1125. {
  1126. errorinfo = ex.Message.ToString();
  1127. return "";
  1128. }
  1129. }
  1130. /// <summary>
  1131. /// 发送停机指令
  1132. /// </summary>
  1133. /// <param name="maccode"></param>
  1134. /// <param name="errorinfo"></param>
  1135. /// <returns></returns>
  1136. #region Web接口使用
  1137. public IEnumerable<ParamsComMst> Get(int start, int length, string order, string sort, string filter, string errorinfo)
  1138. {
  1139. var sql = new ParamsComMst().GetSelectSql();
  1140. var pros = CurrDb.FindListForCondition<ParamsComMst>($" {filter} order by {sort} {order} limit {start - 1},{length}", ref errorinfo).ToList();
  1141. // 加入参数信息
  1142. if (pros != null && pros.Count() > 0)
  1143. {
  1144. for (var i = 0; i < pros.Count(); i++)
  1145. {
  1146. var detail = CurrDb.FindListForCondition<ParamsComDetail>($" and a.PreID='{pros[i].ID}'", ref errorinfo).ToList();
  1147. // var detail = CurrDb.FindList<ParamsComDetail>(sql).ToList();
  1148. if (detail == null)
  1149. {
  1150. detail = new List<ParamsComDetail>();
  1151. }
  1152. pros[i].CurrDetails = detail;
  1153. }
  1154. }
  1155. return pros;
  1156. }
  1157. public int GetCount(string filter)
  1158. {
  1159. string errorinfo = string.Empty;
  1160. var entities = CurrDb.FindListForCondition<ParamsComMst>(filter, ref errorinfo);
  1161. if (entities != null)
  1162. {
  1163. return entities.Count();
  1164. }
  1165. return 0;
  1166. }
  1167. #endregion
  1168. private List<FileParamsComDetail> MadeFileParamsComDetail(List<ProgramFileParams> programparams, ref string errorinfo)
  1169. {
  1170. List<FileParamsComDetail> datas = new List<FileParamsComDetail>();
  1171. FileParamsComDetail tempentity = null;
  1172. foreach (var item in programparams)
  1173. {
  1174. tempentity = new FileParamsComDetail();
  1175. tempentity.ID = 0;
  1176. tempentity.FName = item.FName;
  1177. tempentity.FNum = item.FNum;
  1178. tempentity.FVal = "";
  1179. tempentity.UCL = item.UCL;
  1180. tempentity.CL = item.CL;
  1181. tempentity.LCL = item.LCL;
  1182. datas.Add(tempentity);
  1183. }
  1184. return datas;
  1185. }
  1186. private int CompareFileParamsComDetail(FileParamsComDetail entity)
  1187. {
  1188. if (!string.IsNullOrEmpty(entity.CL))
  1189. {
  1190. //说明是比较固定值
  1191. if (entity.CL == entity.FVal)
  1192. {
  1193. entity.IsPass = 1;
  1194. }
  1195. else
  1196. {
  1197. entity.IsPass = -1;
  1198. }
  1199. return 1;
  1200. }
  1201. if(string.IsNullOrEmpty(entity.FVal))
  1202. {
  1203. entity.IsPass = -1;
  1204. return 1;
  1205. }
  1206. if (decimal.Parse(entity.FVal) < decimal.Parse(entity.LCL))
  1207. {
  1208. entity.IsPass = -1;
  1209. return 1;
  1210. }
  1211. if (decimal.Parse(entity.FVal) > decimal.Parse(entity.UCL))
  1212. {
  1213. entity.IsPass = -1;
  1214. return 1;
  1215. }
  1216. entity.IsPass = 1;
  1217. return 1;
  1218. }
  1219. public List<FileParamsComDetail> CompareFileParamsDetail(Machine mac, ProgramMst program,MacProgram macprogram, ref string errorinfo)
  1220. {
  1221. try
  1222. {
  1223. //读取程序参数
  1224. string condition = $" and a.preid={program.ID} and a.IsCompare=1";
  1225. List<ProgramFileParams> programparams = CurrDb.FindListForCondition<ProgramFileParams>(condition, ref errorinfo).ToList();
  1226. if (programparams == null)
  1227. return null;
  1228. List<FileParamsComDetail> deslist = MadeFileParamsComDetail(programparams, ref errorinfo);
  1229. if (deslist == null)
  1230. return null;
  1231. if (deslist.Count <= 0)//没有设置比对参数
  1232. return deslist;
  1233. //int result = CompareParamsDetail(deslist, mac, SecType.SVID, ref errorinfo);
  1234. //if (result <= 0)
  1235. // return null;
  1236. //result = CompareParamsDetail(deslist, mac, SecType.ECID, ref errorinfo);
  1237. //if (result <= 0)
  1238. // return null;
  1239. //读取机台程序文件,并解析出参数值
  1240. string rarpath = AppConfigurtaionServices.Configuration["rarpath"];
  1241. string desdir = AppConfigurtaionServices.Configuration["DesDir"];
  1242. string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
  1243. Dad3350ProgramDal knsprogram = new Dad3350ProgramDal(CurrDb);
  1244. List<FileParams> fileparams = knsprogram.GetProgramParams(rarpath, mac, program, desdir,programdir,macprogram, ref errorinfo);
  1245. if (fileparams == null)
  1246. return null;
  1247. //遍历参数明细,判断每条的比对结果
  1248. foreach (var item in deslist)
  1249. {
  1250. List<FileParams> tempfileparams = fileparams.Where(t => t.FName == item.FName).ToList();
  1251. if (tempfileparams.Count > 0)
  1252. item.FVal = tempfileparams[0].FVal;
  1253. int result = CompareFileParamsComDetail(item);
  1254. }
  1255. return deslist;
  1256. }
  1257. catch (Exception ex)
  1258. {
  1259. errorinfo = ex.Message.ToString();
  1260. return null;
  1261. }
  1262. }
  1263. /// <summary>
  1264. /// 文件参数比对
  1265. /// </summary>
  1266. /// <param name="mac"></param>
  1267. /// <param name="programmst"></param>
  1268. /// <param name="errorinfo"></param>
  1269. /// <returns></returns>
  1270. public FileParamsComMst CompareFileParams(Machine mac, ProgramMst programmst,MacProgram macprogram, ref string errorinfo)
  1271. {
  1272. try
  1273. {
  1274. //读取机台信息
  1275. //Machine mac = ReadMachine(maccode, ref errorinfo);
  1276. //if (mac == null)
  1277. // return null;
  1278. List<FileParamsComDetail> deslist = CompareFileParamsDetail(mac, programmst,macprogram, ref errorinfo);
  1279. if (deslist == null)
  1280. return null;
  1281. FileParamsComMst mst = new FileParamsComMst();
  1282. mst.CurrDetails = deslist;
  1283. List<FileParamsComDetail> nopass = deslist.Where(t => t.IsPass <= 0).ToList();
  1284. if (nopass.Count > 0)
  1285. {
  1286. mst.IsPass = -1;
  1287. }
  1288. else
  1289. {
  1290. mst.IsPass = 1;
  1291. }
  1292. mst.MacID = mac.ID;
  1293. mst.ProgramID = programmst.ID;
  1294. return mst;
  1295. }
  1296. catch (Exception ex)
  1297. {
  1298. errorinfo = ex.Message.ToString();
  1299. return null;
  1300. }
  1301. }
  1302. public FileParamsComMst IUFileParamsComMst(FileParamsComMst mst, string usercode, ref string errorinfo)
  1303. {
  1304. try
  1305. {
  1306. int result = CurrDb.InsertFor(mst, usercode);
  1307. if (result < 0)
  1308. {
  1309. return null;
  1310. }
  1311. object objid = CurrDb.FindObject("select @@IDENTITY");
  1312. if (objid.ToString() == "")
  1313. {
  1314. return null;
  1315. }
  1316. int id = int.Parse(objid.ToString());
  1317. foreach (var item in mst.CurrDetails)
  1318. {
  1319. item.PreID = id;
  1320. item.EntityStatusID = 1;
  1321. item.ID = 0;
  1322. }
  1323. result = CurrDb.InsertFor<FileParamsComDetail>(mst.CurrDetails, usercode);
  1324. if (result < 0)
  1325. return null;
  1326. mst = CurrDb.FindEntityFor<FileParamsComMst>(id);
  1327. return mst;
  1328. }
  1329. catch (Exception e)
  1330. {
  1331. errorinfo = e.Message;
  1332. return null;
  1333. }
  1334. }
  1335. }
  1336. }