CallFunction.cs 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using DllEapCommon.Notice;
  5. using DllEapDal;
  6. using DllEapDal.OFILM;
  7. using DllEapDal.OFILM.MES;
  8. using DllEapDal.Onsemi;
  9. using DllEapEntity;
  10. using DllEapEntity.Onsemi;
  11. using DllEapEntity.Rms;
  12. using DllHsms;
  13. using DllSocketFile;
  14. using DllStatusShowDal;
  15. using Microsoft.Extensions.Logging;
  16. using Newtonsoft.Json;
  17. using RabbitMQ.Client;
  18. using System;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using System.Threading.Tasks;
  22. using WebStatusToolkit.Notice;
  23. namespace WebStatusToolkit
  24. {
  25. public class CallFunction
  26. {
  27. private static string mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"];
  28. //public static string MesApiPrefix
  29. //{
  30. // get
  31. // {
  32. // if (string.IsNullOrEmpty(mesApiPrefix))
  33. // mesApiPrefix = AppConfigurtaionServices.Configuration["mesApiPrefix"];
  34. // return mesApiPrefix;
  35. // }
  36. //}
  37. // private static string mesApiPrefix = "http://192.168.51.100:8080/ofilm/eap/";
  38. public static string CurrDbCode = "eap";
  39. public static string ReadDbCode = "eapslave";
  40. public static MacStatus CallIMacStatus(IModel channel, MacStatus entity, string usercode, ref string errorinfo)
  41. {
  42. IDatabase CurrDb = null;
  43. try
  44. {
  45. // entity.ProgramName = AppConfigurtaionServices.Configuration["SystemCode"];
  46. CurrDb = DbFactory.Base(CurrDbCode);
  47. CurrDb.BeginTrans();
  48. MacStatusDal tempdal = new MacStatusDal(CurrDb);
  49. MacStatus laststatus = tempdal.GetLastStatus(entity.MacCode, ref errorinfo);
  50. // 当机台的上一个状态是待机程序上传的并且该状态还未结束时,应等待待机程序解除状态,
  51. // 未解除时从队列上获取到的新状态不再插入数据库
  52. //if (laststatus != null && laststatus.ETime.ToString("yyyy-MM-dd HH:mm:ss") == "0001-01-01 00:00:00"
  53. // && (laststatus.ProgramName == "待机程序" || laststatus.ProgramName == "EAPWeb程序") && (laststatus.StatusID == 10 ||
  54. // laststatus.StatusID > 200000) && entity.ProgramName != "待机程序"
  55. // && entity.ProgramName != "EAPWeb程序")
  56. if (laststatus != null && laststatus.IsCover == -1 && entity.ProgramName != "待机程序"
  57. && entity.ProgramName != "EAPWeb程序")
  58. {
  59. errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," +
  60. $"该状态已被配置为不可覆盖," +
  61. $"不再插入队列中的新状态";
  62. return null;
  63. }
  64. if (laststatus != null && laststatus.StatusID == 204906 && entity.StatusID == 1)
  65. {
  66. errorinfo = $"当前机台【{laststatus.MacCode}】的前一状态为【{laststatus.StatusFName}】且该状态未解除," +
  67. $"且当前状态为离线," +
  68. $"不再插入队列中的新状态";
  69. return null;
  70. }
  71. if (laststatus != null)
  72. {
  73. if (string.IsNullOrEmpty(entity.Remark))
  74. {
  75. if (!string.IsNullOrEmpty(laststatus.Remark) && laststatus.Remark != "\0")
  76. {
  77. entity.Remark = laststatus.Remark;
  78. }
  79. else
  80. {
  81. var recipeS = CurrDb.FindListForCondition<MacStatus>($" and a.Maccode='{entity.MacCode}' " +
  82. $"and a.remark is not null and a.remark !='\0'", ref errorinfo).FirstOrDefault();
  83. if (recipeS != null)
  84. {
  85. entity.Remark = recipeS.Remark;
  86. }
  87. }
  88. }
  89. }
  90. //插入最后状态
  91. int result = tempdal.AddMacStatus01(entity, usercode, ref errorinfo);
  92. if (result <= 0)
  93. {
  94. errorinfo = $"添加MacStatus01发生错误:{errorinfo}";
  95. return null;
  96. }
  97. if (laststatus != null)//说明最后的状态与当前状态相同,直接返回
  98. {
  99. if (laststatus.Remark != entity.Remark)
  100. {
  101. laststatus.Remark = entity.Remark;
  102. if (CurrDb.UpdateFor<MacStatus>(laststatus, usercode) < 0)
  103. {
  104. errorinfo = $"机台【{laststatus.MacCode}】更新机种信息【{entity.Remark}】失败";
  105. return null;
  106. }
  107. if (NeedUpdateRecipe(laststatus.Remark, entity.Remark))
  108. {
  109. PushStatusData(channel, CurrDb, entity, errorinfo);
  110. }
  111. }
  112. if (laststatus.StatusID == entity.StatusID)
  113. {
  114. if (entity.StatusID == 6)
  115. {
  116. if (entity.AlarmCode == "SVID")
  117. {
  118. return entity;
  119. }
  120. else
  121. {
  122. int alarmTimeSpan = Convert.ToInt32(AppConfigurtaionServices.Configuration["SVIDTimeSpan"]);
  123. if (laststatus.AlarmCode == "0000")
  124. {
  125. if ((entity.STime - laststatus.STime).TotalSeconds <= alarmTimeSpan)
  126. {
  127. var res = tempdal.UpdateLastSvidAlarm(laststatus, entity, string.Empty, ref errorinfo);
  128. if (res == null)
  129. {
  130. CurrDb.Rollback();
  131. return null;
  132. }
  133. }
  134. }
  135. else
  136. {
  137. entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true);
  138. if (entity == null)
  139. {
  140. CurrDb.Rollback();
  141. return null;
  142. }
  143. PushStatusData(channel, CurrDb, entity, errorinfo);
  144. CurrDb.Commit();
  145. return entity;
  146. }
  147. }
  148. }
  149. // 当上一个状态与当前状态间隔时间大于5分钟时 结束上个状态,插入当前状态
  150. if ((entity.STime - laststatus.STime).TotalMinutes > 5)
  151. {
  152. entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, false);
  153. if (entity == null)
  154. {
  155. CurrDb.Rollback();
  156. return null;
  157. }
  158. }
  159. CurrDb.Commit();
  160. return entity;
  161. }
  162. else
  163. {
  164. if (entity.AlarmCode == "SVID")
  165. {
  166. entity.AlarmCode = "0000";
  167. entity.AlarmDescribe = "No Description Alarm";
  168. }
  169. }
  170. }
  171. else
  172. {
  173. if (entity.AlarmCode == "SVID")
  174. {
  175. entity.AlarmCode = "0000";
  176. entity.AlarmDescribe = "No Description Alarm";
  177. }
  178. }
  179. entity = tempdal.IMacStatus(entity, usercode, ref errorinfo, true);
  180. if (entity == null)
  181. {
  182. CurrDb.Rollback();
  183. return null;
  184. }
  185. PushStatusData(channel, CurrDb, entity, errorinfo);
  186. CurrDb.Commit();
  187. // 调用蓝信接口发送断线通知给相关人员
  188. if (entity.StatusID == 1 && AppConfigurtaionServices.Configuration["Client"] != null
  189. && AppConfigurtaionServices.Configuration["Client"] == "Ofilm")
  190. {
  191. var machine = CurrDb.FindListForCondition<Machine>($" and a.fcode='{entity.MacCode}'", ref errorinfo).FirstOrDefault();
  192. //if (machine.FactoryId == 8)
  193. //{
  194. Task.Run(() =>
  195. {
  196. string error = string.Empty;
  197. OfilmLanxinNoticeService.NoticeDisconn(machine, entity, error);
  198. });
  199. //}
  200. }
  201. return entity;
  202. }
  203. catch (Exception ex)
  204. {
  205. errorinfo = ex.Message.ToString();
  206. return null;
  207. }
  208. finally
  209. {
  210. if (CurrDb != null)
  211. CurrDb.Close();
  212. }
  213. }
  214. /// <summary>
  215. /// 程序参数比较
  216. /// </summary>
  217. /// <param name="maccode"></param>
  218. /// <param name="usercode"></param>
  219. /// <param name="errorinfo"></param>
  220. /// <returns></returns>
  221. //public static int CompareParams(string maccode,string usercode, ref string errorinfo)
  222. //{
  223. // IDatabase CurrDb = null;
  224. // try
  225. // {
  226. // CurrDb = DbFactory.Base(CurrDbCode);
  227. // CurrDb.BeginTrans();
  228. // //读取机台信息
  229. // string condition = $" and a.FCode='{maccode}'";
  230. // Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
  231. // if (mac.IsControl <= 0)
  232. // {
  233. // //说明此机台没有开启参数比对功能,无需比对
  234. // CurrDb.Commit();
  235. // return 1;
  236. // }
  237. // //string programname = (string)imputds["programname"];
  238. // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
  239. // //string programname = comdal.GetMacProgram(maccode, ref errorinfo);
  240. // //if (string.IsNullOrEmpty(programname))
  241. // //{
  242. // // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
  243. // // CurrDb.Rollback();
  244. // // return -1;
  245. // //}
  246. // ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo);
  247. // if (programmst==null)
  248. // {
  249. // errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
  250. // CurrDb.Rollback();
  251. // return -1;
  252. // }
  253. // //比较文件参数
  254. // ParamsComMst mst = comdal.CompareParams(mac, programmst, ref errorinfo);
  255. // if (mst == null)
  256. // {
  257. // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
  258. // CurrDb.Rollback();
  259. // return -1;
  260. // }
  261. // //插入比对记录
  262. // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo);
  263. // if (mst == null)
  264. // {
  265. // errorinfo = $"插入比对结果发生错误:{errorinfo}";
  266. // CurrDb.Rollback();
  267. // return -1;
  268. // }
  269. // CurrDb.Commit();
  270. // //如果参数不对,就发送停机指令
  271. // if (mst.IsPass <= 0)
  272. // {
  273. // int result = comdal.SendStopMac(maccode, ref errorinfo);
  274. // if (result <= 0)
  275. // {
  276. // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
  277. // return -1;
  278. // }
  279. // }
  280. // return 1;
  281. // }
  282. // catch (Exception ex)
  283. // {
  284. // errorinfo = ex.Message.ToString();
  285. // CurrDb.Rollback();
  286. // return -1;
  287. // }
  288. // finally
  289. // {
  290. // if (CurrDb != null)
  291. // CurrDb.Close();
  292. // }
  293. //}
  294. //public static int CompareParams(string maccode, string usercode, ref string errorinfo)
  295. //{
  296. // IDatabase CurrDb = null;
  297. // try
  298. // {
  299. // CurrDb = DbFactory.Base(CurrDbCode);
  300. // CurrDb.BeginTrans();
  301. // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
  302. // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
  303. // if (mac == null)
  304. // {
  305. // //string logerrorinfo = "";
  306. // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
  307. // CurrDb.Rollback();
  308. // return -1;
  309. // }
  310. // if(mac.SupplierFCode.ToLower()=="kns")
  311. // {
  312. // List<OrderData> datas = macdal.SendOrder(mac, 2, 15, "s2f15", ref errorinfo);
  313. // }
  314. // string partcode = MesDal.GetProductCode(maccode, ref errorinfo);
  315. // if (!string.IsNullOrEmpty(errorinfo))
  316. // {
  317. // errorinfo = $"从MES中获取产品发生错误,错误信息为:{errorinfo}";
  318. // return -1;
  319. // }
  320. // //没有找到产品编号,说明没有正在进行的任务,直接返回
  321. // if (string.IsNullOrEmpty(partcode))
  322. // return 1;
  323. // ProgramDal programdal = new ProgramDal(CurrDb);
  324. // ProgramMst programmst = programdal.FindProgram(mac, partcode, mac.PCode, ref errorinfo);
  325. // if (programmst == null)
  326. // {
  327. // //string logerrorinfo = "";
  328. // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"查找程序错误:{errorinfo}", ref logerrorinfo);
  329. // CurrDb.Rollback();
  330. // return -1;
  331. // }
  332. // ParamsComMst mst = null;
  333. // //比较机台程序名称
  334. // ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
  335. // string programname = comdal.GetMacProgramName(mac, ref errorinfo);
  336. // if(programmst.FName!=programname)
  337. // {
  338. // //errorinfo = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}";
  339. // //CurrDb.Rollback();
  340. // //return -1;
  341. // mst = new ParamsComMst();
  342. // mst.MacID = mac.ID;
  343. // mst.ProgramID = programmst.ID;
  344. // mst.IsPass = -1;
  345. // mst.Remark = $"当前产品{partcode}使用的程序为{programmst.FName},而实际程序名称为{programname}";
  346. // mst.CurrDetails = new List<ParamsComDetail>();
  347. // }
  348. // else
  349. // {
  350. // //比对程序参数
  351. // mst = comdal.CompareParams(mac, programmst, ref errorinfo);
  352. // if (mst == null)
  353. // {
  354. // errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
  355. // CurrDb.Rollback();
  356. // return -1;
  357. // }
  358. // }
  359. // //插入比对记录
  360. // mst = comdal.IUParamsComMst(mst, usercode, ref errorinfo);
  361. // if (mst == null)
  362. // {
  363. // errorinfo = $"插入比对结果发生错误:{errorinfo}";
  364. // CurrDb.Rollback();
  365. // return -1;
  366. // }
  367. // CurrDb.Commit();
  368. // //如果参数不对,就发送停机指令
  369. // if (mst.IsPass <= 0)
  370. // {
  371. // MacOrderDal macorderdal = new MacOrderDal(CurrDb);
  372. // int result = macorderdal.SendStopMac(maccode, ref errorinfo);
  373. // if (result <= 0)
  374. // {
  375. // errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
  376. // return -1;
  377. // }
  378. // }
  379. // return 1;
  380. // }
  381. // catch (Exception ex)
  382. // {
  383. // errorinfo =ex.Message.ToString();
  384. // CurrDb.Rollback();
  385. // return -1;
  386. // }
  387. // finally
  388. // {
  389. // if (CurrDb != null)
  390. // CurrDb.Close();
  391. // }
  392. //}
  393. // 判断是否需要推送更新机种信息给BI
  394. private static bool NeedUpdateRecipe(string lastRemark, string currentRemark)
  395. {
  396. if (string.IsNullOrEmpty(currentRemark))
  397. return false;
  398. if (string.IsNullOrEmpty(lastRemark))
  399. return true;
  400. var separators = new char[] { ' ', '-', '_', '.' };
  401. var oldRecipe = lastRemark.Split(separators).FirstOrDefault();
  402. var newRecipe = lastRemark.Split(separators).FirstOrDefault();
  403. return oldRecipe != newRecipe;
  404. }
  405. private static void PushStatusData(IModel channel, IDatabase db, MacStatus entity, string errorinfo)
  406. {
  407. if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null
  408. && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"]))
  409. {
  410. channel.QueueDeclare("BIStatus", false, false, false, null);
  411. byte[] queuedata = EntityHelper.SerializeBytes<MacStatus>(entity);
  412. channel.BasicPublish("", "BIStatus", null, queuedata);
  413. //var biDal = new BICollectDal(db);
  414. //biDal.PushStatusToBI(new List<MacStatus>() { entity }, errorinfo);
  415. }
  416. }
  417. public static int CompareParams(string maccode, string usercode, ref string errorinfo)
  418. {
  419. IDatabase CurrDb = null;
  420. try
  421. {
  422. CurrDb = DbFactory.Base(CurrDbCode);
  423. CurrDb.BeginTrans();
  424. #region 注销代码
  425. // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
  426. // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
  427. // if (mac == null)
  428. // {
  429. // //string logerrorinfo = "";
  430. // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
  431. // CurrDb.Rollback();
  432. // return -1;
  433. // }
  434. // if(mac.IsControl<=0)
  435. // {
  436. // CurrDb.Rollback();
  437. // return 1;
  438. // }
  439. //if(mac.MModeCode.ToLower()=="dad3350")
  440. // {
  441. // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
  442. // int result = dal.CompareParams(mac, "", ref errorinfo);
  443. // if(result<=0)
  444. // {
  445. // CurrDb.Commit();
  446. // return -1;
  447. // }
  448. // }
  449. // if (mac.MModeCode.ToLower() == "dfd6341")
  450. // {
  451. // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb);
  452. // int result = dal.CompareParams(mac, "", ref errorinfo);
  453. // if (result <= 0)
  454. // {
  455. // CurrDb.Commit();
  456. // return -1;
  457. // }
  458. // }
  459. #endregion
  460. string logerrorinfo = "";
  461. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对参数", ref logerrorinfo);
  462. int result = CompareParamsFor(CurrDb, maccode, usercode, ref errorinfo);
  463. CurrDb.Commit();
  464. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数结束:{errorinfo}", ref logerrorinfo);
  465. if (result <= 0)
  466. {
  467. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"比对参数失败001:{errorinfo}", ref logerrorinfo);
  468. string temperrorinfo = "";
  469. MacOrderSendDal macorderdal = new MacOrderSendDal(CurrDb);
  470. #region 台湾亿光停机
  471. if (AppConfigurtaionServices.Configuration["Client"] != null && AppConfigurtaionServices.Configuration["Client"].ToLower() == "everlight")
  472. {
  473. Machine mac = macorderdal.ReadMachine(maccode, ref temperrorinfo);
  474. EverLightStopMac stopMac = new EverLightStopMac();
  475. stopMac.StopMac(maccode, mac.IPAddress);
  476. result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo);
  477. if (result <= 0)
  478. {
  479. //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo);
  480. errorinfo = $"{errorinfo},{temperrorinfo}";
  481. }
  482. }
  483. #endregion
  484. else
  485. {
  486. result = macorderdal.SendStopMac(maccode, ref temperrorinfo);
  487. if (result <= 0)
  488. {
  489. errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo},{temperrorinfo}";
  490. //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"发送停止指令失败:{errorinfo}", ref logerrorinfo);
  491. return -1;
  492. }
  493. result = macorderdal.SendS10F3(maccode, "Parameter comparison failed", ref temperrorinfo);
  494. if (result <= 0)
  495. {
  496. //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"给机台发送消息失败:{errorinfo}", ref logerrorinfo);
  497. errorinfo = $"{errorinfo},{temperrorinfo}";
  498. }
  499. //string client = AppConfigurtaionServices.Configuration["Client"];
  500. string resume = AppConfigurtaionServices.Configuration["Resume"];
  501. if (int.Parse(resume) > 0)
  502. {
  503. //发送resume指令
  504. macorderdal.SendResumeMac(maccode, ref temperrorinfo);
  505. }
  506. }
  507. return -1;
  508. }
  509. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"参数比对完成", ref logerrorinfo);
  510. return 1;
  511. }
  512. catch (Exception ex)
  513. {
  514. errorinfo = $"比对参数发生异常:{ex.Message.ToString()}";
  515. return -1;
  516. }
  517. finally
  518. {
  519. if (CurrDb != null)
  520. CurrDb.Close();
  521. }
  522. }
  523. public static int CompareParamsForOfilm(string maccode, string usercode, ref string errorinfo)
  524. {
  525. var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"];
  526. if (callMesInterface == null || !Convert.ToBoolean(callMesInterface))
  527. {
  528. return 1;
  529. }
  530. try
  531. {
  532. //调用欧菲MES运行接口
  533. string url = $"{mesApiPrefix}equipmentStartUp";
  534. var paras = new Dictionary<string, string>();
  535. paras.Add("equipmentID", maccode);
  536. var response = HttpRequestHelper<OfilmMesApiResponse>.Get(url, paras, ref errorinfo);
  537. errorinfo = $"调用欧非MES设备运行接口equipmentStartUp,传入的参数:{JsonConvert.SerializeObject(paras)}," +
  538. $"接收到的值为:{JsonConvert.SerializeObject(response)}";
  539. return 1;
  540. }
  541. catch (Exception ex)
  542. {
  543. errorinfo = $"比对参数发生异常:{ex.Message.ToString()}";
  544. return -1;
  545. }
  546. finally
  547. {
  548. }
  549. }
  550. public static int CompareParamsFor(IDatabase CurrDb, string maccode, string usercode, ref string errorinfo)
  551. {
  552. try
  553. {
  554. MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
  555. Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
  556. if (mac == null)
  557. {
  558. //string logerrorinfo = "";
  559. //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
  560. return -1;
  561. }
  562. if (mac.IsControl <= 0)
  563. {
  564. return 1;
  565. }
  566. int result = 0;
  567. switch (mac.MModeCode.ToLower())
  568. {
  569. case "dad3350":
  570. Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
  571. result = dal.CompareParams(mac, "", ref errorinfo);
  572. if (result <= 0)
  573. {
  574. return -1;
  575. }
  576. return 1;
  577. case "dfd6341":
  578. Dfd6341ProgramDal dal6341 = new Dfd6341ProgramDal(CurrDb);
  579. result = dal6341.CompareParams(mac, "", ref errorinfo);
  580. if (result <= 0)
  581. {
  582. return -1;
  583. }
  584. return 1;
  585. case "dad3650":
  586. case "dfd6362":
  587. Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb);
  588. result = dal3650.CompareParams(mac, "", ref errorinfo);
  589. if (result <= 0)
  590. {
  591. return -1;
  592. }
  593. return 1;
  594. case "dfg8540":
  595. BgProgramDal bgdal = new BgProgramDal(CurrDb);
  596. result = bgdal.CompareParams(mac, "", ref errorinfo);
  597. if (result <= 0)
  598. {
  599. return -1;
  600. }
  601. return 1;
  602. default:
  603. string logerrorinfo = "";
  604. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"开始比对ASM参数......", ref logerrorinfo);
  605. Ad830PlusProgramDal tempdal = new Ad830PlusProgramDal(CurrDb);
  606. result = tempdal.CompareParams(mac, "", ref errorinfo);
  607. if (result <= 0)
  608. {
  609. WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"ASM参数比对失败{errorinfo}", ref logerrorinfo);
  610. return -1;
  611. }
  612. return 1;
  613. }
  614. }
  615. catch (Exception ex)
  616. {
  617. errorinfo = ex.Message.ToString();
  618. return -1;
  619. }
  620. }
  621. //public static int CompareParams(string maccode, string usercode, ref string errorinfo)
  622. //{
  623. // IDatabase CurrDb = null;
  624. // try
  625. // {
  626. // CurrDb = DbFactory.Base(CurrDbCode);
  627. // CurrDb.BeginTrans();
  628. // MacOrderSendDal macdal = new MacOrderSendDal(CurrDb);
  629. // Machine mac = macdal.ReadMachine(maccode, ref errorinfo);
  630. // if (mac == null)
  631. // {
  632. // //string logerrorinfo = "";
  633. // //WriteLog.WriteLogStr(maccode, "", DateTime.Now, $"读取机台错误:{errorinfo}", ref logerrorinfo);
  634. // CurrDb.Rollback();
  635. // return -1;
  636. // }
  637. // if (mac.IsControl <= 0)
  638. // {
  639. // CurrDb.Rollback();
  640. // return 1;
  641. // }
  642. // if (mac.MModeCode.ToLower() == "dad3350")
  643. // {
  644. // Dad3350ProgramDal dal = new Dad3350ProgramDal(CurrDb);
  645. // int result = dal.CompareParams(mac, "", ref errorinfo);
  646. // if (result <= 0)
  647. // {
  648. // CurrDb.Commit();
  649. // return -1;
  650. // }
  651. // }
  652. // if (mac.MModeCode.ToLower() == "dfd6341")
  653. // {
  654. // Dfd6341ProgramDal dal = new Dfd6341ProgramDal(CurrDb);
  655. // int result = dal.CompareParams(mac, "", ref errorinfo);
  656. // if (result <= 0)
  657. // {
  658. // CurrDb.Commit();
  659. // return -1;
  660. // }
  661. // }
  662. // return 1;
  663. // }
  664. // catch (Exception ex)
  665. // {
  666. // errorinfo = ex.Message.ToString();
  667. // CurrDb.Rollback();
  668. // return -1;
  669. // }
  670. // finally
  671. // {
  672. // if (CurrDb != null)
  673. // CurrDb.Close();
  674. // }
  675. //}
  676. /// <summary>
  677. /// <summary>
  678. /// 文件参数比较
  679. /// </summary>
  680. /// <param name="maccode"></param>
  681. /// <param name="usercode"></param>
  682. /// <param name="errorinfo"></param>
  683. /// <returns></returns>
  684. public static int CompareFileParams(string maccode, string usercode, ref string errorinfo)
  685. {
  686. IDatabase CurrDb = null;
  687. try
  688. {
  689. CurrDb = DbFactory.Base(CurrDbCode);
  690. CurrDb.BeginTrans();
  691. //读取机台信息
  692. string condition = $" and a.FCode='{maccode}'";
  693. Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
  694. if (mac.IsControl <= 0)
  695. {
  696. //说明此机台没有开启参数比对功能,无需比对
  697. CurrDb.Commit();
  698. return 1;
  699. }
  700. if (mac.SupplierFCode != "KNS")
  701. {
  702. //只有KNS机台才开启文件比对
  703. CurrDb.Commit();
  704. return 1;
  705. }
  706. //string programname = (string)imputds["programname"];
  707. ParamsComMstDal comdal = new ParamsComMstDal(CurrDb);
  708. ProgramMst programmst = comdal.GetMacProgram(mac, ref errorinfo);
  709. if (programmst == null)
  710. {
  711. errorinfo = $"未找到机台【{maccode}】对应的程序。{errorinfo}";
  712. CurrDb.Rollback();
  713. return -1;
  714. }
  715. //从机台上读取文件并保存
  716. string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
  717. KnsProgramDal knsdal = new KnsProgramDal(CurrDb);
  718. MacProgram macprogram = knsdal.SaveProgramFromMac(mac, programmst.FName, programdir, ref errorinfo);
  719. if (macprogram == null)
  720. {
  721. CurrDb.Rollback();
  722. return -1;
  723. }
  724. CurrDb.Commit();//先提交保存程序文件记录
  725. CurrDb.BeginTrans();
  726. //比较文件参数
  727. FileParamsComMst mst = comdal.CompareFileParams(mac, programmst, macprogram, ref errorinfo);
  728. if (mst == null)
  729. {
  730. errorinfo = $"未找到机台【{maccode}】程序【{programmst.FName}】对应的比对主档。{errorinfo}";
  731. CurrDb.Rollback();
  732. return -1;
  733. }
  734. //插入比对记录
  735. mst = comdal.IUFileParamsComMst(mst, usercode, ref errorinfo);
  736. if (mst == null)
  737. {
  738. errorinfo = $"插入比对结果发生错误:{errorinfo}";
  739. CurrDb.Rollback();
  740. return -1;
  741. }
  742. CurrDb.Commit();
  743. //如果参数不对,就发送停机指令
  744. if (mst.IsPass <= 0)
  745. {
  746. MacOrderDal macorderdal = new MacOrderDal(CurrDb);
  747. int result = macorderdal.SendStopMac(maccode, ref errorinfo);
  748. if (result <= 0)
  749. {
  750. errorinfo = $"发送停机指令发生错误,错误信息为:{errorinfo}";
  751. return -1;
  752. }
  753. }
  754. return 1;
  755. }
  756. catch (Exception ex)
  757. {
  758. errorinfo = ex.Message.ToString();
  759. CurrDb.Rollback();
  760. return -1;
  761. }
  762. finally
  763. {
  764. if (CurrDb != null)
  765. CurrDb.Close();
  766. }
  767. }
  768. public static int UpProgram(OrderBlock entitys, string filedir, string usercode, ref string errorinfo)
  769. {
  770. IDatabase CurrDb = null;
  771. try
  772. {
  773. CurrDb = DbFactory.Base(CurrDbCode);
  774. CurrDb.BeginTrans();
  775. string temperrorinfo1 = "";
  776. MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb);
  777. //上传文件
  778. string programname = "";
  779. int result = UpProgram(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo);
  780. if (result == -100)
  781. {
  782. //提示机台只能上传当前运行的程序
  783. senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1);
  784. CurrDb.Rollback();
  785. return result;
  786. }
  787. if (result <= 0)
  788. {
  789. senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1);
  790. CurrDb.Rollback();
  791. return result;
  792. }
  793. //调MES上传程序接口
  794. //string actionName = "uploadRecipe";
  795. //string fullUrl = mesApiPrefix + actionName;
  796. //IDictionary<string, string> dic = new Dictionary<string, string>();
  797. //dic.Add("equipmentID", entitys.MainMsg.McaCode);
  798. //dic.Add("recipeName", programname);
  799. //dic.Add("version", result.ToString());
  800. //var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
  801. //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," +
  802. // $"接收到的值为:{JsonConvert.SerializeObject(response)}";
  803. senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
  804. CurrDb.Commit();
  805. CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
  806. return 1;
  807. }
  808. catch (Exception ex)
  809. {
  810. errorinfo = ex.Message.ToString();
  811. CurrDb.Rollback();
  812. return -1;
  813. }
  814. finally
  815. {
  816. if (CurrDb != null)
  817. CurrDb.Close();
  818. }
  819. }
  820. /// <summary>
  821. /// 文件方式上传程序
  822. /// </summary>
  823. /// <param name="entitys"></param>
  824. /// <param name="filedir"></param>
  825. /// <param name="usercode"></param>
  826. /// <param name="errorinfo"></param>
  827. /// <returns></returns>
  828. public static int UpProgramForFile(OrderBlock entitys, string filedir, string usercode, ref string errorinfo)
  829. {
  830. IDatabase CurrDb = null;
  831. try
  832. {
  833. CurrDb = DbFactory.Base(CurrDbCode);
  834. CurrDb.BeginTrans();
  835. string temperrorinfo1 = "";
  836. MacOrderSendDal senddal1 = new MacOrderSendDal(CurrDb);
  837. //剔除WB机型
  838. string checkMachineForWB = string.Format($"SELECT COUNT(1) from machine WHERE MModeID in('14','184','187') and FCode='{entitys.MainMsg.McaCode}' ");
  839. int resultCheck = CurrDb.ExecuteBySql(checkMachineForWB);
  840. if (resultCheck > 0)
  841. return 1;
  842. //上传文件
  843. string programname = "";
  844. int result = UpProgramForFile(CurrDb, entitys, filedir, usercode, ref programname, ref errorinfo);
  845. //CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
  846. if (result == -100)
  847. {
  848. //提示机台只能上传当前运行的程序
  849. senddal1.SendS10F3(entitys.MainMsg.McaCode, $"Upload recipe fail,Please check Loading again.", ref temperrorinfo1);
  850. CurrDb.Rollback();
  851. return result;
  852. }
  853. if (result <= 0)
  854. {
  855. senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload fail {programname}", ref temperrorinfo1);
  856. CurrDb.Rollback();
  857. return result;
  858. }
  859. senddal1.SendS10F3(entitys.MainMsg.McaCode, $" Recipe upload success {programname}", ref temperrorinfo1);
  860. CurrDb.Commit();
  861. //调MES上传程序接口
  862. //string actionName = "uploadRecipe";
  863. //string fullUrl = mesApiPrefix + actionName;
  864. //IDictionary<string, string> dic = new Dictionary<string, string>();
  865. //dic.Add("equipmentID", entitys.MainMsg.McaCode);
  866. //dic.Add("recipeName", programname);
  867. //dic.Add("version", result.ToString());
  868. //var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
  869. //errorinfo = $"调用MES上传程序接口:uploadRecipe,传入的参数:{JsonConvert.SerializeObject(dic)}," +
  870. // $"接收到的值为:{JsonConvert.SerializeObject(response)}";
  871. CallMesuploadRecipe(entitys.MainMsg.McaCode, programname, result, ref errorinfo);
  872. return 1;
  873. }
  874. catch (Exception ex)
  875. {
  876. errorinfo = ex.Message.ToString();
  877. CurrDb.Rollback();
  878. return -1;
  879. }
  880. finally
  881. {
  882. if (CurrDb != null)
  883. CurrDb.Close();
  884. }
  885. }
  886. private static int CallMesuploadRecipe(string maccode, string programname, int version, ref string errorinfo)
  887. {
  888. var callMesInterface = AppConfigurtaionServices.Configuration["CallMesInterface"];
  889. if (callMesInterface == null || !Convert.ToBoolean(callMesInterface))
  890. {
  891. return 1;
  892. }
  893. try
  894. {
  895. //处理程序名称,传给MES的程序名称不能含.RCP扩展名称
  896. if (programname.Length > 4)
  897. {
  898. string extname = programname.Substring(programname.Length - 4, 4);
  899. if (extname == ".rcp")
  900. programname = programname.Substring(0, programname.Length - 4);
  901. }
  902. string actionName = "uploadRecipe";
  903. string fullUrl = mesApiPrefix + actionName;
  904. IDictionary<string, string> dic = new Dictionary<string, string>();
  905. dic.Add("equipmentID", maccode);
  906. dic.Add("recipeName", programname);
  907. dic.Add("version", version.ToString());
  908. var response = HttpRequestHelper<OfilmMesApiResponse>.Get(fullUrl, dic, ref errorinfo);
  909. errorinfo = $"调用MES上传程序接口:{fullUrl},传入的参数:{JsonConvert.SerializeObject(dic)}," +
  910. $"接收到的值为:{JsonConvert.SerializeObject(response)}";
  911. return 1;
  912. }
  913. catch (Exception ex)
  914. {
  915. errorinfo = ex.ToString();
  916. return -1;
  917. }
  918. }
  919. public static int ClearProgram(OrderBlock entitys, string usercode, ref string errorinfo)
  920. {
  921. IDatabase CurrDb = null;
  922. try
  923. {
  924. CurrDb = DbFactory.Base(CurrDbCode);
  925. CurrDb.BeginTrans();
  926. string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'";
  927. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  928. if (macs[0].IsRemoveProgram <= 0)
  929. {
  930. errorinfo = $"机台【{entitys.MainMsg.McaCode}】设置为不清除程序。";
  931. return -1;
  932. }
  933. int result = 0;
  934. switch (macs[0].MModeCode.ToLower())
  935. {
  936. case "dad3350"://未测试
  937. case "dfd6340-wash":
  938. case "dfd6341-wash":
  939. case "dfd6341":
  940. case "dfd6340":
  941. Dad3350ProgramDal dad3350 = new Dad3350ProgramDal(CurrDb);
  942. if (AppConfigurtaionServices.Configuration["Client"] == "Onsemi")
  943. {
  944. result = dad3350.ClearProgramAutoDir(entitys.MainMsg.McaCode, ref errorinfo);
  945. }
  946. else
  947. {
  948. result = dad3350.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo);
  949. }
  950. if (result <= 0)
  951. {
  952. CurrDb.Rollback();
  953. return -1;
  954. }
  955. break;
  956. default:
  957. MacProgramDal dal = new MacProgramDal(CurrDb);
  958. result = dal.ClearProgram(entitys.MainMsg.McaCode, ref errorinfo);
  959. if (result <= 0)
  960. {
  961. CurrDb.Rollback();
  962. return -1;
  963. }
  964. break;
  965. }
  966. CurrDb.Commit();
  967. return 1;
  968. }
  969. catch (Exception ex)
  970. {
  971. errorinfo = ex.Message.ToString();
  972. CurrDb.Rollback();
  973. return -1;
  974. }
  975. finally
  976. {
  977. if (CurrDb != null)
  978. CurrDb.Close();
  979. }
  980. }
  981. private static int UpProgram(IDatabase db, OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo)
  982. {
  983. try
  984. {
  985. List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
  986. int parentid = datas[0].ID;//获取L的ID值
  987. datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
  988. programname = datas[0].FContent;
  989. string remark = programname;
  990. byte[] filedatas = datas[1].OrgDatas;
  991. string condition = $" and a.fcode='{entity.MainMsg.McaCode}'";
  992. List<Machine> macs = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  993. if (macs.Count <= 0)
  994. {
  995. errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
  996. return -1;
  997. }
  998. if (macs[0].MModeCode == "ADT7900DUO")
  999. {
  1000. // ADT 设备没有上传程序按钮,也没法通过共享文件的形式上传。故不响应上传事件,全部使用WEP-Web端业务进行处理。
  1001. return 1;
  1002. }
  1003. if (AppConfigurtaionServices.Configuration["CallMesInterface"] != null && Convert.ToBoolean(AppConfigurtaionServices.Configuration["CallMesInterface"]))
  1004. {
  1005. string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo);
  1006. if (currprogramname == "")
  1007. {
  1008. return -1;
  1009. }
  1010. if (programname != currprogramname)
  1011. {
  1012. errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......";
  1013. return -100;
  1014. }
  1015. }
  1016. string logerrorinfo = "";
  1017. WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"机台型号={macs[0].MModeCode.Trim().ToLower()}", ref logerrorinfo);
  1018. switch (macs[0].MModeCode.Trim().ToLower())
  1019. {
  1020. case "dad3350":
  1021. case "dad3650":
  1022. case "dfd6362":
  1023. case "dfd6341":
  1024. case "dfd6340":
  1025. case "dfd6340-001":
  1026. WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"开始解析disco程序名称", ref logerrorinfo);
  1027. programname = DiodesProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
  1028. if (errorinfo != "")
  1029. {
  1030. errorinfo = $"分析文件名称发生错误:{errorinfo}";
  1031. return -1;
  1032. }
  1033. WriteLog.WriteLogStr(macs[0].FCode, "", DateTime.Now, $"解析程序名称完成,解析后程序名称={programname}", ref logerrorinfo);
  1034. break;
  1035. case "dfg8540":
  1036. programname = Bg8761ProgramFileHelper.GetProgramName01(filedatas, ref errorinfo);
  1037. if (errorinfo != "")
  1038. {
  1039. errorinfo = $"分析文件名称发生错误:{errorinfo}";
  1040. return -1;
  1041. }
  1042. break;
  1043. }
  1044. BusinessFileDal dal = new BusinessFileDal(db);
  1045. BusinessFile busifile = dal.UpdownFile(filedatas, filedir, programname, macs[0], remark, usercode, ref errorinfo);
  1046. if (busifile == null)
  1047. {
  1048. errorinfo = $"处理文件发生错误:{errorinfo}";
  1049. return -1;
  1050. }
  1051. //添加程序,用于参数比对
  1052. ProgramMstDal pmdal = new ProgramMstDal(db);
  1053. pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
  1054. return busifile.Version;
  1055. }
  1056. catch (Exception ex)
  1057. {
  1058. errorinfo = ex.Message.ToString();
  1059. return -1;
  1060. }
  1061. }
  1062. private static int UpProgramForFile(IDatabase db, OrderBlock entity, string filedir, string usercode, ref string programname, ref string errorinfo)
  1063. {
  1064. try
  1065. {
  1066. List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
  1067. int parentid = datas[0].ID;//获取L的ID值
  1068. datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
  1069. programname = datas[0].FContent;
  1070. string remark = programname;
  1071. string condition = $" and a.fcode='{entity.MainMsg.McaCode}'";
  1072. List<Machine> macs = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1073. if (macs.Count <= 0)
  1074. {
  1075. errorinfo = $"未找到机台编号{entity.MainMsg.McaCode}的信息。";
  1076. return -1;
  1077. }
  1078. string currprogramname = CallFunction.GetProgramName(macs[0].FCode, ref errorinfo);
  1079. currprogramname = $"{currprogramname}.rcp";
  1080. if (currprogramname == "")
  1081. {
  1082. return -1;
  1083. }
  1084. //if (programname != currprogramname)
  1085. //{
  1086. // errorinfo = $"当前程序名称={currprogramname},上传程序名称={programname},只能上传当前运行的程序......";
  1087. // return -100;
  1088. //}
  1089. //调用文件上传模式
  1090. SocketFile dal = new SocketFile();
  1091. BusinessFile busifile = dal.UploadFile(macs[0], programname, ref errorinfo);
  1092. if (busifile == null)
  1093. {
  1094. errorinfo = $"处理文件发生错误:{errorinfo}";
  1095. return -1;
  1096. }
  1097. //添加程序,用于参数比对
  1098. ProgramMstDal pmdal = new ProgramMstDal(db);
  1099. pmdal.IUProgramMst(macs[0], programname, ref errorinfo);
  1100. return busifile.Version;
  1101. }
  1102. catch (Exception ex)
  1103. {
  1104. errorinfo = ex.Message.ToString();
  1105. return -1;
  1106. }
  1107. }
  1108. private static int UpProgram001(IDatabase db, OrderBlock entity, string usercode, ref string errorinfo)
  1109. {
  1110. try
  1111. {
  1112. List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
  1113. int parentid = datas[0].ID;//获取L的ID值
  1114. datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
  1115. string programname = datas[0].FContent;
  1116. //string filepath = datas[1].FContent;
  1117. //查找程序表,是否存在此程序名称的记录
  1118. string condition = $" and {EntityAttribute.GetPropertyCondition<ProgramMst>(nameof(ProgramMst.FName))}='{programname}'";
  1119. List<ProgramMst> programmst = db.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  1120. ProgramMst programentity = null;
  1121. if (programmst.Count <= 0)
  1122. {
  1123. //添加程序记录
  1124. programentity = new ProgramMst();
  1125. errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。";
  1126. return -1;
  1127. }
  1128. else
  1129. {
  1130. programentity = programmst[0];
  1131. }
  1132. //读取机台
  1133. condition = $" and a.FCode='{entity.MainMsg.McaCode}'";
  1134. Machine mac = db.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
  1135. if (mac == null)
  1136. {
  1137. //说明此机台没有开启参数比对功能,无需比对
  1138. errorinfo = $"未找到机台【{entity.MainMsg.McaCode}】";
  1139. return -1;
  1140. }
  1141. //比对参数,并保存比对结果
  1142. ParamsComMstDal comparedal = new ParamsComMstDal(db);
  1143. ParamsComMst commst = comparedal.CompareParams(mac, programentity, ref errorinfo);
  1144. if (commst == null)
  1145. return -1;
  1146. commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo);
  1147. if (commst == null)
  1148. return -1;
  1149. if (commst.IsPass <= 0)
  1150. {
  1151. errorinfo = "参数比对没有通过。";
  1152. return -100;
  1153. }
  1154. //programentity.ServerPath = filepath;
  1155. ////更新服务器程序路径
  1156. //int result = db.UpdateFor<ProgramMst>(programentity, usercode);
  1157. //if (result <= 0)
  1158. // return -1;
  1159. return 1;
  1160. }
  1161. catch (Exception ex)
  1162. {
  1163. errorinfo = ex.Message.ToString();
  1164. return -1;
  1165. }
  1166. }
  1167. //private static int UpProgram(IDatabase db, OrderBlock entity, string usercode, ref string errorinfo)
  1168. //{
  1169. // try
  1170. // {
  1171. // string filedir = AppConfigurtaionServices.Configuration["ProgramDir"];
  1172. // List<OrderData> datas = entity.Datalists.Where(t => t.ParentID == 0).OrderBy(t => t.FNum).ToList();
  1173. // int parentid = datas[0].ID;//获取L的ID值
  1174. // datas = entity.Datalists.Where(t => t.ParentID == parentid).OrderBy(t => t.FNum).ToList();
  1175. // string programname = datas[0].FContent;
  1176. // string programdata = datas[1].FContent;
  1177. // byte[] filedatas = datas[1].OrgDatas;
  1178. // //查找程序表,是否存在此程序名称的记录
  1179. // string condition = $" and {EntityAttribute.GetPropertyCondition<ProgramMst>(nameof(ProgramMst.FName))}='{programname}'";
  1180. // List<ProgramMst> programmst = db.FindListForCondition<ProgramMst>(condition, ref errorinfo).ToList();
  1181. // ProgramMst programentity = null;
  1182. // if (programmst.Count <= 0)
  1183. // {
  1184. // //添加程序记录
  1185. // programentity = new ProgramMst();
  1186. // errorinfo = $"未找到程序【{programname}】,请先配置程序及其比对的参数。";
  1187. // return -1;
  1188. // }
  1189. // else
  1190. // {
  1191. // programentity = programmst[0];
  1192. // }
  1193. // //比对参数,并保存比对结果
  1194. // ParamsComMstDal comparedal = new ParamsComMstDal(db);
  1195. // ParamsComMst commst = comparedal.CompareParams(entity.MainMsg.McaCode, programentity.ID, ref errorinfo);
  1196. // if (commst == null)
  1197. // return -1;
  1198. // //if(commst.IsPass<=0)
  1199. // //{
  1200. // // errorinfo = "参数比对没有通过。";
  1201. // // return -100;
  1202. // //}
  1203. // commst = comparedal.IUParamsComMst(commst, usercode, ref errorinfo);
  1204. // if (commst == null)
  1205. // return -1;
  1206. // if (commst.IsPass <= 0)
  1207. // {
  1208. // errorinfo = "参数比对没有通过。";
  1209. // return -100;
  1210. // }
  1211. // programentity.ServerPath = filedir + $"\\{programentity.ID}";
  1212. // int result = UnityHelper.WriteFile(programentity.ServerPath, filedatas, ref errorinfo);
  1213. // if (result <= 0)
  1214. // return -1;
  1215. // //更新服务器程序路径
  1216. // result = db.UpdateFor<ProgramMst>(programentity, usercode);
  1217. // if (result <= 0)
  1218. // return -1;
  1219. // return 1;
  1220. // }
  1221. // catch (Exception ex)
  1222. // {
  1223. // errorinfo = ex.Message.ToString();
  1224. // return -1;
  1225. // }
  1226. //}
  1227. /// <summary>
  1228. /// 计算机台产量
  1229. /// </summary>
  1230. /// <param name="maccode"></param>
  1231. /// <param name="usercode"></param>
  1232. /// <param name="errorinfo"></param>
  1233. /// <returns></returns>
  1234. public static int AccountMacCount(string maccode, string usercode, ref string errorinfo)
  1235. {
  1236. IDatabase CurrDb = null;
  1237. try
  1238. {
  1239. CurrDb = DbFactory.Base(CurrDbCode);
  1240. CurrDb.BeginTrans();
  1241. MacCountDal dal = new MacCountDal(CurrDb);
  1242. List<Machine> macs = CurrDb.FindListForCondition<Machine>($" and a.fcode='{maccode}'", ref errorinfo).ToList();
  1243. int result = dal.IMacCount(macs[0], usercode, ref errorinfo);
  1244. if (result < 0)
  1245. {
  1246. CurrDb.Rollback();
  1247. return -1;
  1248. }
  1249. CurrDb.Commit();
  1250. return result;
  1251. }
  1252. catch (Exception ex)
  1253. {
  1254. errorinfo = ex.Message.ToString();
  1255. CurrDb.Rollback();
  1256. return -1;
  1257. }
  1258. finally
  1259. {
  1260. if (CurrDb != null)
  1261. CurrDb.Close();
  1262. }
  1263. }
  1264. /// <summary>
  1265. /// 保存机台程序
  1266. /// </summary>
  1267. /// <param name="maccode"></param>
  1268. /// <param name="usercode"></param>
  1269. /// <param name="errorinfo"></param>
  1270. /// <returns></returns>
  1271. public static int SaveProgram(string maccode, string usercode, ref string errorinfo)
  1272. {
  1273. IDatabase CurrDb = null;
  1274. try
  1275. {
  1276. CurrDb = DbFactory.Base(CurrDbCode);
  1277. CurrDb.BeginTrans();
  1278. //读取机台信息
  1279. string condition = $" and a.FCode='{maccode}'";
  1280. Machine mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList()[0];
  1281. if (mac == null)
  1282. {
  1283. CurrDb.Rollback();
  1284. return -1;
  1285. }
  1286. //从机台上读取文件并保存
  1287. string programdir = AppConfigurtaionServices.Configuration["ProgramDir"];
  1288. if (mac.SupplierFCode == "KNS")
  1289. {
  1290. KnsProgramDal knsdal = new KnsProgramDal(CurrDb);
  1291. MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo);
  1292. if (macprogram == null)
  1293. {
  1294. CurrDb.Rollback();
  1295. return -1;
  1296. }
  1297. }
  1298. else
  1299. {
  1300. AsmProgramDal knsdal = new AsmProgramDal(CurrDb);
  1301. MacProgram macprogram = knsdal.SaveProgram(maccode, usercode, ref errorinfo);
  1302. if (macprogram == null)
  1303. {
  1304. CurrDb.Rollback();
  1305. return -1;
  1306. }
  1307. }
  1308. CurrDb.Commit();//先提交保存程序文件记录
  1309. return 1;
  1310. }
  1311. catch (Exception ex)
  1312. {
  1313. errorinfo = ex.Message.ToString();
  1314. CurrDb.Rollback();
  1315. return -1;
  1316. }
  1317. finally
  1318. {
  1319. if (CurrDb != null)
  1320. CurrDb.Close();
  1321. }
  1322. }
  1323. public static MacOrder GetMacOrder(string maccode, ref string errorinfo)
  1324. {
  1325. IDatabase CurrDb = null;
  1326. try
  1327. {
  1328. CurrDb = DbFactory.Base(CurrDbCode);
  1329. CurrDb.BeginTrans();
  1330. //读取机台信息
  1331. string condition = $" and b.FCode='{maccode}'";
  1332. List<MacOrder> mac = CurrDb.FindListForCondition<MacOrder>(condition, ref errorinfo).ToList();
  1333. if (mac.Count <= 0)
  1334. {
  1335. errorinfo = $"未找到机台【{maccode}】对应的指令信息。";
  1336. return null;
  1337. }
  1338. CurrDb.Commit();
  1339. return mac[0];
  1340. }
  1341. catch (Exception ex)
  1342. {
  1343. errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】";
  1344. CurrDb.Rollback();
  1345. return null;
  1346. }
  1347. finally
  1348. {
  1349. if (CurrDb != null)
  1350. CurrDb.Close();
  1351. }
  1352. }
  1353. public static Machine GetMachine(string maccode, ref string errorinfo)
  1354. {
  1355. IDatabase CurrDb = null;
  1356. try
  1357. {
  1358. CurrDb = DbFactory.Base(CurrDbCode);
  1359. CurrDb.BeginTrans();
  1360. //读取机台信息
  1361. string condition = $" and a.FCode='{maccode}'";
  1362. List<Machine> mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1363. if (mac.Count <= 0)
  1364. {
  1365. errorinfo = $"未找到机台【{maccode}】。";
  1366. return null;
  1367. }
  1368. CurrDb.Commit();
  1369. return mac[0];
  1370. }
  1371. catch (Exception ex)
  1372. {
  1373. errorinfo = $"读取机台【{maccode}】指令发生错误,错误信息为【{ex.Message.ToString()}】";
  1374. CurrDb.Rollback();
  1375. return null;
  1376. }
  1377. finally
  1378. {
  1379. if (CurrDb != null)
  1380. CurrDb.Close();
  1381. }
  1382. }
  1383. public static List<OrderStatus> GetOrderStatus(int orderid, ref string errorinfo)
  1384. {
  1385. IDatabase CurrDb = null;
  1386. try
  1387. {
  1388. CurrDb = DbFactory.Base(CurrDbCode);
  1389. CurrDb.BeginTrans();
  1390. //读取机台信息
  1391. string condition = $" and a.PreID={orderid}";
  1392. List<OrderStatus> entitys = CurrDb.FindListForCondition<OrderStatus>(condition, ref errorinfo).ToList();
  1393. if (entitys == null)
  1394. {
  1395. CurrDb.Rollback();
  1396. return null;
  1397. }
  1398. CurrDb.Commit();
  1399. return entitys;
  1400. }
  1401. catch (Exception ex)
  1402. {
  1403. errorinfo = $"读取指令状态发生错误,错误信息为【{ex.Message.ToString()}】";
  1404. CurrDb.Rollback();
  1405. return null;
  1406. }
  1407. finally
  1408. {
  1409. if (CurrDb != null)
  1410. CurrDb.Close();
  1411. }
  1412. }
  1413. public static int AutoTrackOut(OrderBlock entitys, ref string errorinfo)
  1414. {
  1415. IDatabase CurrDb = null;
  1416. try
  1417. {
  1418. CurrDb = DbFactory.Base(CurrDbCode);
  1419. CurrDb.BeginTrans();
  1420. string condition = $" and a.FCode='{entitys.MainMsg.McaCode}'";
  1421. List<Machine> macs = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1422. StepTrackDal dal = new StepTrackDal(CurrDb);
  1423. int result = dal.AutoTrackOut(macs[0], ref errorinfo);
  1424. if (result <= 0)
  1425. {
  1426. CurrDb.Rollback();
  1427. return -1;
  1428. }
  1429. CurrDb.Commit();
  1430. return 1;
  1431. }
  1432. catch (Exception ex)
  1433. {
  1434. errorinfo = ex.Message.ToString();
  1435. CurrDb.Rollback();
  1436. return -1;
  1437. }
  1438. finally
  1439. {
  1440. if (CurrDb != null)
  1441. CurrDb.Close();
  1442. }
  1443. }
  1444. public static string GetProgramName(string maccode, ref string errorinfo)
  1445. {
  1446. IDatabase CurrDb = null;
  1447. try
  1448. {
  1449. CurrDb = DbFactory.Base(ReadDbCode);
  1450. //读取机台信息
  1451. string condition = $" and a.FCode='{maccode}'";
  1452. List<Machine> mac = CurrDb.FindListForCondition<Machine>(condition, ref errorinfo).ToList();
  1453. if (mac.Count <= 0)
  1454. {
  1455. errorinfo = $"未找到机台【{maccode}】。";
  1456. return null;
  1457. }
  1458. switch (mac[0].MModeCode.ToLower())
  1459. {
  1460. case "dad3650":
  1461. case "dfd6362":
  1462. Dad3650ProgramDal dal3650 = new Dad3650ProgramDal(CurrDb);
  1463. return dal3650.GetProgramName(mac[0], ref errorinfo);
  1464. case "dfg8540":
  1465. BgProgramDal bgdal = new BgProgramDal(CurrDb);
  1466. return bgdal.GetProgramName(mac[0], ref errorinfo);
  1467. default:
  1468. Ad830PlusProgramDal dal = new Ad830PlusProgramDal(CurrDb);
  1469. return dal.GetProgramName(mac[0], ref errorinfo);
  1470. }
  1471. }
  1472. catch (Exception ex)
  1473. {
  1474. errorinfo = $"读取机台【{maccode}】程序名称发生错误,错误信息为【{ex.Message.ToString()}】";
  1475. return null;
  1476. }
  1477. finally
  1478. {
  1479. if (CurrDb != null)
  1480. CurrDb.Close();
  1481. }
  1482. }
  1483. public static int RequestProgram(OrderBlock entitys, ILogger loger, ref string errorinfo)
  1484. {
  1485. IDatabase CurrDb = null;
  1486. try
  1487. {
  1488. CurrDb = DbFactory.Base(CurrDbCode);
  1489. CurrDb.BeginTrans();
  1490. string programname = entitys.Datalists[0].FContent.Trim();
  1491. //根据程序名称获取程序数据
  1492. ProgramDal dal = new ProgramDal(CurrDb, loger);
  1493. //int result = dal.DownloadProgramS7F6(entitys.MainMsg.McaCode, programname, ref errorinfo);
  1494. int result = dal.DownloadProgram(entitys.MainMsg.McaCode, programname, ref errorinfo);
  1495. return result;
  1496. }
  1497. catch (Exception ex)
  1498. {
  1499. errorinfo = ex.StackTrace + ex.Message.ToString();
  1500. CurrDb.Rollback();
  1501. return -1;
  1502. }
  1503. finally
  1504. {
  1505. if (CurrDb != null)
  1506. CurrDb.Close();
  1507. }
  1508. }
  1509. /// <summary>
  1510. /// 请求strip map
  1511. /// </summary>
  1512. /// <param name="entitys"></param>
  1513. /// <param name="errorinfo"></param>
  1514. /// <returns></returns>
  1515. public static int RequestStripmap(OrderBlock entitys, ref string errorinfo)
  1516. {
  1517. IDatabase CurrDb = null;
  1518. try
  1519. {
  1520. CurrDb = DbFactory.Base(CurrDbCode);
  1521. CurrDb.BeginTrans();
  1522. StripMapDal dal = new StripMapDal(CurrDb);
  1523. int result = dal.RequestStripmapE142(entitys, ref errorinfo);
  1524. if (result <= 0)
  1525. {
  1526. CurrDb.Rollback();
  1527. return -1;
  1528. }
  1529. CurrDb.Commit();
  1530. return 1;
  1531. }
  1532. catch (Exception ex)
  1533. {
  1534. errorinfo = ex.Message.ToString();
  1535. CurrDb.Rollback();
  1536. return -1;
  1537. }
  1538. finally
  1539. {
  1540. if (CurrDb != null)
  1541. CurrDb.Close();
  1542. }
  1543. }
  1544. public static int RequestUploadStripMap(OrderBlock entities, List<ReportDetail> reportDetails, ref string errorinfo)
  1545. {
  1546. IDatabase CurrDb = null;
  1547. try
  1548. {
  1549. CurrDb = DbFactory.Base(CurrDbCode);
  1550. CurrDb.BeginTrans();
  1551. StripMapDal dal = new StripMapDal(CurrDb);
  1552. int result = dal.RequestUploadStripMapE142(entities, reportDetails, ref errorinfo);
  1553. if (result <= 0)
  1554. {
  1555. CurrDb.Rollback();
  1556. return -1;
  1557. }
  1558. CurrDb.Commit();
  1559. return 1;
  1560. }
  1561. catch (Exception ex)
  1562. {
  1563. errorinfo = ex.Message.ToString();
  1564. CurrDb.Rollback();
  1565. return -1;
  1566. }
  1567. finally
  1568. {
  1569. if (CurrDb != null)
  1570. CurrDb.Close();
  1571. }
  1572. }
  1573. }
  1574. }