MesDal.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. using Cksoft.Data;
  2. using Cksoft.Data.Repository;
  3. using Cksoft.Unity;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. using System.Data.OracleClient;
  9. namespace DllEapDal
  10. {
  11. public class MesDal
  12. {
  13. ///// <summary>
  14. ///// 根据lot编号和机台编号,读取程序名称
  15. ///// </summary>
  16. ///// <param name="lot"></param>
  17. ///// <param name="maccode"></param>
  18. ///// <param name="errorinfo"></param>
  19. ///// <returns></returns>
  20. //public string GetLotProgramName(string lot, ref string errorinfo)
  21. //{
  22. // try
  23. // {
  24. // //return "12NE152-P-0-205-TP47";
  25. // //读取程序名称
  26. // string sqlstr = $@"select a.simtype,a.value,c.dt_description from FWCATNS_SIMS_PID a
  27. // inner join FWCATNS_STG_CONTROLLOT b on a.pid=b.sourcedevice and a.diepart=b.diepart
  28. // left outer join FWCATNS_AS_DEVICETOOLING c on a.pid=c.dt_device and a.diepart=c.dt_diepart and a.simtype=c.dt_tooltype
  29. // where b.controllotid='{lot}' and a.simtype in('MTP','TTP','BackGrindProgram')";
  30. // DataTable tempdt = QueryFromMes(sqlstr, ref errorinfo);
  31. // //读取
  32. // DataRow[] temprows = tempdt.Select("simtype='BackGrindProgram'");
  33. // if(temprows.Length<=0)
  34. // {
  35. // errorinfo = $"未找到lot【{lot}】对应的程序名称。";
  36. // return "";
  37. // }
  38. // string programname = temprows[0]["value"].ToString();
  39. // temprows = tempdt.Select("simtype='TTP'");
  40. // if (temprows.Length <= 0)
  41. // {
  42. // errorinfo = $"未找到lot【{lot}】对应的TTP信息。";
  43. // return "";
  44. // }
  45. // programname = $"{programname}-{temprows[0]["dt_description"].ToString()}";
  46. // temprows = tempdt.Select("simtype='MTP'");
  47. // if (temprows.Length <= 0)
  48. // {
  49. // errorinfo = $"未找到lot【{lot}】对应的MTP信息。";
  50. // return "";
  51. // }
  52. // if(temprows[0]["value"].ToString().Substring(0,1)=="1")
  53. // {
  54. // programname = $"{programname}-F";
  55. // }
  56. // else
  57. // {
  58. // programname = $"{programname}-TP";
  59. // }
  60. // string[] tts = temprows[0]["value"].ToString().Split('-');
  61. // programname = $"{programname}{int.Parse(tts[tts.Length-1])}";
  62. // return programname;
  63. // }
  64. // catch (Exception ex)
  65. // {
  66. // errorinfo = ex.Message.ToString();
  67. // return "";
  68. // }
  69. //}
  70. /// <summary>
  71. /// 根据lot编号和机台编号,读取程序名称
  72. /// </summary>
  73. /// <param name="lot"></param>
  74. /// <param name="maccode"></param>
  75. /// <param name="errorinfo"></param>
  76. /// <returns></returns>
  77. //public string GetLotProgramName(string lot, ref string errorinfo)
  78. //{
  79. // try
  80. // {
  81. // //return "12NE250-P-1-0059-0048";
  82. // //读取程序名称
  83. // //string sqlstr = $@"select a.simtype,a.value from FWCATNS_SIMS_PID a
  84. // // inner join FWCATNS_STG_CONTROLLOT b on a.pid=b.sourcedevice and a.diepart=b.diepart
  85. // // where b.controllotid='{lot}' and a.simtype in('MTP','TTP','BackGrindProgram')";
  86. // string sqlstr = $@"select a.simtype,a.value,b.diepart,b.sourcedevice from FWCATNS_SIMS_PID a
  87. // inner join FWCATNS_STG_CONTROLLOT b on a.pid=b.sourcedevice and a.diepart=b.diepart
  88. // where b.controllotid='{lot}' and a.simtype ='BackGrindProgram'";
  89. // DataTable tempdt = QueryFromMes(sqlstr, ref errorinfo);
  90. // if(tempdt==null)
  91. // {
  92. // return "";
  93. // }
  94. // //读取
  95. // DataRow[] temprows = tempdt.Select("simtype='BackGrindProgram'");
  96. // if (temprows.Length <= 0)
  97. // {
  98. // errorinfo = $"未找到lot【{lot}】对应的程序名称。";
  99. // return "";
  100. // }
  101. // string programname = temprows[0]["value"].ToString();
  102. // string diepart= temprows[0]["diepart"].ToString();
  103. // string sourcedevice = temprows[0]["sourcedevice"].ToString();
  104. // //sqlstr = $@"select a.dt_toolmodel value,a.dt_tooltype simtype from FWCATNS_AS_DEVICETOOLING a
  105. // // inner join FWCATNS_STG_CONTROLLOT b on a.dt_device=b.sourcedevice and a.dt_diepart=b.diepart
  106. // // where b.controllotid='{lot}' and a.dt_tooltype in('MTP','TTP')";
  107. // sqlstr = $@"select a.dt_toolmodel value,a.dt_tooltype simtype from FWCATNS_AS_DEVICETOOLING a
  108. // inner join FWCATNS_STG_CONTROLLOT b on a.dt_device=b.sourcedevice and a.dt_diepart=b.diepart
  109. // where b.controllotid='{lot}' and a.dt_tooltype ='TTP'";
  110. // tempdt = QueryFromMes(sqlstr, ref errorinfo);
  111. // if (tempdt == null)
  112. // {
  113. // return "";
  114. // }
  115. // temprows = tempdt.Select("simtype='TTP'");
  116. // if (temprows.Length <= 0)
  117. // {
  118. // errorinfo = $"未找到lot【{lot}】对应的TTP信息。";
  119. // return "";
  120. // }
  121. // programname = $"{programname}-{temprows[0]["value"].ToString().Substring(temprows[0]["value"].ToString().Length-4, 4)}";
  122. // sqlstr = $@"SELECT MAX (A.MATPRODUCTID) mtp
  123. // FROM MACMATERIALPRODUCT A, MACMATERIALPRODUCT_PN2M B
  124. // WHERE A.SYSID = B.FROMID
  125. // AND B.KEYDATA = 'IsTooling'
  126. // AND B.VALDATA = 'Y'
  127. // AND A.MATPRODUCTID IN
  128. // (SELECT B.CHILDMATPRODUCT
  129. // FROM MACMATERIALPRODUCT A,
  130. // MACMBOMLINK B,
  131. // FWCATNS_AS_SPEC C
  132. // WHERE A.TYPE = 'EPXY'
  133. // AND A.MATPRODUCTID = B.CHILDMATPRODUCT
  134. // AND B.MATPRODUCTID = C.SPE_BOM
  135. // AND C.SPE_DEVICE = '{sourcedevice}'
  136. // AND C.SPE_DIEPART = '{diepart}')";
  137. // tempdt = QueryFromMes(sqlstr, ref errorinfo);
  138. // if (tempdt == null)
  139. // {
  140. // return "";
  141. // }
  142. // if (tempdt.Rows.Count <= 0)
  143. // {
  144. // errorinfo = $"未找到lot【{lot}】对应的MTP信息。";
  145. // return "";
  146. // }
  147. // programname = $"{programname}-{tempdt.Rows[0]["mtp"].ToString().Substring(tempdt.Rows[0]["mtp"].ToString().Length - 4, 4)}";
  148. // //if (temprows[0]["value"].ToString().Substring(0, 1) == "1")
  149. // //{
  150. // // programname = $"{programname}-F";
  151. // //}
  152. // //else
  153. // //{
  154. // // programname = $"{programname}-TP";
  155. // //}
  156. // //string[] tts = temprows[0]["value"].ToString().Split('-');
  157. // //programname = $"{programname}{int.Parse(tts[tts.Length - 1])}";
  158. // return programname;
  159. // }
  160. // catch (Exception ex)
  161. // {
  162. // errorinfo = "函数名称[GetLotProgramName01]" + ex.Message.ToString();
  163. // return "";
  164. // }
  165. //}
  166. public string GetLotProgramName(string lot, ref string errorinfo)
  167. {
  168. try
  169. {
  170. //return "12NE250-P-1-0059-0048";
  171. string sqlstr = $@"select a.simtype,a.value,b.diepart,b.sourcedevice from FWCATNS_SIMS_PID a
  172. inner join FWCATNS_STG_CONTROLLOT b on a.pid=b.sourcedevice and a.diepart=b.diepart
  173. where b.controllotid='{lot}' and a.simtype in('BackGrindProgram','MTP','TTP')";
  174. DataTable tempdt = QueryFromMes(sqlstr, ref errorinfo);
  175. if (tempdt == null)
  176. {
  177. return "";
  178. }
  179. //读取
  180. DataRow[] temprows = tempdt.Select("simtype='BackGrindProgram'");
  181. if (temprows.Length <= 0)
  182. {
  183. errorinfo = $"未找到lot【{lot}】对应的程序名称。";
  184. return "";
  185. }
  186. string programname = temprows[0]["value"].ToString();
  187. string diepart = temprows[0]["diepart"].ToString();
  188. string sourcedevice = temprows[0]["sourcedevice"].ToString();
  189. temprows = tempdt.Select("simtype='TTP'");
  190. if (temprows.Length > 0&&temprows[0]["value"].ToString().Length>=4)
  191. {
  192. programname = $"{programname}-{temprows[0]["value"].ToString().Substring(temprows[0]["value"].ToString().Length - 4, 4)}";
  193. }
  194. else
  195. {
  196. sqlstr = $@"select a.dt_toolmodel value,a.dt_tooltype simtype from FWCATNS_AS_DEVICETOOLING a
  197. inner join FWCATNS_STG_CONTROLLOT b on a.dt_device=b.sourcedevice and a.dt_diepart=b.diepart
  198. where b.controllotid='{lot}' and a.dt_tooltype ='TTP'";
  199. DataTable subtempdt = QueryFromMes(sqlstr, ref errorinfo);
  200. if (subtempdt == null)
  201. {
  202. return "";
  203. }
  204. if (subtempdt.Rows.Count <= 0)
  205. {
  206. errorinfo = $"未找到lot【{lot}】对应的TTP信息。";
  207. return "";
  208. }
  209. programname = $"{programname}-{subtempdt.Rows[0]["value"].ToString().Substring(subtempdt.Rows[0]["value"].ToString().Length - 4, 4)}";
  210. }
  211. temprows = tempdt.Select("simtype='MTP'");
  212. if (temprows.Length > 0 && temprows[0]["value"].ToString().Length >= 4)
  213. {
  214. programname = $"{programname}-{temprows[0]["value"].ToString().Substring(temprows[0]["value"].ToString().Length - 4, 4)}";
  215. }
  216. else
  217. {
  218. sqlstr = $@"SELECT MAX (A.MATPRODUCTID) mtp
  219. FROM MACMATERIALPRODUCT A, MACMATERIALPRODUCT_PN2M B
  220. WHERE A.SYSID = B.FROMID
  221. AND B.KEYDATA = 'IsTooling'
  222. AND B.VALDATA = 'Y'
  223. AND A.MATPRODUCTID IN
  224. (SELECT B.CHILDMATPRODUCT
  225. FROM MACMATERIALPRODUCT A,
  226. MACMBOMLINK B,
  227. FWCATNS_AS_SPEC C
  228. WHERE A.TYPE = 'EPXY'
  229. AND A.MATPRODUCTID = B.CHILDMATPRODUCT
  230. AND B.MATPRODUCTID = C.SPE_BOM
  231. AND C.SPE_DEVICE = '{sourcedevice}'
  232. AND C.SPE_DIEPART = '{diepart}')";
  233. DataTable subtempdt = QueryFromMes(sqlstr, ref errorinfo);
  234. if (subtempdt == null)
  235. {
  236. return "";
  237. }
  238. if (subtempdt.Rows.Count <= 0)
  239. {
  240. errorinfo = $"未找到lot【{lot}】对应的MTP信息。";
  241. return "";
  242. }
  243. programname = $"{programname}-{subtempdt.Rows[0]["mtp"].ToString().Substring(subtempdt.Rows[0]["mtp"].ToString().Length - 4, 4)}";
  244. }
  245. return programname;
  246. }
  247. catch (Exception ex)
  248. {
  249. errorinfo = "函数名称[GetLotProgramName01]" + ex.Message.ToString();
  250. return "";
  251. }
  252. }
  253. public string GetLotProgramNameForMac(string maccode, ref string errorinfo)
  254. {
  255. try
  256. {
  257. //return "12NE152-P-0-205-TP47";
  258. //读取程序名称
  259. string sqlstr = $@"select a.appid from FWLOT a
  260. where a.lastlocation='{maccode}' and a.processingstatus='Active'
  261. order by a.startdate desc,a.starttime desc";
  262. DataTable tempdt = QueryFromMes(sqlstr, ref errorinfo);
  263. if(tempdt.Rows.Count<=0)
  264. {
  265. errorinfo = "未找到机台对应的批号。";
  266. return "";
  267. }
  268. string controlid = tempdt.Rows[0]["appid"].ToString();
  269. return GetLotProgramName(controlid,ref errorinfo);
  270. }
  271. catch (Exception ex)
  272. {
  273. errorinfo = ex.Message.ToString();
  274. return "";
  275. }
  276. }
  277. /// <summary>
  278. /// 根据lot编号,获取lot对应的机台编号和程序名称
  279. /// </summary>
  280. /// <param name="lot"></param>
  281. /// <param name="maccode">机台编号</param>
  282. /// <param name="errorinfo"></param>
  283. /// <returns>程序名称</returns>
  284. private DataTable QueryFromMes(string sqlstr, ref string errorinfo)
  285. {
  286. return QueryFromMes(sqlstr, "temp", ref errorinfo);
  287. }
  288. private DataTable QueryFromMes(string sqlstr, string tablename, ref string errorinfo)
  289. {
  290. OracleConnection conn = null;
  291. try
  292. {
  293. string connstr = AppConfigurtaionServices.Configuration["mesdb:ConnectionStrings"];
  294. conn = new OracleConnection(connstr);
  295. OracleDataAdapter oda = new OracleDataAdapter(sqlstr, conn);
  296. DataTable redt = new DataTable(tablename);
  297. oda.Fill(redt);
  298. return redt;
  299. }
  300. catch (Exception ex)
  301. {
  302. errorinfo = "函数名称[QueryFromMes]" + ex.Message.ToString();
  303. return null;
  304. }
  305. finally
  306. {
  307. if (conn != null)
  308. conn.Close();
  309. }
  310. }
  311. public int DownloadProgram(string lot,string mac, ref string errorinfo)
  312. {
  313. IDatabase db = null;
  314. try
  315. {
  316. //调程
  317. //db = DbFactory.Base("eap");
  318. //db.BeginTrans();
  319. //string programname = GetLotProgramName(lot, ref errorinfo);
  320. //if (programname == "")
  321. //{
  322. // errorinfo = $"从MES库中获取程序名称出错:{errorinfo},lot={lot}";
  323. // MacOrderSendDal senddal = new MacOrderSendDal(db);
  324. // string temperrorinfo = "";
  325. // senddal.SendS10F3(mac, $"Read recipe from MES error [{lot}]", ref temperrorinfo);
  326. // return -1;
  327. //}
  328. //errorinfo = "";
  329. //ProgramDal dal = new ProgramDal(db);
  330. //int result = dal.DownloadProgram(mac, programname, lot, ref errorinfo);
  331. //if (result <= 0)
  332. //{
  333. // db.Rollback();
  334. // MacOrderSendDal senddal = new MacOrderSendDal(db);
  335. // string temperrorinfo = "";
  336. // senddal.SendS10F3(mac, $"Can not found recipe[{programname}]", ref temperrorinfo);
  337. // return -1;
  338. //}
  339. //db.Commit();
  340. return 1;
  341. }
  342. catch (Exception ex)
  343. {
  344. db.Rollback();
  345. errorinfo = ex.Message.ToString();
  346. return -1;
  347. }
  348. finally
  349. {
  350. if (db != null)
  351. db.Close();
  352. }
  353. }
  354. }
  355. }