ProgramDal.cs 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  1. using Cksoft.Data;
  2. using Cksoft.Unity;
  3. using DllEapEntity;
  4. using DllEapEntity.Rms;
  5. using DllHsms;
  6. using DllHsmsWeb;
  7. using Microsoft.Extensions.Logging;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading;
  13. using ZipFileHelper;
  14. namespace DllEapDal
  15. {
  16. public class ProgramDal
  17. {
  18. private IDatabase CurrDb = null;
  19. public ProgramDal(IDatabase db)
  20. {
  21. CurrDb = db;
  22. loger = AppConfigurtaionServices.MyLog;// (ILogger)AppConfigurtaionServices.Instance.GetService(typeof(ILogger<ProgramDal>));// (ILogger)log4net.LogManager.GetLogger(typeof(ProgramDal));
  23. //loger.LogError("自己创建loger实例......");
  24. //loger.LogError("自己创建loger实例......2222");
  25. }
  26. private ILogger loger = null;
  27. public ProgramDal(IDatabase db,ILogger loger)
  28. {
  29. CurrDb = db;
  30. this.loger = loger;
  31. }
  32. public OrderDetail ReadMachineOrderDetail(int macid, int sval, int fval, ref string errorinfo)
  33. {
  34. //读取机台信息
  35. string condition = $" and a.macid={macid}";
  36. List<MacOrder> macs = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  37. if (macs == null)
  38. return null;
  39. if (macs.Count <= 0)
  40. {
  41. errorinfo = $"未找到机台ID【{macid}】的机台指令信息。";
  42. return null;
  43. }
  44. condition = $" and a.preid={macs[0].PreID} and a.sval={sval} and a.fval={fval}";
  45. List<OrderDetail> details = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  46. if (details == null)
  47. return null;
  48. if (details.Count <= 0)
  49. {
  50. errorinfo = "未找到您要的指令。";
  51. return null;
  52. }
  53. return details[0];
  54. }
  55. /// <summary>
  56. /// 获取请求机台程序的指令数据
  57. /// </summary>
  58. /// <param name="programname"></param>
  59. /// <param name="preid"></param>
  60. /// <param name="errorinfo"></param>
  61. /// <returns></returns>
  62. private List<OrderData> GetS2F41Data(string programname, int preid, ref string errorinfo)
  63. {
  64. string rcmd = "PP_PREP";
  65. List<OrderData> ldata = new List<OrderData>();
  66. OrderData lentity = new OrderData();
  67. lentity.ID = 1;
  68. lentity.ParentID = 0;
  69. lentity.PreID = preid;
  70. lentity.FCode = "L";
  71. lentity.FLen = 2;
  72. ldata.Add(lentity);
  73. OrderData entity = new OrderData();
  74. entity.ID = 2;
  75. entity.ParentID = 1;
  76. entity.FNum = 10;
  77. entity.PreID = preid;
  78. entity.FCode = "A";
  79. entity.FContent = rcmd;
  80. entity.FLen = rcmd.Length;
  81. ldata.Add(entity);
  82. entity = new OrderData();//添加L节点
  83. entity.ID = 3;
  84. entity.ParentID = 1;
  85. entity.FNum = 20;
  86. entity.PreID = preid;
  87. entity.FCode = "L";
  88. entity.FLen = 1;
  89. ldata.Add(entity);
  90. entity = new OrderData();//添加L节点
  91. entity.ID = 4;
  92. entity.ParentID = 3;
  93. entity.FNum = 10;
  94. entity.PreID = preid;
  95. entity.FCode = "L";
  96. entity.FLen = 2;
  97. ldata.Add(entity);
  98. string cpname = "PPID";
  99. entity = new OrderData();
  100. entity.ID = 5;
  101. entity.ParentID = 4;
  102. entity.FNum = 10;
  103. entity.PreID = preid;
  104. entity.FCode = "A";
  105. entity.FContent = cpname;
  106. entity.FLen = cpname.Length;
  107. ldata.Add(entity);
  108. entity = new OrderData();
  109. entity.ID = 6;
  110. entity.ParentID = 4;
  111. entity.FNum = 20;
  112. entity.PreID = preid;
  113. entity.FCode = "A";
  114. entity.FContent = programname;
  115. entity.FLen = programname.Length;
  116. ldata.Add(entity);
  117. return ldata;
  118. }
  119. /// <summary>
  120. /// DP机台装载程序指令数据
  121. /// </summary>
  122. /// <param name="programname">要装载的程序名称</param>
  123. /// <param name="preid"></param>
  124. /// <param name="errorinfo"></param>
  125. /// <returns></returns>
  126. private List<OrderData> GetS2F41DataForPPSelect(string programname, int preid, ref string errorinfo)
  127. {
  128. string rcmd = "PP_SELECT";
  129. List<OrderData> ldata = new List<OrderData>();
  130. OrderData lentity = new OrderData();
  131. lentity.ID = 1;
  132. lentity.ParentID = 0;
  133. lentity.PreID = preid;
  134. lentity.FCode = "L";
  135. lentity.FLen = 2;
  136. ldata.Add(lentity);
  137. OrderData entity = new OrderData();
  138. entity.ID = 2;
  139. entity.ParentID = 1;
  140. entity.FNum = 10;
  141. entity.PreID = preid;
  142. entity.FCode = "A";
  143. entity.FContent = rcmd;
  144. entity.FLen = rcmd.Length;
  145. ldata.Add(entity);
  146. entity = new OrderData();//添加L节点
  147. entity.ID = 3;
  148. entity.ParentID = 1;
  149. entity.FNum = 20;
  150. entity.PreID = preid;
  151. entity.FCode = "L";
  152. entity.FLen = 1;
  153. ldata.Add(entity);
  154. entity = new OrderData();//添加L节点
  155. entity.ID = 4;
  156. entity.ParentID = 3;
  157. entity.FNum = 10;
  158. entity.PreID = preid;
  159. entity.FCode = "L";
  160. entity.FLen = 2;
  161. ldata.Add(entity);
  162. string cpname = "PPID";
  163. entity = new OrderData();
  164. entity.ID = 5;
  165. entity.ParentID = 4;
  166. entity.FNum = 10;
  167. entity.PreID = preid;
  168. entity.FCode = "A";
  169. entity.FContent = cpname;
  170. entity.FLen = cpname.Length;
  171. ldata.Add(entity);
  172. entity = new OrderData();
  173. entity.ID = 6;
  174. entity.ParentID = 4;
  175. entity.FNum = 20;
  176. entity.PreID = preid;
  177. entity.FCode = "A";
  178. entity.FContent = programname;
  179. entity.FLen = programname.Length;
  180. ldata.Add(entity);
  181. return ldata;
  182. }
  183. private List<OrderData> GetS2F41DataForHit(int preid,string rcmd, ref string errorinfo)
  184. {
  185. //string rcmd = "ENTER_HIT";
  186. List<OrderData> ldata = new List<OrderData>();
  187. OrderData lentity = new OrderData();
  188. lentity.ID = 1;
  189. lentity.ParentID = 0;
  190. lentity.PreID = preid;
  191. lentity.FCode = "L";
  192. lentity.FLen = 2;
  193. ldata.Add(lentity);
  194. OrderData entity = new OrderData();
  195. entity.ID = 2;
  196. entity.ParentID = 1;
  197. entity.FNum = 10;
  198. entity.PreID = preid;
  199. entity.FCode = "A";
  200. entity.FContent = rcmd;
  201. entity.FLen = rcmd.Length;
  202. ldata.Add(entity);
  203. entity = new OrderData();//添加L节点
  204. entity.ID = 3;
  205. entity.ParentID = 1;
  206. entity.FNum = 20;
  207. entity.PreID = preid;
  208. entity.FCode = "L";
  209. entity.FLen = 0;
  210. ldata.Add(entity);
  211. return ldata;
  212. }
  213. private List<OrderData> GetS7F5Data(string programname, int preid, ref string errorinfo)
  214. {
  215. List<OrderData> ldata = new List<OrderData>();
  216. OrderData lentity = new OrderData();
  217. lentity.ID = 1;
  218. lentity.ParentID = 0;
  219. lentity.PreID = preid;
  220. lentity.FCode = "A";
  221. lentity.FContent = programname;
  222. lentity.FLen = programname.Length;
  223. ldata.Add(lentity);
  224. return ldata;
  225. }
  226. /// <summary>
  227. /// 将机台设置为1086参数
  228. /// </summary>
  229. /// <param name="mac"></param>
  230. /// <param name="errorinfo"></param>
  231. /// <returns></returns>
  232. private int SetEc1086(Machine mac, ref string errorinfo)
  233. {
  234. try
  235. {
  236. HsmsWeb accessmac = new HsmsWeb();
  237. //发送指令,将程序模式设置为hit模式
  238. OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
  239. List<OrderData> datas = GetS2F41DataForHit(order.PreID, "ENTER_HIT", ref errorinfo);
  240. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  241. if (rec == null)
  242. return -1;
  243. int result = int.Parse(rec.Datalists[1].FContent);
  244. if (result > 0)
  245. {
  246. errorinfo = $"将机台设置为HIT模式出错,错误代码为:{result}";
  247. return -1;
  248. }
  249. return 1;
  250. }
  251. catch (Exception ex)
  252. {
  253. errorinfo = ex.Message.ToString();
  254. return -1;
  255. }
  256. }
  257. /// <summary>
  258. /// 发送指令
  259. /// </summary>
  260. /// <param name="mac"></param>
  261. /// <param name="errorinfo"></param>
  262. /// <returns></returns>
  263. public int SendOrder(Machine mac,int sval,int fval, ref string errorinfo)
  264. {
  265. try
  266. {
  267. string condition = $"";
  268. List<MacOrder> macorder = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  269. if(macorder.Count<=0)
  270. {
  271. errorinfo = $"未找到机台【{mac.FCode}】对应的指令。";
  272. return -1;
  273. }
  274. condition = $" and a.preid={macorder[0].PreID} and a.sval={sval} and a.fval={fval}";
  275. List<OrderDetail> order = CurrDb.FindListForCondition<OrderDetail>(condition, ref errorinfo).ToList();
  276. if(order.Count<=0)
  277. {
  278. errorinfo = $"未找到机台【{mac.FCode}】对应的S2F15指令。";
  279. return -1;
  280. }
  281. condition = $" and a.preid={order[0].ID}";
  282. List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
  283. HsmsWeb accessmac = new HsmsWeb();
  284. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order[0], datas, ref errorinfo);
  285. if (rec == null)
  286. return -1;
  287. int result = int.Parse(rec.Datalists[0].FContent);
  288. if (result > 0)
  289. {
  290. errorinfo = $"设置机台ECID参数出错,错误代码为:{result}";
  291. return -1;
  292. }
  293. return 1;
  294. }
  295. catch (Exception ex)
  296. {
  297. errorinfo = ex.Message.ToString();
  298. return -1;
  299. }
  300. }
  301. /// <summary>
  302. /// 将机台设置为HIT模式
  303. /// </summary>
  304. /// <param name="mac"></param>
  305. /// <param name="errorinfo"></param>
  306. /// <returns></returns>
  307. private int SetHit(Machine mac,string rcmd,ref string errorinfo)
  308. {
  309. try
  310. {
  311. HsmsWeb accessmac = new HsmsWeb();
  312. //发送指令,将程序模式设置为hit模式
  313. OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
  314. List<OrderData> datas = GetS2F41DataForHit(order.PreID, rcmd, ref errorinfo);
  315. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  316. if (rec == null)
  317. return -1;
  318. int result = int.Parse(rec.Datalists[1].FContent);
  319. if (result == 5)
  320. return 1;
  321. if (result == 0)
  322. return 1;
  323. return -1;
  324. }
  325. catch(Exception ex)
  326. {
  327. errorinfo = ex.Message.ToString();
  328. return -1;
  329. }
  330. }
  331. /// <summary>
  332. /// 获取机台当前使用的程序文件,并将文件放到指定的目录
  333. /// </summary>
  334. /// <param name="mac"></param>
  335. /// <param name="errorinfo"></param>
  336. /// <returns></returns>
  337. public string ReadProgramFromMac(Machine mac,ProgramMst program,string desdir,ref string errorinfo)
  338. {
  339. try
  340. {
  341. HsmsWeb accessmac = new HsmsWeb();
  342. //发送指令,将程序模式设置为hit模式
  343. //OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
  344. //List<OrderData> datas = GetS2F41DataForHit(program.FName, order.PreID, ref errorinfo);
  345. //OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  346. //if (rec == null)
  347. // return null;
  348. //int result = int.Parse(rec.Datalists[1].FContent);
  349. //if(result>0)
  350. //{
  351. // errorinfo = $"将机台设置为HIT模式出错,错误代码为:{result}";
  352. // return null;
  353. //}
  354. int result = SetHit(mac, "ENTER_HIT", ref errorinfo);
  355. if(result<=0)
  356. {
  357. return null;
  358. }
  359. //发送取程序的指令
  360. OrderDetail order = ReadMachineOrderDetail(mac.ID, 2, 41, ref errorinfo);
  361. List<OrderData> datas = GetS2F41Data(program.FName, order.PreID, ref errorinfo);
  362. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  363. if (rec == null)
  364. return null;
  365. result = int.Parse(rec.Datalists[1].FContent);
  366. if (result != 0&& result != 4)
  367. {
  368. errorinfo = $"下载程序不成功,错误代码为:{rec.Datalists[1].FContent}。";
  369. return null;
  370. }
  371. if(result==4)
  372. {
  373. //说明机台已经开始处理程序,休眠5秒钟,等待机台处理
  374. //或等待处理完成事件上来
  375. Thread.Sleep(1000 * 5);
  376. }
  377. order = ReadMachineOrderDetail(mac.ID, 7, 5, ref errorinfo);
  378. datas = GetS7F5Data(program.FName, order.PreID, ref errorinfo);
  379. rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  380. if (rec == null)
  381. return null;
  382. datas = rec.Datalists;
  383. if(datas[0].FLen==0)
  384. {
  385. errorinfo = "未能正确的获取程序文件。";
  386. return "";
  387. }
  388. result = UnityHelper.WriteFile(desdir, program.FName, datas[2].OrgDatas, ref errorinfo);
  389. if (result <= 0)
  390. return null;
  391. return program.FName;
  392. }
  393. catch(Exception ex)
  394. {
  395. errorinfo = ex.Message.ToString();
  396. return "";
  397. }
  398. }
  399. /// <summary>
  400. /// 获取程序参数
  401. /// </summary>
  402. /// <param name="mac"></param>
  403. /// <param name="program"></param>
  404. /// <param name="desdir"></param>
  405. /// <param name="errorinfo"></param>
  406. /// <returns></returns>
  407. public List<FileParams> GetProgramParams(string rarpath,Machine mac, ProgramMst program, string desdir, ref string errorinfo)
  408. {
  409. try
  410. {
  411. string programname = ReadProgramFromMac(mac, program, desdir, ref errorinfo);
  412. if (string.IsNullOrEmpty(programname))
  413. return null;
  414. string filepath = desdir + "\\" + programname;
  415. string tempdesdir = desdir + "\\temp";
  416. List<FileParams> filesdata = UnCompressForKs.GetParamsFor(rarpath, filepath, programname
  417. , tempdesdir, mac.MModeID, ref errorinfo);
  418. return filesdata;
  419. }
  420. catch (Exception ex)
  421. {
  422. errorinfo = ex.Message.ToString();
  423. return null;
  424. }
  425. }
  426. /// <summary>
  427. /// 根据机台编号、产品编号、制程代码等信息查找程序,返回程序ID
  428. /// </summary>
  429. /// <param name="maccode"></param>
  430. /// <param name="partcode"></param>
  431. /// <param name="pcode"></param>
  432. /// <param name="errorinfo"></param>
  433. /// <returns></returns>
  434. public ProgramMst FindProgram(Machine mac, string partcode, string pcode, ref string errorinfo)
  435. {
  436. try
  437. {
  438. string condition = $" and b.ModelID={mac.MModeID} and b.ProcessCode='{pcode}'";
  439. List<ProgramRule> rules = CurrDb.FindListForCondition<ProgramRule>(condition, ref errorinfo).ToList();
  440. if (rules == null)
  441. return null;
  442. if (rules.Count <= 0)
  443. {
  444. errorinfo = "未找到对应的程序规则。";
  445. return null;
  446. }
  447. //先精确匹配产品编号
  448. List<ProgramRule> templist = rules.Where(t => t.PartCode == partcode).ToList();
  449. if (templist.Count > 0)
  450. return CurrDb.FindEntityFor<ProgramMst>(templist[0].ProgramMstID);
  451. //取模糊匹配的规则
  452. rules = rules.Where(t => t.PartCode.Contains("%")).ToList();
  453. if (rules.Count <= 0)
  454. {
  455. errorinfo = "未找到对应的程序规则。";
  456. return null;
  457. }
  458. //去掉规则里产品编号的“%”符号
  459. foreach (var item in rules)
  460. {
  461. item.PartCode = item.PartCode.Replace("%", "");
  462. }
  463. //排序规则列表,按产品编号长度从大到小排列
  464. rules = rules.OrderByDescending(t => t.PartCode.Length).ToList();
  465. foreach (var item in rules)
  466. {
  467. if (partcode.Contains(item.PartCode))
  468. {
  469. return CurrDb.FindEntityFor<ProgramMst>(item.ProgramMstID);
  470. }
  471. }
  472. errorinfo = "未找到对应的程序规则。";
  473. return null;
  474. }
  475. catch (Exception ex)
  476. {
  477. errorinfo = ex.Message.ToString();
  478. return null;
  479. }
  480. }
  481. /// <summary>
  482. /// 根据机台编号读取机台
  483. /// </summary>
  484. /// <param name="maccode"></param>
  485. /// <param name="errorinfo"></param>
  486. /// <returns></returns>
  487. public Machine ReadMachine(string maccode, ref string errorinfo)
  488. {
  489. try
  490. {
  491. string condition = $" and a.fcode='{maccode}'";
  492. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  493. if (macs == null)
  494. {
  495. errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
  496. return null;
  497. }
  498. if (macs.Count <= 0)
  499. {
  500. errorinfo = $"未找到机台编号【{maccode}】的机台信息。";
  501. return null;
  502. }
  503. return macs[0];
  504. }
  505. catch (Exception ex)
  506. {
  507. errorinfo = ex.Message.ToString();
  508. return null;
  509. }
  510. }
  511. private void SendInfo(string maccode,string info)
  512. {
  513. try
  514. {
  515. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  516. string temperrorinfo = "";
  517. senddal.SendS10F3(maccode, info, ref temperrorinfo);
  518. }
  519. catch
  520. {
  521. return;
  522. }
  523. }
  524. public string GetMacStatus(Machine mac, ref string errorinfo)
  525. {
  526. try
  527. {
  528. OrderDetail order = ReadMachineOrderDetail(mac.ID, 1, 3, ref errorinfo);
  529. if (order == null)
  530. return "";
  531. string condition = $" and a.PreID={mac.MModeID} and b.FCode='{StandardCode.SVID_CurrentStatus}'";
  532. List<MMSecDetail> mmsecs = CurrDb.FindListForCondition<MMSecDetail>(condition, ref errorinfo).ToList();
  533. if (mmsecs.Count <= 0)
  534. {
  535. errorinfo = $"未找到机台【{mac.FCode}】对应的状态参数定义。";
  536. return "";
  537. }
  538. List<OrderData> datas = new List<OrderData>();
  539. OrderData lentity = new OrderData();
  540. lentity.ID = 1;
  541. lentity.ParentID = 0;
  542. lentity.PreID = order.ID;
  543. lentity.FCode = "L";
  544. lentity.FContent = "";
  545. lentity.FLen = 1;
  546. lentity.FNum = 10;
  547. datas.Add(lentity);
  548. lentity = new OrderData();
  549. lentity.ID = 2;
  550. lentity.ParentID = 1;
  551. lentity.PreID = order.ID;
  552. lentity.FCode = mmsecs[0].DCode;
  553. lentity.FContent = mmsecs[0].FVal;
  554. lentity.FLen = 1;
  555. lentity.FNum = 10;
  556. datas.Add(lentity);
  557. HsmsWeb accessmac = new HsmsWeb();
  558. OrderBlock rec = accessmac.SendOrderFor(mac.FCode, order, datas, ref errorinfo);
  559. if (rec == null)
  560. return "";
  561. return rec.Datalists[1].FContent;
  562. }
  563. catch (Exception ex)
  564. {
  565. errorinfo = ex.Message.ToString();
  566. return "";
  567. }
  568. }
  569. private int AsmDownloadProgram(Machine mac,string programname, MacOrderSendDal senddal, ref string errorinfo)
  570. {
  571. string temperrorinfo = "";
  572. AsmProgramDal asmdal = new AsmProgramDal(CurrDb);
  573. int result = asmdal.DownloadProgram(mac, programname, ref errorinfo);
  574. if (result == -100)
  575. {
  576. loger.LogError($"S7F2回复代码为{errorinfo}");
  577. temperrorinfo = "";
  578. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
  579. return result;
  580. }
  581. if (result == -200)
  582. {
  583. loger.LogError($"S7F4回复代码为{errorinfo}");
  584. temperrorinfo = "";
  585. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
  586. return result;
  587. }
  588. if (result <= 0)
  589. {
  590. loger.LogError($"下载程序错误{errorinfo}");
  591. temperrorinfo = "";
  592. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
  593. return result;
  594. }
  595. temperrorinfo = "";
  596. loger.LogError($"发送下载程序成功信息到机台上");
  597. senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  598. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  599. //programname += ".WB";
  600. result = asmdal.SelProgram(mac, programname, ref errorinfo);
  601. if (result == -300)
  602. {
  603. temperrorinfo = "";
  604. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
  605. return result;
  606. }
  607. if (result <= 0)
  608. {
  609. temperrorinfo = "";
  610. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
  611. errorinfo = $"选择程序发生错误:{errorinfo}";
  612. return result;
  613. }
  614. temperrorinfo = "";
  615. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  616. return 1;
  617. }
  618. private int KnsDownloadProgram(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
  619. {
  620. string temperrorinfo = "";
  621. KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
  622. int result = asmdal.DownloadProgram(mac, programname, ref errorinfo);
  623. if (result == -100)
  624. {
  625. loger.LogError($"S7F2回复代码为{errorinfo}");
  626. temperrorinfo = "";
  627. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
  628. return result;
  629. }
  630. if (result == -200)
  631. {
  632. loger.LogError($"S7F4回复代码为{errorinfo}");
  633. temperrorinfo = "";
  634. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
  635. return result;
  636. }
  637. if (result <= 0)
  638. {
  639. loger.LogError($"下载程序错误{errorinfo}");
  640. temperrorinfo = "";
  641. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
  642. return result;
  643. }
  644. temperrorinfo = "";
  645. loger.LogError($"发送下载程序成功信息到机台上");
  646. senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  647. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  648. if(!Convert.ToBoolean(AppConfigurtaionServices.Configuration["SelectProgram"]))
  649. {
  650. //不用选择程序
  651. return 1;
  652. }
  653. int KnsSelectProgram = Convert.ToInt32( AppConfigurtaionServices.Configuration["KnsSelectProgram"]);
  654. Thread.Sleep(KnsSelectProgram);
  655. result = asmdal.SelectProgram(mac, programname, ref errorinfo);
  656. if (result == -300)
  657. {
  658. temperrorinfo = "";
  659. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
  660. return result;
  661. }
  662. if (result <= 0)
  663. {
  664. temperrorinfo = "";
  665. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
  666. errorinfo = $"选择程序发生错误:{errorinfo}";
  667. return result;
  668. }
  669. temperrorinfo = "";
  670. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  671. return 1;
  672. }
  673. private int KnsDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
  674. {
  675. string temperrorinfo = "";
  676. KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
  677. int result = asmdal.DownloadProgramS7F6(mac, programname, ref errorinfo);
  678. if (result == -100)
  679. {
  680. loger.LogError($"S7F6回复代码为{errorinfo}");
  681. temperrorinfo = "";
  682. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
  683. return result;
  684. }
  685. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  686. return 1;
  687. }
  688. private int Dad3350DownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
  689. {
  690. string programname = "";
  691. string temperrorinfo = "";
  692. Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
  693. int result = dal.DownloadProgram(mac, orgprogramname, ref programname, ref errorinfo);
  694. if (result == -100)
  695. {
  696. loger.LogError($"S7F2回复代码为{errorinfo}");
  697. temperrorinfo = "";
  698. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
  699. return result;
  700. }
  701. if (result == -200)
  702. {
  703. loger.LogError($"S7F4回复代码为{errorinfo}");
  704. temperrorinfo = "";
  705. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
  706. return result;
  707. }
  708. if (result <= 0)
  709. {
  710. temperrorinfo = "";
  711. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}]", ref temperrorinfo);
  712. return result;
  713. }
  714. temperrorinfo = "";
  715. loger.LogError($"发送下载程序成功信息到机台上");
  716. senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
  717. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  718. result = dal.SelectProgram(mac, programname, ref errorinfo);
  719. if (result <= 0)
  720. {
  721. temperrorinfo = "";
  722. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{orgprogramname}]", ref temperrorinfo);
  723. errorinfo = $"选择程序发生错误:{errorinfo}";
  724. return result;
  725. }
  726. temperrorinfo = "";
  727. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{orgprogramname}]", ref temperrorinfo);
  728. return 1;
  729. }
  730. private int BgDownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
  731. {
  732. string temperrorinfo = "";
  733. BgProgramDal bgdal = new BgProgramDal(CurrDb);
  734. int result = bgdal.DownloadProgram(mac, orgprogramname, ref errorinfo);
  735. if (result == -100)
  736. {
  737. loger.LogError($"S7F2回复代码为{errorinfo}");
  738. temperrorinfo = "";
  739. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
  740. return result;
  741. }
  742. if (result == -200)
  743. {
  744. loger.LogError($"S7F4回复代码为{errorinfo}");
  745. temperrorinfo = "";
  746. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
  747. return result;
  748. }
  749. if (result <= 0)
  750. {
  751. loger.LogError($"下载程序错误{errorinfo}");
  752. temperrorinfo = "";
  753. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] unknow error", ref temperrorinfo);
  754. return result;
  755. }
  756. temperrorinfo = "";
  757. senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
  758. return 1;
  759. }
  760. /// <summary>
  761. /// 清除程序
  762. /// </summary>
  763. /// <param name="maccode"></param>
  764. /// <param name="errorinfo"></param>
  765. /// <returns></returns>
  766. private int ClearProgramAuto(string maccode,ref string errorinfo)
  767. {
  768. //if (!string.IsNullOrEmpty(AppConfigurtaionServices.Configuration["Client"])
  769. // && AppConfigurtaionServices.Configuration["Client"] == "Onsemi")
  770. //{
  771. var dal = new Dad3350ProgramDal(CurrDb);
  772. return dal.ClearProgramAutoDir(maccode, ref errorinfo);
  773. //}
  774. //return 1;
  775. }
  776. private int DiodesBgDownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
  777. {
  778. string temperrorinfo = "";
  779. BgProgramDal bgdal = new BgProgramDal(CurrDb);
  780. int result = bgdal.DiodesDownloadProgram(mac, orgprogramname, ref errorinfo);
  781. if (result == -100)
  782. {
  783. loger.LogError($"S7F2回复代码为{errorinfo}");
  784. temperrorinfo = "";
  785. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F1({errorinfo})", ref temperrorinfo);
  786. return result;
  787. }
  788. if (result == -200)
  789. {
  790. loger.LogError($"S7F4回复代码为{errorinfo}");
  791. temperrorinfo = "";
  792. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] S7F3({errorinfo})", ref temperrorinfo);
  793. return result;
  794. }
  795. if (result <= 0)
  796. {
  797. loger.LogError($"下载程序错误{errorinfo}");
  798. temperrorinfo = "";
  799. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{orgprogramname}] unknow error", ref temperrorinfo);
  800. return result;
  801. }
  802. temperrorinfo = "";
  803. senddal.SendS10F3(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
  804. result = bgdal.SelectProgram(mac, orgprogramname, ref errorinfo);
  805. if (result <= 0)
  806. {
  807. temperrorinfo = "";
  808. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{orgprogramname}]", ref temperrorinfo);
  809. errorinfo = $"选择程序发生错误:{errorinfo}";
  810. return result;
  811. }
  812. temperrorinfo = "";
  813. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{orgprogramname}]", ref temperrorinfo);
  814. return 1;
  815. }
  816. private int Dad3650DownloadProgram(Machine mac, string orgprogramname, MacOrderSendDal senddal, ref string errorinfo)
  817. {
  818. string programname = "";
  819. string temperrorinfo = "";
  820. Dad3650ProgramDal dal = new Dad3650ProgramDal(CurrDb, loger);
  821. int result = dal.DownloadProgram(mac, orgprogramname, ref programname, ref errorinfo);
  822. if (result <= 0)
  823. {
  824. temperrorinfo = "";
  825. senddal.SendS10F3NoAnswer(mac.FCode, $"Recipe download fail [{orgprogramname}]", ref temperrorinfo);
  826. return result;
  827. }
  828. temperrorinfo = "";
  829. loger.LogError($"发送下载程序成功信息到机台上");
  830. senddal.SendS10F3NoAnswer(mac.FCode, $"Recipe download success [{orgprogramname}]", ref temperrorinfo);
  831. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  832. result = dal.SelectProgram(mac, programname, ref errorinfo);
  833. if (result <= 0)
  834. {
  835. temperrorinfo = "";
  836. senddal.SendS10F3NoAnswer(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
  837. errorinfo = $"选择程序发生错误:{errorinfo}";
  838. return result;
  839. }
  840. temperrorinfo = "";
  841. senddal.SendS10F3NoAnswer(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  842. return 1;
  843. }
  844. public int DownloadProgram(string maccode, string orgprogramname,ref string errorinfo)
  845. {
  846. try
  847. {
  848. int result = 0;
  849. string condition = $" and a.fcode='{maccode}'";
  850. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  851. if (macs == null || macs.Count <= 0)
  852. {
  853. errorinfo = "未找到机台信息。";
  854. return -1;
  855. }
  856. // 清除原有程序
  857. //if (ClearProgramAuto(macs[0].FCode, ref errorinfo) < 0)
  858. // return -1;
  859. ClearProgramAuto(macs[0].FCode, ref errorinfo);
  860. errorinfo = "";
  861. //提示下载程序成功
  862. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  863. switch (macs[0].MModeCode.ToLower())
  864. {
  865. case "dad3350":
  866. case "dfd6341":
  867. case "dfd6340":
  868. return Dad3350DownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  869. case "dad3650":
  870. case "dfd6362":
  871. return Dad3650DownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  872. case "dfg8540":
  873. return BgDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  874. case "bg":
  875. return DiodesBgDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  876. default:
  877. if(macs[0].SupplierFCode.ToLower()=="kns")
  878. {
  879. if(macs[0].FCode.ToLower()=="wkb-074")
  880. {
  881. return KnsDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
  882. }
  883. else
  884. {
  885. return KnsDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  886. }
  887. }
  888. else
  889. {
  890. return AsmDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  891. }
  892. }
  893. }
  894. catch (Exception ex)
  895. {
  896. errorinfo = ex.StackTrace+ ex.Message.ToString();
  897. return -1;
  898. }
  899. }
  900. public int WBDownloadProgram(Machine mac, string programname,int ver, MacOrderSendDal senddal, ref string errorinfo)
  901. {
  902. string temperrorinfo = "";
  903. Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
  904. int result = dal.DownloadProgramForWB(mac, programname,ver, ref errorinfo);
  905. if (result == -100)
  906. {
  907. loger.LogError($"S7F2回复代码为{errorinfo}");
  908. temperrorinfo = "";
  909. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
  910. return result;
  911. }
  912. if (result == -200)
  913. {
  914. loger.LogError($"S7F4回复代码为{errorinfo}");
  915. temperrorinfo = "";
  916. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
  917. return result;
  918. }
  919. if (result <= 0)
  920. {
  921. temperrorinfo = "";
  922. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}]", ref temperrorinfo);
  923. return result;
  924. }
  925. temperrorinfo = "";
  926. loger.LogError($"发送下载程序成功信息到机台上");
  927. senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  928. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  929. result = dal.SelectProgram(mac, programname, ref errorinfo);
  930. if (result <= 0)
  931. {
  932. temperrorinfo = "";
  933. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
  934. errorinfo = $"选择程序发生错误:{errorinfo}";
  935. return result;
  936. }
  937. temperrorinfo = "";
  938. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  939. return 1;
  940. }
  941. public int DownloadProgramForLot(string maccode, string programname,int ver, ref string errorinfo)
  942. {
  943. try
  944. {
  945. int result = 0;
  946. string condition = $" and a.fcode='{maccode}'";
  947. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  948. if (macs == null || macs.Count <= 0)
  949. {
  950. errorinfo = "未找到机台信息。";
  951. return -1;
  952. }
  953. //提示下载程序成功
  954. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  955. switch (macs[0].MModeID)
  956. {
  957. case 14:
  958. case 184://WB调程
  959. return WBDownloadProgram(macs[0], programname,ver, senddal, ref errorinfo);
  960. default:
  961. programname = $"{programname}.rcp";
  962. return DownloadProgramForFile(macs[0], programname, ver, senddal, ref errorinfo);
  963. //采用文件传输
  964. }
  965. }
  966. catch (Exception ex)
  967. {
  968. errorinfo = ex.Message.ToString();
  969. return -1;
  970. }
  971. }
  972. public int DownloadProgramForLot01(string maccode, string programname, int ver, ref string errorinfo)
  973. {
  974. try
  975. {
  976. int result = 0;
  977. string condition = $" and a.fcode='{maccode}'";
  978. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  979. if (macs == null || macs.Count <= 0)
  980. {
  981. errorinfo = "未找到机台信息。";
  982. return -1;
  983. }
  984. //提示下载程序成功
  985. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  986. switch (macs[0].MModeID)
  987. {
  988. case 14:
  989. case 184://WB调程
  990. return WBDownloadProgram(macs[0], programname, ver, senddal, ref errorinfo);
  991. default:
  992. return DownloadProgramForFile(macs[0], programname, ver, senddal, ref errorinfo);
  993. //采用文件传输
  994. }
  995. }
  996. catch (Exception ex)
  997. {
  998. errorinfo = ex.Message.ToString();
  999. return -1;
  1000. }
  1001. }
  1002. private int DownloadProgramForFile(Machine mac, string programname, int ver, MacOrderSendDal senddal, ref string errorinfo)
  1003. {
  1004. string temperrorinfo = "";
  1005. Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb, loger);
  1006. int result = dal.DownloadProgramForFile(mac, programname, ver, ref errorinfo);
  1007. if (result == -100)
  1008. {
  1009. loger.LogError($"S7F2回复代码为{errorinfo}");
  1010. temperrorinfo = "";
  1011. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F1({errorinfo})", ref temperrorinfo);
  1012. return result;
  1013. }
  1014. if (result == -200)
  1015. {
  1016. loger.LogError($"S7F4回复代码为{errorinfo}");
  1017. temperrorinfo = "";
  1018. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] S7F3({errorinfo})", ref temperrorinfo);
  1019. return result;
  1020. }
  1021. if (result <= 0)
  1022. {
  1023. temperrorinfo = "";
  1024. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}]", ref temperrorinfo);
  1025. return result;
  1026. }
  1027. temperrorinfo = "";
  1028. loger.LogError($"发送下载程序成功信息到机台上");
  1029. senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  1030. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  1031. result = dal.SelectProgram(mac, programname, ref errorinfo);
  1032. if (result <= 0)
  1033. {
  1034. temperrorinfo = "";
  1035. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}]", ref temperrorinfo);
  1036. errorinfo = $"选择程序发生错误:{errorinfo}";
  1037. return result;
  1038. }
  1039. temperrorinfo = "";
  1040. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  1041. return 1;
  1042. }
  1043. private int UpProgramForOfilm(OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo)
  1044. {
  1045. try
  1046. {
  1047. List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
  1048. int parentid = datas[0].ID;//获取L的ID值
  1049. datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
  1050. programname = datas[0].FContent;
  1051. string remark = programname;
  1052. byte[] filedatas = datas[1].OrgDatas;
  1053. string condition = $" and a.fcode='{entity.MainMsg.McaCode}'";
  1054. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1055. if (macs.Count <= 0)
  1056. {
  1057. errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
  1058. return -1;
  1059. }
  1060. switch (macs[0].MModeCode.ToLower())
  1061. {
  1062. case "dad3350":
  1063. case "dad3650":
  1064. case "dfd6362":
  1065. case "dfd6341":
  1066. programname = DiodesProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
  1067. if (errorinfo != "")
  1068. {
  1069. errorinfo = $"分析文件名称发生错误:{errorinfo}";
  1070. return -1;
  1071. }
  1072. break;
  1073. case "dfg8540":
  1074. programname = Bg8761ProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
  1075. if (errorinfo != "")
  1076. {
  1077. errorinfo = $"分析文件名称发生错误:{errorinfo}";
  1078. return -1;
  1079. }
  1080. break;
  1081. }
  1082. BusinessFileDal dal = new BusinessFileDal(CurrDb);
  1083. BusinessFile busifile = dal.UpdownFile(filedatas, filedir, programname, macs[0], remark, usercode, ref errorinfo);
  1084. if (busifile == null)
  1085. {
  1086. errorinfo = $"处理文件发生错误:{errorinfo}";
  1087. return -1;
  1088. }
  1089. //添加程序,用于参数比对
  1090. ProgramMstDal pmdal = new ProgramMstDal(CurrDb);
  1091. pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
  1092. //调用MES接口,把程序信息传给MES
  1093. //string temperrorinfo1 = "";
  1094. //MacOrderSendDal senddal1 = new MacOrderSendDal(db);
  1095. //int result=senddal1.SendS10F3(entity.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
  1096. //if(result<=0)
  1097. //{
  1098. // log
  1099. //}
  1100. return 1;
  1101. }
  1102. catch (Exception ex)
  1103. {
  1104. errorinfo = ex.Message.ToString();
  1105. return -1;
  1106. }
  1107. }
  1108. public int DownloadProgramS7F6(string maccode, string orgprogramname, ref string errorinfo)
  1109. {
  1110. try
  1111. {
  1112. int result = 0;
  1113. string condition = $" and a.fcode='{maccode}'";
  1114. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1115. if (macs == null || macs.Count <= 0)
  1116. {
  1117. errorinfo = "未找到机台信息。";
  1118. return -1;
  1119. }
  1120. MacOrderSendDal senddal = new MacOrderSendDal(CurrDb);
  1121. if (macs[0].SupplierFCode.ToLower() == "kns")
  1122. {
  1123. if(macs[0].FCode.ToLower()=="wkb-074")
  1124. {
  1125. return KnsDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
  1126. }
  1127. else
  1128. {
  1129. return KnsDownloadProgram(macs[0], orgprogramname, senddal, ref errorinfo);
  1130. }
  1131. }
  1132. else
  1133. {
  1134. return AsmDownloadProgramS7F6(macs[0], orgprogramname, senddal, ref errorinfo);
  1135. }
  1136. }
  1137. catch (Exception ex)
  1138. {
  1139. errorinfo = ex.Message.ToString();
  1140. return -1;
  1141. }
  1142. }
  1143. private int AsmDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
  1144. {
  1145. string temperrorinfo = "";
  1146. AsmProgramDal asmdal = new AsmProgramDal(CurrDb);
  1147. int result = DownloadProgramS7F6(mac, programname, ref errorinfo);
  1148. if (result <= 0)
  1149. {
  1150. loger.LogError($"下载程序错误{errorinfo}");
  1151. temperrorinfo = "";
  1152. senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
  1153. return result;
  1154. }
  1155. temperrorinfo = "";
  1156. loger.LogError($"发送下载程序成功信息到机台上");
  1157. senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  1158. loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  1159. result = asmdal.SelProgram(mac, programname, ref errorinfo);
  1160. if (result == -300)
  1161. {
  1162. temperrorinfo = "";
  1163. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
  1164. return result;
  1165. }
  1166. if (result <= 0)
  1167. {
  1168. temperrorinfo = "";
  1169. senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
  1170. errorinfo = $"选择程序发生错误:{errorinfo}";
  1171. return result;
  1172. }
  1173. temperrorinfo = "";
  1174. senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  1175. return 1;
  1176. }
  1177. //private int KnsDownloadProgramS7F6(Machine mac, string programname, MacOrderSendDal senddal, ref string errorinfo)
  1178. //{
  1179. // string temperrorinfo = "";
  1180. // KnsProgramDal asmdal = new KnsProgramDal(CurrDb);
  1181. // int result = DownloadProgramS7F6(mac, programname, ref errorinfo);
  1182. // if (result <= 0)
  1183. // {
  1184. // loger.LogError($"下载程序错误{errorinfo}");
  1185. // temperrorinfo = "";
  1186. // senddal.SendS10F3(mac.FCode, $"Recipe download fail [{programname}] unknow error", ref temperrorinfo);
  1187. // return result;
  1188. // }
  1189. // temperrorinfo = "";
  1190. // loger.LogError($"发送下载程序成功信息到机台上");
  1191. // senddal.SendS10F3(mac.FCode, $"Recipe download success [{programname}]", ref temperrorinfo);
  1192. // loger.LogError($"信息发送完成:{temperrorinfo}开始装载程序......");
  1193. // Thread.Sleep(1000);
  1194. // result = asmdal.SelectProgram(mac, programname, ref errorinfo);
  1195. // if (result == -300)
  1196. // {
  1197. // temperrorinfo = "";
  1198. // senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] S2F41({errorinfo})", ref temperrorinfo);
  1199. // return result;
  1200. // }
  1201. // if (result <= 0)
  1202. // {
  1203. // temperrorinfo = "";
  1204. // senddal.SendS10F3(mac.FCode, $"Selcet Recipe fail [{programname}] unknow error", ref temperrorinfo);
  1205. // errorinfo = $"选择程序发生错误:{errorinfo}";
  1206. // return result;
  1207. // }
  1208. // temperrorinfo = "";
  1209. // senddal.SendS10F3(mac.FCode, $"Selcet Recipe success [{programname}]", ref temperrorinfo);
  1210. // return 1;
  1211. //}
  1212. public int DownloadProgramS7F6(Machine mac, string orgprogramname, ref string errorinfo)
  1213. {
  1214. try
  1215. {
  1216. orgprogramname = orgprogramname.Trim();
  1217. #region
  1218. #endregion
  1219. string programname = orgprogramname;
  1220. int result = 0;
  1221. if (mac.CallPMode <= 2)
  1222. {
  1223. //说明要下载程序
  1224. MacProgramDal macprogramdal = new MacProgramDal(CurrDb);
  1225. int orgtypeid = 1;
  1226. string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
  1227. if (mac.CallPMode == 1)
  1228. {
  1229. orgtypeid = 1;
  1230. }
  1231. else
  1232. {
  1233. orgtypeid = 2;
  1234. }
  1235. byte[] filedatas = macprogramdal.ReadMacProgram(mac, orgprogramname, orgtypeid, programdir, ref errorinfo);
  1236. if (filedatas == null)
  1237. return -30;
  1238. result = DownloadProgramS7F6(mac, programname, filedatas, ref errorinfo);
  1239. if (result <= 0)
  1240. return result;
  1241. }
  1242. return 1;
  1243. }
  1244. catch (Exception ex)
  1245. {
  1246. errorinfo = ex.Message.ToString();
  1247. return -1;
  1248. }
  1249. }
  1250. public int DownloadProgramS7F6(Machine mac, string programname, byte[] filedatas, ref string errorinfo)
  1251. {
  1252. try
  1253. {
  1254. //要修改程序名称
  1255. OrderDetail order = ReadMachineOrderDetail(mac.ID, 7, 6, ref errorinfo);
  1256. if (order == null)
  1257. return -1;
  1258. string condition = $" and a.preid={order.ID}";
  1259. List<OrderData> datas = CurrDb.FindListForCondition<OrderData>(condition, ref errorinfo).ToList();
  1260. if (datas == null)
  1261. return -1;
  1262. List<OrderData> tempdatas = datas.Where(t => t.ParentID == 0).ToList();
  1263. tempdatas = datas.Where(t => t.ParentID == tempdatas[0].ID).OrderBy(t => t.FNum).ToList();
  1264. tempdatas[0].FContent = programname;
  1265. tempdatas[1].OrgDatas = filedatas;
  1266. HsmsWeb accessmac = new HsmsWeb();
  1267. int result = accessmac.SendOrderNoAnswer(mac.FCode, order, datas, ref errorinfo);
  1268. return result;
  1269. }
  1270. catch (Exception ex)
  1271. {
  1272. errorinfo = ex.Message.ToString();
  1273. return -1;
  1274. }
  1275. }
  1276. }
  1277. }