You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

805 lines
35 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using CommonFunc;
using CommonFunc.Tools;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using XGL.Data.DBService;
using XGL.Dats.DBServiceFinishProd;
using XGL.Models.Model.FoamingMac;
using XGL.Models.Model.OrderPrepare;
using XGL.Thrift;
namespace XGLFinishPro.Views
{
/// <summary>
/// LanJu_Operator.xaml 的交互逻辑
/// </summary>
public partial class LanJu_Operator : UserControl
{
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");
Timer timerDeciveState = new Timer();
string _workOrderCode = "";
public enum WindowID
{
frame
}
public LanJu_Operator()
{
InitializeComponent();
WindowChange(WindowID.frame);
}
public void WindowChange(WindowID windowID)
{
Window1.Content = frame;
}
List<string> 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 UCOperator_Loaded(object sender, RoutedEventArgs e)
{
timerDeciveState.Interval = Utils.GetAppSetting("GetDeviceStateInterval") == "" ? 15000 : 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<FoamingMacModel> orderList = new List<FoamingMacModel>();
//int currHour = DateTime.Now.Hour;
//int currMinute = DateTime.Now.Minute;
////modelWareHouse = new List<WorkOrder>();
////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<WorkOrder>();
DataTable dt = userDbWareHouse.GetWetPlanInfo(deviceCode, LoginUser.WorkDate);//formingMachineService.GetFormingMachineInfo(deviceCode, currShiftDate.ToString());
if (dt == null) return;
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<FoamingMacModel> orderList = new List<FoamingMacModel>();
//int currHour = DateTime.Now.Hour;
//int currMinute = DateTime.Now.Minute;
////modelWareHouse = new List<WorkOrder>();
////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<WorkOrder>();
DataTable dt = userDbWareHouse.GetWetPlanInfo(deviceCode, LoginUser.WorkDate);
if (dt == null) return;
this.dgWorkOrderInfo.ItemsSource = null;
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)
{
MessageBox.Show("请选择你要暂停的工单!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
var workordercode = selectedRow["workorder_code"].ToString();//.workorder_code;
string currStatus = selectedRow["status"].ToString();//.status;
if (currStatus != "w2")
{
MessageBox.Show("只有活动中的工单才支持暂停!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
PauseOrderWin pauseOrderWin = new PauseOrderWin();
if (pauseOrderWin.ShowDialog() == true)
{
PauseRecoverOrderS(workordercode,"w4", pauseOrderWin);
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);
}
DataTable dtSubOrders = userDbWareHouse.GetSubOrderInfo(workordercode);
if (dtSubOrders != null)
{
// 递归更新子单状态
foreach (DataRow subOrder in dtSubOrders.Rows)
{
UpdateOrderStatus(subOrder["workorder_code"].ToString());
}
}
return true;
}
private void btnRecover_Click(object sender, RoutedEventArgs e)
{
//var selectedRow = dgWorkOrderInfo.SelectedItem as FoamingMacModel;
var selectedRow = (dgWorkOrderInfo.SelectedItem as DataRowView);
if (selectedRow == null)
{
MessageBox.Show("请选择你要恢复的工单!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
var workordercode = selectedRow["workorder_code"].ToString();//.workorder_code;
string currStatus = selectedRow["status"].ToString();//.status;
if (currStatus != "w4")
{
MessageBox.Show("只有暂停中的工单才支持恢复!", "温馨提示", MessageBoxButton.OK, MessageBoxImage.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);
//formingMachineService.UpdateWorkOrder(workordercode, "w2", pauseOrderWin.remark, pauseOrderWin.type, deviceCode);
GetWorkOrderInfo();
}
}
/// <summary>
/// 查看工艺
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// 查看物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// 查看SOP
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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"))
{
CustomMessageBox.Show("你选择的工单不能报工!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
if (selectedRow["batchStatus"].ToString().Equals("0"))
{
CustomMessageBox.Show("你选择的该批次不能报工!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
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);
////获取报工编码
//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<Rootobjectresu>(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)
{
}
}
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 void btnPause1_Click(object sender, RoutedEventArgs e)
{
CheckUserWin checkUserWin = new CheckUserWin();
checkUserWin.ShowDialog();
if (!checkUserWin.loginFlag)
{
CustomMessageBox.Show("请先校验用户!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
if (dgWorkOrderInfo.SelectedItems.Count == 0)
{
CustomMessageBox.Show("请选择要开始的工单!", CustomMessageBoxIcon.Warning);
return;
}
string workorderID = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString();
string status = (dgWorkOrderInfo.SelectedItem as DataRowView)["status"].ToString();
if (!status.Equals("w1"))
{
if (status != "")
{
CustomMessageBox.Show("该工单不符合条件,请选择其他的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
}
//更新工单状态
if (!UpdateOrderStatus(workorderID))
{
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);
TimerDeciveState_Elapsed(null,null);
}
}
private bool UpdateOrderStatus(string workorderID)
{
//更新工单状态
var updatestatus = userDbWareHouse.UpdateSycnFlag(workorderID,deviceCode);
if (!updatestatus)
{
CustomMessageBox.Show("开始工单失败!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
}
DataTable dtSubOrders = userDbWareHouse.GetSubOrderInfo(workorderID);
if (dtSubOrders != null)
{
// 递归更新子单状态
foreach (DataRow subOrder in dtSubOrders.Rows)
{
UpdateOrderStatus(subOrder["workorder_code"].ToString());
}
}
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 status = (dgWorkOrderInfo.SelectedItem as DataRowView)["status"].ToString();
if (!status.Equals("w2"))
{
if (status != "")
{
CustomMessageBox.Show("该工单不符合条件,请选择其他的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
return;
}
}
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;
}
}
string workorderCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_code"].ToString();
string workorderID= (dgWorkOrderInfo.SelectedItem as DataRowView)["workorder_id"].ToString();
string batchCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["batch_code"].ToString();
//调用首件检验接口
string apiUrl = formingMachineService.GetInterfaceUrl("createCheckProduceTask");
FirstCheckModel firstCheck = new FirstCheckModel();
firstCheck.factoryCode = Utils.GetAppSetting("SiteCode");
firstCheck.incomeBatchNo = (dgWorkOrderInfo.SelectedItem as DataRowView)["batch_code"].ToString();
firstCheck.orderNo = workorderCode;
firstCheck.materialName = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_name"].ToString();
firstCheck.materialCode = (dgWorkOrderInfo.SelectedItem as DataRowView)["product_code"].ToString();
firstCheck.checkType = "checkTypeSC";
firstCheck.quality = (dgWorkOrderInfo.SelectedItem as DataRowView)["quantity_split"].ToString();
firstCheck.unit = (dgWorkOrderInfo.SelectedItem as DataRowView)["unit"].ToString();
//根据线体编码获取车间编码
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 = (dgWorkOrderInfo.SelectedItem as DataRowView)["plan_time"].ToString();
firstCheck.checkManName = LoginUser.UserName;
firstCheck.checkManCode = LoginUser.UserCode;
firstCheck.checkLoc = deviceCode;
// 将要发送的数据序列化为JSON格式
var jsonContent = JsonConvert.SerializeObject(firstCheck);
LogHelper.instance.log.Info("开始首检>>" + jsonContent);
RestHelper restClient = new RestHelper();
//var response =;
Rootobjectresu result = Utils.DeJson<Rootobjectresu>(await restClient.PostAsync(apiUrl, jsonContent));
if (result.code == 200)
{
//调用首件检验接口
bool isSuccess = formingMachineService.UpdateFirstCheckTask(workorderID, batchCode);
if (isSuccess)
{
CustomMessageBox.Show("首件检验任务创建成功", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Success);
LogHelper.instance.log.Info("首检检验成功>>" + result.msg);
GetWorkOrderInfo();
}
else
{
CustomMessageBox.Show("更新首检任务状态失败", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
LogHelper.instance.log.Info("更新首检任务状态失败>>" + result.msg);
}
}
else
{
LogHelper.instance.log.Info("首检检验失败>>" + result.msg);
CustomMessageBox.Show("调用首件检验接口失败:" + result.msg, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("首检检验发生异常>>" + ex.Message);
CustomMessageBox.Show("首检检验发生异常:" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Error);
}
}
}
public class ReportWorkModel
{
public string factoryCode { get; set; }
public string reportCode { get; set; }
}
public class FirstCheckModel
{
/// <summary>
/// 工厂编码
/// </summary>
public string factoryCode { get; set; }
/// <summary>
/// 批次号
/// </summary>
public string incomeBatchNo { get; set; }
/// <summary>
/// orderNo订单号
/// </summary>
public string orderNo { get; set; }
/// <summary>
/// 物料名称
/// </summary>
public string materialName { get; set; }
/// <summary>
/// 物料编码
/// </summary>
public string materialCode { get; set; }
/// <summary>
/// 检测类型固定 checkTypeSC首次检验 checkTypeHF烘房检验
/// </summary>
public string checkType { get; set; }
/// <summary>
/// 收货数量
/// </summary>
public string quality { get; set; }
/// <summary>
/// 单位
/// </summary>
public string unit { get; set; }
/// <summary>
/// 车间名称
/// </summary>
public string carName { get; set; }
/// <summary>
/// 车间编码
/// </summary>
public string carCode { get; set; }
/// <summary>
/// 生产时间 格式yyyy-MM-dd HH:mm:ss
/// </summary>
public string produceDate { get; set; }
/// <summary>
/// 检测人姓名
/// </summary>
public string checkManName { get; set; }
/// <summary>
/// 检测人工号
/// </summary>
public string checkManCode { get; set; }
/// <summary>
/// 检测地点
/// </summary>
public string checkLoc { get; set; }
}
}