/// <summary> /// 记录标签值 /// </summary> /// <param name="tagSetting">标签配置信息</param> /// <param name="tagValue">标签值</param> private void TagValueRecord(FmsAssetTagSetting tagSetting, string tagValue) { lock (lockRecord) { try { EventLogger.Log($"======开始写入【{tagSetting.TAG_VALUE_NAME}】Record====="); FmsSamplingRecord record = new FmsSamplingRecord { PKNO = CBaseData.NewGuid(), ASSET_CODE = tagSetting.ASSET_CODE, TAG_SETTING_PKNO = tagSetting.PKNO, TAG_VALUE_NAME = tagSetting.TAG_VALUE_NAME, TAG_VALUE = tagValue, SAMPLING_TIME = DateTime.Now, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, REMARK = "", }; ws.UseService(s => s.AddFmsSamplingRecord(record)); EventLogger.Log($"======完成写入【{tagSetting.TAG_VALUE_NAME}】Record====="); } catch (Exception ex) { EventLogger.Log($"!!!!!!写入【{tagSetting.TAG_VALUE_NAME}】Record失败,原因:{ex.Message}!!!!!!"); } } }
public string GetMaterialInfo(string jsMaterialInfo) { NetLog.Write("GetRawMaterialInfo" + " " + jsMaterialInfo); List <FDIGetMaterialInfo> mains = new List <FDIGetMaterialInfo>(); try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetMaterialInfo> >(jsMaterialInfo); foreach (var main in mains) { var check = GetFDIGetMaterialInfos($"ItemCode = '{main.ItemCode}'"); foreach (var c in check) { DelFDIGetMaterialInfo(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetMaterialInfo(main); } } catch (Exception ex) { NetLog.Error("GetRawMaterialInfo error", ex); return("error: " + ex.Message); } return("OK"); }
/// <summary> /// 获取新工单 /// </summary> /// <param name="productPKNO">产品PKNO</param> /// <param name="orderType">工单类型 1:原料入库;2:加工;3:成品出库;4:转换;5:换刀</param> /// <returns></returns> private MesJobOrder BuildNewJobOrder(string productPKNO, int orderType, string batchNO, DateTime dtCreateTime) { return(new MesJobOrder() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, LINE_PKNO = CBaseData.CurLinePKNO, LINE_TASK_PKNO = "", // ITEM_PKNO = productPKNO, // TODO:暂无 JOB_ORDER_NO = TableNOHelper.GetNewNO("MES_JOB_ORDER.JOB_ORDER_NO", "J"), BATCH_NO = batchNO, ROUTING_DETAIL_PKNO = "", JOB_ORDER_TYPE = orderType, TASK_QTY = 1, COMPLETE_QTY = 0, ONLINE_QTY = 0, ONCE_QTY = 0, RUN_STATE = 10, //直接生产 CREATION_DATE = dtCreateTime, CREATED_BY = CBaseData.LoginNO, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "", }); }
private void Timer5_Elapsed(object sender, ElapsedEventArgs e) { this.timer5.Enabled = false; WcfClient <IFMSService> ws = new WcfClient <IFMSService>(); //try //{ lock (objLock) { FmsSamplingRecord record = new FmsSamplingRecord() { PKNO = CBaseData.NewGuid(), ASSET_CODE = "A20002", SAMPLING_TIME = DateTime.Now, TAG_SETTING_PKNO = "fe0e40d4bb57424088c1876bba50f229", TAG_VALUE_NAME = "测试", TAG_VALUE = (new Random()).Next(100).ToString(), CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, REMARK = "", }; ws.UseService(s => s.AddFmsSamplingRecord(record)); } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} Console.WriteLine($"3Thread Write{iWriteTest2++}"); this.timer5.Enabled = true; }
public static void FinishProcessPrepare(PmTaskLine taskLine, List <MesProcessCtrol> processCtrols) { WcfClient <IPLMService> wsPLM = new WcfClient <IPLMService>(); //计划 #region 更新任务状态 if (taskLine.RUN_STATE == 0) { taskLine.RUN_STATE = 1; taskLine.UPDATED_BY = CBaseData.LoginName; taskLine.LAST_UPDATE_DATE = DateTime.Now; wsPLM.UseService(s => s.UpdatePmTaskLine(taskLine)); } #endregion foreach (MesProcessCtrol process in processCtrols) { process.PKNO = CBaseData.NewGuid(); process.COMPANY_CODE = ""; process.CREATED_BY = CBaseData.LoginName; process.CREATION_DATE = DateTime.Now; process.USE_FLAG = 1; wsPLM.UseService(s => s.AddMesProcessCtrol(process)); } }
/// <summary> /// 显示询问的对话框 /// Yes No Cancel三个按钮 /// </summary> /// <param name="text"></param> /// <param name="caption"></param> /// <returns></returns> public static WPFMessageBoxResult ShowQuestion(string text, string caption) { string gridName = "grid" + CBaseData.NewGuid(); DialogResult result = DialogResult.Cancel; Application.Current.Dispatcher.Invoke(new Action(() => { if (CBaseData.bWPFEffect) { GrayContent.AddGrayContent(CBaseData.MainWindow, gridName); } result = MessageBox.Show(text, caption, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (CBaseData.bWPFEffect) { GrayContent.RemoveGrayContent(CBaseData.MainWindow, gridName); } })); return(result == DialogResult.Yes ? WPFMessageBoxResult.Yes : result == DialogResult.No ? WPFMessageBoxResult.No : WPFMessageBoxResult.Cancel); }
/// <summary> /// 保存 自学习情况 /// </summary> public void Save() { if (string.IsNullOrEmpty(this.Text) || string.IsNullOrEmpty(this.Value) || (EnumType != 1)) //不自学习 { return; } ComboBoxItem select = SelectedItem as ComboBoxItem; if (select != null) //是选择的下拉框,则不需要自学习 { return; } try { if (ws == null) { ws = new WcfClient <ISDMService>(); } #region 照Value自学习 string sValue = "";//this.Value; string sName = this.Text; string sNO = this.Text; SysEnumItems item = new SysEnumItems() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 ENUM_IDENTIFY = this.EnumIdentify, USE_FLAG = 1, ITEM_CODE = "", ITEM_NAME = sName, ITEM_NO = sNO, ITEM_INDEX = this.Items.Count, }; ws.UseService(s => s.AddSysEnumItems(item)); sValue = item.ITEM_NAME; ComboBoxItem comboBoxItem = new ComboBoxItem() { Content = this.Text, Tag = sValue, }; this.Items.Add(comboBoxItem); this.SelectedIndex = this.Items.Count - 1; this.SelectedItem = comboBoxItem; #endregion } catch (Exception ex) { // ignored Console.WriteLine("error:BasicItemCombox.Save " + ex.Message); } }
private void BtnItemSave_Click(object sender, RoutedEventArgs e) { FmsActionFormulaMain main = tvMain.SelectedItem as FmsActionFormulaMain; if ((main == null) || (string.IsNullOrEmpty(main.PKNO))) { return; } FmsActionFormulaDetail detail = gbItem.DataContext as FmsActionFormulaDetail; if (detail == null) { return; } #region 校验 if (string.IsNullOrEmpty(detail.FORMULA_CODE)) { WPFMessageBox.ShowWarring("请选择配方主信息。", "保存"); return; } if (string.IsNullOrEmpty(detail.FORMULA_DETAIL_NAME)) { WPFMessageBox.ShowWarring("请输入配方明细名称。", "保存"); return; } #endregion if (string.IsNullOrEmpty(detail.PKNO)) //新增 { detail.PKNO = CBaseData.NewGuid(); ws.UseService(s => s.AddFmsActionFormulaDetail(detail)); //重新刷新数据 List <FmsActionFormulaDetail> details = ws.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = {main.FORMULA_CODE} AND USE_FLAG >= 0")) .OrderBy(c => c.PROCESS_INDEX) .ToList(); gridItem.ItemsSource = details; } else //修改 { ws.UseService(s => s.UpdateFmsActionFormulaDetail(detail)); } //提示保存成功 gbItem.IsCollapsed = true; gbItem.Visibility = Visibility.Collapsed; BindHelper.SetDictDataBindingGridItem(gbItem, gridItem); }
private void btnOK_Click(object sender, RoutedEventArgs e) { FmsActionFormulaMain main = gbInfo.DataContext as FmsActionFormulaMain; if (main == null) { return; } #region 检验 if (string.IsNullOrEmpty(main.FORMULA_CODE)) { WPFMessageBox.ShowError("请输入动作配方编码", "保存"); return; } var check = ws.UseService(s => s.GetFmsActionFormulaMains( $"USE_FLAG = 1 AND FORMULA_CODE = '{main.FORMULA_CODE}' AND PKNO <> '{main.PKNO}'")); if (check.Any()) { WPFMessageBox.ShowError($"输入动作配方编码已经存在不能{(string.IsNullOrEmpty(main.PKNO) ? "新增" : "修改")}该编码,请核实", "保存"); return; } #endregion if (string.IsNullOrEmpty(main.PKNO)) //新增 { main.PKNO = CBaseData.NewGuid(); main.CREATION_DATE = DateTime.Now; main.CREATED_BY = CBaseData.LoginName; main.LAST_UPDATE_DATE = DateTime.Now; //最后修改日期 ws.UseService(s => s.AddFmsActionFormulaMain(main)); } else { main.UPDATED_BY = CBaseData.LoginName; main.LAST_UPDATE_DATE = DateTime.Now; ws.UseService(s => s.UpdateFmsActionFormulaMain(main)); } if (!string.IsNullOrEmpty(formulaCode)) { string sql = $"UPDATE FMS_ACTION_FORMULA_DETAIL SET FORMULA_CODE = '{main.FORMULA_CODE}' WHERE FORMULA_CODE = '{formulaCode}'"; WcfClient <ISQLService> wsSQL = new WcfClient <ISQLService>(); wsSQL.UseService(s => s.ExecuteSql(sql)); } Close(); }
/// <summary> /// 形成过程控制信息 /// </summary> /// <param name="jobOrder">订单</param> /// <param name="formulaDetail">配方明细</param> /// <param name="paramValues">参数</param> /// <returns></returns> private MesProcessCtrol BuildNewProcess(MesJobOrder jobOrder, FmsActionFormulaDetail formulaDetail, Dictionary <string, string> paramValues) { return(new MesProcessCtrol() { #region 标准信息 PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, ITEM_PKNO = jobOrder?.ITEM_PKNO, //成品PKNO TODO:暂无 JOB_ORDER_PKNO = jobOrder?.PKNO, JOB_ORDER = jobOrder?.JOB_ORDER_NO, SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", // #endregion PROCESS_CTROL_NAME = formulaDetail.FORMULA_DETAIL_NAME, //名称 PROCESS_DEVICE_PKNO = ProcessParamReplace.Replace(formulaDetail.PROCESS_DEVICE_PKNO, paramValues), //生产设备 PROCESS_PROGRAM_NO = ProcessParamReplace.Replace(formulaDetail.PROCESS_PROGRAM_NO, paramValues), //加工程序号 PROCESS_PROGRAM_CONTENT = formulaDetail.PROCESS_PROGRAM_CONTENT, //加工程序内容 PROCESS_INDEX = formulaDetail.PROCESS_INDEX, //工序顺序 BEGIN_ITEM_PKNO = ProcessParamReplace.Replace(formulaDetail.BEGIN_ITEM_PKNO, paramValues), //生产前项目PKNO FINISH_ITEM_PKNO = ProcessParamReplace.Replace(formulaDetail.FINISH_ITEM_PKNO, paramValues), //生产后项目PKNO BEGIN_POSITION = ProcessParamReplace.Replace(formulaDetail.BEGIN_POSITION, paramValues), //生产前位置 FINISH_POSITION = ProcessParamReplace.Replace(formulaDetail.FINISH_POSITION, paramValues), //生产后位置 PALLET_NO = formulaDetail.PALLET_NO, //托盘号 PROCESS_ACTION_TYPE = formulaDetail.PROCESS_ACTION_TYPE, //工序动作类型 PROCESS_ACTION_PKNO = formulaDetail.PROCESS_ACTION_PKNO, //工序动作控制PKNO PROCESS_ACTION_PARAM1_VALUE = ProcessParamReplace.Replace(formulaDetail.PROCESS_ACTION_PARAM1_VALUE, paramValues), //工序动作参数1 PROCESS_ACTION_PARAM2_VALUE = ProcessParamReplace.Replace(formulaDetail.PROCESS_ACTION_PARAM2_VALUE, paramValues), //工序动作参数2 CUR_PRODUCT_CODE_PKNO = "", //当前生产加工的产品编码PKNO PROCESS_QTY = 1, //加工数量(上线数量) COMPLETE_QTY = 0, //完成数量 QUALIFIED_QTY = 0, //合格数量 PROCESS_STATE = 1, //准备完成 CREATION_DATE = DateTime.Now, //创建日期 CREATED_BY = CBaseData.LoginNO, //创建人 LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = formulaDetail.USE_FLAG, //启用标识 REMARK = "", //备注 }); }
//增加物料确定 private void View_Closed(object sender, EventArgs e) { ItemSelectView view = sender as ItemSelectView; RsItemMaster mRsItemMaster = view?.Tag as RsItemMaster; if (mRsItemMaster == null) { return; } if (treeList.SelectedItem == null || mRsItemMaster.MP_FLAG == "1") //新增产品 { RsBom mRsBom = new RsBom { PKNO = CBaseData.NewGuid(), PARENT_PKNO = "0", ITEM_PKNO = mRsItemMaster.PKNO, //当前物料PKNO CHILD_NAME = mRsItemMaster.ITEM_NAME, //当前物料信息 CHILD_NORM = mRsItemMaster.ITEM_NORM, CHILD_MODEL = mRsItemMaster.ITEM_SPECS, USE_FLAG = 1 }; _RSMService.UseService(s => s.AddRsBom(mRsBom)); } else //增加物料 { RsBom mRsBom = new RsBom { PKNO = CBaseData.NewGuid(), PARENT_PKNO = (treeList.SelectedItem as RsBom)?.PKNO, //父节点PKNO ITEM_PKNO = mRsItemMaster.PKNO, //当前物料PKNO PARENT_NAME = (treeList.SelectedItem as RsBom)?.PARENT_NAME, //父节点Name CHILD_NAME = mRsItemMaster.ITEM_NAME, //当前物料信息 CHILD_NORM = mRsItemMaster.ITEM_NORM, CHILD_MODEL = mRsItemMaster.ITEM_SPECS, USE_FLAG = 1 }; _RSMService.UseService(s => s.AddRsBom(mRsBom)); } Initialize(); }
private void BtnSave_Click(object sender, RoutedEventArgs e) { //保存 AmAssetMasterN asset = cmbAssetInfo.SelectedItem as AmAssetMasterN; FmsAssetCommParam assetComm = gbItem.DataContext as FmsAssetCommParam; if (assetComm == null) { return; } #region //TODO: 校验;保存 if (asset == null) { MessageBox.Show("请选择设备!", "保存", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (assetComm.PKNO == "") { assetComm.PKNO = CBaseData.NewGuid(); assetComm.CREATED_BY = CBaseData.LoginName; assetComm.CREATION_DATE = DateTime.Now; assetComm.LAST_UPDATE_DATE = DateTime.Now; //最后修改日期 _fmsClient.UseService(s => s.AddFmsAssetCommParam(assetComm)); } else { assetComm.UPDATED_BY = CBaseData.LoginName; assetComm.LAST_UPDATE_DATE = DateTime.Now; _fmsClient.UseService(s => s.UpdateFmsAssetCommParam(assetComm)); } NotificationInvoke.NewNotification("保存", "设备通讯配置信息已保存。"); #endregion GetPage(); //重新刷新数据,根据需求是否进行刷新数据 //保存成功 gbItem.IsCollapsed = true; gbItem.Visibility = Visibility.Collapsed; BindHelper.SetDictDataBindingGridItem(gbItem, gridItem); }
private void BtnSave_Click(object sender, RoutedEventArgs e) { //保存 AmAssetMasterN asset = cmbAssetInfo.SelectedItem as AmAssetMasterN; FmsActionControl actionControl = gbItem.DataContext as FmsActionControl; if (actionControl == null) { return; } #region //TODO: 校验;保存 if (asset == null) { WPFMessageBox.ShowError("请选择设备!", "保存"); return; } if (string.IsNullOrEmpty(actionControl.ACTION_NAME)) { WPFMessageBox.ShowError("请输入指令动作名称!", "保存"); return; } if (actionControl.PKNO == "") { actionControl.PKNO = CBaseData.NewGuid(); _fmsClient.UseService(s => s.AddFmsActionControl(actionControl)); } else { _fmsClient.UseService(s => s.UpdateFmsActionControl(actionControl)); } WPFMessageBox.ShowTips("指令动作配置信息已保存。", "保存"); #endregion GetPage(); //重新刷新数据,根据需求是否进行刷新数据 //保存成功 gbItem.IsCollapsed = true; gbItem.Visibility = Visibility.Collapsed; BindHelper.SetDictDataBindingGridItem(gbItem, gridItem); }
/// <summary> /// 显示警告提示框 /// 输入信息检验失败 /// </summary> /// <param name="text"></param> /// <param name="caption"></param> public static void ShowWarring(string text, string caption) { string gridName = "grid" + CBaseData.NewGuid(); Application.Current.Dispatcher.Invoke(new Action(() => { if (CBaseData.bWPFEffect) { GrayContent.AddGrayContent(CBaseData.MainWindow, gridName); } MessageBox.Show(text, caption, MessageBoxButtons.OK, MessageBoxIcon.Warning); if (CBaseData.bWPFEffect) { GrayContent.RemoveGrayContent(CBaseData.MainWindow, gridName); } })); }
public string GetRawMaterial(string jsMaterialMain, string jsMaterialDetail) { NetLog.Write("GetRawMaterial" + " " + jsMaterialMain); NetLog.Write("GetRawMaterial" + " " + jsMaterialDetail); List <FDIGetRawMaterial> mains = new List <FDIGetRawMaterial>(); List <FDIGetRawMaterialDetail> detials = new List <FDIGetRawMaterialDetail>(); try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetRawMaterial> >(jsMaterialMain); detials = SafeConverter.JsonDeserializeObject <List <FDIGetRawMaterialDetail> >(jsMaterialDetail); foreach (var main in mains) { var check = GetFDIGetRawMaterials($"DocEntry = '{main.DocEntry}'"); foreach (var c in check) { DelFDIGetRawMaterial(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetRawMaterial(main); } foreach (var detail in detials) { var check = GetFDIGetRawMaterialDetails($"DocEntry = '{detail.DocEntry}' and LineId = '{detail.LineId}'"); foreach (var c in check) { DelFDIGetRawMaterialDetail(c.PKNO); } detail.PKNO = CBaseData.NewGuid(); AddFDIGetRawMaterialDetail(detail); } } catch (Exception ex) { NetLog.Error("GetRawMaterial error", ex); return("error: " + ex.Message); } return("OK"); }
public string GetRawMaterial(string jsMaterialMain, string jsMaterialDetail) { List <FDIGetMaterial> mains = new List <FDIGetMaterial>(); List <FDIGetMaterialDetail> detials = new List <FDIGetMaterialDetail>(); try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetMaterial> >(jsMaterialMain); detials = SafeConverter.JsonDeserializeObject <List <FDIGetMaterialDetail> >(jsMaterialDetail); foreach (var main in mains) { var check = GetFDIGetMaterials($"ReciverID = '{main.ReciverID}'"); foreach (var c in check) { DelFDIGetMaterial(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetMaterial(main); } foreach (var detail in detials) { var check = GetFDIGetMaterialDetails($"ReciverID = '{detail.ReciverID}'"); foreach (var c in check) { DelFDIGetMaterialDetail(c.PKNO); } detail.PKNO = CBaseData.NewGuid(); AddFDIGetMaterialDetail(detail); } } catch (Exception ex) { return("error: " + ex.Message); } return("OK"); }
public static WPFMessageBoxResult Show(string text, string caption, MessageBoxButtons button, MessageBoxIcon icon = MessageBoxIcon.Information) { string gridName = "grid" + CBaseData.NewGuid(); if (CBaseData.bWPFEffect) { GrayContent.AddGrayContent(CBaseData.MainWindow, gridName); } DialogResult result = MessageBox.Show(text, caption, button, icon); if (CBaseData.bWPFEffect) { GrayContent.RemoveGrayContent(CBaseData.MainWindow, gridName); } return((result == DialogResult.Yes) ? WPFMessageBoxResult.Yes : (result == DialogResult.No) ? WPFMessageBoxResult.No : (result == DialogResult.OK) ? WPFMessageBoxResult.OK : WPFMessageBoxResult.Cancel); }
public string GetWorkOrder(string jsWOMain, string jsWODetail) { NetLog.Write("GetWorkOrder" + " " + jsWOMain); NetLog.Write("GetWorkOrder" + " " + jsWODetail); List <FDIGetWOrder> mains = new List <FDIGetWOrder>(); List <FDIGetWOrderDetail> detials = new List <FDIGetWOrderDetail>(); //String jsWOMain = "[{\r\n" + // "\"DocEntry\": \"5\",\r\n" + // "\"ItemCode\": \"P00000001\",\r\n" + // "\"Status\": \"L\",\r\n" + // "\"Type\": \"S\",\r\n" + // "\"PlannedQty\": \"100.000000\",\r\n" + // " \"Comments\": \"\",\"RlsDate\": \"2019-03-26\",\r\n" + // " \"Warehouse\": \"W001\",\r\n" + // "\"Project\": \"\",\r\n" + // "\"OcrCode\": \"\",\r\n" + // "\"OcrCode2\": \"\",\r\n" + // " \"OcrCode3\": \"\",\"OcrCode4\": \"\",\r\n" + // "\"OcrCode5\": \"\",\r\n" + // "\"OriginNum\": \"-1\",\r\n" + // "\"Cardcode\": \"\",\r\n" + // "\"UserSign\": \"9\",\r\n" + // "\"StartDate\": \"2019-03-26\",\"DueDate\": \"2019-03-26\",\r\n" + // "\"DocTime\": \"142602\",\r\n" + // "\"Udf1\": \"\",\r\n" + // "\"Udf2\": \"\",\r\n" + // "\"Udf3\": \"\",\r\n" + // "\"Udf4\": \"\",\r\n" + // " \"Udf5\": \"\"\r\n" + // "}\r\n" + // "]"; //String jsWODetail = "[{\r\n" + // "\"DocEntry\": \"5\",\r\n" + // "\"LineNum\": \"0\",\r\n" + // " \"ItemCode\": \"M00000001\",\r\n" + // " \"ItemName\": \"16寸轮毂毛坯\",\r\n" + // " \"BaseQty\": \"1.000000\",\r\n" + // " \"PlannedQty\": \"100.000000\",\r\n" + // " \"WareHouse\": \"W001\",\r\n" + // " \"Project\": \"\",\r\n" + // " \"OcrCode\": \"\",\r\n" + // " \"OcrCode2\": \"\",\r\n" + // " \"OcrCode3\": \"\",\r\n" + // " \"OcrCode4\": \"\",\r\n" + // " \"OcrCode5\": \"\",\r\n" + // " \"Udf1\": \"\",\r\n" + // " \"Udf2\": \"\",\r\n" + // " \"Udf3\": \"\",\r\n" + // " \"Udf4\": \"\",\r\n" + // " \"Udf5\": \"\"\r\n" + // " }\r\n" + // "]"; try { mains = SafeConverter.JsonDeserializeObject <List <FDIGetWOrder> >(jsWOMain); detials = SafeConverter.JsonDeserializeObject <List <FDIGetWOrderDetail> >(jsWODetail); foreach (var main in mains) { var check = GetFDIGetWOrders($"DocEntry = '{main.DocEntry}'"); foreach (var c in check) { DelFDIGetWOrder(c.PKNO); } main.PKNO = CBaseData.NewGuid(); AddFDIGetWOrder(main); } foreach (var detail in detials) { var check = GetFDIGetWOrderDetails($"DocEntry = '{detail.DocEntry}'and LineNum = '{detail.LineNum}'"); foreach (var c in check) { DelFDIGetWOrderDetail(c.PKNO); } detail.PKNO = CBaseData.NewGuid(); AddFDIGetWOrderDetail(detail); } } catch (Exception ex) { NetLog.Error("GetRawMaterial error", ex); return("error: " + ex.Message); } return("OK"); }
private void Timer_Elapsed(object sender, ElapsedEventArgs e) { this.timer.Enabled = false; string deviceNO = "1"; string deviceState = "2"; try { Dispatcher.BeginInvoke((Action)(delegate() { deviceNO = this.tbDeviceNO.Text; deviceState = this.tbDeviceState.Text; })); } catch (Exception ex) { } WcfClient <IMESService> ws = new WcfClient <IMESService>(); try { //数据采集 #region 写入数据库 if (bFirstRecord) { MesStateResultRecord record = new MesStateResultRecord() { PKNO = CBaseData.NewGuid(), DevicePKNO = deviceNO, TagValue = deviceState, BeginTime = DateTime.Now, EndTime = DateTime.Now, }; Console.WriteLine(record.PKNO); ws.UseService(s => s.AddMesStateResultRecord(record)); } else { List <MesStateResultRecord> records = ws.UseService(s => s.GetAllMesStateResultRecord("")); MesStateResultRecord record = records.Where(c => c.DevicePKNO == deviceNO) .OrderByDescending(c => c.EndTime) .FirstOrDefault(); if ((record == null) || (record.EndTime <= DateTime.Now.AddMinutes(-10))) //10分钟之前的数据则重新增加 { record = new MesStateResultRecord() { PKNO = CBaseData.NewGuid(), DevicePKNO = deviceNO, TagValue = deviceState, BeginTime = DateTime.Now, EndTime = DateTime.Now, }; Console.WriteLine(record.PKNO); ws.UseService(s => s.AddMesStateResultRecord(record)); } else { DateTime nowTime = DateTime.Now; record.EndTime = nowTime; ws.UseService(s => s.UpdateMesStateResultRecord(record)); if (record.TagValue != deviceState) //不相同情况下新增 { MesStateResultRecord newRecord = new MesStateResultRecord() { PKNO = CBaseData.NewGuid(), DevicePKNO = deviceNO, TagValue = deviceState, BeginTime = nowTime, EndTime = nowTime.AddSeconds(1), //提取最新数据 }; Console.WriteLine(newRecord.PKNO); ws.UseService(s => s.AddMesStateResultRecord(newRecord)); } } } #endregion } catch (Exception ex) { Console.WriteLine(ex.Message); } bFirstRecord = false; this.timer.Enabled = true; }
private void bSave_Click(object sender, System.Windows.RoutedEventArgs e) { if (cmbRoutingMain.SelectedValue == null) { return; } #region 创建生产过程 //生产线数据 PmTaskLine taskLine = cmbTask.SelectedItem as PmTaskLine; //产品数据 string itemPKNO = cmbProduct.SelectedValue.ToString(); RsItemMaster product = wsRSM.UseService(s => s.GetRsItemMasterById(itemPKNO)); if (product == null) { MessageBox.Show("产品信息不存在,请核实.", "完成生产准备", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //准备完成 List <MesProcessCtrol> processCtrols = new List <MesProcessCtrol>(); List <RsRoutingDetail> rsRoutingDetails = gridProcessInfo.ItemsSource as List <RsRoutingDetail>; //已创建加工数量 int qty = CheckPlanQTY(taskLine.TASK_NO); decimal preparedQty = 0; decimal.TryParse(tbTaskQty.Text.ToString(), out preparedQty); if (preparedQty <= 0) { MessageBox.Show("请输入正确的任务数量.", "完成生产准备", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #region 判断加工数量 if (tbTaskQty.Text.ToString() == "") { MessageBox.Show($"请输入数量", "未输入数量", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (int.Parse(tbTaskQty.Text.ToString()) + qty > taskLine.TASK_QTY) { MessageBox.Show($"输入数量超出订单加工数量", "数量超限", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #endregion AmAssetMasterN mainDevice = cmbAssetInfo.SelectedItem as AmAssetMasterN; if (mainDevice == null) { MessageBox.Show("请选择主控PLC", "完成生产准备", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } #region 创建工单表 MesJobOrder jobOrder = new MesJobOrder() { PKNO = Guid.NewGuid().ToString("N"), COMPANY_CODE = "", LINE_PKNO = taskLine.LINE_PKNO, //产线信息 LINE_TASK_PKNO = taskLine.PKNO, ITEM_PKNO = itemPKNO, JOB_ORDER_NO = taskLine.TASK_NO + lbBatchIndex.Content.ToString(), BATCH_NO = lbBatchIndex.Content.ToString(), ROUTING_DETAIL_PKNO = cmbRoutingMain.SelectedValue.ToString(), TASK_QTY = preparedQty, COMPLETE_QTY = 0, ONLINE_QTY = 0, ONCE_QTY = 0, RUN_STATE = 1, //准备完成 CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "", }; #endregion List <MesProcessCtrol> newMesProcessCtrols = new List <MesProcessCtrol>(); int iProcessIndex = 0; string DeviceInfos = ""; string Programs = ""; #region 获取加工设备、程序号 foreach (RsRoutingDetail item in rsRoutingDetails) { if (string.IsNullOrEmpty(item.WC_ABV)) { MessageBox.Show($"工序【{item.OP_NAME}】加工设备不能为空,请选择加工设备!", "完成生产准备", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } AmAssetMasterN device = wsEAM.UseService(s => s.GetAmAssetMasterNById(item.WC_ABV)); if (device == null) { MessageBox.Show($"工序【{item.OP_NAME}】加工设备,请选择加工设备!", "完成生产准备", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } DeviceInfos += device.ASSET_LABEL; //设备 Programs += item.NC_PRO_NAME; //程序号 } #endregion wsPLM.UseService(s => s.AddMesJobOrder(jobOrder)); //添加工单 #region 添加加工工序,共5步 FmsActionControl ctrl1 = wsFMS.UseService(s => s.GetFmsActionControls($"ASSET_CODE = '{mainDevice.ASSET_CODE}' AND ACTION_NAME = '发送产品信息'")) .FirstOrDefault(); // FmsActionControl ctrl2 = wsFMS.UseService(s => s.GetFmsActionControls($"ASSET_CODE = '{mainDevice.ASSET_CODE}' AND ACTION_NAME = '发送数量'")) .FirstOrDefault(); // FmsActionControl ctrl3 = wsFMS.UseService(s => s.GetFmsActionControls($"ASSET_CODE = '{mainDevice.ASSET_CODE}' AND ACTION_NAME = '发送设备及程序号'")) .FirstOrDefault(); // FmsActionControl ctrl4 = wsFMS.UseService(s => s.GetFmsActionControls($"ASSET_CODE = '{mainDevice.ASSET_CODE}' AND ACTION_NAME = '订单确认'")) .FirstOrDefault(); // FmsActionControl ctrl5 = wsFMS.UseService(s => s.GetFmsActionControls($"ASSET_CODE = '{mainDevice.ASSET_CODE}' AND ACTION_NAME = '订单完成'")) .FirstOrDefault(); // #region 1.第一步发送产品信息 MesProcessCtrol step1 = new MesProcessCtrol() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = cmbTask.Text + lbBatchIndex.Content, //工单编号 ITEM_PKNO = jobOrder.ITEM_PKNO, //产品PKNO SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", //工序编号(工艺路线明细)为空,不按照工艺进行控制 PROCESS_DEVICE_PKNO = mainDevice.PKNO, //加工设备为 主控PLC PROCESS_INDEX = 0, PROCESS_ACTION_TYPE = 0, PROCESS_ACTION_PKNO = (ctrl1 == null) ? "" : ctrl1.PKNO, PROCESS_ACTION_PARAM1_VALUE = product.ITEM_ABV, //产品简称 PROCESS_ACTION_PARAM2_VALUE = "", CUR_PRODUCT_CODE_PKNO = "", PROCESS_QTY = preparedQty, COMPLETE_QTY = 0, QUALIFIED_QTY = 0, PROCESS_STATE = 1, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "系统自动形成", }; #endregion end 1 #region 2.第二步发送数量 MesProcessCtrol step2 = new MesProcessCtrol() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = cmbTask.Text + lbBatchIndex.Content, //工单编号 ITEM_PKNO = jobOrder.ITEM_PKNO, //产品PKNO SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", //工序编号(工艺路线明细)为空,不按照工艺进行控制 PROCESS_DEVICE_PKNO = mainDevice.PKNO, //加工设备为 主控PLC PROCESS_INDEX = 1, PROCESS_ACTION_TYPE = 0, PROCESS_ACTION_PKNO = (ctrl2 == null) ? "" : ctrl2.PKNO, PROCESS_ACTION_PARAM1_VALUE = preparedQty.ToString(), //数量 PROCESS_ACTION_PARAM2_VALUE = "", CUR_PRODUCT_CODE_PKNO = "", PROCESS_QTY = preparedQty, COMPLETE_QTY = 0, QUALIFIED_QTY = 0, PROCESS_STATE = 1, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "系统自动形成", }; #endregion end 2 #region 3.第三步发送设备及程序号 MesProcessCtrol step3 = new MesProcessCtrol() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = cmbTask.Text + lbBatchIndex.Content, //工单编号 ITEM_PKNO = jobOrder.ITEM_PKNO, //产品PKNO SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", //工序编号(工艺路线明细)为空,不按照工艺进行控制 PROCESS_DEVICE_PKNO = mainDevice.PKNO, //加工设备为 主控PLC PROCESS_INDEX = 2, PROCESS_ACTION_TYPE = 0, PROCESS_ACTION_PKNO = (ctrl3 == null) ? "" : ctrl3.PKNO, PROCESS_ACTION_PARAM1_VALUE = DeviceInfos, //设备ID PROCESS_ACTION_PARAM2_VALUE = Programs, //程序号 CUR_PRODUCT_CODE_PKNO = "", PROCESS_QTY = preparedQty, COMPLETE_QTY = 0, QUALIFIED_QTY = 0, PROCESS_STATE = 1, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "系统自动形成", }; #endregion end 3 #region 4.第四步发送订单确认 MesProcessCtrol step4 = new MesProcessCtrol() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = cmbTask.Text + lbBatchIndex.Content, //工单编号 ITEM_PKNO = jobOrder.ITEM_PKNO, //产品PKNO SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", //工序编号(工艺路线明细)为空,不按照工艺进行控制 PROCESS_DEVICE_PKNO = mainDevice.PKNO, //加工设备为 主控PLC PROCESS_INDEX = 3, PROCESS_ACTION_TYPE = 0, PROCESS_ACTION_PKNO = (ctrl4 == null) ? "" : ctrl4.PKNO, PROCESS_ACTION_PARAM1_VALUE = cmbTask.Text + lbBatchIndex.Content, //订单ID PROCESS_ACTION_PARAM2_VALUE = "", // CUR_PRODUCT_CODE_PKNO = "", PROCESS_QTY = preparedQty, COMPLETE_QTY = 0, QUALIFIED_QTY = 0, PROCESS_STATE = 1, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "系统自动形成", }; #endregion end 4 #region 5.第五步订单完成 MesProcessCtrol step5 = new MesProcessCtrol() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = cmbTask.Text + lbBatchIndex.Content, //工单编号 ITEM_PKNO = jobOrder.ITEM_PKNO, //产品PKNO SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", //工序编号(工艺路线明细)为空,不按照工艺进行控制 PROCESS_DEVICE_PKNO = mainDevice.PKNO, //加工设备为 主控PLC PROCESS_INDEX = 4, PROCESS_ACTION_TYPE = 0, PROCESS_ACTION_PKNO = (ctrl5 == null) ? "" : ctrl5.PKNO, PROCESS_ACTION_PARAM1_VALUE = "", // PROCESS_ACTION_PARAM2_VALUE = "", // CUR_PRODUCT_CODE_PKNO = "", PROCESS_QTY = preparedQty, COMPLETE_QTY = 0, QUALIFIED_QTY = 0, PROCESS_STATE = 1, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, USE_FLAG = 1, REMARK = "系统自动形成", }; #endregion end 5 wsPLM.UseService(s => s.AddMesProcessCtrol(step1)); wsPLM.UseService(s => s.AddMesProcessCtrol(step2)); wsPLM.UseService(s => s.AddMesProcessCtrol(step3)); wsPLM.UseService(s => s.AddMesProcessCtrol(step4)); wsPLM.UseService(s => s.AddMesProcessCtrol(step5)); #endregion #endregion //修改产线任务的完成数量 taskLine.PREPARED_QTY += preparedQty; if (taskLine.RUN_STATE == 0) { taskLine.RUN_STATE = 1; } wsPLM.UseService(s => s.UpdatePmTaskLine(taskLine)); cmbTask.ItemsSource = wsPLM.UseService(s => s.GetPmTaskLines("USE_FLAG = 1 AND RUN_STATE < 10 ")) //未完成的 .Where(c => c.TASK_QTY > c.PREPARED_QTY) .OrderBy(c => c.CREATION_DATE) .ToList(); //生产线任务 cmbTask.SelectedIndex = -1; gridProcessInfo.ItemsSource = null; }
/// <summary> /// 获取新的编号 /// </summary> /// <param name="IdentifyCode">PmTaskLine.TASK_NO</param> /// <param name="formate">格式 前缀符,日期格式,后缀符,开始编号,当前编号 没有,表示只有前缀符的标准格式 </param> /// <returns></returns> public static string GetNewNO(string IdentifyCode, string formate = "") { SysTableNOSetting tableNoSetting = ws.UseService(s => s.GetSysTableNOSettings($"USE_FLAG = 1 AND IDENTIFY_CODE = '{IdentifyCode}'")) .FirstOrDefault(); string sDate; if (tableNoSetting == null) //自动初始化 { string[] values = IdentifyCode.Split('.', '。'); if (values.Length <= 1) { return($"编号代码({IdentifyCode})未能初始化."); } string[] formates = formate.Split(','); #region 自动添加编号 string sTableName = values[0]; string sFieldValue = values[1]; tableNoSetting = new SysTableNOSetting() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", IDENTIFY_CODE = IdentifyCode, TABLE_NAME = sTableName, TABLE_INTROD = sTableName, //描述 FIELD_NAME = sFieldValue, MAX_LENGTH = 50, PREFIX_STR = (!string.IsNullOrEmpty(formate)) ? formates[0] : "N", DATE_FORMATE = (formates.Length > 1) ? formates[1] : "yyMMdd", POSTFIX_STR = (formates.Length > 2) ? formates[2] : "", FIRST_NO = (formates.Length > 3) ? formates[3] : "001", CUR_NO = (formates.Length > 4) ? formates[4] : "001", NO_INTROD = "编号组成:{前缀符}+{服务器编号}+{格式化的日期}+{顺序号}+{后缀符}", CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "系统自动创建", }; ws.UseService(s => s.AddSysTableNOSetting(tableNoSetting)); #endregion sDate = ""; if (!string.IsNullOrEmpty(tableNoSetting.DATE_FORMATE)) { sDate = DateTime.Now.ToString(tableNoSetting.DATE_FORMATE); } return(tableNoSetting.PREFIX_STR + sDate + tableNoSetting.FIRST_NO + tableNoSetting.POSTFIX_STR); } sDate = ""; string sCurIndex = tableNoSetting.FIRST_NO; if (!string.IsNullOrEmpty(tableNoSetting.DATE_FORMATE)) { sDate = DateTime.Now.ToString(tableNoSetting.DATE_FORMATE); } if (!string.IsNullOrEmpty(tableNoSetting.CUR_NO)) //有当前编号 { sCurIndex = tableNoSetting.CUR_NO; } else //如果没有当前编号,从数据读取 { //string sql = $" SELECT {tableNoSetting.FIELD_NAME} FROM {tableNoSetting.TABLE_NAME} " + // $" WHERE {tableNoSetting.FIELD_NAME} LIKE '{tableNoSetting.PREFIX_STR}{sDate}%{tableNoSetting.POSTFIX_STR}'" + // $" ORDER BY "; sCurIndex = tableNoSetting.FIRST_NO; } string sNewIndex = sCurIndex; #region 获取下一个顺序号 Int64 index = 0; Int64.TryParse(sCurIndex, out index); index++; if (sCurIndex.Length < index.ToString().Length) //位数边长 { sNewIndex = 1.ToString().PadLeft(sCurIndex.Length + 1, '0'); } else { sNewIndex = index.ToString().PadLeft(sCurIndex.Length, '0'); } #endregion string sNewNO = tableNoSetting.PREFIX_STR + sDate + sNewIndex + tableNoSetting.POSTFIX_STR; if (sNewNO.Length > tableNoSetting.MAX_LENGTH) //长度超过数据库的长度,重新编号,智能升级号码 { tableNoSetting.PREFIX_STR += "N"; //新增长度 sNewIndex = 1.ToString() .PadLeft( tableNoSetting.MAX_LENGTH - tableNoSetting.PREFIX_STR.Length - sDate.Length - tableNoSetting.POSTFIX_STR.Length, '0'); } #region 反馈到数据库 tableNoSetting.CUR_NO = sNewIndex; ws.UseService(s => s.UpdateSysTableNOSetting(tableNoSetting)); #endregion return(sNewNO); }
private void BtnAutoChange_Click(object sender, RoutedEventArgs e) { TmsToolsMaster mToolsMasterUp = GridControlInvTool.SelectedItem as TmsToolsMaster; //库存 TmsDeviceToolsPos mTmsDeviceToolsPos = GridControlDeviceTool.SelectedItem as TmsDeviceToolsPos; //机床刀位信息 if (mToolsMasterUp == null) { return; } if (mTmsDeviceToolsPos == null) { return; } AmAssetMasterN asset = ComAsset.SelectedItem as AmAssetMasterN; if (asset == null) { WPFMessageBox.ShowError("请选择机床信息!", "自动换刀管理"); return; } TmsToolsMaster mToolsMasterDown = ws.UseService(s => s.GetTmsToolsMasterById(mTmsDeviceToolsPos.TOOLS_PKNO)); if (mToolsMasterDown == null) { WPFMessageBox.ShowError("选中的需要换下的机床刀具信息不存在,请核实!", "自动换刀管理"); return; } MesJobOrder jobOrder = null; WmsInventory inv = null; List <MesProcessCtrol> processCtrols = new List <MesProcessCtrol>(); #region 形成工单 jobOrder = new MesJobOrder() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, LINE_PKNO = CBaseData.CurLinePKNO, LINE_TASK_PKNO = "", //产线任务PKNO ITEM_PKNO = "", // TODO:暂无 JOB_ORDER_NO = TableNOHelper.GetNewNO("MES_JOB_ORDER.JOB_ORDER_NO", "J"), BATCH_NO = "自动换刀", ROUTING_DETAIL_PKNO = "", JOB_ORDER_TYPE = 2, //工单类型 1:原料入库;2:加工;3:成品出库;4:转换 TASK_QTY = 1, COMPLETE_QTY = 0, ONLINE_QTY = 0, ONCE_QTY = 0, RUN_STATE = 10, //直接生产 CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginNO, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "", }; #endregion #region 增加参数 Dictionary <string, string> ParamValues = new Dictionary <string, string>(); ParamValues.Add("{机床刀号}", mTmsDeviceToolsPos.TOOLS_POS_NO); //机床刀号 ParamValues.Add("{卸下刀具编号}", mToolsMasterDown.TOOLS_CODE.PadRight(25)); //卸下刀具编号 ParamValues.Add("{装上刀具编号}", mToolsMasterUp.TOOLS_CODE.PadRight(25)); //装上刀具编号 ParamValues.Add("{装上刀具PKNO}", mToolsMasterUp.PKNO); //装上刀具PKNO ParamValues.Add("{卸下刀具PKNO}", mToolsMasterDown.PKNO); //卸下刀具PKNO ParamValues.Add("{长度形状补偿}", SafeConverter.SafeToStr(mToolsMasterUp.COMPENSATION_SHAPE_LENGTH)); //长度形状补偿 - 装上 ParamValues.Add("{半径形状补偿}", SafeConverter.SafeToStr(mToolsMasterUp.COMPENSATION_SHAPE_DIAMETER)); //半径形状补偿 - 装上 ParamValues.Add("{卸下刀位PKNO}", mTmsDeviceToolsPos.PKNO); //卸下刀位PKNO ParamValues.Add("{装上刀位PKNO}", mTmsDeviceToolsPos.PKNO); //装上刀位PKNO ParamValues.Add("{装刀机床PKNO}", asset?.PKNO); //装刀机床PKNO #endregion string sFormulaCode = "换刀-" + asset.ASSET_CODE; List <FmsActionFormulaDetail> formulaDetails = wsFms.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = '{sFormulaCode}' AND USE_FLAG= 1")) .OrderBy(c => c.PROCESS_INDEX) .ToList(); foreach (var detail in formulaDetails) //配方 { MesProcessCtrol process = new MesProcessCtrol() { #region 标准信息 PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, ITEM_PKNO = "", //成品PKNO TODO:暂无 JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = jobOrder.JOB_ORDER_NO, SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", // #endregion PROCESS_CTROL_NAME = detail.FORMULA_DETAIL_NAME, //名称 PROCESS_DEVICE_PKNO = ProcessParamReplace.Replace(detail.PROCESS_DEVICE_PKNO, ParamValues), //生产设备 PROCESS_PROGRAM_NO = ProcessParamReplace.Replace(detail.PROCESS_PROGRAM_NO, ParamValues), //加工程序号 PROCESS_PROGRAM_CONTENT = detail.PROCESS_PROGRAM_CONTENT, //加工程序内容 PROCESS_INDEX = detail.PROCESS_INDEX, //工序顺序 BEGIN_ITEM_PKNO = ProcessParamReplace.Replace(detail.BEGIN_ITEM_PKNO, ParamValues), //生产前项目PKNO FINISH_ITEM_PKNO = ProcessParamReplace.Replace(detail.FINISH_ITEM_PKNO, ParamValues), //生产后项目PKNO BEGIN_POSITION = ProcessParamReplace.Replace(detail.BEGIN_POSITION, ParamValues), //生产前位置 FINISH_POSITION = ProcessParamReplace.Replace(detail.FINISH_POSITION, ParamValues), //生产后位置 PALLET_NO = detail.PALLET_NO, //托盘号 PROCESS_ACTION_TYPE = detail.PROCESS_ACTION_TYPE, //工序动作类型 PROCESS_ACTION_PKNO = detail.PROCESS_ACTION_PKNO, //工序动作控制PKNO PROCESS_ACTION_PARAM1_VALUE = ProcessParamReplace.Replace(detail.PROCESS_ACTION_PARAM1_VALUE, ParamValues), //工序动作参数1 PROCESS_ACTION_PARAM2_VALUE = ProcessParamReplace.Replace(detail.PROCESS_ACTION_PARAM2_VALUE, ParamValues), //工序动作参数2 CUR_PRODUCT_CODE_PKNO = "", //当前生产加工的产品编码PKNO PROCESS_QTY = 1, //加工数量(上线数量) COMPLETE_QTY = 0, //完成数量 QUALIFIED_QTY = 0, //合格数量 PROCESS_STATE = 1, //准备完成 CREATION_DATE = DateTime.Now, //创建日期 CREATED_BY = CBaseData.LoginNO, //创建人 LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = detail.USE_FLAG, //启用标识 REMARK = "", //备注 }; processCtrols.Add(process); } Cursor = Cursors.Wait; wsPLM.UseService(s => s.AddMesJobOrder(jobOrder)); foreach (MesProcessCtrol processCtrol in processCtrols) { wsPLM.UseService(s => s.AddMesProcessCtrol(processCtrol)); } Cursor = Cursors.Arrow; MessageBox.Show("换刀下单成功."); GridControlInvTool.ItemsSource = ws.UseService(s => s.GetTmsToolsMasters("USE_FLAG > 0 AND TOOLS_POSITION = 1")).OrderBy(n => n.CREATION_DATE).ToList();; }
private void BtnItemSave_Click(object sender, RoutedEventArgs e) { FmsActionFormulaMain main = tvMain.SelectedItem as FmsActionFormulaMain; if ((main == null) || (string.IsNullOrEmpty(main.PKNO))) { return; } FmsActionFormulaDetail detail = gbItem.DataContext as FmsActionFormulaDetail; if (detail == null) { return; } #region 校验 if (string.IsNullOrEmpty(detail.FORMULA_CODE)) { WPFMessageBox.ShowWarring("请选择配方主信息。", "保存"); return; } if (string.IsNullOrEmpty(detail.FORMULA_DETAIL_NAME)) { WPFMessageBox.ShowWarring("请输入配方明细名称。", "保存"); return; } #endregion if (string.IsNullOrEmpty(detail.PKNO)) //新增 { detail.PKNO = CBaseData.NewGuid(); FmsActionControl action = new FmsActionControl() { PKNO = CBaseData.NewGuid(), ACTION_NAME = detail.FORMULA_DETAIL_NAME, ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString(), START_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbCondition.Text)? "": cmbCondition.SelectedValue.ToString(), START_CONDITION_VALUE = tbConditionValue.Text, EXECUTE_TAG_PKNO = string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString(), EXECUTE_WRITE_VALUE = tbExecuteValue.Text, EXECUTE_PARAM1_TAG_PKNO = string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString(), EXECUTE_PARAM2_TAG_PKNO = string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString(), FINISH_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString(), FINISH_CONDITION_VALUE = tbFinishValue.Text, }; detail.PROCESS_ACTION_PKNO = action.PKNO; ws.UseService(s => s.AddFmsActionControl(action)); ws.UseService(s => s.AddFmsActionFormulaDetail(detail)); //重新刷新数据 List <FmsActionFormulaDetail> details = ws.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = {main.FORMULA_CODE} AND USE_FLAG >= 0")) .OrderBy(c => c.PROCESS_INDEX) .ToList(); gridItem.ItemsSource = details; } else //修改 { FmsActionControl action = ws.UseService(s => s.GetFmsActionControlById(detail.PROCESS_ACTION_PKNO)); if (action == null) { action = new FmsActionControl() { PKNO = CBaseData.NewGuid(), ACTION_NAME = detail.FORMULA_DETAIL_NAME, ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString(), START_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbCondition.Text) ? "" : cmbCondition.SelectedValue.ToString(), START_CONDITION_VALUE = tbConditionValue.Text, EXECUTE_TAG_PKNO = string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString(), EXECUTE_WRITE_VALUE = tbExecuteValue.Text, EXECUTE_PARAM1_TAG_PKNO = string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString(), EXECUTE_PARAM2_TAG_PKNO = string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString(), FINISH_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString(), FINISH_CONDITION_VALUE = tbFinishValue.Text, }; detail.PROCESS_ACTION_PKNO = action.PKNO; ws.UseService(s => s.AddFmsActionControl(action)); } else //修改控制 { action.ACTION_NAME = detail.FORMULA_DETAIL_NAME; action.ACTION_TYPE = detail.PROCESS_ACTION_TYPE.ToString(); action.START_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbCondition.Text) ? "" : cmbCondition.SelectedValue.ToString(); action.START_CONDITION_VALUE = tbConditionValue.Text; action.EXECUTE_TAG_PKNO = string.IsNullOrEmpty(cmbExecute.Text) ? "" : cmbExecute.SelectedValue.ToString(); action.EXECUTE_WRITE_VALUE = tbExecuteValue.Text; action.EXECUTE_PARAM1_TAG_PKNO = string.IsNullOrEmpty(cmbParam1.Text) ? "" : cmbParam1.SelectedValue.ToString(); action.EXECUTE_PARAM2_TAG_PKNO = string.IsNullOrEmpty(cmbParam2.Text) ? "" : cmbParam2.SelectedValue.ToString(); action.FINISH_CONDITION_TAG_PKNO = string.IsNullOrEmpty(cmbFinish.Text) ? "" : cmbFinish.SelectedValue.ToString(); action.FINISH_CONDITION_VALUE = tbFinishValue.Text; ws.UseService(s => s.UpdateFmsActionControl(action)); } ws.UseService(s => s.UpdateFmsActionFormulaDetail(detail)); } //保存成功 gbItem.IsCollapsed = true; gbItem.Visibility = Visibility.Collapsed; BindHelper.SetDictDataBindingGridItem(gbItem, gridItem); }
/// <summary> /// 后台自动升级程序 /// <param name="bFisrtCheck">是否首次检测</param> /// </summary> public static void UpdateAppVersion(bool bFisrtCheck) { try { if (File.Exists(UpgradeBatFile)) { File.Delete(UpgradeBatFile); } //删除升级文件 string updateCmd = ""; int iUpdateIndex = 0; //升级文件的序号 bool bForceUpdate = false; //强制升级 foreach (SysAppInfo appInfo in AllModels) { string error; List <string> value = VersionProcess.GetDBVersionNO(appInfo.MODEL_CODE, out error); //获取服务器的新版本 if (!string.IsNullOrEmpty(error)) //错误 { if (bFisrtCheck) //第一次检验失败 { WPFMessageBox.ShowError(error + "请检查连接!", "系统启动失败"); App.AppExit(5); //系统退出 } continue; } int dbVersion = -1; string newAppPKNO = ""; if (value.Count >= 2) { newAppPKNO = value[0]; dbVersion = SafeConverter.SafeToInt(value[1]); } if (dbVersion < appInfo.MODEL_INNER_VERSION) //服务器版本 < 当前版本 => 上传 { string filename = Environment.CurrentDirectory + "\\" + (String.IsNullOrEmpty(appInfo.APP_RELATIVE_PATH) ? "" : appInfo.APP_RELATIVE_PATH + "\\") + appInfo.APP_NAME; if (!File.Exists(filename)) { continue; } #region 版本 SysAppInfo newApp = new SysAppInfo() { PKNO = CBaseData.NewGuid(), MODEL_CODE = appInfo.MODEL_CODE, MODEL_NAME = appInfo.MODEL_NAME, MODEL_INNER_VERSION = appInfo.MODEL_INNER_VERSION, MODEL_VERSION = appInfo.MODEL_VERSION, APP_NAME = appInfo.APP_NAME, APP_RELATIVE_PATH = appInfo.APP_RELATIVE_PATH, VERSION_INTROD = appInfo.VERSION_INTROD, MODEL_CONTENT = FileHelper.FileToBytes(filename), //上传文档 CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, VERSION_TYPE = appInfo.VERSION_TYPE, REMARK = appInfo.REMARK, }; bool ret = VersionProcess.UploadApp(newApp); //上传到数据库 if (ret) { EventLogger.Log($"上传最新版本 {newApp.MODEL_VERSION} 的程序【{newApp.MODEL_NAME}】到服务器。"); } #endregion } else if (dbVersion > appInfo.MODEL_INNER_VERSION) //服务器版本 > 当前版本 => 升级 { #region 载最新版本 SysAppInfo newApp = VersionProcess.GetNewApp(newAppPKNO); //下载 #endregion if (string.IsNullOrEmpty(newApp?.PKNO)) //下载失败 { continue; } bool updateResult = false; //强制升级 #region 保存到本地,并升级 string newfilename = Environment.CurrentDirectory + "\\Temp\\" + (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; string directory = Path.GetDirectoryName(newfilename); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } FileHelper.BytesToFile(newApp.MODEL_CONTENT, newfilename); string oldfilename = Environment.CurrentDirectory + "\\" + (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; string filename = (String.IsNullOrEmpty(newApp.APP_RELATIVE_PATH) ? "" : newApp.APP_RELATIVE_PATH + "\\") + newApp.APP_NAME; try { File.Copy(newfilename, oldfilename); updateResult = true; //升级成功 EventLogger.Log($"【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 完成自动升级。"); } catch (Exception) //升级失败 { iUpdateIndex++; //索引号 #region 形成升级Bat updateCmd += $"echo {iUpdateIndex}. 正在升级 【{appInfo.MODEL_NAME}】 到 {appInfo.MODEL_VERSION} ..." + Environment.NewLine; //显示提示信息 updateCmd += "ping 127.0.0.1 -n 2 > nul " + Environment.NewLine; //暂停2s updateCmd += "if not exist Temp\\" + filename + " (" + Environment.NewLine; //检验是否已经下载了文件 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} ... 尚未下载,升级失败!" + Environment.NewLine; // updateCmd += $")" + Environment.NewLine; // updateCmd += "copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine; //复制 => 升级文件 updateCmd += "if %ERRORLEVEL% == 0 (" + Environment.NewLine; //复制成功 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += ") else (" + Environment.NewLine; //复制失败 updateCmd += " copy /y " + "Temp\\" + filename + " " + filename + Environment.NewLine; //二次复制 => 升级文件 updateCmd += " if %ERRORLEVEL% == 0 (" + Environment.NewLine; //复制成功 updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级成功。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 完成【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 的升级 >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += " ) else (" + Environment.NewLine; updateCmd += $" echo 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,请退出系统后,运行【{UpgradeBatFile}】。" + Environment.NewLine; // updateCmd += $" echo %DATE% %TIME% 【{appInfo.MODEL_NAME}】 {appInfo.MODEL_VERSION} 升级失败,错误代码为 %ERRORLEVEL% >>log\\AutoUpdate.txt" + Environment.NewLine; // updateCmd += " pause" + Environment.NewLine; updateCmd += " exit" + Environment.NewLine; updateCmd += " )" + Environment.NewLine; updateCmd += ")" + Environment.NewLine; #endregion updateResult = false; } #endregion if ((!updateResult) && (!bForceUpdate)) //升级失败,检验是否强制升级 { if (bFisrtCheck) { bForceUpdate = true; //强制升级 } else //不是第一次检测,则需要检测是否强制升级 { int updateType = VersionProcess.CheckUpdateVersion(appInfo.MODEL_CODE, appInfo.MODEL_INNER_VERSION.Value); //获取版本升级信息,是否强制升级 #region 强制升级 if (updateType == 2) //强制升级 { bForceUpdate = true; //强制升级 } #endregion } } } } //end foreach if (!string.IsNullOrEmpty(updateCmd)) //有升级 { if (!Directory.Exists("log")) { Directory.CreateDirectory("log"); } updateCmd = "@echo off " + Environment.NewLine + " color fc " + Environment.NewLine + " title ******** 客户端自动升级程序 ******* " + Environment.NewLine + " echo *****************客户端自动升级程序(共" + iUpdateIndex + "个) ************* " + Environment.NewLine + updateCmd; updateCmd += "echo 系统升级成功!" + (bFisrtCheck ? "请重新打开程序。": "") + Environment.NewLine; //升级成功 updateCmd += "del /f /q " + UpgradeBatFile + Environment.NewLine; //删除本身 FileHelper.SaveStrToFile(updateCmd, UpgradeBatFile, true); //保存升级文件 } if (bForceUpdate) //强制升级 { Application.Current.Dispatcher.Invoke(new Action(() => { WPFMessageBox.ShowWarring( $"检测到系统有强制升级的新版本,系统自动升级失败,需要强制升级。" + Environment.NewLine + "***!系统将退出!***", "自动升级程序"); })); App.AppExit(5); } } catch (Exception ex) { NetLog.Error("自动升级程序失败,", ex); Console.WriteLine("自动升级程序失败,错误为:" + ex.Message); } }
public bool StartCurrentProgerss() { if (curProcess.PROCESS_STATE == 1) //准备完成,未开始执行 { if (!string.IsNullOrEmpty(startCondition) && LimitConditions.Contains(startCondition)) //如果前面的Job存在需要判断该状态,则不执行当前的 { string sErrorInfo = $"等待执行"; if (mesJobOrder.PROCESS_INFO != sErrorInfo) { mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } return(false); } #region 开始执行工序 共 5 步 string startCustomParam = ""; //开始执行的参数,增加到同步写入数据后面 /************ !!!工序开始的条件!!! ************/ #region 1. 检验当前执行的工序是否可以执行,启动条件 if (startTag != null) //启动条件为空则直接执行 { string checkValue = startTag.CUR_VALUE.Split('|')[0]; //当前执行条件的结果 string startValue = curAction.START_CONDITION_VALUE; //开始条件 string[] startValues = startValue.Split('|'); //多个开启条件 if ((string.IsNullOrEmpty(checkValue)) || (!startValues.Contains(checkValue))) //当前值不是工序开始检测值 { #region 条件不符合的 流程分支情况 if (curProcess.PROCESS_ACTION_TYPE == 4) //流程分支,不启用,直接往下运行 { #region 直接完成当前工序 #region 第一道工序处理 if (bFirstProcess) //第一道工序 { mesJobOrder.RUN_STATE = 20; //正在执行 mesJobOrder.ACT_START_TIME = DateTime.Now; //修改任务开始时间 mesJobOrder.PROCESS_INFO = "正常"; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } #endregion curProcess.PROCESS_STATE = 10; //直接完成 curProcess.PROCESS_END_TYPE = 1; curProcess.PROCESS_END_TIME = DateTime.Now; curProcess.REMARK = "条件不满足,不启用流程分支,直接执行现有流程。"; PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); return(false); //直接执行重新执行 #endregion } #endregion #region 判断条件不满足 string sErrorInfo = $"生产过程【{ctrolName}】开启条件【{startTag?.TAG_NAME}】不足,当前状态为【{checkValue}】,需要状态【{startValue}】"; if (mesJobOrder.PROCESS_INFO != sErrorInfo) { mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } if (!LimitConditions.Contains(startCondition)) { LimitConditions.Add(startCondition); //起始条件不满足,则添加限制条件 } return(false); #endregion } } #endregion /************ !!!工序开始的条件满足,直接执行!!! ************/ Console.WriteLine($"========生产过程【{ctrolName}】开始条件【{startTag?.TAG_NAME}】满足,开始执行======="); #region 2. 启动流程分支 if (curProcess.PROCESS_ACTION_TYPE == 4) //流程分支 { string disableProcesses = curProcess.PROCESS_ACTION_PARAM1_VALUE; //禁用的流程 string enableProcesses = curProcess.PROCESS_ACTION_PARAM2_VALUE; //启用的流程 string stemp = $"触发流程分支.禁用流程[{disableProcesses}], 启用流程[{enableProcesses}]"; mesJobOrder.PROCESS_INFO = stemp; //生产执行信息 Console.WriteLine(stemp); #region 启动流程分支 if (!string.IsNullOrEmpty(disableProcesses)) { foreach (var disableP in disableProcesses.Split(';')) { MesProcessCtrol process = unFinishProcessCtrols.FirstOrDefault(c => c.PROCESS_INDEX == SafeConverter.SafeToInt(disableP, -1)); process.USE_FLAG = 0; //禁用 PServiceEvent?.Invoke(d => d.UpdateMesProcessCtrol(process)); } } if (!string.IsNullOrEmpty(enableProcesses)) { foreach (var enableP in enableProcesses.Split(';')) { MesProcessCtrol process = unFinishProcessCtrols.FirstOrDefault(c => c.PROCESS_INDEX == SafeConverter.SafeToInt(enableP, -1)); process.USE_FLAG = 1; //启用 PServiceEvent?.Invoke(d => d.UpdateMesProcessCtrol(process)); } } #endregion #region 更新数据 #region 加工控制 curProcess.PROCESS_STATE = 10; //直接完成 curProcess.PROCESS_END_TYPE = 1; curProcess.PROCESS_START_TIME = DateTime.Now.AddMilliseconds(-100); curProcess.PROCESS_END_TIME = DateTime.Now; curProcess.REMARK = $"流程分支条件满足,启用流程分支,禁用流程[{disableProcesses}], 启用流程[{enableProcesses}]"; PServiceEvent?.Invoke(d => d.UpdateMesProcessCtrol(curProcess)); #endregion #region Job处理 if (bFirstProcess) //第一道工序 { mesJobOrder.RUN_STATE = 20; //正在执行 mesJobOrder.ACT_START_TIME = DateTime.Now; //修改任务开始时间 } PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); #endregion DeviceMonitor.SetTagSettingValueById(curAction.START_CONDITION_TAG_PKNO, ""); //将检测结果置为空 //产品处理 if (productProcess != null) { productProcess.PRODUCT_STATE = curProcess.PROCESS_ACTION_TYPE; //当前状态 productProcess.LAST_UPDATE_DATE = DateTime.Now; var process = productProcess; PServiceEvent?.Invoke(d => d.UpdateMesProductProcess(process)); } #endregion return(false); //直接开启下一次流程 } //启动流程分支 #endregion //增加限制条件 if (!string.IsNullOrEmpty(startCondition) && !LimitConditions.Contains(startCondition)) //未完成的任务需要增加开始条件 { LimitConditions.Add(startCondition); } #region 3. 获取产品,第一道工序形成产品 if (bFirstProcess || (productProcess == null)) //第一道控制,且没有形成 { string productPKNO = CBaseData.NewGuid(); productProcess = new MesProductProcess() //生成新的产品 { PKNO = productPKNO, COMPANY_CODE = CBaseData.BelongCompPKNO, ITEM_PKNO = curProcess.ITEM_PKNO, JOB_ORDER_PKNO = curProcess.JOB_ORDER_PKNO, JOB_ORDER = curProcess.JOB_ORDER, SUB_JOB_ORDER_NO = curProcess.SUB_JOB_ORDER_NO, PRODUCT_CODE = TableNOHelper.GetNewNO("MesProductProcess.PRODUCT_CODE", "P"), PRODUCT_POSITION = "", //当前位置 CUR_ROCESS_CTROL_PKNO = curProcess.PKNO, //当前过程 RAW_NUMBER = curProcess.PROCESS_QTY, //原料数量 PRODUCT_NUMBER = curProcess.COMPLETE_QTY, //完成数量 QUALIFIED_NUMBER = curProcess.QUALIFIED_QTY, //合格品数量 PALLET_NO = curProcess.PALLET_NO, //托盘号 PRODUCT_STATE = -1, //尚未开始 CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginNO, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "", //备注 }; //生成新的产品 curProcess.CUR_PRODUCT_CODE_PKNO = productPKNO; //新产品编号 } else { curProcess.CUR_PRODUCT_CODE_PKNO = firstProcess.CUR_PRODUCT_CODE_PKNO; //将所有的产品 } #endregion #region 4. 执行当前工序 => 向设备写入数据 写 3 个值 int ret = 0; string error = ""; string tagPKNO = ""; string sTagValue = ""; bool bWriteSuccess = true; //写入设备成功标志 #region 4.1 写参数1 tagPKNO = curAction.EXECUTE_PARAM1_TAG_PKNO; sTagValue = GetDynamicValue(curProcess.PROCESS_ACTION_PARAM1_VALUE); if ((!string.IsNullOrEmpty(tagPKNO)) && (!string.IsNullOrEmpty(sTagValue))) { #region 多次重写 int iWrite = 0; while (iWrite < ReWriteCount) { ret = DeviceMonitor.WriteTagToDevice(tagPKNO, sTagValue, out error); if (ret == 0) { Thread.Sleep(100); //写入成功后暂停 break; } iWrite++; Thread.Sleep(100); } #endregion if (ret == 10) //写入设备失败 { string sErrorInfo = $"向设备写入参数1失败。错误为:{error}"; //生产执行信息 if (mesJobOrder.PROCESS_INFO != sErrorInfo) { mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } Console.WriteLine(sErrorInfo); return(false); } if (ret == 0) { bWriteSuccess = true; //写入成功 } } #endregion #region 4.2 写参数2 tagPKNO = curAction.EXECUTE_PARAM2_TAG_PKNO; sTagValue = GetDynamicValue(curProcess.PROCESS_ACTION_PARAM2_VALUE); if ((!string.IsNullOrEmpty(tagPKNO)) && (!string.IsNullOrEmpty(sTagValue))) { #region 多次重写 int iWrite = 0; while (iWrite < ReWriteCount) { ret = DeviceMonitor.WriteTagToDevice(tagPKNO, sTagValue, out error); if (ret == 0) { Thread.Sleep(100); //写入成功后暂停 break; } iWrite++; Thread.Sleep(100); } #endregion if (ret == 10) //写入设备失败 { string sErrorInfo = $"向设备写入参数2失败。错误为:{error}"; //生产执行信息 if (mesJobOrder.PROCESS_INFO != sErrorInfo) { mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } Console.WriteLine(sErrorInfo); return(false); } if (ret == 0) { bWriteSuccess = true; //写入成功 } } #endregion #region 4.3 写执行 tagPKNO = curAction.EXECUTE_TAG_PKNO; sTagValue = GetDynamicValue(curAction.EXECUTE_WRITE_VALUE) + "|" + (string.IsNullOrEmpty(curProcess.PROCESS_ACTION_PARAM1_VALUE) ? "0" : curProcess.PROCESS_ACTION_PARAM1_VALUE) + "|" + (string.IsNullOrEmpty(curProcess.PROCESS_ACTION_PARAM2_VALUE) ? "0" : curProcess.PROCESS_ACTION_PARAM2_VALUE) + "|" + (string.IsNullOrEmpty(startCustomParam) ? "0" : startCustomParam); if ((!string.IsNullOrEmpty(tagPKNO)) && (!string.IsNullOrEmpty(sTagValue.Replace("|", "")))) { #region 多次重写 int iWrite = 0; while (iWrite < ReWriteCount) { ret = DeviceMonitor.WriteTagToDevice(tagPKNO, sTagValue, out error); if (ret == 0) { //Thread.Sleep(100); //写入成功后暂停,最后不需要 break; } iWrite++; Thread.Sleep(100); } #endregion if (ret == 10) //写入设备失败 { string sErrorInfo = $"向设备写入开始动作值失败。错误为:{error}"; //生产执行信息 if (mesJobOrder.PROCESS_INFO != sErrorInfo) { mesJobOrder.PROCESS_INFO = sErrorInfo; //生产执行信息 PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); } Console.WriteLine(sErrorInfo); return(false); } if (ret == 0) { bWriteSuccess = true; //写入成功 } } #endregion if (bWriteSuccess) { Console.WriteLine("给设备发送指令成功.开始进行执行" + (string.IsNullOrEmpty(curProcess.SUB_JOB_ORDER_NO) ? curProcess.JOB_ORDER_PKNO : curProcess.SUB_JOB_ORDER_NO)); //给设备发送动作指令成功 } #endregion #region 5. 更新数据 共更新 4 个模块 #region 5.1 加工控制 curProcess.PROCESS_STATE = 2; //正在执行 curProcess.PROCESS_START_TYPE = 1; //自动开始 curProcess.PROCESS_START_TIME = DateTime.Now; PServiceEvent?.Invoke(d => d.UpdateMesProcessCtrol(curProcess)); #endregion #region 5.2 业务相关处理 if (curProcess.PROCESS_ACTION_TYPE == 11) //开始 出库 { mesJobOrder.ONLINE_QTY = curProcess.PROCESS_QTY; //在线数量 } if (bFirstProcess) //第一道工序,新增产品信息 { PServiceEvent?.Invoke(s => s.AddMesProductProcess(productProcess)); } string sError = ""; string result = DeviceProcessControl.BeginCurBusiness(curProcess, ref sError); //开始当前控制的业务 if (result != "OK") { mesJobOrder.PROCESS_INFO = $"业务开始执行发生错误,写入数据库错误! 具体:{sError}"; } #endregion #region 5.3 Job处理 if (bFirstProcess) //第一道工序 { mesJobOrder.RUN_STATE = 20; //正在执行 mesJobOrder.ACT_START_TIME = DateTime.Now; //修改任务开始时间 } PServiceEvent?.Invoke(d => d.UpdateMesJobOrder(mesJobOrder)); #endregion #region 5.4 将开始和结束条件 置空 DeviceMonitor.SetTagSettingValueById(curAction.START_CONDITION_TAG_PKNO, ""); //将检测结果置为空 FmsAssetTagSetting finishTag = DeviceMonitor.GetTagSettingById(curAction.FINISH_CONDITION_TAG_PKNO); if (finishTag != null) { if (finishTag.SAMPLING_MODE == 11) { finishTag.SAMPLING_MODE = 10; //按照条件开启 } DeviceMonitor.SetTagSettingValue(finishTag, ""); } #endregion #endregion #endregion if (startTag != null) { FMSControlService.iConditionStartAddPause = 500; //按条件启动后增加的延时 } FMSControlService.bStart = true; //本次订单已经启动过了 } return(true); }
private void BtnAutoChange_Click(object sender, RoutedEventArgs e) { TmsToolsMaster mToolsMaster = GridControlInvTool.SelectedItem as TmsToolsMaster; TmsDeviceToolsPos mTmsDeviceToolsPos = GridControlDeviceTool.SelectedItem as TmsDeviceToolsPos; MesJobOrder jobOrder = null; WmsInventory inv = null; List <MesProcessCtrol> processCtrols = new List <MesProcessCtrol>(); #region 形成工单 jobOrder = new MesJobOrder() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, LINE_PKNO = CBaseData.CurLinePKNO, LINE_TASK_PKNO = "", //产线任务PKNO ITEM_PKNO = "", // TODO:暂无 JOB_ORDER_NO = TableNOHelper.GetNewNO("MES_JOB_ORDER.JOB_ORDER_NO", "J"), BATCH_NO = "", ROUTING_DETAIL_PKNO = "", JOB_ORDER_TYPE = 2, //工单类型 1:原料入库;2:加工;3:成品出库;4:转换 TASK_QTY = 1, COMPLETE_QTY = 0, ONLINE_QTY = 0, ONCE_QTY = 0, RUN_STATE = 10, //直接生产 CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginNO, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "", }; #endregion #region 增加参数 Dictionary <string, string> ParamValues = new Dictionary <string, string>(); #endregion string sFormulaCode = "换刀"; List <FmsActionFormulaDetail> formulaDetails = wsFms.UseService(s => s.GetFmsActionFormulaDetails($"FORMULA_CODE = '{sFormulaCode}' AND USE_FLAG= 1")) .OrderBy(c => c.PROCESS_INDEX) .ToList(); foreach (var detail in formulaDetails) //配方 { MesProcessCtrol process = new MesProcessCtrol() { #region 标准信息 PKNO = CBaseData.NewGuid(), COMPANY_CODE = CBaseData.BelongCompPKNO, ITEM_PKNO = "", //成品PKNO TODO:暂无 JOB_ORDER_PKNO = jobOrder.PKNO, JOB_ORDER = jobOrder.JOB_ORDER_NO, SUB_JOB_ORDER_NO = "", ROUTING_DETAIL_PKNO = "", // #endregion PROCESS_CTROL_NAME = detail.FORMULA_DETAIL_NAME, //名称 PROCESS_DEVICE_PKNO = Replace(detail.PROCESS_DEVICE_PKNO, ParamValues), //生产设备 PROCESS_PROGRAM_NO = Replace(detail.PROCESS_PROGRAM_NO, ParamValues), //加工程序号 PROCESS_PROGRAM_CONTENT = detail.PROCESS_PROGRAM_CONTENT, //加工程序内容 PROCESS_INDEX = detail.PROCESS_INDEX, //工序顺序 BEGIN_ITEM_PKNO = Replace(detail.BEGIN_ITEM_PKNO, ParamValues), //生产前项目PKNO FINISH_ITEM_PKNO = Replace(detail.FINISH_ITEM_PKNO, ParamValues), //生产后项目PKNO BEGIN_POSITION = Replace(detail.BEGIN_POSITION, ParamValues), //生产前位置 FINISH_POSITION = Replace(detail.FINISH_POSITION, ParamValues), //生产后位置 PALLET_NO = detail.PALLET_NO, //托盘号 PROCESS_ACTION_TYPE = detail.PROCESS_ACTION_TYPE, //工序动作类型 PROCESS_ACTION_PKNO = detail.PROCESS_ACTION_PKNO, //工序动作控制PKNO PROCESS_ACTION_PARAM1_VALUE = Replace(detail.PROCESS_ACTION_PARAM1_VALUE, ParamValues), //工序动作参数1 PROCESS_ACTION_PARAM2_VALUE = Replace(detail.PROCESS_ACTION_PARAM2_VALUE, ParamValues), //工序动作参数2 CUR_PRODUCT_CODE_PKNO = "", //当前生产加工的产品编码PKNO PROCESS_QTY = 1, //加工数量(上线数量) COMPLETE_QTY = 0, //完成数量 QUALIFIED_QTY = 0, //合格数量 PROCESS_STATE = 1, //准备完成 CREATION_DATE = DateTime.Now, //创建日期 CREATED_BY = CBaseData.LoginNO, //创建人 LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = detail.USE_FLAG, //启用标识 REMARK = "", //备注 }; processCtrols.Add(process); } Cursor = Cursors.Wait; wsPLM.UseService(s => s.AddMesJobOrder(jobOrder)); foreach (MesProcessCtrol processCtrol in processCtrols) { wsPLM.UseService(s => s.AddMesProcessCtrol(processCtrol)); } Cursor = Cursors.Arrow; MessageBox.Show("换刀下单成功."); GridControlInvTool.ItemsSource = ws.UseService(s => s.GetTmsToolsMasters("USE_FLAG > 0")).OrderBy(n => n.CREATION_DATE).ToList();; }
private void BtnSave_Click(object sender, RoutedEventArgs e) { //保存 AmAssetMasterN asset = cmbAssetInfo.SelectedItem as AmAssetMasterN; FmsAssetTagSetting assetTag = gbItem.DataContext as FmsAssetTagSetting; if (assetTag == null) { return; } #region 校验 if (asset == null) { MessageBox.Show("请选择设备!", "保存", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } if (!string.IsNullOrEmpty(assetTag.TAG_CODE)) //标签编码 { List <FmsAssetTagSetting> existTags = _fmsClient.UseService(s => s.GetFmsAssetTagSettings( $"USE_FLAG = 1 AND TAG_CODE = '{assetTag.TAG_CODE}'")); if (!string.IsNullOrEmpty(assetTag.PKNO)) //修改 { existTags = existTags.Where(c => c.PKNO != assetTag.PKNO).ToList(); } if (existTags.Any()) { WPFMessageBox.ShowWarring( $"该标签编码【{assetTag.TAG_CODE}】已存在不能" + (string.IsNullOrEmpty(assetTag.PKNO) ? "添加" : "修改") + "为这个编码!", "保存"); return; } } #endregion #region 保存 if (string.IsNullOrEmpty(assetTag.PKNO)) { assetTag.PKNO = CBaseData.NewGuid(); assetTag.CREATED_BY = CBaseData.LoginName; assetTag.CREATION_DATE = DateTime.Now; assetTag.LAST_UPDATE_DATE = DateTime.Now; //最后修改日期 _fmsClient.UseService(s => s.AddFmsAssetTagSetting(assetTag)); } else { assetTag.UPDATED_BY = CBaseData.LoginName; assetTag.LAST_UPDATE_DATE = DateTime.Now; _fmsClient.UseService(s => s.UpdateFmsAssetTagSetting(assetTag)); } NotificationInvoke.NewNotification("保存", "设备通讯标签配置信息已保存。"); #endregion GetPage(); //重新刷新数据,根据需求是否进行刷新数据 //保存成功 gbItem.IsCollapsed = true; gbItem.Visibility = Visibility.Collapsed; BindHelper.SetDictDataBindingGridItem(gbItem, gridItem); }
/// <summary> /// 状态类标签值保存结果 /// </summary> /// <param name="tagSetting"></param> /// <param name="tagValue"></param> private void TagValueResultRecord(FmsAssetTagSetting tagSetting, string tagValue) { const int addMinutes = -10; //分钟 const int spanSaveSec = -5; //每个5秒更新结束时间 lock (lockResultRecord) { try { EventLogger.Log($"======开始写入【{tagSetting.TAG_VALUE_NAME}】Result====="); DateTime dtNow = DateTime.Now; List <FmsStateResultRecord> records = ws.UseService( s => s.GetFmsStateResultRecords( $"ASSET_CODE = '{tagSetting.ASSET_CODE}' AND TAG_SETTING_PKNO = '{tagSetting.PKNO}' " + $"AND END_TIME >= '{dtNow.AddMinutes(addMinutes * 2)}'")) //2倍时间以上时不再继续续写 .OrderByDescending(c => c.END_TIME) .ThenByDescending(c => c.BEGINT_TIME) .ThenByDescending(c => c.CREATION_DATE) .ToList(); FmsStateResultRecord oldRecord = records.FirstOrDefault(); bool bFirstRecord = !ResultRecordFirsts.ContainsKey(tagSetting.PKNO) || ResultRecordFirsts[tagSetting.PKNO]; bool isAddNewResult = (bFirstRecord) || (oldRecord == null) || (oldRecord.TAG_VALUE != tagValue) || (oldRecord.END_TIME <= dtNow.AddMinutes(addMinutes)) || //10分钟之前的数据则重新增加; (oldRecord.END_TIME.Value.Date != dtNow.Date); //跨天数据则新增加 if ((!bFirstRecord) && (oldRecord != null)) //不是第一次运行则修改之前的时间,一个周期更新一次结束时间+++++ { if ((isAddNewResult) || (oldRecord.END_TIME <= dtNow.AddSeconds(spanSaveSec))) //新增记录时,修改原值 { oldRecord.END_TIME = dtNow; //更新状态时间 ws.UseService(s => s.UpdateFmsStateResultRecord(oldRecord)); } } if (isAddNewResult) //新增值 { #region 新增值 FmsStateResultRecord record = new FmsStateResultRecord { PKNO = CBaseData.NewGuid(), ASSET_CODE = tagSetting.ASSET_CODE, TAG_SETTING_PKNO = tagSetting.PKNO, TAG_VALUE_NAME = tagSetting.TAG_VALUE_NAME, TAG_VALUE = tagValue, BEGINT_TIME = dtNow, END_TIME = DateTime.Now, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, REMARK = "", }; ws.UseService(s => s.AddFmsStateResultRecord(record)); #endregion } if (!ResultRecordFirsts.ContainsKey(tagSetting.PKNO)) { ResultRecordFirsts.Add(tagSetting.PKNO, false); //不是第一次 } else { ResultRecordFirsts[tagSetting.PKNO] = false; } EventLogger.Log($"======完成写入【{tagSetting.TAG_VALUE_NAME}】Result====="); } catch (Exception ex) { EventLogger.Log($"!!!!!!写入【{tagSetting.TAG_VALUE_NAME}】Result失败,原因:{ex.Message}!!!!!!"); } } }
/// <summary> /// 读取DA数据 /// </summary> /// <param name="device"></param> private void ThreadGetDaMonitor(FmsAssetCommParam device) { if ((!bMonitor) || (device == null)) { return; //未开启监控 } int readSpan = 0; //设定采样周期的变量 #region 获取基础参数 string deviceCode = device.ASSET_CODE; DeviceCommInterface interfaceType = EnumHelper.ParserEnumByValue(device.INTERFACE_TYPE, DeviceCommInterface.CNC_Fanuc); string commAddress = device.COMM_ADDRESS; int period = Convert.ToInt32(device.SAMPLING_PERIOD); //采样周期 List <FmsAssetTagSetting> tagSettings = _tagSettings.Where(c => c.ASSET_CODE == deviceCode && c.SAMPLING_MODE == 3).ToList(); //DA采集模式 if (tagSettings.Count <= 0) { return; } #endregion DeviceManager deviceCommunication = new DeviceManager(CBaseData.NewGuid(), interfaceType, commAddress, period * 1000); List <DeviceTagParam> deviceTags = new List <DeviceTagParam>(); foreach (var tagSetting in tagSettings) { DeviceTagParam deviceTag = new DeviceTagParam(tagSetting.PKNO, tagSetting.TAG_CODE, tagSetting.TAG_NAME, tagSetting.TAG_ADDRESS, EnumHelper.ParserEnumByValue(tagSetting.VALUE_TYPE, TagDataType.Default), EnumHelper.ParserEnumByValue(tagSetting.SAMPLING_MODE, DataSimplingMode.ReadAndWrite), deviceCommunication); //通讯参数 deviceTags.Add(deviceTag); //添加 } deviceCommunication.InitialDevice(deviceTags, SaveData); while (!CBaseData.AppClosing) { #region 暂停 if (bPause) { System.Threading.Thread.Sleep(200); continue; } #endregion try { readSpan++; if ((period > 0) && (readSpan % (period * 10) == 0)) //读取数据 { string error = ""; lock (locakDA) { List <FmsAssetTagSetting> daTags = tagSettings.Where(c => c.SAMPLING_MODE == 3).ToList(); //这些为Focas的 if (daTags.Any()) { #region 采集实时信息 DAMachineRealTimeInfo realTimeInfo = ws_DA.UseService( s => s.GetDAMachineRealTimeInfos("ASSET_CODE = " + device.ASSET_CODE + "")) .FirstOrDefault(); if (realTimeInfo != null) { //实况信息采集和录入 realTimeInfo.STATUS = int.Parse(deviceCommunication.SyncReadData("状态", out error)); realTimeInfo.MAIN_PROG = deviceCommunication.SyncReadData("程序号", out error); realTimeInfo.SPINDLE_OVERRIDE = deviceCommunication.SyncReadData("主轴负载", out error); realTimeInfo.SPINDLE_SPPED = deviceCommunication.SyncReadData("主轴转速", out error); realTimeInfo.FEED_SPEED = deviceCommunication.SyncReadData("进给速度", out error); realTimeInfo.FEED_RATE = deviceCommunication.SyncReadData("进给倍率", out error); realTimeInfo.DA_TIME = DateTime.Now; ws_DA.UseService(s => s.UpdateDAMachineRealTimeInfo(realTimeInfo)); //实时更新 } #endregion #region 采集产量信息 //设备产量记录采集 DAProductRecord productRecord = ws_DA.UseService(s => s.GetDAProductRecords($"ASSET_CODE = '{device.ASSET_CODE}'")) .OrderByDescending(c => c.END_TIME) .FirstOrDefault(); //获取生产记录 if (productRecord != null) { int part_num = 0; int.TryParse(deviceCommunication.SyncReadData("工件数", out error), out part_num); int total_num = 0; int.TryParse(deviceCommunication.SyncReadData("工件总数", out error), out total_num); if (part_num == productRecord.PART_NUM) { if (productRecord.END_TIME <= DateTime.Now.AddMinutes(-5)) //每5分钟,更新数据库 { productRecord.END_TIME = DateTime.Now; ws_DA.UseService(s => s.UpdateDAProductRecord(productRecord)); } } else //不一致 { productRecord.END_TIME = DateTime.Now; ws_DA.UseService(s => s.UpdateDAProductRecord(productRecord)); //插入新的纪录 DAProductRecord newProductRecord = new DAProductRecord(); newProductRecord.ASSET_CODE = deviceCode; newProductRecord.PKNO = Guid.NewGuid().ToString("N"); newProductRecord.START_TIME = DateTime.Now; newProductRecord.END_TIME = DateTime.Now.AddMilliseconds(100); newProductRecord.PART_NUM = part_num; newProductRecord.TOTAL_PART_NUM = total_num; ws_DA.UseService(s => s.AddDAProductRecord(newProductRecord)); //新增当前值到数据库 } } #endregion #region 采集报警信息 string a = deviceCommunication.SyncReadData("报警信息", out error); #endregion } } } readSpan = 0; } catch (Exception ex) { Console.WriteLine("ThreadGetDAMonitor, 错误为:" + ex.Message); } System.Threading.Thread.Sleep(100); } }
/// <summary> /// 控件初始化,当EnumIdentify不为空时初始化,只初始化一次 /// 提取数据库中控件的类型,数据 /// </summary> private void Initial() { if ((string.IsNullOrEmpty(EnumIdentify)) || (_bFinishInitial)) //已完成初始化 { return; } try { if (ws == null) { ws = new WcfClient <ISDMService>(); } SysEnumMain main = ws.UseService(s => s.GetSysEnumMains($"ENUM_IDENTIFY = '{EnumIdentify}'")).FirstOrDefault(); if (main != null) { #region 获取基础信息 EnumType = main.ENUM_TYPE; //设置下拉框属性 ValueField = main.VALUE_FIELD; //0:ItemName 名称(默认);1:ItemNO 编号;2:ItemCode 代号;3:PKNO 唯一标志(Sys_EnumItems.PKNO) ItemData = ws.UseService(s => s.GetSysEnumItemss($"ENUM_IDENTIFY = '{main.ENUM_IDENTIFY}'")) .OrderBy(c => c.ITEM_INDEX) .ToList(); this.ItemsSource = ItemData; this.DisplayMemberPath = "ITEM_NAME"; #region 设置Value的绑定路径 switch (ValueField) { case 1: //编号 SelectedValuePath = "ITEM_NO"; break; case 2: //代码 SelectedValuePath = "ITEM_CODE"; break; case 3: //PKNO SelectedValuePath = "PKNO"; break; default: //名称 SelectedValuePath = "ITEM_NAME"; break; } #endregion #endregion } else { #region 新增主信息 string[] mainTexts = EnumIdentify.Split('.'); string sort = mainTexts[0]; string name = mainTexts.Length < 2 ? mainTexts[0] : mainTexts[1]; for (int i = 2; i < mainTexts.Length; i++) { name += "." + mainTexts[i]; } main = new SysEnumMain() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", ENUM_IDENTIFY = this.EnumIdentify, ENUM_SORT = sort, ENUM_NAME = name, ENUM_INTROD = "", ENUM_TYPE = 0, //ValueField = 0, CREATION_DATE = DateTime.Now, CREATED_BY = CBaseData.LoginName, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 USE_FLAG = 1, REMARK = "系统自动添加", }; ws.UseService(s => s.AddSysEnumMain(main)); #endregion } _bFinishInitial = true; } catch (Exception ex) { Console.WriteLine("error:BasicItemCombox.Initial " + ex.Message); } }