using CentralControl.BaseData; using CommonFunc; using CommonFunc.Tools; using HandyControl.Tools.Extension; using LiveCharts.Charts; using Microsoft.SqlServer.Server; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Net.Http; using System.Net.Sockets; using System.Text; using System.Threading.Tasks; using System.Timers; using System.Windows; using System.Windows.Controls; using NLog; using Xceed.Wpf.Toolkit.Primitives; using XGL.Data; using XGL.Data.DBService; using XGL.Dats.DBServiceFinishProd; using XGL.Models.Model; using XGL.Models.Model.FoamingMac; using XGL.Models.Model.OrderPrepare; using XGL.Thrift; using static System.Windows.Forms.VisualStyles.VisualStyleElement; namespace XGLFinishPro.Views { /// /// LanJu_Operator.xaml 的交互逻辑 /// public partial class LanJu_Operator : UserControl { public static string PlcIp = "172.18.15.20"; public static bool isSuccess = false; public static bool IsWrite = false; public static PlcHelper plc = new PlcHelper(); FormingMachineService formingMachineService = new FormingMachineService(); FinishProdDBService userDbWareHouse = new FinishProdDBService(); public static LanJu_Operator lanJu_Operator; Frame frame = new Frame() { Content = new Views.LanJu_InOut() }; string deviceCode = Utils.GetAppSetting("DeviceCode"); private List lineList = new List //用于过滤产线来写入PLC箱型尺寸 { "XL01", "XL02", "XL03", "XL04", "XL05", "XL06", "XL07", "XL08", "XL09", "XL10", "XL11" }; Timer timerDeciveState = new Timer(); string _workOrderCode = ""; userDB usdb = new userDB(); private readonly Dictionary _dic = new Dictionary() { {"XL01","1" }, {"XL02","2" }, {"XL03","3" }, {"XL04","4" }, {"XL05","5" }, {"XL06","6" }, {"XL07","7" }, {"XL08","8" }, {"XL09","9" }, {"XL10","A" }, {"XL11","B" }, {"XL12","C" }, {"XL13","D" }, {"XL14","E" }, {"XL15","F" }, {"XL16","G" }, {"XL17","H" }, }; public enum WindowID { frame } public LanJu_Operator() { InitializeComponent(); WindowChange(WindowID.frame); //WritePlcBoxMessage("000000010101000115"); } public void WindowChange(WindowID windowID) { Window1.Content = frame; } List sfcList = null; private void InOut_Click(object sender, RoutedEventArgs e) { LanJu_InOut lanJu_InOut = new LanJu_InOut(_workOrderCode, deviceCode); // 在主界面中的某个位置订阅事件 lanJu_InOut.ValueSelected += (sender1, args) => { // 在这里处理从子窗口传回的值 sfcList = lanJu_InOut.SFCCodeList; // 执行需要的操作 }; Window1.Content = new Frame { Content = lanJu_InOut }; } private void Complete_Click(object sender, RoutedEventArgs e) { LanJu_Complete lanJu_Complete = new LanJu_Complete(); Window1.Content = new Frame { Content = lanJu_Complete }; } private void DeviceItems_Click(object sender, RoutedEventArgs e) { LanJu_DeviceItems lanJu_DeviceItems = new LanJu_DeviceItems(); Window1.Content = new Frame { Content = lanJu_DeviceItems }; } private void Paused_Click(object sender, RoutedEventArgs e) { LanJu_Paused lanJu_Paused = new LanJu_Paused(); Window1.Content = new Frame { Content = lanJu_Paused }; } private void Button_Click_2(object sender, RoutedEventArgs e) { firstInspection lanJu_Paused = new firstInspection(); Window1.Content = new Frame { Content = lanJu_Paused }; } private void Button_Click_1(object sender, RoutedEventArgs e) { firstInspection firstInspection = new firstInspection(); Window1.Content = new Frame { Content = firstInspection }; } private void UCOperator_Loaded(object sender, RoutedEventArgs e) { timerDeciveState.Interval = Utils.GetAppSetting("GetDeviceStateInterval") == "" ? 10000 : Convert.ToInt32(Utils.GetAppSetting("GetDeviceStateInterval")); timerDeciveState.Elapsed += TimerDeciveState_Elapsed; timerDeciveState.Start(); Complete_Click(null, null); GetWorkOrderInfo(); } string isbaiye; string plantime; private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e) { if (Utils.isAnyBodyPerating) return; try { List orderList = new List(); //int currHour = DateTime.Now.Hour; //int currMinute = DateTime.Now.Minute; ////modelWareHouse = new List(); ////userDbWareHouse = new DBService(); //int shiftId = 0; //DataTable shiftlist = formingMachineService.GetShiftList(); //string endTimeRecord = ""; //string startTimeRecord = ""; //foreach (DataRow shift in shiftlist.Rows) //{ // string[] timeStart = shift["Shift_Start_Time"].ToString().Split(':'); // string[] timeEnd = shift["Shift_End_Time"].ToString().Split(':'); // // 创建两个不带日期的时间点 // TimeSpan currTime = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 // TimeSpan startTime = new TimeSpan(Convert.ToInt32(timeStart[0]), Convert.ToInt32(timeStart[1]), 0); // 表示9小时45分钟0秒 // TimeSpan endTime = new TimeSpan(Convert.ToInt32(timeEnd[0]), Convert.ToInt32(timeEnd[1]), 0); // // 比较当前时间点和班次开始的时间点 // int comparisonResultStart = TimeSpan.Compare(currTime, startTime); // // 比较当前时间点和班次结束的时间点 // int comparisonResultEnd = TimeSpan.Compare(currTime, endTime); // //if (comparisonResultStart > 0) { Console.WriteLine("time1 大于 time2"); } // if (comparisonResultStart >= 0 && comparisonResultEnd < 0) // { // endTimeRecord = shift["Shift_Start_Time"].ToString(); // startTimeRecord = shift["Shift_End_Time"].ToString(); // shiftId = Convert.ToInt32(shift["shift_id"].ToString()); // break; // } // else if (comparisonResultStart >= 0 || comparisonResultEnd < 0) // { // endTimeRecord = shift["Shift_Start_Time"].ToString(); // startTimeRecord = shift["Shift_End_Time"].ToString(); // shiftId = Convert.ToInt32(shift["shift_id"].ToString()); // break; // } // //if (Convert.ToInt32(timeStart[0]) <= currHourWithDecimal && currHourWithDecimal < Convert.ToInt32(timeEnd[0])) // //{ // // shiftId = shift.shiftId; // // break; // //} // //else if (currHourWithDecimal >= Convert.ToInt32(timeStart[0]) || currHourWithDecimal < Convert.ToInt32(timeEnd[0])) // //{ // // shiftId = shift.shiftId; // // break; // //} //} //string[] endTimeReally = endTimeRecord.Split(':'); //string[] startTimeReally = startTimeRecord.Split(':'); //DateTime currShiftDate = DateTime.Now.Date; //TimeSpan currTimeNew = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 //TimeSpan startTimeNew = new TimeSpan(Convert.ToInt32(startTimeReally[0]), Convert.ToInt32(startTimeReally[1]), 0); // 表示9小时45分钟0秒 //TimeSpan endTimeNew = new TimeSpan(Convert.ToInt32(endTimeReally[0]), Convert.ToInt32(endTimeReally[1]), 0); // 表示9小时45分钟0秒 ////计算白夜班工作日期用 //int resultstart = TimeSpan.Compare(currTimeNew, startTimeNew); //// 比较当前时间点和班次结束的时间点 //int resultEnd = TimeSpan.Compare(currTimeNew, endTimeNew); ////夜班、 //if (resultstart < 0 && resultEnd < 0) //{ // currShiftDate = DateTime.Now.Date.AddDays(-1); //} //modelWareHouse = new List(); DataTable dt = userDbWareHouse.GetWetPlanInfo(deviceCode, LoginUser.WorkDate);//formingMachineService.GetFormingMachineInfo(deviceCode, currShiftDate.ToString()); if (dt == null) return; if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { // 如果还有其他情况需要处理,可以继续添加 elseif 分支 row["workorder_code_sap"] = row["workorder_code_sap"].ToString().TrimStart('0'); // 更新当前行的值 dt.AcceptChanges(); } } if (orderList != null) { //使用Dispatcher来在UI线程上更新UI this.Dispatcher.Invoke( new Action(() => { this.dgWorkOrderInfo.ItemsSource = null; this.dgWorkOrderInfo.ItemsSource = dt.DefaultView; dgWorkOrderInfo.SelectedIndex = 0; } ), System.Windows.Threading.DispatcherPriority.Render); } } catch (Exception ex) { LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message); } } private void GetWorkOrderInfo() { try { List orderList = new List(); //int currHour = DateTime.Now.Hour; //int currMinute = DateTime.Now.Minute; ////modelWareHouse = new List(); ////userDbWareHouse = new DBService(); //int shiftId = 0; //DataTable shiftlist = formingMachineService.GetShiftList(); //string endTimeRecord = ""; //string startTimeRecord = ""; //foreach (DataRow shift in shiftlist.Rows) //{ // string[] timeStart = shift["Shift_Start_Time"].ToString().Split(':'); // string[] timeEnd = shift["Shift_End_Time"].ToString().Split(':'); // // 创建两个不带日期的时间点 // TimeSpan currTime = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 // TimeSpan startTime = new TimeSpan(Convert.ToInt32(timeStart[0]), Convert.ToInt32(timeStart[1]), 0); // 表示9小时45分钟0秒 // TimeSpan endTime = new TimeSpan(Convert.ToInt32(timeEnd[0]), Convert.ToInt32(timeEnd[1]), 0); // // 比较当前时间点和班次开始的时间点 // int comparisonResultStart = TimeSpan.Compare(currTime, startTime); // // 比较当前时间点和班次结束的时间点 // int comparisonResultEnd = TimeSpan.Compare(currTime, endTime); // //if (comparisonResultStart > 0) { Console.WriteLine("time1 大于 time2"); } // if (comparisonResultStart >= 0 && comparisonResultEnd < 0) // { // endTimeRecord = shift["Shift_Start_Time"].ToString(); // startTimeRecord = shift["Shift_End_Time"].ToString(); // shiftId = Convert.ToInt32(shift["shift_id"].ToString()); // break; // } // else if (comparisonResultStart >= 0 || comparisonResultEnd < 0) // { // endTimeRecord = shift["Shift_Start_Time"].ToString(); // startTimeRecord = shift["Shift_End_Time"].ToString(); // shiftId = Convert.ToInt32(shift["shift_id"].ToString()); // break; // } // //if (Convert.ToInt32(timeStart[0]) <= currHourWithDecimal && currHourWithDecimal < Convert.ToInt32(timeEnd[0])) // //{ // // shiftId = shift.shiftId; // // break; // //} // //else if (currHourWithDecimal >= Convert.ToInt32(timeStart[0]) || currHourWithDecimal < Convert.ToInt32(timeEnd[0])) // //{ // // shiftId = shift.shiftId; // // break; // //} //} //string[] endTimeReally = endTimeRecord.Split(':'); //string[] startTimeReally = startTimeRecord.Split(':'); //DateTime currShiftDate = DateTime.Now.Date; //TimeSpan currTimeNew = new TimeSpan(currHour, currMinute, 0); // 获取当前小时+分钟数 //TimeSpan startTimeNew = new TimeSpan(Convert.ToInt32(startTimeReally[0]), Convert.ToInt32(startTimeReally[1]), 0); // 表示9小时45分钟0秒 //TimeSpan endTimeNew = new TimeSpan(Convert.ToInt32(endTimeReally[0]), Convert.ToInt32(endTimeReally[1]), 0); // 表示9小时45分钟0秒 ////计算白夜班工作日期用 //int resultstart = TimeSpan.Compare(currTimeNew, startTimeNew); //// 比较当前时间点和班次结束的时间点 //int resultEnd = TimeSpan.Compare(currTimeNew, endTimeNew); ////夜班、 //if (resultstart < 0 && resultEnd < 0) //{ // currShiftDate = DateTime.Now.Date.AddDays(-1); //} //modelWareHouse = new List(); DataTable dt = userDbWareHouse.GetWetPlanInfo(deviceCode, DateTime.Parse(LoginUser.WorkDate).ToString("yyyy-MM-dd")); if (dt != null && dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { // 如果还有其他情况需要处理,可以继续添加 elseif 分支 row["workorder_code_sap"] = row["workorder_code_sap"].ToString().TrimStart('0'); // 更新当前行的值 dt.AcceptChanges(); } } this.dgWorkOrderInfo.ItemsSource = null; if (dt != null && dt.Rows.Count > 0) this.dgWorkOrderInfo.ItemsSource = dt.DefaultView; } catch (Exception ex) { LogHelper.instance.log.Error("操作界面:获取成品工单准备信息时发生异常:" + ex.Message); } } private void dgWorkOrderInfo_LoadingRow(object sender, DataGridRowEventArgs e) { e.Row.Header = (e.Row.GetIndex() + 1).ToString(); } private void btnPause_Click(object sender, RoutedEventArgs e) { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); //var selectedRow = dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) { CustomMessageBox.Show("请选择你要暂停的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } var workordercode = selectedRow["workorder_code"].ToString();//.workorder_code; string currStatus = selectedRow["status"].ToString();//.status; if (currStatus != "w2") { CustomMessageBox.Show("只有活动中的工单才支持暂停!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } PauseOrderWin pauseOrderWin = new PauseOrderWin(); if (pauseOrderWin.ShowDialog() == true) { PauseRecoverOrderS(workordercode, "w4", pauseOrderWin); ProWorkBatchInWork("w4", dgWorkOrderInfo.SelectedItem as DataRowView, 2); GetWorkOrderInfo(); } //MessageBoxResult result = MessageBox.Show("你确定要暂停该工单吗?", "温馨提示", MessageBoxButton.YesNo, MessageBoxImage.Information); //if (result == MessageBoxResult.No) // return; } private bool PauseRecoverOrderS(string workordercode, string status, PauseOrderWin pauseOrderWin) { bool updatestatus = formingMachineService.UpdateWorkOrder(workordercode, status, pauseOrderWin.remark, pauseOrderWin.type, deviceCode); if (!updatestatus) { CustomMessageBox.Show("操作失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); } return UpdateOrderStatus(workordercode, status); } private void btnRecover_Click(object sender, RoutedEventArgs e) { //var selectedRow = dgWorkOrderInfo.SelectedItem as FoamingMacModel; var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); if (selectedRow == null) { CustomMessageBox.Show("请选择你要恢复的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } int orderCount = GetActivedOrdersCount(this.deviceCode, LoginUser.WorkDate); if (orderCount >= 1) { CustomMessageBox.Show("已有活动中的工单,请先报工再开始下一个工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } var workordercode = selectedRow["workorder_code"].ToString();//.workorder_code; string currStatus = selectedRow["status"].ToString();//.status; if (currStatus != "w4") { CustomMessageBox.Show("只有暂停中的工单才支持恢复!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } //MessageBoxResult result = MessageBox.Show("你确定要恢复该工单吗?", "温馨提示", MessageBoxButton.YesNo, MessageBoxImage.Information); //if (result == MessageBoxResult.No) // return; PauseOrderWin pauseOrderWin = new PauseOrderWin(); if (pauseOrderWin.ShowDialog() == true) { PauseRecoverOrderS(workordercode, "w2", pauseOrderWin); ProWorkBatchInWork("w2", dgWorkOrderInfo.SelectedItem as DataRowView, 0); // 添加写入PLC尺寸信息的逻辑 string materialCode = selectedRow["product_code"].ToString(); WritePlcBoxMessage(materialCode); GetWorkOrderInfo(); } } /// /// 查看工艺 /// /// /// private void Flow_Click(object sender, RoutedEventArgs e) { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView);//dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) return; var workordercode = selectedRow["workorder_code"].ToString();//.workorder_code; DataTable dt = userDbWareHouse.GetFlowInfo(workordercode); FlowInfoWin flowInfoWin = new FlowInfoWin(dt); flowInfoWin.ShowDialog(); } /// /// 查看物料 /// /// /// private void Material_Click(object sender, RoutedEventArgs e) { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); //dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) return; var processid = selectedRow["workorder_code"].ToString();//.workorder_code; DataTable dt = userDbWareHouse.GetMaterialInfo(processid); LanJu_Material sopInfoWin = new LanJu_Material(dt); sopInfoWin.ShowDialog(); } /// /// 查看SOP /// /// /// private void Button_Click(object sender, RoutedEventArgs e) { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); //dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) return; var workordercode = selectedRow["route_code"].ToString();//.workorder_code; DataTable dt = userDbWareHouse.GetSOPInfo(workordercode); SopInfoWin sopInfoWin = new SopInfoWin(dt); sopInfoWin.ShowDialog(); } private void btnRefresh_Click(object sender, RoutedEventArgs e) { GetWorkOrderInfo(); LanJu_InOut lanJu_In = new LanJu_InOut(_workOrderCode, deviceCode); lanJu_In.GetInOutRecordInfo(); } private async void btnComplete_Click(object sender, RoutedEventArgs e) { try { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); //dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) { //MessageBox.Show("请选择你要报工的工单!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning); CustomMessageBox.Show("请选择你要报工的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } if (!selectedRow["status"].ToString().Equals("w2") && !selectedRow["status"].ToString().Equals("w4")) { LogHelper.instance.log.Info("当前选择的工单" + (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString() + "状态为:" + selectedRow["status"].ToString()); string status = selectedRow["status"].ToString(); string st = status.Equals("w1") ? "已派发" : status.Equals("w3") ? "已报工" : status.Equals("w0") ? "未派发" : "已暂停"; CustomMessageBox.Show("你选择的工单不能报工,请检查工单状态,当前工单状态为:" + st, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } //20240424预报工功能,不能限制批次报工次数, //if (selectedRow["batchStatus"].ToString().Equals("0")) //{ // CustomMessageBox.Show("你选择的该批次不能报工!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // return; //} #region 添加验证 string workorderId = selectedRow["workorder_id"].ToString(); string batch_code = selectedRow["batch_code"].ToString(); string qc_status = selectedRow["qc_status"].ToString(); if (qc_status != "2" && selectedRow["status"].ToString() != "w4") { CustomMessageBox.Show("该工单未首检,请重新选择!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } if (!formingMachineService.GetProOrderWorkOrder(workorderId)) { CustomMessageBox.Show("该工单已经被删除,请重新选择!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); GetWorkOrderInfo(); return; } #endregion ExecReportWorkWin execReport = new ExecReportWorkWin(selectedRow, deviceCode, Utils.GetAppSetting("SiteCode")); if (execReport.ShowDialog() == true) { string materialCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_code"].ToString(); string materialDesc = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_name"].ToString(); userDbWareHouse.InsertOperationLog((dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString(), "w3", "", "工单报工", deviceCode, materialCode, materialDesc); bool isProwork = true; DataRowView dataRowView = dgWorkOrderInfo.SelectedItem as DataRowView; foreach (var selectItem in dgWorkOrderInfo.Items) { if (selectItem is DataRowView selectRow) { string v = selectRow["BtnTest"].ToString(); if (selectRow["BtnTest"].ToString() == "结束" && selectRow["batch_code"].ToString() != dataRowView["batch_code"].ToString()) { isProwork = false; break; } } } if (isProwork) { ProWorkBatchInWork("w3", dataRowView, 2); } ////获取报工编码 //string newReportCode = ""; //DataTable dtNewReportCode = formingMachineService.GetReportCode(); //if (dtNewReportCode == null || dtNewReportCode.Rows.Count == 0) //{ // newReportCode = DateTime.Now.ToString("yyyyMMdd") + "0001"; //} //else //{ // if (string.IsNullOrEmpty(dtNewReportCode.Rows[0]["report_code"].ToString())) // { // newReportCode = DateTime.Now.ToString("yyyyMMdd") + "0001"; // } // else // { // newReportCode = (Convert.ToInt64(dtNewReportCode.Rows[0]["report_code"].ToString()) + 1).ToString(); // } //} //string workTime = execReport._workTime; //string costCenter = execReport._costCenter; //string userCount = execReport._useMan; //string workCount = execReport._workQuntity; //string batchCode = execReport.batchCode; //string isEndReport = execReport._isEndReport == true ? "1" : "0"; //bool issucc = formingMachineService.ExecuteReportWork(selectedRow, workCount, newReportCode, workTime, userCount, costCenter, batchCode, isEndReport, deviceCode); //if (issucc) //{ // //调用报工接口 // //string apiUrl = formingMachineService.InterfaceUrl("reportWork"); // ReportWork reportWork = new ReportWork(); // reportWork.factoryCode = Utils.GetAppSetting("SiteCode"); // reportWork.reportCode = newReportCode; // // 将要发送的数据序列化为JSON格式 // var jsonContent = JsonConvert.SerializeObject(reportWork); // LogHelper.instance.log.Info("开始报工>>" + jsonContent); // RestHelper restClient = new RestHelper(); //var response =; // Rootobjectresu result = Utils.DeJson(await restClient.PostAsync(apiUrl, jsonContent)); // if (result.code == 200) // { // GetWorkOrderInfo(); // } // else // { // CustomMessageBox.Show("调用报工接口失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // } //} //else //{ // CustomMessageBox.Show("报工失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); //} GetWorkOrderInfo(); } } catch (Exception ex) { LogHelper.instance.log.Error("报工失败11>>" + ex.Message); CustomMessageBox.Show("报工失败:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } private void btnCheckLog_Click(object sender, RoutedEventArgs e) { ViewLogWin viewLogWin = new ViewLogWin(); viewLogWin.ShowDialog(); } private void btnViewPlcvalue_Click(object sender, RoutedEventArgs e) { ViewPlcInfoWin viewPlcWin = new ViewPlcInfoWin(); viewPlcWin.ShowDialog(); } private void dgWorkOrderInfo_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (dgWorkOrderInfo.SelectedItems.Count == 0) { return; } var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); _workOrderCode = selectedRow["workorder_code"].ToString(); //InOut_Click(null,null); //Complete_Click(null,null); } private void HFPlcvalue_Click(object sender, RoutedEventArgs e) { HBLogWin HFPlcWin = new HBLogWin(); HFPlcWin.ShowDialog(); } private async void btnPause1_Click(object sender, RoutedEventArgs e) { try { //陈恒杰在2024-01-07日与榄菊的苏振华确认,不需要用户验证 //CheckUserWin checkUserWin = new CheckUserWin(); //checkUserWin.ShowDialog(); //if (!checkUserWin.loginFlag) //{ // CustomMessageBox.Show("请先校验用户!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // return; //} bool connectResult = plc.Connection(PlcIp); if (!connectResult) { LogHelper.instance.log.Info("PLC连接失败"); CustomMessageBox.Show("PLC连接失败无法开始工单!"); return; } if (dgWorkOrderInfo.SelectedItems.Count == 0) { CustomMessageBox.Show("请选择要开始的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } if (dgWorkOrderInfo.SelectedItem is DataRowView selectedRow) { string rowContent = string.Join(", ", selectedRow.Row.ItemArray); LogHelper.instance.log.Info("开始工单选择的行内容: " + rowContent); } else { LogHelper.instance.log.Info("未选择任何行或选择的项不是 DataRowView 类型"); } string workorderID = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString(); string status = (dgWorkOrderInfo.SelectedItem as DataRowView)["status"].ToString(); LogHelper.instance.log.Info("记录开始工单状态:" + status + ", 开始工单号为:" + workorderID); if (status != "w1") { string st = string.Empty; if (status == "w2") { CustomMessageBox.Show("该工单已经活动中,请勿再次开始工单!!!"); return; } else if (status == "w0") { st = "未派发"; } else if (status == "w3") { st = "已报工"; } else if (status == "w4") { st = "已暂停"; } LogHelper.instance.log.Info("该工单不符合条件,请检查工单状态,当前工单状态为:" + st); CustomMessageBox.Show("该工单不符合条件,请检查工单状态,当前工单状态为:" + st, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); GetWorkOrderInfo(); return; } CustomMessageBoxResult result = CustomMessageBox.Show("你确定要开始工单么?", CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning); if (result == CustomMessageBoxResult.Cancel) return; //2024-04-23赵啸林要求添加一条产线同一天只能有一个活动状态下的工单,如果有未报工的则不允许开始新的工单 int orderCount = GetActivedOrdersCount(this.deviceCode, LoginUser.WorkDate); if (orderCount >= 1) { CustomMessageBox.Show("已有活动中的工单,请先报工再开始下一个工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info("开始工单:已有活动中的工单,请先报工再开始下一个工单!"); return; } LogHelper.instance.log.Info("查询到当前正在活动的工单数量为" + orderCount); //更新工单状态 if (!UpdateOrderStatus(workorderID, "w2")) { LogHelper.instance.log.Info("开始工单返回失败"); CustomMessageBox.Show("开始工单失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); } else { //巡检 string materialCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_code"].ToString(); string materialDesc = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_name"].ToString(); userDbWareHouse.InsertOperationLog(workorderID, "w2", "", "开始工单", deviceCode, materialCode, materialDesc); ProWorkBatchInWork("w2", dgWorkOrderInfo.SelectedItem as DataRowView, 0); LogHelper.instance.log.Info("问题跟踪:设备编号是否为空:"+ deviceCode); if (!string.IsNullOrEmpty(deviceCode) && lineList.Contains(deviceCode)) { LogHelper.instance.log.Info("问题跟踪:尝试将箱型信息写给PLC"+ materialCode ); WritePlcBoxMessage(materialCode); } // await CallCheckApi("checkTypeSCXJ");20240403赵啸林因为切线方案调整,要求取消上位机生成巡检任务的功能; GetWorkOrderInfo(); } } catch (Exception ex) { LogHelper.instance.log.Error("开始工单异常:" + ex.Message); } } /// /// /// /// /// /// 0:开始工单,要更改基本信息,1:只改批次号,2:只改状态 /// private bool ProWorkBatchInWork(string status, DataRowView dataRow, int type) { var lineCode = deviceCode; var batchCode = dataRow["batch_code"].ToString(); var productCode = dataRow["product_code"].ToString(); var workorderCode = dataRow["workorder_code"].ToString(); var productName = dataRow["product_name"].ToString(); DataTable dtBaseProduct = formingMachineService.GetBaseProduct(productCode); DataTable dtBaseProductAtt = formingMachineService.GetBaseProductAtt(productCode); //string parentStatus = formingMachineService.GetWorkOrderParentStatus(workorderCode); //if (!string.IsNullOrEmpty(parentStatus)) //{ // status = parentStatus; //} if (dtBaseProduct == null || dtBaseProduct.Rows.Count == 0) { CustomMessageBox.Show("未找到该产品箱型信息!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return false; } if (dtBaseProductAtt == null || dtBaseProductAtt.Rows.Count == 0) { CustomMessageBox.Show("未找到该产品垛型属性信息!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return false; } string productdescen = dtBaseProduct.Rows[0]["product_desc_en"].ToString(); //string boxType = dtBaseProduct.Rows[0]["box_type"].ToString(); _dic.TryGetValue(deviceCode, out var boxType); string umrez = dtBaseProduct.Rows[0]["umrez"].ToString(); string packType = dtBaseProductAtt.Rows[0]["pack_type"].ToString(); if (type == 0) { batchCode = ""; LogHelper.instance.log.Info($"开始工单:" + lineCode + "," + batchCode + "," + workorderCode + "," + productCode + "," + productName + "," + productdescen + "," + boxType + "," + packType + "," + umrez + "," + status + "," + LoginUser.WorkDate); if (!formingMachineService.UpdateProWorkBatchInWork(lineCode, batchCode, workorderCode, productCode, productName, productdescen, boxType, packType, umrez, status, LoginUser.WorkDate)) { CustomMessageBox.Show("更新打印机表状态失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info($"更新打印机表状态失败:" + CustomMessageBoxButton.OK +";"+ CustomMessageBoxIcon.Warning); return false; } } else if (type == 1) { if (!formingMachineService.UpdateProWorkBatchInWorkBatchCode(lineCode, batchCode, status, productCode, productName)) { CustomMessageBox.Show("更新打印机表状态失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info($"更新打印机表状态失败:" + CustomMessageBoxButton.OK + ";" + CustomMessageBoxIcon.Warning); return false; } } else if (type == 2) { if (!formingMachineService.UpdateProWorkBatchInWorkStatus(lineCode, status, packType)) { CustomMessageBox.Show("更新打印机表状态失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info($"更新打印机表状态失败:" + CustomMessageBoxButton.OK + ";" + CustomMessageBoxIcon.Warning); return false; } } return true; } private int GetActivedOrdersCount(string deviceCode, string workDate) { DataTable dtActivedOrdersQty = userDbWareHouse.GetActivedOrdersQty(deviceCode, workDate); if (dtActivedOrdersQty == null) return 0; int count = Convert.ToInt32(dtActivedOrdersQty.Rows[0][0]); return count; } private bool UpdateOrderStatus(string workorderID, string status) { try { string name = LoginUser.UserName + "-" + LoginUser.UserId; if (name.IsNullOrEmpty()) { name = "无-0"; } DataTable dtSubOrders = userDbWareHouse.GetOrderInfo(workorderID); if (dtSubOrders != null && dtSubOrders.Rows.Count > 0) { string remarks = status == "w2" ? "开始工单" : "暂停工单"; var belong_work_order = dtSubOrders.Rows[0]["belong_work_order"].ToString(); var updatestatus = userDbWareHouse.UpdateSycnFlagByBelongWorkOrder(belong_work_order, deviceCode, name, status); if (!updatestatus) { CustomMessageBox.Show($"{remarks}失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info($"{remarks}失败"); return false; } else { LogHelper.instance.log.Info($"{remarks}正常"); } } //更新工单状态 //var updatestatus = userDbWareHouse.UpdateSycnFlag(workorderID, deviceCode, name); //if (!updatestatus) //{ // CustomMessageBox.Show("开始工单失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // LogHelper.instance.log.Info("开始工单失败"); // return false; //} //else //{ // LogHelper.instance.log.Info("开始工单正常"); //} //DataTable dtSubOrders = userDbWareHouse.GetSubOrderInfo(workorderID); //if (dtSubOrders != null) //{ // // 递归更新子单状态 // foreach (DataRow subOrder in dtSubOrders.Rows) // { // UpdateOrderStatus(subOrder["workorder_code"].ToString()); // } //} } catch (Exception ex) { LogHelper.instance.log.Info("开始工单异常" + ex.Message); } return true; } private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) { if (sender is DatePicker datePicker) { DateTime selectedDate = datePicker.SelectedDate ?? DateTime.MinValue; } } private void GetQitaolv_Click(object sender, RoutedEventArgs e) { QitaoLvUC lanJu_QitaoLv = new QitaoLvUC(_workOrderCode); Window1.Content = new Frame { Content = lanJu_QitaoLv }; } private void btnCallMaterial_Click(object sender, RoutedEventArgs e) { string workorderID = (dgWorkOrderInfo.SelectedItem as DataRowView)["parent_order"].ToString(); if (!workorderID.Equals("0")) { CustomMessageBox.Show("请对母单使用叫料功能!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } } private async void btnFirstCheck_Click(object sender, RoutedEventArgs e) { if (dgWorkOrderInfo.SelectedItems.Count == 0) { CustomMessageBox.Show("请选择要首件检验的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } try { string status1 = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString(); string status = (dgWorkOrderInfo.SelectedItem as DataRowView)["status"].ToString(); if (!status.Equals("w2")) { if (status != "") { string st = status.Equals("w1") ? "未派发" : status.Equals("w3") ? "已报工" : status.Equals("w0") ? "未派发" : "已暂停"; CustomMessageBox.Show("该工单不符合条件,请检查工单状态,当前工单状态为:" + st, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } } string batchCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["batch_code"].ToString(); CustomMessageBoxResult result = CustomMessageBox.Show($"你确定要为批次号:{batchCode}进行首检么?", CustomMessageBoxButton.OKCancel, CustomMessageBoxIcon.Warning); if (result == CustomMessageBoxResult.Cancel) return; LogHelper.instance.log.Info($"首检检验按钮被点击工单号为:{(dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"]},批次号为:{batchCode}"); //2024-04-16添加不限制首检确认的功能; //string qcStatus = (dgWorkOrderInfo.SelectedItem as DataRowView)["qc_status"].ToString(); //if (qcStatus.Equals("1") || qcStatus.Equals("2")) //{ // if (qcStatus != "") // { // CustomMessageBox.Show("该工单已完成质检,请不要重复创建质检任务!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // return; // } //} //首件检验 await CallCheckApi("checkTypeSC", batchCode); } catch (Exception ex) { LogHelper.instance.log.Error("首检检验发生异常>>" + ex.Message); CustomMessageBox.Show("首检检验发生异常:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } /// /// 首检/巡检 /// /// /// private async Task CallCheckApi(string checkType, string batchCode) { try { string workorderCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString(); string workorderID = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_id"].ToString(); string productCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_code"].ToString(); string productName = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_name"].ToString(); string quality = (dgWorkOrderInfo.SelectedItem as DataRowView)["quantity_split"].ToString(); string unit = (dgWorkOrderInfo.SelectedItem as DataRowView)["unit"].ToString(); string plan_time = (dgWorkOrderInfo.SelectedItem as DataRowView)["plan_time"].ToString(); plan_time = plan_time.Replace("/", "-"); //调用首件检验接口 string apiUrl = formingMachineService.GetInterfaceUrl("createCheckProduceTask"); FirstCheckModel firstCheck = new FirstCheckModel(); firstCheck.factoryCode = Utils.GetAppSetting("SiteCode"); string taskName = ""; if (checkType.Equals("checkTypeSCXJ")) { taskName = "巡检任务"; LogHelper.instance.log.Info($"准备触发巡检任务{workorderCode}>>批次号为:{batchCode}"); firstCheck.incomeBatchNo = null; } else { taskName = "首件检验任务"; LogHelper.instance.log.Info($"准备触发首件检验任务{workorderCode}>>批次号为:{batchCode}"); firstCheck.incomeBatchNo = batchCode; } firstCheck.orderNo = workorderCode; firstCheck.materialName = productName; firstCheck.materialCode = productCode; firstCheck.checkType = checkType;//"checkTypeSC"; firstCheck.quality = quality; firstCheck.unit = unit; //根据线体编码获取车间编码 DataTable dtCar = userDbWareHouse.GetCarInfo(deviceCode); string carCode = dtCar.Rows[0][0].ToString(); string carName = dtCar.Rows[0][1].ToString(); firstCheck.carName = carName; firstCheck.carCode = carCode; firstCheck.produceDate = plan_time; firstCheck.checkManName = LoginUser.UserName; firstCheck.checkManCode = LoginUser.UserCode; firstCheck.checkLoc = deviceCode; // 将要发送的数据序列化为JSON格式 var jsonContent = JsonConvert.SerializeObject(firstCheck); LogHelper.instance.log.Info($"开始{taskName}>>" + jsonContent); RestHelper restClient = new RestHelper(); //var response =; Rootobjectresu result = Utils.DeJson(await restClient.PostAsync(apiUrl, jsonContent)); if (result.code == 200) { //巡检 if (checkType.Equals("checkTypeSCXJ")) { CustomMessageBox.Show($"{taskName}创建成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success); LogHelper.instance.log.Info($"{taskName}创建成功>>" + result.msg); GetWorkOrderInfo(); } else { //调用首件检验 bool isSuccess = formingMachineService.UpdateFirstCheckTask(workorderID, batchCode); if (isSuccess) { CustomMessageBox.Show($"{taskName}创建成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success); LogHelper.instance.log.Info($"{taskName}创建成功>>" + result.msg); GetWorkOrderInfo(); } else { CustomMessageBox.Show($"更新{taskName}状态失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); LogHelper.instance.log.Info($"更新{taskName}状态失败>>" + result.msg); } } } else { LogHelper.instance.log.Info($"{taskName}失败>>" + result.msg); CustomMessageBox.Show($"调用{taskName}接口失败:" + result.msg, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); } } catch (Exception ex) { LogHelper.instance.log.Error("首检检验接口发生异常>>" + ex.Message); CustomMessageBox.Show("首检检验接口发生异常:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } private void btnMachineRepair_Click(object sender, RoutedEventArgs e) { var selefuel = formingMachineService.ConvertToFaultModelList(); //调用首件检验接口 string apiUrl = formingMachineService.GetInterfaceUrl("machineRepair"); var eqment = formingMachineService.GetReportCodeeqment(Utils.GetAppSetting("DeviceCode")); MachineRepairWin machineRepairWin = new MachineRepairWin(apiUrl, selefuel, eqment); machineRepairWin.ShowDialog(); } private void btnSalaryCal_Click(object sender, RoutedEventArgs e) { var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView); //dgWorkOrderInfo.SelectedItem as FoamingMacModel; if (selectedRow == null) { //MessageBox.Show("请选择你要报工的工单!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning); CustomMessageBox.Show("请选择你要操作的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } //if (!selectedRow["status"].ToString().Equals("w2")) //{ // CustomMessageBox.Show("你选择的工单不符合条件!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); // return; //} if (selectedRow["salary_flag"].ToString().Equals("1")) { CustomMessageBox.Show("你选择的工单已录入计件薪酬信息,不允许重复录入!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } string prodCode = selectedRow["product_code"].ToString(); string prodName = selectedRow["product_name"].ToString(); string workOrderCode = selectedRow["workorder_code"].ToString(); string sapWorkOrderCode = selectedRow["workorder_code_sap"].ToString(); PieceSalaryCalWin pieceSalaryCalWin = new PieceSalaryCalWin(prodCode, prodName, deviceCode, workOrderCode, sapWorkOrderCode); pieceSalaryCalWin.ShowDialog(); } private void weigh_Click(object sender, RoutedEventArgs e) { punchCard punchCard = new punchCard(); punchCard.ShowDialog(); } private void report_Click(object sender, RoutedEventArgs e) { new ReportPageSelect().ShowDialog(); } private void auxiliary_personnel(object sender, RoutedEventArgs e) { //先判断是否为管理人员 var sys_users = usdb.GetUserList(LoginUser.UserId); if (sys_users.Count == 0 || sys_users[0].user_m_type == null || sys_users[0].user_m_type.ToLower() != "g") { CustomMessageBox.Show("你不是管理人员,无权操作!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } new PersonView().ShowDialog(); } private void Button_Click_3(object sender, RoutedEventArgs e) { try { if (sender is System.Windows.Controls.Button btn) { string batchId = btn.Tag.ToString(); DataTable dt = userDbWareHouse.GetWetPlanInfo(deviceCode, DateTime.Parse(LoginUser.WorkDate).ToString("yyyy-MM-dd")); foreach (DataRow row in dt.Rows) { string content = btn.Content.ToString(); if (batchId == row["batchId"].ToString()) { if (row["BtnTest"] != null && row["BtnTest"].ToString() == content) { string attr1 = "0"; if (content == "开始") { attr1 = "1"; if (row["status"].ToString() != "w2") { CustomMessageBox.Show("只有已经活动的工单才能开始批次!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } //if (!isSuccess && !IsWrite) //{ // CustomMessageBoxResult customMessageBoxResult = CustomMessageBox.Show("是否需要再次同步尺寸信息?", CustomMessageBoxButton.YesNo, CustomMessageBoxIcon.Question); // if (customMessageBoxResult == CustomMessageBoxResult.Yes) // { // WritePlcBoxMessage(row["product_code"].ToString()); // } //} if (ProWorkBatchInWork("w2", dgWorkOrderInfo.SelectedItem as DataRowView, 1)) { DataRowView temp = dgWorkOrderInfo.SelectedItem as DataRowView; var batchCode = temp["batch_code"].ToString(); LogHelper.instance.log.Info(DateTime.Now + $"已开始批次:" + batchCode); } } else if (content == "结束") { attr1 = "0"; } userDbWareHouse.UpdateProWorkOrderBatch(batchId, attr1); GetWorkOrderInfo(); } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } private void WritePlcBoxMessage(string productCode) { int count = 0; try { IsWrite = true; if (dgWorkOrderInfo.SelectedItem is DataRowView dataRowView) { Task.Run(() => { try { DataTable dt = formingMachineService.GetProductSize(productCode); int number = int.Parse(deviceCode.Substring(2)); string height = "heigh" + number.ToString(); string width1 = "width" + number.ToString(); string length1 = "long" + number.ToString(); string[] plcPointNo = { height, width1, length1 }; DataTable pointsDt = formingMachineService.GetWcsPlcPoint(plcPointNo, "ProductSize"); if (pointsDt == null || pointsDt.Rows.Count == 0) { LogHelper.instance.log.Info("问题跟踪:pointsDt为空或者数量为零"); return; } if (dt != null && dt.Rows.Count > 0) { LogHelper.instance.log.Info("问题跟踪:dt不为空" ); string heigh = dt.Rows[0]["height"].ToString(); string width = dt.Rows[0]["width"].ToString(); string length = dt.Rows[0]["length"].ToString(); short h = Convert.ToInt16(Convert.ToDecimal(heigh)); short w = Convert.ToInt16(Convert.ToDecimal(width)); short l = Convert.ToInt16(Convert.ToDecimal(length)); while (count < 5) { try { count++; //bool connectResult = plc.Connection(PlcIp); //if (!connectResult) //{ // LogHelper.instance.log.Info("问题跟踪:PLC连接失败"); //} //else //{ //} if (pointsDt != null && pointsDt.Rows.Count > 0) { bool writeResult = false; foreach (DataRow row in pointsDt.Rows) { if (row["plc_point_no"].ToString() == height) { writeResult = plc.Write(new PlcSetting() { PlcAddress = row["plc_point_address"].ToString(), PlcValueLength = "2" }, h); } else if (row["plc_point_no"].ToString() == width1) { writeResult = plc.Write(new PlcSetting() { PlcAddress = row["plc_point_address"].ToString(), PlcValueLength = "2" }, w); } else if (row["plc_point_no"].ToString() == length1) { writeResult = plc.Write(new PlcSetting() { PlcAddress = row["plc_point_address"].ToString(), PlcValueLength = "2" }, l); } if (writeResult) { LogHelper.instance.log.Info($"写入PLC尺寸信息成功,新高度{h},新宽度{w},新长度{l}"); Dispatcher.Invoke(() => { CustomMessageBox.Show($"写入PLC尺寸信息成功,新高度{h},新宽度{w},新长度{l}"); }); } else { LogHelper.instance.log.Info($"写入PLC尺寸信息失败!"); Dispatcher.Invoke(() => { CustomMessageBox.Show($"写入PLC尺寸信息失败!"); }); } } isSuccess = writeResult; break; } } catch (Exception ex) { isSuccess = false; LogHelper.instance.log.Error($"写入PLC尺寸信息失败,第{count}次重试,异常信息:{ex.Message}", ex); plc = new PlcHelper(); } } if (!isSuccess) { Dispatcher.Invoke(() => { CustomMessageBox.Show("同步数据到PLC尺寸信息失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); }); } } } catch(Exception ex) { LogHelper.instance.log.Info("问题跟踪异常:" + ex); } }); } } catch { } finally { IsWrite = false; } } /// /// 叫料按钮事件 /// /// /// private async void btnCallMaterialRequest_Click(object sender, RoutedEventArgs e) { // 判断当前窗口内容是否为QitaoLvUC if (Window1.Content is Frame frame && frame.Content is XGLFinishPro.Views.QitaoLvUC qitaoLvUC) { var selectedRow = qitaoLvUC.SelectedMaterialRow; if (selectedRow == null) { CustomMessageBox.Show("请先选中一条领料记录!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); return; } // 组装数据 string materialCode = selectedRow["material_code"].ToString(); string materialName = selectedRow["material_name"].ToString(); string quantity = qitaoLvUC.InputQuantity ?? selectedRow["quantity"].ToString(); string locator = selectedRow["locator"].ToString(); // TODO: 这里根据实际需求组装更多字段 // 发送请求(伪代码,需替换为实际接口调用) try { // 这里可以用HttpClient或RestHelper等工具发送请求 // var result = await SomeApiHelper.SendMaterialRequest(materialCode, materialName, quantity, locator); // 假设成功 CustomMessageBox.Show($"叫料请求已发送!\n物料编码:{materialCode}\n物料名称:{materialName}\n数量:{quantity}\n库位:{locator}", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success); } catch (Exception ex) { CustomMessageBox.Show($"叫料请求失败:{ex.Message}", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error); } } else { CustomMessageBox.Show("请先点击领料单并选中一条记录!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning); } } } public class ReportWorkModel { public string factoryCode { get; set; } public string reportCode { get; set; } } public class FirstCheckModel { /// /// 工厂编码 /// public string factoryCode { get; set; } /// /// 批次号 /// public string incomeBatchNo { get; set; } /// /// orderNo:订单号 /// public string orderNo { get; set; } /// /// 物料名称 /// public string materialName { get; set; } /// /// 物料编码 /// public string materialCode { get; set; } /// /// 检测类型固定 checkTypeSC首次检验 checkTypeHF烘房检验 /// public string checkType { get; set; } /// /// 收货数量 /// public string quality { get; set; } /// /// 单位 /// public string unit { get; set; } /// /// 车间名称 /// public string carName { get; set; } /// /// 车间编码 /// public string carCode { get; set; } /// /// 生产时间 格式yyyy-MM-dd HH:mm:ss /// public string produceDate { get; set; } /// /// 检测人姓名 /// public string checkManName { get; set; } /// /// 检测人工号 /// public string checkManCode { get; set; } /// /// 检测地点 /// public string checkLoc { get; set; } } }