123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- using Sunny.UI.Win32;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace MainForm.FaForm
- {
- public partial class Form_MESTest : Form
- {
- #region 变量
- public event AlarmMessageHandler MessageEvent;
- #endregion 变量
- #region 窗体事件
- public Form_MESTest()
- {
- InitializeComponent();
- }
- private void Form_MESTest_Load(object sender, EventArgs e)
- {
- cmbSNType.SelectedIndex = 0;
- cmbProResult.SelectedIndex = 0;
- }
- #endregion 窗体事件
- #region 进站相关
- /// <summary>
- /// 进站
- /// </summary>
- private async void btnStationIn_Click(object sender, EventArgs e)
- {
- try
- {
- string sn = txtSN.Text.Trim();
- if (string.IsNullOrEmpty(sn))
- {
- MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- string snType = cmbSNType.Text.Trim();
- switch (snType)
- {
- case "产品SN":
- (int, string) result = StationInFunc_ProductSN(sn);
- ShowLog(result.Item2);
- break;
- case "载具SN":
- case "弹夹SN":
- MessageBox.Show("暂不支持的进站方式");
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
- }
- }
- /// <summary>
- /// 进站 - 产品SN
- /// </summary>
- /// <param name="sn">产品SN</param>
- /// <returns></returns>
- private (int, string) StationInFunc_ProductSN(string sn)
- {
- string stationStr = cmbStationName.Text.Trim();
- #region 校验
- string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
- string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
- string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
- string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = cmbProResult.Text.Trim(),
- });
- if (string.IsNullOrEmpty(vehicleCode))
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCode,
- });
- if (string.IsNullOrEmpty(vehicleCodeNum))
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = vehicleCodeNum,
- });
- if (string.IsNullOrEmpty(bulletclipCode))
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = bulletclipCode,
- });
- if (string.IsNullOrEmpty(bulletclipCodeNum))
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = bulletclipCodeNum,
- });
- #endregion 校验
- int mesResult = Form_Main.formHome.SaveStationInData(stationStr, GlobalContext.WorkOrderCode, GlobalContext.Mtltmrk, sn, item, out string errorMsg);
- switch (mesResult)
- {
- case 1:
- return (1, "[1]成功;" + errorMsg);
- case 5:
- return (5, "[5]MES报警;" + errorMsg);
- case 6:
- return (6, "[6]上位机报警;" + errorMsg);
- default:
- return (999, "[999]未知结果;" + errorMsg);
- }
- }
- #endregion 进站相关
- #region 出站相关
- /// <summary>
- /// 出站
- /// </summary>
- private async void btnStationOut_Click(object sender, EventArgs e)
- {
- try
- {
- string sn = txtSN.Text.Trim();
- if (string.IsNullOrEmpty(sn))
- {
- MessageBox.Show("SN号不可为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- string snType = cmbSNType.Text.Trim();
- switch (snType)
- {
- case "产品SN":
- (int, string) result = StationOutFunc_ProductSN(sn);
- ShowLog(result.Item2);
- break;
- case "载具SN":
- case "弹夹SN":
- MessageBox.Show("暂不支持的出站方式");
- break;
- default:
- break;
- }
- }
- catch (Exception ex)
- {
- string str = ex.StackTrace;
- MessageBox.Show("进站异常!异常位置:" + str.Substring(str.LastIndexOf("\\") + 1, str.Length - str.LastIndexOf("\\") - 1) + ";异常信息:" + ex.Message.ToString());
- }
- }
- /// <summary>
- /// 出站 - 产品SN
- /// </summary>
- /// <param name="sn">产品SN</param>
- /// <returns></returns>
- private (int, string) StationOutFunc_ProductSN(string sn)
- {
- string stationStr = cmbStationName.Text.Trim();
- #region 校验
- string vehicleCode = txtVehicleCode.Text.Trim(); // 载具码
- string vehicleCodeNum = txtVehicleCodeNum.Text.Trim(); // 载具穴号
- string bulletclipCode = txtBulletclipCode.Text.Trim(); // 弹夹码
- string bulletclipCodeNum = txtBulletclipCodeNum.Text.Trim(); // 弹夹穴号
- List<TestItem> item = new List<TestItem>();
- item.Add(new TestItem()
- {
- Parameter_name = "产品结果",
- Parameter_value = cmbProResult.Text.Trim(),
- });
- if (string.IsNullOrEmpty(vehicleCode))
- item.Add(new TestItem()
- {
- Parameter_name = "载具码",
- Parameter_value = vehicleCode,
- });
- if (string.IsNullOrEmpty(vehicleCodeNum))
- item.Add(new TestItem()
- {
- Parameter_name = "载具穴号",
- Parameter_value = vehicleCodeNum,
- });
- if (string.IsNullOrEmpty(bulletclipCode))
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹码",
- Parameter_value = bulletclipCode,
- });
- if (string.IsNullOrEmpty(bulletclipCodeNum))
- item.Add(new TestItem()
- {
- Parameter_name = "弹夹穴号",
- Parameter_value = bulletclipCodeNum,
- });
- #endregion 校验
- string workorder_code = GlobalContext.WorkOrderCode; // 工单号
- string mtltmrk = GlobalContext.Mtltmrk; // 型号
- bool pass = cmbProResult.Text == "OK";
- string zj = vehicleCode;
- string zjxh = vehicleCodeNum;
- if (!string.IsNullOrEmpty(bulletclipCode) && !string.IsNullOrEmpty(bulletclipCodeNum))
- {
- zj = bulletclipCode;
- zjxh = bulletclipCodeNum;
- }
- string equipmentCode = "";
- string processItem = "";
- //[S1]Tray盘上料装备
- //[S2]FCT
- //[S3]值板机
- //[S4_1]载具下线装备
- //[S4_3]提升机1
- //[S4_4]提升机2
- //[S4_5]载具上线装备
- //[S5]Tray盘下料装备
- switch (stationStr)
- {
- case "[S1]Tray盘上料装备":
- equipmentCode = GlobalContext.LineCode + "-[S1]";
- processItem = "Tray盘上料装备";
- break;
- case "[S2]FCT":
- equipmentCode = GlobalContext.LineCode + "-[S2]";
- processItem = "FCT";
- break;
- case "[S3]值板机":
- equipmentCode = GlobalContext.LineCode + "-[S3]";
- processItem = "值板机";
- break;
- case "[S4_1]载具下线装备":
- equipmentCode = GlobalContext.LineCode + "-[S4_1]";
- processItem = "载具下线装备";
- break;
- case "[S4_3]提升机1":
- equipmentCode = GlobalContext.LineCode + "-[S4_3]";
- processItem = "提升机1";
- break;
- case "[S4_4]提升机2":
- equipmentCode = GlobalContext.LineCode + "-[S4_4]";
- processItem = "提升机2";
- break;
- case "[S4_5]载具上线装备":
- equipmentCode = GlobalContext.LineCode + "-[S4_5]";
- processItem = "载具上线装备";
- break;
- case "[S5]Tray盘下料装备":
- equipmentCode = GlobalContext.LineCode + "-[S5]";
- processItem = "Tray盘下料装备";
- break;
- }
- //int mesResult = 0;
- int mesResult = Form_Main.formHome.SaveProcessDataByDB(stationStr, item, equipmentCode, processItem
- , workorder_code, mtltmrk, sn, pass, zj, zjxh);
- switch (mesResult)
- {
- case 1:
- return (1, "[1]成功");
- case 5:
- return (5, "[5]MES报警");
- case 6:
- return (6, "[6]上位机报警");
- default:
- return (999, "[999]未知结果");
- }
- }
- #endregion 出站相关
- #region 其他方法
- /// <summary>
- /// 显示信息
- /// </summary>
- /// <param name="msg">信息</param>
- public void ShowLog(string msg)
- {
- txtInfo.Invoke(new Action(() =>
- {
- txtInfo.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
- }));
- }
- /// <summary>
- /// 添加记录
- /// </summary>
- /// <param name="logType">日志类型</param>
- /// <param name="msg">日志信息</param>
- private void AddMessage(LogType logType, string msg)
- {
- MessageEvent?.Invoke(logType, msg);
- }
- #endregion 其他方法
- }
- }
|