Form_MESTest.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. using Sunny.UI.Win32;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace MainForm.FaForm
  11. {
  12. public partial class Form_MESTest : Form
  13. {
  14. #region 变量
  15. public event AlarmMessageHandler MessageEvent;
  16. #endregion 变量
  17. #region 窗体事件
  18. public Form_MESTest()
  19. {
  20. InitializeComponent();
  21. }
  22. private void Form_MESTest_Load(object sender, EventArgs e)
  23. {
  24. cmbSNType.SelectedIndex = 0;
  25. cmbProResult.SelectedIndex = 0;
  26. }
  27. #endregion 窗体事件
  28. #region 进站相关
  29. /// <summary>
  30. /// 进站
  31. /// </summary>
  32. private async void btnStationIn_Click(object sender, EventArgs e)
  33. {
  34. try
  35. {
  36. string sn = txtSN.Text.Trim();
  37. if (string.IsNullOrEmpty(sn))
  38. {
  39. MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  40. return;
  41. }
  42. string snType = cmbSNType.Text.Trim();
  43. switch (snType)
  44. {
  45. case "产品SN":
  46. (int, string) result = StationInFunc_ProductSN(sn);
  47. ShowLog(result.Item2);
  48. break;
  49. case "载具SN":
  50. case "弹夹SN":
  51. MessageBox.Show("暂不支持的进站方式");
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. string str = ex.StackTrace;
  60. MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  61. }
  62. }
  63. /// <summary>
  64. /// 进站 - 产品SN
  65. /// </summary>
  66. /// <param name="sn">产品SN</param>
  67. /// <returns></returns>
  68. private (int, string) StationInFunc_ProductSN(string sn)
  69. {
  70. string stationStr = cmbStationName.Text.Trim();
  71. #region 校验
  72. string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
  73. string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
  74. string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
  75. string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
  76. List<TestItem> item = new List<TestItem>();
  77. item.Add(new TestItem()
  78. {
  79. Parameter_name = "产品结果",
  80. Parameter_value = cmbProResult.Text.Trim(),
  81. });
  82. if (string.IsNullOrEmpty(vehicleCode))
  83. item.Add(new TestItem()
  84. {
  85. Parameter_name = "载具码",
  86. Parameter_value = vehicleCode,
  87. });
  88. if (string.IsNullOrEmpty(vehicleCodeNum))
  89. item.Add(new TestItem()
  90. {
  91. Parameter_name = "载具穴号",
  92. Parameter_value = vehicleCodeNum,
  93. });
  94. if (string.IsNullOrEmpty(bulletclipCode))
  95. item.Add(new TestItem()
  96. {
  97. Parameter_name = "弹夹码",
  98. Parameter_value = bulletclipCode,
  99. });
  100. if (string.IsNullOrEmpty(bulletclipCodeNum))
  101. item.Add(new TestItem()
  102. {
  103. Parameter_name = "弹夹穴号",
  104. Parameter_value = bulletclipCodeNum,
  105. });
  106. #endregion 校验
  107. int mesResult = Form_Main.formHome.SaveStationInData(stationStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
  108. switch (mesResult)
  109. {
  110. case 1:
  111. return (1, "[1]成功;" + errorMsg);
  112. case 5:
  113. return (5, "[5]MES报警;" + errorMsg);
  114. case 6:
  115. return (6, "[6]上位机报警;" + errorMsg);
  116. default:
  117. return (999, "[999]未知结果;" + errorMsg);
  118. }
  119. }
  120. #endregion 进站相关
  121. #region 出站相关
  122. /// <summary>
  123. /// 出站
  124. /// </summary>
  125. private async void btnStationOut_Click(object sender, EventArgs e)
  126. {
  127. try
  128. {
  129. string sn = txtSN.Text.Trim();
  130. if (string.IsNullOrEmpty(sn))
  131. {
  132. MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  133. return;
  134. }
  135. string snType = cmbSNType.Text.Trim();
  136. switch (snType)
  137. {
  138. case "产品SN":
  139. (int, string) result = StationOutFunc_ProductSN(sn);
  140. ShowLog(result.Item2);
  141. break;
  142. case "载具SN":
  143. case "弹夹SN":
  144. MessageBox.Show("暂不支持的出站方式");
  145. break;
  146. default:
  147. break;
  148. }
  149. }
  150. catch (Exception ex)
  151. {
  152. string str = ex.StackTrace;
  153. MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
  154. }
  155. }
  156. /// <summary>
  157. /// 出站 - 产品SN
  158. /// </summary>
  159. /// <param name="sn">产品SN</param>
  160. /// <returns></returns>
  161. private (int, string) StationOutFunc_ProductSN(string sn)
  162. {
  163. string stationStr = cmbStationName.Text.Trim();
  164. #region 校验
  165. string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
  166. string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
  167. string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
  168. string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
  169. List<TestItem> item = new List<TestItem>();
  170. item.Add(new TestItem()
  171. {
  172. Parameter_name = "产品结果",
  173. Parameter_value = cmbProResult.Text.Trim(),
  174. });
  175. if (string.IsNullOrEmpty(vehicleCode))
  176. item.Add(new TestItem()
  177. {
  178. Parameter_name = "载具码",
  179. Parameter_value = vehicleCode,
  180. });
  181. if (string.IsNullOrEmpty(vehicleCodeNum))
  182. item.Add(new TestItem()
  183. {
  184. Parameter_name = "载具穴号",
  185. Parameter_value = vehicleCodeNum,
  186. });
  187. if (string.IsNullOrEmpty(bulletclipCode))
  188. item.Add(new TestItem()
  189. {
  190. Parameter_name = "弹夹码",
  191. Parameter_value = bulletclipCode,
  192. });
  193. if (string.IsNullOrEmpty(bulletclipCodeNum))
  194. item.Add(new TestItem()
  195. {
  196. Parameter_name = "弹夹穴号",
  197. Parameter_value = bulletclipCodeNum,
  198. });
  199. #endregion 校验
  200. string workorder_code = GlobalContext.WorkOrderCode; // 工单号
  201. string mtltmrk = GlobalContext.Mtltmrk; // 型号
  202. bool pass = cmbProResult.Text == "OK";
  203. string zj = vehicleCode;
  204. string zjxh = vehicleCodeNum;
  205. if (!string.IsNullOrEmpty(bulletclipCode) && !string.IsNullOrEmpty(bulletclipCodeNum))
  206. {
  207. zj = bulletclipCode;
  208. zjxh = bulletclipCodeNum;
  209. }
  210. string equipmentCode = "";
  211. string processItem = "";
  212. //[S1]Tray盘上料装备
  213. //[S2]FCT
  214. //[S3]值板机
  215. //[S4_1]载具下线装备
  216. //[S4_3]提升机1
  217. //[S4_4]提升机2
  218. //[S4_5]载具上线装备
  219. //[S5]Tray盘下料装备
  220. switch (stationStr)
  221. {
  222. case "[S1]Tray盘上料装备":
  223. equipmentCode = GlobalContext.LineCode + "-[S1]";
  224. processItem = "Tray盘上料装备";
  225. break;
  226. case "[S2]FCT":
  227. equipmentCode = GlobalContext.LineCode + "-[S2]";
  228. processItem = "FCT";
  229. break;
  230. case "[S3]值板机":
  231. equipmentCode = GlobalContext.LineCode + "-[S3]";
  232. processItem = "值板机";
  233. break;
  234. case "[S4_1]载具下线装备":
  235. equipmentCode = GlobalContext.LineCode + "-[S4_1]";
  236. processItem = "载具下线装备";
  237. break;
  238. case "[S4_3]提升机1":
  239. equipmentCode = GlobalContext.LineCode + "-[S4_3]";
  240. processItem = "提升机1";
  241. break;
  242. case "[S4_4]提升机2":
  243. equipmentCode = GlobalContext.LineCode + "-[S4_4]";
  244. processItem = "提升机2";
  245. break;
  246. case "[S4_5]载具上线装备":
  247. equipmentCode = GlobalContext.LineCode + "-[S4_5]";
  248. processItem = "载具上线装备";
  249. break;
  250. case "[S5]Tray盘下料装备":
  251. equipmentCode = GlobalContext.LineCode + "-[S5]";
  252. processItem = "Tray盘下料装备";
  253. break;
  254. }
  255. //int mesResult = 0;
  256. int mesResult = Form_Main.formHome.SaveProcessDataByDB(stationStr, item, equipmentCode, processItem
  257. , workorder_code, mtltmrk, sn, pass, zj, zjxh);
  258. switch (mesResult)
  259. {
  260. case 1:
  261. return (1, "[1]成功");
  262. case 5:
  263. return (5, "[5]MES报警");
  264. case 6:
  265. return (6, "[6]上位机报警");
  266. default:
  267. return (999, "[999]未知结果");
  268. }
  269. }
  270. #endregion 出站相关
  271. #region 其他方法
  272. /// <summary>
  273. /// 显示信息
  274. /// </summary>
  275. /// <param name="msg">信息</param>
  276. public void ShowLog(string msg)
  277. {
  278. txtInfo.Invoke(new Action(() =>
  279. {
  280. txtInfo.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
  281. }));
  282. }
  283. /// <summary>
  284. /// 添加记录
  285. /// </summary>
  286. /// <param name="logType">日志类型</param>
  287. /// <param name="msg">日志信息</param>
  288. private void AddMessage(LogType logType, string msg)
  289. {
  290. MessageEvent?.Invoke(logType, msg);
  291. }
  292. #endregion 其他方法
  293. }
  294. }