using EIP_Protocol;
using MainForm.ClassFile.XiaomiAPI;
using Sunny.UI.Win32;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static MainForm.ClassFile.XiaomiAPI.XiaomiMqttClient_Extend;
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 进站相关
///
/// 进站
///
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());
}
}
///
/// 进站 - 产品SN
///
/// 产品SN
///
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 item = new List();
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 出站相关
///
/// 出站
///
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());
}
}
///
/// 出站 - 产品SN
///
/// 产品SN
///
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 item = new List();
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 Iot手动上传 Tap
///
/// 上传按钮_Iot
///
private async void btnSend_Iot_Click(object sender, EventArgs e)
{
try
{
await Task.Run(async () =>
{
string stationStr = cmbStationName_Iot.Text.Trim(); // 工站名称
string mesStation = "";
switch (stationStr)
{
//[S1]Tray盘上料装备
//[S2]FCT
//[S3]值板机
//[S4_1]载具下线装备
//[S4_5]载具上线装备
//[S5]Tray盘下料装备
case "[OP10]壳体清洁上料":
mesStation = GlobalContext.S1_station;
break;
case "[OP20]上盖板上料装备":
mesStation = GlobalContext.S2_station;
break;
case "[OP30]点散热胶装备_Left":
mesStation = GlobalContext.s3_1_station;
break;
case "[OP30]点散热胶装备_Right":
mesStation = GlobalContext.s3_2_station;
break;
case "[OP40]胶线检测":
mesStation = GlobalContext.s4_station;
break;
case "[OP50]ADD板上料组装装备":
mesStation = GlobalContext.s5_station;
break;
case "[OP60]组上盖板":
mesStation = GlobalContext.s6_station;
break;
case "[OP70]上盖板锁螺丝_Left":
mesStation = GlobalContext.s7_1_station;
break;
case "[OP70]上盖板锁螺丝_Right":
mesStation = GlobalContext.s7_2_station;
break;
case "[OP80]NG下料":
mesStation = GlobalContext.s8_station;
break;
case "[OP90]半成品下料":
mesStation = GlobalContext.s8_station;
break;
}
string iotSendType = cmbSendType_Iot.Text.Trim();
switch (iotSendType)
{
//设备状态
//故障日志
//节拍日志
//操作记录
case "设备状态":
(int, string) resultDeviceState = SendIotDeviceStateFun(mesStation);
ShowLog_Iot($"[{resultDeviceState.Item1}]" + resultDeviceState.Item2);
break;
case "故障日志":
(int, string) resultFaultLog = SendIotFaultLogFun(mesStation);
ShowLog_Iot($"[{resultFaultLog.Item1}]" + resultFaultLog.Item2);
break;
case "节拍日志":
(int, string) resultInputBegin = SendIotInputBeginFun(mesStation);
ShowLog_Iot($"[{resultInputBegin.Item1}]" + resultInputBegin.Item2);
break;
case "操作记录":
(int, string) resultOperateLog = SendIotOperateLogFun(mesStation);
ShowLog_Iot($"[{resultOperateLog.Item1}]" + resultOperateLog.Item2);
break;
case "过站结果":
(int, string) resultPassStation = SendIotPassStationFun(mesStation);
ShowLog_Iot($"[{resultPassStation.Item1}]" + resultPassStation.Item2);
break;
case "过站明细":
(int, string) resultPassStationDetail = SendIotPassStationDetailFun(mesStation);
ShowLog_Iot($"[{resultPassStationDetail.Item1}]" + resultPassStationDetail.Item2);
break;
case "非结构化":
Task<(int, string)> resultFileUp = SendIotFileUpFun(mesStation);
var result = await resultFileUp;
ShowLog_Iot($"[{result.Item1}]" + result.Item2);
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());
}
}
///
/// 上传设备状态_Iot
///
/// mes工站名称
///
private (int, string) SendIotDeviceStateFun(string mesStation)
{
string xmDeviceState = cmbXiaomiDeviceState.Text.Trim(); // 设备状态
if (string.IsNullOrEmpty(xmDeviceState))
return (999, "‘状态类型’不可为空!");
DeviceStateDataRequest request = new DeviceStateDataRequest();
request.station = mesStation; // ⼯位
request.state = xmDeviceState; // 设备状态
request.time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 状态切换时的时间 2022-06-01 14:27:57.283
if (xmDeviceState == "Fault" || xmDeviceState == "Alarm")
{
string faultCode = txtFaultCode.Text.Trim();
if (string.IsNullOrEmpty(faultCode))
return (999, "‘故障编码’不可为空!");
request.fault_code = faultCode; // 对应的故障编码
request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发⽣时间
}
// 上传
(int, string) iotResult = XiaomiMqttClient_Extend.Write_DeviceStateData(request);
return iotResult;
}
///
/// 上传故障日志_Iot
///
/// mes工站名称
///
private (int, string) SendIotFaultLogFun(string mesStation)
{
string xmFaultName = txtFaultName.Text.Trim(); // 故障名称
string xmFaultCode2 = txtFaultCode2.Text.Trim(); // 故障编码
string xmFaultCmpnt = txtFaultCmpnt.Text.Trim(); // 故障部件
string xmFaultDesc = txtFaultDesc.Text.Trim(); // 故障描述
if (string.IsNullOrEmpty(xmFaultName))
return (999, "‘故障名称’不可为空!");
else if (string.IsNullOrEmpty(xmFaultCode2))
return (999, "‘故障编码’不可为空!");
else if (string.IsNullOrEmpty(xmFaultCmpnt))
return (999, "‘故障部件’不可为空!");
else if (string.IsNullOrEmpty(xmFaultDesc))
return (999, "‘故障描述’不可为空!");
FaultLogRequest request = new FaultLogRequest();
request.station = mesStation; // ⼯位
request.fault_name = xmFaultName; // 故障名称(同数据字典中的事件名称)
request.fault_code = xmFaultCode2; // 故障编码(A,B,C,D,E)
request.typ4 = xmFaultCmpnt; // 故障部件
request.fault_desc = xmFaultDesc; // 故障描述
request.fault_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 故障发⽣时间 2022-06-01 14:27:57.283
// 上传
(int, string) iotResult = XiaomiMqttClient_Extend.Write_FaultLog(request);
//(int, string) iotResult = (0, "");
return iotResult;
}
///
/// 上传节拍日志_Iot
///
/// mes工站名称
///
private (int, string) SendIotInputBeginFun(string mesStation)
{
string action = cmbAction.Text.Trim(); // 节拍动作
string partSn = txtPartSn.Text.Trim(); // 物料SN
string vSn = txtVSn.Text.Trim(); // 载具SN
string vIndexSn = txtVIndexSn.Text.Trim(); // 载具穴位编号
string extra = txtExtra.Text.Trim(); // 额外信息
string class_level_1 = txtClassLevel1.Text.Trim(); // 分类层级1
string class_level_2 = txtClassLevel2.Text.Trim(); // 分类层级2
string class_level_3 = txtClassLevel3.Text.Trim(); // 分类层级3
string station = "";
if (string.IsNullOrEmpty(action))
return (999, "‘节拍动作’不可为空!");
else if (string.IsNullOrEmpty(partSn))
return (999, "‘物料SN’不可为空!");
else if (string.IsNullOrEmpty(vSn))
return (999, "‘载具SN’不可为空!");
//else if (string.IsNullOrEmpty(vIndexSn))
// return (999, "‘载具穴位编号’不可为空!");
else if (string.IsNullOrEmpty(class_level_1))
return (999, "‘分类层级1’不可为空!");
else if (string.IsNullOrEmpty(class_level_2))
return (999, "‘分类层级2’不可为空!");
else if (string.IsNullOrEmpty(class_level_3))
return (999, "‘分类层级3’不可为空!");
StationInputBeginRequest request = new StationInputBeginRequest();
switch (action)
{
/// 上料开始:beat_log/business/OEE/station_input_begin
/// 上料结束:beat_log/business/OEE/station_input_end
/// 作业开始:beat_log/business/OEE/station_work_begin
/// 作业结束:beat_log/business/OEE/station_work_end
/// 下料开始:beat_log/business/OEE/station_output_begin
/// 下料结束:beat_log/business/OEE/station_output_end
case "上料开始":
request.action = "beat_log/business/OEE/station_input_begin"; // 节拍动作(XiaomiDeviceOEE)
break;
case "上料结束":
request.action = "beat_log/business/OEE/station_input_end"; // 节拍动作(XiaomiDeviceOEE)
break;
case "作业开始":
request.action = "beat_log/business/OEE/station_work_begin"; // 节拍动作(XiaomiDeviceOEE)
break;
case "作业结束":
request.action = "beat_log/business/OEE/station_work_end"; // 节拍动作(XiaomiDeviceOEE)
break;
case "下料开始":
request.action = "beat_log/business/OEE/station_output_begin"; // 节拍动作(XiaomiDeviceOEE)
break;
case "下料结束":
request.action = "beat_log/business/OEE/station_output_end"; // 节拍动作(XiaomiDeviceOEE)
break;
}
Form_Home home = new Form_Home();
request.beat_tm = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
request.action_subject = partSn; // 该动作操作的⽬标对象(SN)
request.action_subject_parent = vSn; // ⼤板SN/载具SN
if (Form_Home.xiaomiParm.stationCode=="")
{
if (cmbStationName_Iot.Text=="[OP30]点散热胶装备_Left")
station=GlobalContext.s3_1_station+ "_01-SLOT-01";
else if (cmbStationName_Iot.Text=="[OP30]点散热胶装备_Right")
station=GlobalContext.s3_2_station+ "_01-SLOT-02";
else if (cmbStationName_Iot.Text=="[OP70]上盖板锁螺丝_Left")
station=GlobalContext.s7_1_station+ "_01-SLOT-01";
else if (cmbStationName_Iot.Text=="[OP70]上盖板锁螺丝_Right")
station=GlobalContext.s7_2_station+ "_01-SLOT-02";
}
else
{
station = Form_Home.xiaomiParm.stationCode; // 该动作的位置信息(⼯位、槽位),如:F06-GSTPLA11_01-SLOT-01
}
request.action_location=station;
request.action_material = vIndexSn; // 该动作的物料信息
request.extra = extra; // 额外信息
request.class_level_1 = class_level_1; // 分类层级1
request.class_level_2 = class_level_2; // 分类层级2
request.class_level_3 = class_level_3; // 分类层级3
// 上传
(int, string) iotResult = XiaomiMqttClient_Extend.Write_StationInputBegin(request);
return iotResult;
}
///
/// 上传操作记录⽇志_Iot
///
/// mes工站名称
///
private (int, string) SendIotOperateLogFun(string mesStation)
{
string operateAction = cmbOperateAction.Text.Trim(); // 操作动作
string actionParam = txtActionParam.Text.Trim(); // 动作参数
string operateDesc = txtOperateDesc.Text.Trim(); // 操作描述
string operateResult = cmbOperateResult.Text.Trim(); // 操作结果
if (string.IsNullOrEmpty(operateAction))
return (999, "‘操作动作’不可为空!");
else if (string.IsNullOrEmpty(operateDesc))
return (999, "‘操作描述’不可为空!");
else if (string.IsNullOrEmpty(operateResult))
return (999, "‘操作结果’不可为空!");
OperateLogRequest request = new OperateLogRequest();
request.software_version = "V" + Application.ProductVersion; // 软件版本号;如:V1.2.4
request.operate_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 操作时间(2022-06-01 14:27:57.283)
request.operate_action = operateAction; // 操作动作(对应软件开启/关闭/重新加载项⽬;startup、shutdown、reload)
request.action_param = actionParam; // 动作参数;选填,附带额外的信息
request.operate_module = "MES调试模块"; // 操作模块;选填
request.operate_page = "手动调试页面"; // 操作⻚⾯;选填
request.current_process = Process.GetCurrentProcess()?.Id.ToString(); // 当前进程;进程ID
request.operate_desc = operateDesc; // 操作描述;如:供应商软件开启/关闭/重新加载项⽬
request.operate_result = operateResult; // 操作结果
//request.operator_name = GlobalContext.currentRole; // 操作账号名;填当前操作⽤⼾,如⽆则填default
// 上传
(int, string) iotResult = XiaomiMqttClient_Extend.Write_OperateLog(request);
//(int, string) iotResult=(0,"");
return iotResult;
}
///
/// 上传过站数据_Iot
///
/// mes工站名称
///
private (int, string) SendIotPassStationFun(string mesStation)
{
string stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
string slot = txtSlot.Text.Trim(); // 槽位编码
string sn = txtSn_PassStation.Text.Trim(); // 产品SN
string enter_status = cmbEnterStatus.Text.Trim(); // 进站状态
string result = cmbResult.Text.Trim(); // 过站结果
string work_type = cmbWorkType.Text.Trim(); // 作业类型
if (string.IsNullOrEmpty(slot))
return (999, "‘槽位编码’不可为空!");
else if (string.IsNullOrEmpty(sn))
return (999, "‘产品SN’不可为空!");
else if (string.IsNullOrEmpty(enter_status))
return (999, "‘进站状态’不可为空!");
else if (string.IsNullOrEmpty(result))
return (999, "‘过站结果’不可为空!");
else if (string.IsNullOrEmpty(work_type))
return (999, "‘作业类型’不可为空!");
PassStationResultRequest request = new PassStationResultRequest();
request.project_code = GlobalContext.Project_Code; // 项⽬编码
request.factory_code = GlobalContext.Factory_Code; // ⼯⼚Id
request.process_section_code = GlobalContext.Process_Section_Code; // ⼯段编码
request.line_code = GlobalContext.LineCode; // 线体编码
switch (stationStr)
{
case "[OP10]壳体清洁上料":
request.work_station = GlobalContext.S1_work_station; // ⼯站
request.device_code = GlobalContext.S1_device_code; // 装备编码
break;
case "[OP20]上盖板上料装备":
request.work_station = GlobalContext.S2_work_station; // ⼯站
request.device_code = GlobalContext.S2_device_code; // 装备编码
break;
case "[OP30]点散热胶装备_Left":
request.work_station = GlobalContext.s3_1_work_station; // ⼯站
request.device_code = GlobalContext.s3_1_device_code; // 装备编码
break;
case "[OP30]点散热胶装备_Right":
request.work_station = GlobalContext.s3_2_work_station; // ⼯站
request.device_code = GlobalContext.s3_2_device_code; // 装备编码
break;
case "[OP40]胶线检测":
request.work_station = GlobalContext.s4_work_station; // ⼯站
request.device_code = GlobalContext.s4_device_code; // 装备编码
break;
case "[OP50]ADD板上料组装装备":
request.work_station = GlobalContext.s5_work_station; // ⼯站
request.device_code = GlobalContext.s5_device_code; // 装备编码
break;
case "[OP60]组上盖板":
request.work_station = GlobalContext.s6_work_station; // ⼯站
request.device_code = GlobalContext.s6_device_code; // 装备编码
break;
case "[OP70]上盖板锁螺丝_Left":
request.work_station = GlobalContext.s7_1_work_station; // ⼯站
request.device_code = GlobalContext.s7_1_device_code; // 装备编码
break;
case "[OP70]上盖板锁螺丝_Right":
request.work_station = GlobalContext.s7_2_work_station; // ⼯站
request.device_code = GlobalContext.s7_2_device_code; // 装备编码
break;
case "[OP80]NG下料":
request.work_station = GlobalContext.s8_work_station; // ⼯站
request.device_code = GlobalContext.s8_device_code; // 装备编码
break;
case "[OP90]半成品下料":
request.work_station = GlobalContext.s9_work_station; // ⼯站
request.device_code = GlobalContext.s9_device_code; // 装备编码
break;
}
request.station = mesStation;
request.process_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); // 节拍发⽣时间(2022-06-01 14:27:57.283)
request.slot = "01-SLOT-01"; // 槽位编码
request.sn = sn; // 产品SN
request.enter_status = enter_status; // 进站状态
request.result = result; // 过站结果
request.work_type = work_type; // 作业类型
// 上传过站结果
(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationResult(request);
//(int, string) iotResult = (0, "");
return iotResult;
}
private int test_item_num = 0;
///
/// 上传过站数据_Iot
///
/// mes工站名称
///
private (int, string) SendIotPassStationDetailFun(string mesStation)
{
test_item_num += 1;//⽰例:1,2,递增
string _stationStr = cmbStationName_Iot.Text.Trim(); // 工站名
string _slot = PassStationDetail_slot.Text.Trim(); // 槽位编码
string _sn = PassStationDetail_SN.Text.Trim(); // 产品SN
string _function_name= pnlPassStationDetail_functionNname.Text.Trim();
string _test_item= pnlPassStationDetail_testItem.Text.Trim();
string _result_val= pnlPassStationDetail_resultVal.Text.Trim();
string _status = pnlPassStationDetail_status.Text.Trim();
if (string.IsNullOrEmpty(_slot))
return (999, "‘槽位编码’不可为空!");
else if (string.IsNullOrEmpty(_sn))
return (999, "‘产品SN’不可为空!");
else if (string.IsNullOrEmpty(_function_name))
return (999, "‘功能名称’不可为空!");
else if (string.IsNullOrEmpty(_test_item))
return (999, "‘测试项’不可为空!");
else if (string.IsNullOrEmpty(_result_val))
return (999, "‘测试值’不可为空!");
PassStationDetailRequest request = new PassStationDetailRequest();
request.sn = _sn; // 产品SN
request.slot = "01-SLOT-01"; // 槽位编码
request.test_item_num = test_item_num.ToString();
request.function_name = _function_name;
request.test_item = _test_item;
request.result_val = _result_val;
request.status=_status;
request.description = _test_item;
// 上传过站结果
(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
//(int, string) iotResult = (0, "");
return iotResult;
}
///
/// 显示信息
///
/// 信息
public void ShowLog_Iot(string msg)
{
txtInfo.Invoke(new Action(() =>
{
txtInfo_Iot.Text = string.Concat("\r\n", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "=> ", msg);
}));
}
// 更改上传类型
private void cmbSendType_Iot_SelectedIndexChanged(object sender, EventArgs e)
{
string iotSendType = cmbSendType_Iot.Text.Trim();
switch (iotSendType)
{
//设备状态
//故障日志
//节拍日志
//操作记录
case "设备状态":
pnlDeviceState.Enabled = true;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Yellow;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "故障日志":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = true;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Yellow;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "节拍日志":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = true;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Yellow;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "操作记录":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = true;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Yellow;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "过站结果":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = true;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Yellow;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "过站明细":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = true;
pnlFileUp.Enabled = false;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Yellow;
pnlFileUp.BackColor = Color.Gray;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
case "非结构化":
pnlDeviceState.Enabled = false;
pnlFaultLog.Enabled = false;
pnlStationInputBegin.Enabled = false;
pnlOperateLog.Enabled = false;
pnlPassStation.Enabled = false;
pnlPassStationDetail.Enabled = false;
pnlFileUp.Enabled = true;
pnlDeviceState7.Enabled = false;
pnlDeviceState8.Enabled = false;
pnlDeviceState.BackColor = Color.Gray;
pnlFaultLog.BackColor = Color.Gray;
pnlStationInputBegin.BackColor = Color.Gray;
pnlOperateLog.BackColor = Color.Gray;
pnlPassStation.BackColor = Color.Gray;
pnlPassStationDetail.BackColor = Color.Gray;
pnlFileUp.BackColor = Color.Yellow;
pnlDeviceState7.BackColor = Color.Gray;
pnlDeviceState8.BackColor = Color.Gray;
break;
default:
break;
}
}
// 更改状态类型
private void cmbXiaomiDeviceState_SelectedIndexChanged(object sender, EventArgs e)
{
string xmDeviceState = cmbXiaomiDeviceState.Text.Trim();
if (xmDeviceState == "Fault" || xmDeviceState == "Alarm")
{
label23.Enabled = true;
label24.Enabled = true;
txtFaultCode.Enabled = true;
}
else
{
label23.Enabled = false;
label24.Enabled = false;
txtFaultCode.Enabled = false;
}
}
///
/// 上传过站数据_Iot
///
/// mes工站名称
///
private async Task<(int, string)> SendIotFileUpFun(string mesStation)
{
(int, string) iotResult;
BarcodeSet_t BarcodeSet=new BarcodeSet_t();
BarcodeSet.strProductBarcode= pnlFileUp_sn.Text.Trim() ;
BarcodeSet.strCarrierBarcode = pnlFileUp_slot.Text.Trim();
string StationName = cmbStationName_Iot.Text.Trim();
string code = StationName.Substring(0, 6);
string name = StationName.Substring(6);
string path= pnlFileUp_path.Text.Trim();
Form_Home home= new Form_Home();
// 创建并显示加载提示框
using (var loadingForm = new LoadingForm())
{
loadingForm.Show();
iotResult = await home.SaveDBbyFileInfo(BarcodeSet, code, name,1, path);
// 关闭加载提示框
loadingForm.Close();
}
// 上传过站结果
//(int, string) iotResult = XiaomiMqttClient_Extend.Write_PassStationDetail(request);
//(int, string) iotResult = (0, "");
return iotResult;
}
#endregion Iot手动上传 Tap
#region 其他方法
///
/// 显示信息
///
/// 信息
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);
}));
}
///
/// 添加记录
///
/// 日志类型
/// 日志信息
private void AddMessage(LogType logType, string msg)
{
MessageEvent?.Invoke(logType, msg);
}
#endregion 其他方法
}
public class LoadingForm : Form
{
private Label label;
public LoadingForm()
{
Text = "请稍候";
Size = new Size(200, 100);
StartPosition = FormStartPosition.CenterScreen;
FormBorderStyle = FormBorderStyle.FixedDialog;
ControlBox = false;
TopMost = true;
label = new Label
{
Text = "正在处理,请稍等...",
Dock = DockStyle.Fill,
TextAlign = System.Drawing.ContentAlignment.MiddleCenter
};
this.Controls.Add(label);
}
}
}