using MaterialTraceability.Business; using MaterialTraceability.Business.Impl; using MaterialTraceability.Entity.DAO; using MaterialTraceability.Entity.DTO; using MaterialTraceability.Entity.Enum; using MaterialTraceability.SqlSugar; using MaterialTraceability.SqlSugar.ServiceImpl; using MaterialTraceability.WebService; using MaterialTraceability.WebService.MiBatchCompleteSfcAndAdujustQtyServiceService; using MaterialTraceability.WebService.MiFirstOperationForsfcServiceService; using MaterialTraceability.WebService.MiSignOffSFCsServiceService; using MaterialTraceability.WebService.Param; using MaterialTraceabilityUI.Common; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; namespace MaterialTraceabilityUI { /// /// CoatingProcess.xaml 的交互逻辑 /// public partial class CoatingProcess : UserControl { /// /// INIFile配置文件 /// private IniFileHelper inifile = new IniFileHelper(System.Environment.CurrentDirectory + "/MesConfig/App.InI"); private IMesWebServices MesWebServices = new MesWebServicesImpl(); private EquipBusiness equipBusiness = new EquipBusiness(); private bool[] mesResult = new bool[6]; private List proDownRecords = new List(); private ProShaftInfo proShaftInfo = new ProShaftInfo(); private int eaValue; private IBaseServices logInfoServices = new BaseServices(); private IBaseServices shftInfoService = new BaseServices(); private IBaseServices downRecordServices = new BaseServices(); private IBaseServices shaftInfoServices = new BaseServices(); private IBaseServices sysClientServices = new BaseServices(); private MesAlarmInfo mesAlarm = new MesAlarmInfo(); private PlcBusiness plcBusiness = new PlcBusiness(); private UpLoadBusiness upLoadBusiness = UpLoadBusiness.Instance; private AppConfigDto appConfig = AppConfigDto.Instance; public CoatingProcess() { LogHelperBusiness.LogInfo("CoatingProcess初始化调用"); InitializeComponent(); try { if (appConfig.processId.Contains("TB")) { TBSignalReadBusiness.ViewModelRefreshEvent += ProductionParam; TBSignalReadBusiness.LogRefreshEvent += LogRefresh; MainBusiness.LogRefreshEvent += LogRefresh; TBSignalReadBusiness.GetSFCByMesEvent += GetOrderByMes; TBSignalReadBusiness.EndProductionEvent += endProduction; TBSignalReadBusiness.ClearViewRefreshEvent += ClearViewRefresh; UserControlInit(); refreshThread(); } } catch (Exception ex) { LogHelperBusiness.LogError("界面异常", ex); } } /// /// 卷轴RFID信息刷新 /// /// public void ProductionParam(ViewModelDto viewModelDto) { Action action; if (viewModelDto.rfidInfo != null) { if (!String.IsNullOrEmpty(viewModelDto.rfidInfo.rfid)) { if (viewModelDto.rfidInfo.position == 1) { action = () => { this.RFID_Position.Text = "RFID:" + viewModelDto.rfidInfo.rfid; }; RFID_Position.Dispatcher.BeginInvoke(action); action = () => { this.EA_Position.Text = "EA:"; }; EA_Position.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 2) { action = () => { this.RFID_Finish.Text = "RFID:" + viewModelDto.rfidInfo.rfid; }; RFID_Finish.Dispatcher.BeginInvoke(action); action = () => { this.EA_Finish.Text = "EA:"; }; EA_Finish.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 3) { action = () => { this.RFID_Position1.Text = "RFID:" + viewModelDto.rfidInfo.rfid; }; RFID_Position1.Dispatcher.BeginInvoke(action); action = () => { this.EA_Position1.Text = "EA:"; }; EA_Position1.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 4) { action = () => { this.RFID_Position2.Text = "RFID:" + viewModelDto.rfidInfo.rfid; }; RFID_Position2.Dispatcher.BeginInvoke(action); action = () => { this.EA_Position2.Text = "EA:"; }; EA_Position2.Dispatcher.BeginInvoke(action); } } if (!String.IsNullOrEmpty(viewModelDto.rfidInfo.sfc)) { if (viewModelDto.rfidInfo.position == 1) { action = () => { this.SFC_Position.Text = "SFC:" + viewModelDto.rfidInfo.sfc; }; SFC_Position.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 2) { action = () => { this.SFC_Finish.Text = "SFC:" + viewModelDto.rfidInfo.sfc; }; SFC_Finish.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 3) { action = () => { this.SFC_Position1.Text = "SFC:" + viewModelDto.rfidInfo.sfc; }; SFC_Position1.Dispatcher.BeginInvoke(action); } else if (viewModelDto.rfidInfo.position == 4) { action = () => { this.SFC_Position2.Text = "SFC:" + viewModelDto.rfidInfo.sfc; }; SFC_Position2.Dispatcher.BeginInvoke(action); } } } } private void refreshThread() { System.Timers.Timer timer = new System.Timers.Timer(1000 * 30); timer.Elapsed += new System.Timers.ElapsedEventHandler(refreshEquipStatus); timer.AutoReset = true; timer.Enabled = true; timer.Start(); } private void refreshEquipStatus(object source, System.Timers.ElapsedEventArgs e) { equipBusiness.CheckEquipState(); UpdataDeviceStatus(); } /// /// 界面更新设备状态 /// private void UpdataDeviceStatus() { var info = equipBusiness.Equiplist.FirstOrDefault(); var infos = equipBusiness.Equiplist; if(infos != null) { foreach(var item in infos) { App.Current.Dispatcher.Invoke(() => { if (item.equipName.Contains("收卷")) { this.TestTC.Text = $"收卷位设备连接{(item.IsConnect ? "成功" : "失败")}"; this.TestTC.Foreground = item.IsConnect ? Brushes.Green : Brushes.Red; string imageUrl = $"pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/{(item.IsConnect ? "正常" : "失败-01")}.png"; BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl)); this.EquipStatusImage.ImageSource = bitmapImage; } else { this.TestTC2.Text = $"放卷位设备连接{(item.IsConnect ? "成功" : "失败")}"; this.TestTC2.Foreground = item.IsConnect ? Brushes.Green : Brushes.Red; string imageUrl = $"pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/{(item.IsConnect ? "正常" : "失败-01")}.png"; BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl)); this.EquipStatusImage2.ImageSource = bitmapImage; } }); } } //Action action; //if (info != null) //{ // if (info.IsConnect) // { // action = () => // { // this.TestTC.Text = "收卷位设备连接成功"; // this.TestTC.Foreground = Brushes.Green; // }; // TestTC.Dispatcher.BeginInvoke(action); // action = () => // { // string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/正常.png"; // BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl)); // this.EquipStatusImage.ImageSource = bitmapImage; // }; // EquipStatusImage.Dispatcher.BeginInvoke(action); // } // else // { // action = () => // { // this.TestTC.Text = "收卷位设备连接失败"; // this.TestTC.Foreground = Brushes.Red; // }; // TestTC.Dispatcher.BeginInvoke(action); // action = () => // { // string imageUrl = "pack://application:,,,/MaterialTraceabilityUI;component/Assets/Images/失败-01.png"; // BitmapImage bitmapImage = new BitmapImage(new Uri(imageUrl)); // this.EquipStatusImage.ImageSource = bitmapImage; // }; // EquipStatusImage.Dispatcher.BeginInvoke(action); // } //} } /// /// 结束异常初始化按钮 /// /// /// private void Init_End(object sender, RoutedEventArgs e) { if (StringExtension.IsBlank(this.proShaftInfo.bindRfid)) { ListBoxItemAdd(this.RfidLog, "下料记录为空,生产过程中未记录到RFID条码信息"); return; } if (!this.mesResult[0]) { if (!SignOffSFCs(this.proShaftInfo)) { return; } } if (!this.mesResult[1]) { if (!this.mesResult[0]) { if (!SignOffSFCs(this.proShaftInfo)) { return; } } //A面开始调整数量事件 if (BeginAdjustNumberByAFunction(this.eaValue, this.proShaftInfo)) { Action action; action = () => { this.BeginAdjustNumberByA.Background = Brushes.Green; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); } else { Action action; action = () => { this.BeginAdjustNumberByA.Background = Brushes.Red; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); return; } } if (!this.mesResult[2]) { //A面自动开始 if (AutoBeginA(this.eaValue, this.proShaftInfo)) { this.BeginAdjustNumberByA.Background = Brushes.Green; Action action; action = () => { this.BeginAdjustNumberByAText.Foreground = Brushes.White; }; BeginAdjustNumberByAText.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByATexts.Foreground = Brushes.White; }; BeginAdjustNumberByATexts.Dispatcher.BeginInvoke(action); action = () => { this.CollectA.Background = Brushes.Yellow; }; CollectA.Dispatcher.BeginInvoke(action); ListBoxItemAdd(this.RfidLog, "A面数据收集与物料消耗,收集完成后点击A面收数按钮"); } else { this.BeginAdjustNumberByA.Background = Brushes.Red; return; } } } /// /// 工单下达接口调用结果 /// /// /// public void GetOrderByMes(bool result, string sfc) { Action action; if (result) { action = () => { this.CancelSfc.Background = Brushes.Green; }; } else { action = () => { this.CancelSfc.Background = Brushes.Red; }; } CancelSfc.Dispatcher.BeginInvoke(action); action = () => { this.CancelSfcText.Foreground = Brushes.White; }; CancelSfcText.Dispatcher.BeginInvoke(action); } /// /// 生产结束流程 /// /// /// public void endProduction(int ea, ProShaftInfo shaftInfo) { //结束流程初始化 ButtonInit(); LogHelperBusiness.LogInfo("进入收卷结束流程" + shaftInfo.bindSfc); Action action; action = () => { this.EndSfc.Text = shaftInfo.bindSfc; }; this.EndSfc.Dispatcher.BeginInvoke(action); if (shaftInfo.positionId == "1") { action = () => { this.EA_Position.Text = "EA: " + ea.ToString(); }; this.EA_Position.Dispatcher.BeginInvoke(action); } else { action = () => { this.EA_Finish.Text = "EA: " + ea.ToString(); }; this.EA_Finish.Dispatcher.BeginInvoke(action); } this.eaValue = ea; this.proShaftInfo = shaftInfo; if (StringExtension.IsBlank(shaftInfo.bindRfid)) { ListBoxItemAdd(this.RfidLog, "下料信息为空,生产过程中未记录到RFID条码信息"); LogHelperBusiness.LogInfo("下料信息为空,生产过程中未记录到RFID条码信息" + shaftInfo.bindSfc); return; } this.UpdateDownRecord(shaftInfo.bindRfid, shaftInfo.bindSfc, 0); //注销SFC if (!SignOffSFCs(shaftInfo)) { return; } action = () => { this.BeginAdjustNumberByA.Background = Brushes.Yellow; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); //A面调整数量事件 if (BeginAdjustNumberByAFunction(ea, shaftInfo)) { action = () => { this.BeginAdjustNumberByA.Background = Brushes.Green; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); //A面入账开始 if (!AutoBeginA(ea, shaftInfo)) { action = () => { this.BeginAdjustNumberByA.Background = Brushes.Red; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); return; } } else { action = () => { this.BeginAdjustNumberByA.Background = Brushes.Red; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); return; } action = () => { this.BeginAdjustNumberByAText.Foreground = Brushes.White; }; BeginAdjustNumberByAText.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByATexts.Foreground = Brushes.White; }; BeginAdjustNumberByATexts.Dispatcher.BeginInvoke(action); action = () => { this.CollectA.Background = Brushes.Yellow; }; CollectA.Dispatcher.BeginInvoke(action); ListBoxItemAdd(this.RfidLog, "A面数据收集与物料消耗,收集完成后点击A面收数按钮"); LogHelperBusiness.LogInfo("日志排查进入收卷完工流程,打印绑定信息shaftInfo:" + JsonChange.ModeToJson(this.proShaftInfo)); } /// /// 注销SFC接口 /// /// /// public bool SignOffSFCs(ProShaftInfo shaftInfo) { LogRefresh(LogType.MesLog, "调用MES注销SFC接口"); LogHelperBusiness.LogInfo("调用MES注销SFC接口" + shaftInfo.bindSfc); MiSignOffSFCsServiceServiceParam miSignOffSFCsServiceServiceParam = new MiSignOffSFCsServiceServiceParam() { url = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "url"), site = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "site"), user = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "user"), operation = appConfig.operationByA, operationRevision = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "operationRevision"), activityId = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "activityId"), Resource = appConfig.resource, amount = inifile.IniReadValue("MiSignOffSFCsServiceServiceParam", "amount"), sfcDataArray = null, sfc = shaftInfo.bindSfc, }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("调用MES注销SFC接口请求参数:" + JsonChange.ModeToJson(miSignOffSFCsServiceServiceParam)); if (appConfig.isMesFlag == 1) { miSignOffSFCsResponse signOffSFCsResponse = MesWebServices.iMiSignOffSFCsServiceService(miSignOffSFCsServiceServiceParam); LogHelperBusiness.LogInfo("调用MES注销SFC接口返回参数:" + JsonChange.ModeToJson(signOffSFCsResponse)); if (signOffSFCsResponse.@return.code > 0) { if (signOffSFCsResponse.@return.code == 13900) { this.mesResult[0] = true; return true; } else { LogRefresh(LogType.MesLog, "注销SFC接口调用失败:" + upLoadBusiness.GetMesMessage(signOffSFCsResponse.@return.code, signOffSFCsResponse.@return.message)); LogRefresh(LogType.AlarmLog, "注销SFC接口调用失败:" + upLoadBusiness.GetMesMessage(signOffSFCsResponse.@return.code, signOffSFCsResponse.@return.message)); this.mesResult[0] = false; return false; } } } } catch (Exception ex) { LogHelperBusiness.LogInfo("调用MES注销SFC接口异常:" + ex.Message); LogRefresh(LogType.MesLog, "注销SFC接口调用异常:" + ex.Message); LogRefresh(LogType.AlarmLog, "注销SFC接口调用异常:" + ex.Message); WebServiceLog.saveMiSignOffSFCsServiceService(miSignOffSFCsServiceServiceParam, null, beginTime, ex.Message); this.mesResult[0] = false; return false; } //更新完工步骤 this.UpdateDownRecord(shaftInfo.bindRfid, shaftInfo.bindSfc, 1); LogRefresh(LogType.MesLog, String.Format("注销SFC接口调用成功,SFC:{0}", shaftInfo.bindSfc)); this.mesResult[0] = true; return true; } /// /// 开始调整A面数量 /// /// /// /// public bool BeginAdjustNumberByAFunction(int ea, ProShaftInfo proShaftInfo) { LogHelperBusiness.LogInfo("开始调整A面数量接口"); MiBatchCompleteSfcAndAdujustQtyServiceServiceParam miBatchCompleteSfcAndAdujustQtyServiceServiceParam = new MiBatchCompleteSfcAndAdujustQtyServiceServiceParam() { url = inifile.IniReadValue("AdujustQtyParam", "url"), site = inifile.IniReadValue("AdujustQtyParam", "site"), sfcPre = proShaftInfo.bindSfc, processLotPre = "", operation = appConfig.operationByA, operationRevision = inifile.IniReadValue("AdujustQtyParam", "operationRevision"), resource = appConfig.resource, user = inifile.IniReadValue("AdujustQtyParam", "user"), activity = inifile.IniReadValue("AdujustQtyParam", "activity"), modeProcessSfc = ModeProcessSfc.MODE_NONE, sfcList = new miBatchCompleteSfcAndAdujustQtySfcEntity[] { new miBatchCompleteSfcAndAdujustQtySfcEntity() { processLot = proShaftInfo.bindRfid, sfc = "", qty = ea.ToString(), unit = "EA" } } }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("开始调整A面数量接口请求参数:" + JsonChange.ModeToJson(miBatchCompleteSfcAndAdujustQtyServiceServiceParam)); Action action; if (appConfig.isMesFlag == 1) { var requestResult = MesWebServices.iMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam); LogHelperBusiness.LogInfo("开始调整A面数量接口返回参数:" + JsonChange.ModeToJson(requestResult)); if (requestResult == null || requestResult.@return.code > 0) { action = () => { this.BeginAdjustNumberByA.Background = Brushes.Red; }; LogRefresh(LogType.MesLog, "调整A面数量接口调用失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); LogRefresh(LogType.AlarmLog, "调整A面数量接口调用失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); this.mesResult[1] = false; return false; } } action = () => { this.BeginAdjustNumberByA.Background = Brushes.Green; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); } catch (Exception ex) { LogHelperBusiness.LogInfo("开始调整A面数量接口异常:" + ex.Message); WebServiceLog.saveMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam, null, beginTime, ex.Message); LogRefresh(LogType.MesLog, "调整A面数量接口异常:" + ex.Message); LogRefresh(LogType.AlarmLog, "调整A面数量接口异常:" + ex.Message); this.mesResult[1] = false; return false; } //更新完工步骤 this.UpdateDownRecord(proShaftInfo.bindRfid, proShaftInfo.bindSfc, 2); LogRefresh(LogType.MesLog, String.Format("调整A面数量接口调用成功,数量调整为", ea)); this.mesResult[1] = true; return true; } /// /// A面自动入账 /// /// /// /// public bool AutoBeginA(int ea, ProShaftInfo shaftInfo) { LogHelperBusiness.LogInfo("调用A面自动入账接口"); MiFirstOperationForsfcServiceServiceParam miFirstOperationForsfcServiceServiceParam = new MiFirstOperationForsfcServiceServiceParam() { url = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "url"), site = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "site"), sfc = shaftInfo.bindSfc, processLot = "", operation = appConfig.operationByA, operationRevision = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "operationRevision"), resource = appConfig.resource, user = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "user"), activity = "", modeProcessSfc = "MODE_START_SFC", }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("调用A面自动入账接口请求参数:" + JsonChange.ModeToJson(miFirstOperationForsfcServiceServiceParam)); if (appConfig.isMesFlag == 1) { miFirstOperationForsfcResponse firstOperationForsfcResponse = MesWebServices.iMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam); LogHelperBusiness.LogInfo("调用A面自动入账接口返回参数:" + JsonChange.ModeToJson(firstOperationForsfcResponse)); if (firstOperationForsfcResponse.@return.code > 0) { ListBoxItemAdd(this.MesLog, "A面自动入账异常:" + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message)); ListBoxItemAdd(this.AlarmLog, "A面自动入账异常:" + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message)); this.mesResult[2] = false; return false; } } } catch (Exception ex) { LogHelperBusiness.LogInfo("调用A面自动入账接口异常:" + ex.Message); ListBoxItemAdd(this.MesLog, "A面自动入账接口调用异常:" + ex.Message); WebServiceLog.saveMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam, null, beginTime, ex.Message); this.mesResult[2] = false; return false; } //更新完工步骤 this.UpdateDownRecord(proShaftInfo.bindRfid, proShaftInfo.bindSfc, 3); ListBoxItemAdd(this.MesLog, "A面自动入账成功"); this.mesResult[2] = true; return true; } /// /// A面收数完工 /// /// /// private void Btn_Click_A(object sender, RoutedEventArgs e) { LogHelperBusiness.LogInfo("A面收集数据,物料消耗"); if (StringExtension.IsBlank(this.proShaftInfo.bindRfid)) { LogHelperBusiness.LogInfo("未进入结束流程"); ListBoxItemAdd(this.AlarmLog, "未进入结束流程"); return; } Action action; //A面完工 if (!EndAdjustNumberByAFunction(this.eaValue, this.proShaftInfo)) { action = () => { this.EndAdjustNumberByA.Background = Brushes.Red; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); return; } action = () => { this.EndAdjustNumberByA.Background = Brushes.Green; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByBText.Foreground = Brushes.White; }; BeginAdjustNumberByBText.Dispatcher.BeginInvoke(action); action = () => { this.BeginBdjustNumberByBText2.Foreground = Brushes.White; }; BeginBdjustNumberByBText2.Dispatcher.BeginInvoke(action); //开始调整B面数量 if (!BeginAdjustNumberByBFunction(this.eaValue, this.proShaftInfo)) { action = () => { this.EndAdjustNumberByA.Background = Brushes.Red; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); return; } action = () => { this.EndAdjustNumberByA.Background = Brushes.Green; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByBText.Foreground = Brushes.White; }; BeginAdjustNumberByBText.Dispatcher.BeginInvoke(action); action = () => { this.BeginBdjustNumberByBText2.Foreground = Brushes.White; }; BeginBdjustNumberByBText2.Dispatcher.BeginInvoke(action); action = () => { this.CollectB.Background = Brushes.Yellow; }; CollectB.Dispatcher.BeginInvoke(action); } /// /// A面调整完成 /// /// /// /// public bool EndAdjustNumberByAFunction(int ea, ProShaftInfo shaftInfo) { LogHelperBusiness.LogInfo("调用A面调整完成接口"); MiBatchCompleteSfcAndAdujustQtyServiceServiceParam miBatchCompleteSfcAndAdujustQtyServiceServiceParam = new MiBatchCompleteSfcAndAdujustQtyServiceServiceParam() { url = inifile.IniReadValue("AdujustQtyParam", "url"), site = inifile.IniReadValue("AdujustQtyParam", "site"), sfcPre = "", processLotPre = shaftInfo.bindRfid, operation = appConfig.operationByA, operationRevision = inifile.IniReadValue("AdujustQtyParam", "operationRevision"), resource = appConfig.resource, user = inifile.IniReadValue("AdujustQtyParam", "user"), activity = inifile.IniReadValue("AdujustQtyParam", "activity"), modeProcessSfc = ModeProcessSfc.MODE_COMPLETE_SFC_POST_DC, //冷压MODE_COMPLETE_SFC_POST_DC、模切MODE_COMPLETE_SFC_POST_DC sfcList = new miBatchCompleteSfcAndAdujustQtySfcEntity[] { new miBatchCompleteSfcAndAdujustQtySfcEntity() { processLot = shaftInfo.bindRfid, sfc = "", qty = ea.ToString(), unit = "EA" } } }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("调用A面调整完成接口请求参数:" + JsonChange.ModeToJson(miBatchCompleteSfcAndAdujustQtyServiceServiceParam)); Action action; if (appConfig.isMesFlag == 1) { var requestResult = MesWebServices.iMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam); LogHelperBusiness.LogInfo("调用A面调整完成接口返回参数:" + JsonChange.ModeToJson(requestResult)); if (requestResult == null || requestResult.@return.code > 0) { action = () => { this.EndAdjustNumberByA.Background = Brushes.Red; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); LogRefresh(LogType.MesLog, "A面调整完工失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); LogRefresh(LogType.AlarmLog, "A面调整完工失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); this.mesResult[3] = false; return false; } } action = () => { this.EndAdjustNumberByA.Background = Brushes.Green; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); } catch (Exception ex) { LogHelperBusiness.LogInfo("A面调整完工接口异常:" + ex.Message); LogRefresh(LogType.AlarmLog, "A面调整完工接口异常:" + ex.Message); WebServiceLog.saveMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam, null, beginTime, ex.Message); this.mesResult[3] = false; return false; } Action actiona; actiona = () => { this.CollectA.Background = Brushes.Green; }; CollectA.Dispatcher.BeginInvoke(actiona); actiona = () => { this.ADataCollect.Foreground = Brushes.White; }; ADataCollect.Dispatcher.BeginInvoke(actiona); actiona = () => { this.ADataCollect2.Foreground = Brushes.White; }; ADataCollect2.Dispatcher.BeginInvoke(actiona); //更新完工步骤 this.UpdateDownRecord(proShaftInfo.bindRfid, proShaftInfo.bindSfc, 4); LogRefresh(LogType.MesLog, "调整A面完工接口调用成功"); this.mesResult[3] = true; return true; } /// /// B面开始 /// /// /// /// public bool BeginAdjustNumberByBFunction(int ea, ProShaftInfo shaftInfo) { LogHelperBusiness.LogInfo("调用B面开始接口"); MiFirstOperationForsfcServiceServiceParam miFirstOperationForsfcServiceServiceParam = new MiFirstOperationForsfcServiceServiceParam() { url = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "url"), site = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "site"), sfc = shaftInfo.bindSfc, processLot = "", operation = appConfig.operationByB, operationRevision = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "operationRevision"), resource = appConfig.resource, user = inifile.IniReadValue("MiFirstOperationForsfcServiceServiceParam", "user"), activity = "", modeProcessSfc = "MODE_START_SFC", }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("调用B面开始接口请求参数:" + JsonChange.ModeToJson(miFirstOperationForsfcServiceServiceParam)); if (appConfig.isMesFlag == 1) { miFirstOperationForsfcResponse firstOperationForsfcResponse = MesWebServices.iMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam); LogHelperBusiness.LogInfo("调用B面开始接口返回参数:" + JsonChange.ModeToJson(firstOperationForsfcResponse)); WebServiceLog.saveMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam, firstOperationForsfcResponse, beginTime, ""); if (firstOperationForsfcResponse.@return.code > 0) { ListBoxItemAdd(this.MesLog, "B面自动入账失败:" + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message)); ListBoxItemAdd(this.AlarmLog, "B面自动入账失败:" + upLoadBusiness.GetMesMessage(firstOperationForsfcResponse.@return.code, firstOperationForsfcResponse.@return.message)); this.mesResult[4] = false; return false; } } } catch (Exception ex) { LogHelperBusiness.LogInfo("调用B面开始接口异常:" + ex.Message); WebServiceLog.saveMiFirstOperationForsfcServiceService(miFirstOperationForsfcServiceServiceParam, null, beginTime, ex.Message); ListBoxItemAdd(this.MesLog, "B面自动入账失败:" + ex.Message); ListBoxItemAdd(this.AlarmLog, "B面自动入账失败:" + ex.Message); this.mesResult[4] = false; return false; } //更新完工步骤 this.UpdateDownRecord(proShaftInfo.bindRfid, proShaftInfo.bindSfc, 5); ListBoxItemAdd(this.MesLog, "B面自动入账完成"); this.mesResult[4] = true; return true; } /// /// B面收数完工 /// /// /// private void Btn_Click_B(object sender, RoutedEventArgs e) { LogHelperBusiness.LogInfo("B面收集数据,物料消耗"); if (StringExtension.IsBlank(this.proShaftInfo.bindRfid)) { LogHelperBusiness.LogInfo("未进入结束流程"); ListBoxItemAdd(this.AlarmLog, "未进入结束流程"); return; } Action action; //B面完工 if (!EndAdjustNumberByBFunction(this.eaValue, this.proShaftInfo)) { action = () => { this.EndAdjustNumberByB.Background = Brushes.Red; }; EndAdjustNumberByB.Dispatcher.BeginInvoke(action); return; } action = () => { this.EndAdjustNumberByB.Background = Brushes.Green; }; EndAdjustNumberByB.Dispatcher.BeginInvoke(action); ListBoxItemAdd(this.RfidLog, "完工流程结束"); //收卷流程完成 DownMaterialEnd(); //流程结束初始化流程状态 ButtonInit(); } /// /// B面调整完成 /// /// /// /// public bool EndAdjustNumberByBFunction(int ea, ProShaftInfo shaftInfo) { LogHelperBusiness.LogInfo("开始调用B面调整完成接口"); MiBatchCompleteSfcAndAdujustQtyServiceServiceParam miBatchCompleteSfcAndAdujustQtyServiceServiceParam = new MiBatchCompleteSfcAndAdujustQtyServiceServiceParam() { url = inifile.IniReadValue("AdujustQtyParam", "url"), site = inifile.IniReadValue("AdujustQtyParam", "site"), sfcPre = "", processLotPre = shaftInfo.bindRfid, operation = appConfig.operationByB, operationRevision = inifile.IniReadValue("AdujustQtyParam", "operationRevision"), resource = appConfig.resource, user = inifile.IniReadValue("AdujustQtyParam", "user"), activity = inifile.IniReadValue("AdujustQtyParam", "activity"), modeProcessSfc = ModeProcessSfc.MODE_COMPLETE_SFC_POST_DC, //冷压MODE_COMPLETE_SFC_POST_DC、模切MODE_COMPLETE_SFC_POST_DC sfcList = new miBatchCompleteSfcAndAdujustQtySfcEntity[] { new miBatchCompleteSfcAndAdujustQtySfcEntity() { processLot = shaftInfo.bindRfid, sfc = shaftInfo.bindSfc, qty = ea.ToString(), unit = "EA" } } }; DateTime beginTime = DateTime.Now; try { LogHelperBusiness.LogInfo("调用B面调整完成接口请求参数:" + JsonChange.ModeToJson(miBatchCompleteSfcAndAdujustQtyServiceServiceParam)); Action action; if (appConfig.isMesFlag == 1) { var requestResult = MesWebServices.iMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam); LogHelperBusiness.LogInfo("调用B面调整完成接口返回参数:" + JsonChange.ModeToJson(requestResult)); WebServiceLog.saveMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam, requestResult, beginTime, ""); if (requestResult == null || requestResult.@return.code > 0) { action = () => { this.EndAdjustNumberByB.Background = Brushes.Red; }; EndAdjustNumberByB.Dispatcher.BeginInvoke(action); LogRefresh(LogType.MesLog, "调整B面完工失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); LogRefresh(LogType.AlarmLog, "调整B面完工失败:" + upLoadBusiness.GetMesMessage(requestResult.@return.code, requestResult.@return.message)); this.mesResult[5] = false; return false; } } action = () => { this.EndAdjustNumberByB.Background = Brushes.Green; }; EndAdjustNumberByB.Dispatcher.BeginInvoke(action); } catch (Exception ex) { LogHelperBusiness.LogInfo("调用B面调整完成接口返回异常:" + ex.Message); WebServiceLog.saveMiBatchCompleteSfcAndAdujustQtyServiceService(miBatchCompleteSfcAndAdujustQtyServiceServiceParam, null, beginTime, ex.Message); LogRefresh(LogType.MesLog, "调整B面完工接口异常:" + ex.Message); LogRefresh(LogType.AlarmLog, "调整B面完工接口异常:" + ex.Message); this.mesResult[5] = false; return false; } //更新完工步骤 this.UpdateDownRecord(proShaftInfo.bindRfid, proShaftInfo.bindSfc, 6); LogRefresh(LogType.MesLog, "调整B面完工接口调用成功"); this.mesResult[5] = true; return true; } /// /// 收卷流程完成后执行 /// public async void DownMaterialEnd() { try { //更新下料信息 Expression> downExp = s1 => true; downExp = downExp.And(x => x.Rfid == this.proShaftInfo.bindRfid && x.Sfc == this.proShaftInfo.bindSfc); Expression> downOrder = (s) => s.RecordTime; ProDownRecord downRecord = await downRecordServices.QueryFirst(downExp, downOrder, false); if (downRecord != null) { downRecord.eaValue = this.eaValue; downRecord.endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); await downRecordServices.Update(downRecord); upLoadBusiness.UpdateDownRecord(downRecord); } #region 界面刷新 Action action; if (proShaftInfo.positionId == "1") { if ("RFID:" + this.proShaftInfo.bindRfid == this.RFID_Position.Text) { action = () => { this.RFID_Position.Text = "RFID:"; }; await this.RFID_Position.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Position.Text = "SFC:"; }; await this.SFC_Position.Dispatcher.BeginInvoke(action); action = () => { this.EA_Position.Text = "EA:"; }; await this.EA_Position.Dispatcher.BeginInvoke(action); } } else { if ("RFID:" + this.proShaftInfo.bindRfid == this.RFID_Finish.Text) { action = () => { this.RFID_Finish.Text = "RFID:"; }; await this.RFID_Finish.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Finish.Text = "SFC:"; }; await this.SFC_Finish.Dispatcher.BeginInvoke(action); action = () => { this.EA_Finish.Text = "EA:"; }; await this.EA_Finish.Dispatcher.BeginInvoke(action); } } #endregion //获取当前卷轴绑定的RFID、SFC是否和流程内的一致,一样则清空,不一样则不处理 Expression> shaftExp = s1 => true; shaftExp = shaftExp.And(x => x.bindRfid == this.proShaftInfo.bindRfid && x.bindSfc == this.proShaftInfo.bindSfc && x.bindEaValue == this.proShaftInfo.bindEaValue && x.processId == appConfig.processId); Expression> shaftOrder = x => x.bindTime; ProShaftInfo shaftInfo = await shaftInfoServices.QueryFirst(shaftExp, shaftOrder, false); if (shaftInfo != null) { LogHelperBusiness.LogInfo("本地绑定RFID:" + shaftInfo.bindRfid + ";流程内RFID:" + this.proShaftInfo.bindRfid); if (shaftInfo.bindRfid == this.proShaftInfo.bindRfid) { LogHelperBusiness.LogInfo("清除收料轴绑定信息"); //清空卷轴绑定的信息 this.proShaftInfo.bindRfid = ""; this.proShaftInfo.bindSfc = ""; this.proShaftInfo.bindEaValue = ""; await shaftInfoServices.Update(this.proShaftInfo); } } LogRefresh(LogType.RfidLog, this.proShaftInfo.shaftName + "收卷结束,下发下料信号"); //下发下料信号 plcBusiness.writePlc(appConfig.TbAddress.控制下料, 0); LogHelperBusiness.LogInfo("收卷流程结束,下发下料信号D9614"); } catch (Exception ex) { LogRefresh(LogType.RfidLog, "收卷完成清空卷轴状态异常:" + ex.Message); LogHelperBusiness.LogError("收卷完成清空卷轴状态异常", ex); } } /// /// 界面初始化 /// public void ButtonInit() { try { Action action; action = () => { this.BeginAdjustNumberByA.Background = Brushes.White; }; BeginAdjustNumberByA.Dispatcher.BeginInvoke(action); action = () => { this.CollectA.Background = Brushes.White; }; CollectA.Dispatcher.BeginInvoke(action); action = () => { this.EndAdjustNumberByA.Background = Brushes.White; }; EndAdjustNumberByA.Dispatcher.BeginInvoke(action); action = () => { this.CollectB.Background = Brushes.White; }; CollectB.Dispatcher.BeginInvoke(action); action = () => { this.EndAdjustNumberByB.Background = Brushes.White; }; EndAdjustNumberByB.Dispatcher.BeginInvoke(action); action = () => { this.BeginBdjustNumberByBText2.Foreground = Brushes.Gray; }; BeginBdjustNumberByBText2.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByBText.Foreground = Brushes.Gray; }; BeginAdjustNumberByBText.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByAText.Foreground = Brushes.Gray; }; BeginAdjustNumberByAText.Dispatcher.BeginInvoke(action); action = () => { this.BeginAdjustNumberByATexts.Foreground = Brushes.Gray; }; BeginAdjustNumberByATexts.Dispatcher.BeginInvoke(action); action = () => { this.ADataCollect.Foreground = Brushes.Gray; }; ADataCollect.Dispatcher.BeginInvoke(action); action = () => { this.ADataCollect2.Foreground = Brushes.Gray; }; ADataCollect2.Dispatcher.BeginInvoke(action); action = () => { this.EndSfc.Text = ""; }; this.EndSfc.Dispatcher.BeginInvoke(action); } catch (Exception ex) { Console.WriteLine(ex.Message); } } public void LogRefresh(LogType logType, string massage) { string info = massage; string logTypeStr = ""; int isAlarm = 0; if (logType == LogType.MesLog) { logTypeStr = "MES"; ListBoxItemAdd(this.MesLog, massage); } if (logType == LogType.PlcLog) { logTypeStr = "PLC"; ListBoxItemAdd(this.PlcLog, massage); } if (logType == LogType.RfidLog) { logTypeStr = "RFID"; ListBoxItemAdd(this.RfidLog, massage); } if (logType == LogType.AlarmLog) { logTypeStr = "Alarm"; isAlarm = 1; ListBoxItemAdd(this.AlarmLog, massage); upLoadBusiness.SaveLogRecord(0, massage); } logInfoServices.Add(new RecordLogInfo() { id = System.Guid.NewGuid().ToString("N"), processId = "TB", machineId = ConfigurationManager.AppSettings["machineId"].ToString(), alarmType = logTypeStr, alarmInfo = info, isAlarm = isAlarm, recordTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") }); } private List logInfos = new List(); /// /// ListBox刷新 /// /// /// private void ListBoxItemAdd(ListBox listBox, string massage) { LogHelperBusiness.ViewLog(massage); if (logInfos != null) { logInfos.Add(new LogInfoItem() { listBox = listBox, recordTime = DateTime.Now, message = String.Format("{0} {1}", DateTime.Now.ToString("MM-dd HH:mm:ss"), massage) }); } while (logInfos.Count > 120) { logInfos.RemoveAt(0); } Action action; action = () => { listBox.Items.Clear(); var loginList = logInfos.ToArray(); var strArray = loginList.Where(x => x.listBox == listBox).OrderByDescending(x => x.recordTime).ToList(); if (strArray != null) { foreach (var str in strArray) { SplitByLen(str.message, 50).ForEach(x => { listBox.Items.Add(x); }); } //for(int i = 0; i < 40; i++) //{ // SplitByLen(strArray[i].message, 50).ForEach(x => // { // listBox.Items.Add(x); // }); //} } #region 历史代码 //listBox.Items.Add(String.Format("{0} {1}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), massage)); //string[] strArray = new string[listBox.Items.Count]; //listBox.Items.CopyTo(strArray, 0); //listBox.Items.Clear(); //listBox.Items.CopyTo(strArray, 0); //var strArray = logInfos.OrderByDescending(x => x.recordTime).ToList(); //if (strArray.Count() <= refreshAmount) //{ // foreach (string str in strArray) // { // SplitByLen(str, 40).ForEach(x => // { // listBox.Items.Add(x); // }); // } //} //else //{ // for(int i = 0; i < refreshAmount; i++) // { // SplitByLen(strArray[i], 45).ForEach(x => // { // listBox.Items.Add(x); // }); // } //} #endregion }; listBox.Dispatcher.BeginInvoke(action); } public static List SplitByLen(string str, int separatorCharNum) { string tempStr = str; List strList = new List(); if (string.IsNullOrEmpty(str) || str.Length <= separatorCharNum) { strList.Add(str); return strList; } int iMax = Convert.ToInt32(Math.Ceiling(str.Length / (separatorCharNum * 1.0))); for (int i = 0; i < iMax; i++) { string currMsg = tempStr.Substring(0, tempStr.Length > separatorCharNum ? separatorCharNum : tempStr.Length); strList.Add(currMsg); if (tempStr.Length > separatorCharNum) { tempStr = tempStr.Substring(separatorCharNum, tempStr.Length - separatorCharNum); } } return strList; } private async void UpdateDownRecord(string rfid, string sfc, int finish) { Expression> downExp = s1 => true; downExp = downExp.And(x => x.Rfid == rfid && x.Sfc == sfc); Expression> downOrder = (s) => s.RecordTime; ProDownRecord downRecord = await downRecordServices.QueryFirst(downExp, downOrder, false); if (downRecord != null) { downRecord.eaValue = eaValue; downRecord.IsProduction = finish == 6 ? 2 : 1; downRecord.isFinish = finish; downRecord.endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); await downRecordServices.Update(downRecord); upLoadBusiness.UpdateDownRecord(downRecord); } } //窗体初始化 private void UserControlInit() { //查询前五个小时的数据 DateTime beginTime = DateTime.Now.AddHours(-5); ListBoxItemAdd(this.RfidLog, "涂布RFID物料追溯系统初始化"); Expression> exp = s1 => true; exp = exp.And(x => x.processId == appConfig.processId && Convert.ToDateTime(x.bindTime) > beginTime); List shaftInfos = shftInfoService.Query(exp).Result; if (shaftInfos == null || shaftInfos.Count == 0) { ListBoxItemAdd(this.RfidLog, "程序初始化数据为空"); return; } shaftInfos.ForEach(x => { Action action; switch (Convert.ToInt32(x.positionId)) { case 1: action = () => { this.RFID_Position.Text = "RFID:" + x.bindRfid; }; RFID_Position.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Position.Text = "SFC:" + x.bindSfc; }; SFC_Position.Dispatcher.BeginInvoke(action); break; case 2: action = () => { this.RFID_Finish.Text = "RFID:" + x.bindRfid; }; RFID_Finish.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Finish.Text = "SFC:" + x.bindSfc; }; SFC_Finish.Dispatcher.BeginInvoke(action); break; default: break; } }); } private void UserControl_Loaded(object sender, RoutedEventArgs e) { UpdataDeviceStatus(); //加载工单预警信息 RefreshShopOrderAmountInfo(); } private void Border_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { WriteInfo write = new WriteInfo("TB", 1); write.ShowDialog(); RefreshMaterialInfo("TB", "1"); } private void StackPanel_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { WriteInfo write = new WriteInfo("TB", 2); write.ShowDialog(); RefreshMaterialInfo("TB", "2"); } /// /// 刷新界面 /// /// /// public void RefreshMaterialInfo(string processId, string position) { DateTime beginTime = DateTime.Now.AddHours(-5); Expression> exp = s1 => true; exp = exp.And(x => x.processId == appConfig.processId && Convert.ToDateTime(x.bindTime) > beginTime); Expression> order = s1 => s1.bindTime; ProShaftInfo shaftInfo = shaftInfoServices.QueryFirst(exp, order, false).Result; if (shaftInfo == null) { //ListBoxItemAdd(this.RfidLog, "获取卷轴数据为空"); return; } Action action; switch (Convert.ToInt32(shaftInfo.positionId)) { case 1: action = () => { this.RFID_Position.Text = "RFID:" + shaftInfo.bindRfid; }; RFID_Position.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Position.Text = "SFC:" + shaftInfo.bindSfc; }; SFC_Position.Dispatcher.BeginInvoke(action); break; case 2: action = () => { this.RFID_Finish.Text = "RFID:" + shaftInfo.bindRfid; }; RFID_Finish.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Finish.Text = "SFC:" + shaftInfo.bindSfc; }; SFC_Finish.Dispatcher.BeginInvoke(action); break; case 3: action = () => { this.RFID_Position1.Text = "RFID:" + shaftInfo.bindRfid; }; RFID_Position1.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Position1.Text = "SFC:" + shaftInfo.bindSfc; }; SFC_Position1.Dispatcher.BeginInvoke(action); break; case 4: action = () => { this.RFID_Position2.Text = "RFID:" + shaftInfo.bindRfid; }; RFID_Position2.Dispatcher.BeginInvoke(action); action = () => { this.SFC_Position2.Text = "SFC:" + shaftInfo.bindSfc; }; SFC_Position2.Dispatcher.BeginInvoke(action); break; default: break; } } private void ClearViewRefresh() { try { ButtonInit(); this.proShaftInfo.bindRfid = ""; this.proShaftInfo.bindSfc = ""; this.proShaftInfo.bindEaValue = ""; Action action; action = () => { this.EndSfc.Text = ""; }; this.EndSfc.Dispatcher.BeginInvoke(action); //this.EndSfc.Text = ""; } catch (Exception ex) { LogHelperBusiness.LogError("界面初始化事件处理异常", ex); } } /// /// 保存工单预警设置 /// /// /// private void TextBlock_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { LogHelperBusiness.LogInfo("设置工单预警"); string shopOrderText = ""; string orderAlarmAmount = "35000"; if (StringExtension.IsBlank(this.shopOrderText.Text)) { MessageBox.Show("请输入需要设置预警的工单编号"); return; } else { shopOrderText = this.shopOrderText.Text; } if (StringExtension.IsNotBlank(this.orderAlarmAmountText.Text)) { orderAlarmAmount = this.orderAlarmAmountText.Text; } if (SetShopOrderAmountInfo(shopOrderText, orderAlarmAmount)) { MessageBox.Show("工单预警设置成功"); LogHelperBusiness.LogInfo("工单预警设置成功"); this.orderAlarmAmountText.Text = orderAlarmAmount; } else { MessageBox.Show("工单预警数量设置失败"); } } /// /// 工单预警信息设置 /// /// 工单编号 /// 工单预警数量 private bool SetShopOrderAmountInfo(string shopOrderText, string orderAlarmAmount) { bool result = false; //保存工单预警信息 =>保存至SysClient表中 //判断配置中是否存在该项配置orderAlarmAmount try { Expression> exp = s1 => true; exp = exp.And(x => x.paramType == "ShopOrderAlarm"); List clients = sysClientServices.Query(exp).Result; if (clients.Count == 0) //添加配置 { clients = new List(); SysClient ShopOrder = new SysClient() { paramKey = "ShopOrder", paramValue = shopOrderText, paramType = "ShopOrderAlarm", processId = appConfig.processId, remark = "涂布工单预警设置:工单编号" }; SysClient OrderAlarmAmount = new SysClient() { paramKey = "OrderAlarmAmount", paramValue = orderAlarmAmount, paramType = "ShopOrderAlarm", processId = appConfig.processId, remark = "涂布工单预警设置:工单预警数量" }; clients.Add(ShopOrder); clients.Add(OrderAlarmAmount); LogHelperBusiness.LogInfo("设置工单预警,修改工单预警配置参数:" + JsonChange.ModeToJson(clients)); var info = sysClientServices.Add(clients).Result; if (info > 0) { result = true; } } else //修改参数 { LogHelperBusiness.LogInfo("设置工单预警,原工单预警配置参数:" + JsonChange.ModeToJson(clients)); foreach (var item in clients) { if (item.paramKey == "ShopOrder") { item.processId = appConfig.processId; item.paramValue = shopOrderText; } if (item.paramKey == "OrderAlarmAmount") { item.processId = appConfig.processId; item.paramValue = orderAlarmAmount; } } LogHelperBusiness.LogInfo("设置工单预警,修改工单预警配置参数:" + JsonChange.ModeToJson(clients)); var info = sysClientServices.Update(clients).Result; if (info) { result = true; } } } catch (Exception ex) { LogHelperBusiness.LogError("工单预警数量设置异常", ex); } return result; } /// /// 刷新工单预警信息 /// private void RefreshShopOrderAmountInfo() { Expression> exp = s1 => true; exp = exp.And(x => x.paramType == "ShopOrderAlarm"); List clients = sysClientServices.Query(exp).Result; if (clients.Count > 0) { foreach (var item in clients) { if (item.paramKey == "ShopOrder") this.shopOrderText.Text = item.paramValue; if (item.paramKey == "OrderAlarmAmount") this.orderAlarmAmountText.Text = item.paramValue; } } } private void FJ_A_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { WriteInfo write = new WriteInfo("TB", 3); write.ShowDialog(); RefreshMaterialInfo("TB", "3"); } private void FJ_B_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { WriteInfo write = new WriteInfo("TB", 4); write.ShowDialog(); RefreshMaterialInfo("TB", "4"); } } }