|
|
using CentralControl.BaseData;
|
|
|
using CentralControl.DBDAO;
|
|
|
using CommonFunc;
|
|
|
using CommonFunc.Tools;
|
|
|
using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Timers;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Controls;
|
|
|
using System.Windows.Data;
|
|
|
using System.Windows.Documents;
|
|
|
using System.Windows.Input;
|
|
|
using System.Windows.Media;
|
|
|
using System.Windows.Media.Imaging;
|
|
|
using System.Windows.Navigation;
|
|
|
using System.Windows.Shapes;
|
|
|
using XGL.Data.DBService;
|
|
|
using XGL.Models;
|
|
|
using XGL.Models.Model.OrderPrepare;
|
|
|
using XGL.Thrift;
|
|
|
|
|
|
namespace XGL.Views
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// LanJu_Prepare.xaml 的交互逻辑
|
|
|
/// </summary>
|
|
|
public partial class LanJu_Prepare : UserControl
|
|
|
{
|
|
|
System.Timers. Timer timerDeciveState = new System.Timers.Timer();
|
|
|
|
|
|
public LanJu_Prepare()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
|
|
|
}
|
|
|
|
|
|
List<WorkOrder> modelWareHouse = new List<WorkOrder>();
|
|
|
DBService userDbWareHouse = new DBService();
|
|
|
FormingMachineService formingMachineService = new FormingMachineService();
|
|
|
WorkOrder list_modelWareHouse = new WorkOrder();
|
|
|
|
|
|
|
|
|
|
|
|
string messageOrderCode = "";
|
|
|
DataTable dt;
|
|
|
List<BaseEquipment> eqment;
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 获取主页显示订单
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void GetWorkOrder()
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
List<WetMaterialModel> wetList = new List<WetMaterialModel>();
|
|
|
|
|
|
//modelWareHouse = new List<WorkOrder>();
|
|
|
//userDbWareHouse = new DBService();
|
|
|
string date;
|
|
|
|
|
|
if (this.dateStart.SelectedDate == null || !DateTime.TryParse(this.dateStart.SelectedDate.ToString(), out DateTime selectedDate))
|
|
|
{
|
|
|
// 如果日期无效或未选择日期,则使用当前日期时间
|
|
|
date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// 使用已选择的日期,并确保月份和日期部分为两位
|
|
|
date = selectedDate.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
}
|
|
|
|
|
|
//string date = this.dateStart.SelectedDate.ToString() == "" ? DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") : this.dateStart.SelectedDate.ToString();
|
|
|
dt = userDbWareHouse.GetWetPlanInfo(date,this.comboBoxShift.SelectedValue == null?"": this.comboBoxShift.SelectedValue.ToString());
|
|
|
eqment = userDbWareHouse.GeteqmentInfo();
|
|
|
if (dt == null)
|
|
|
{
|
|
|
this.WorkOrder.ItemsSource = null;
|
|
|
return;
|
|
|
}
|
|
|
foreach (DataRow i in dt.Rows)
|
|
|
{
|
|
|
WetMaterialModel wet = new WetMaterialModel();
|
|
|
wet.id = i["id"].ToString();
|
|
|
wet.workorder_id = i["workorder_id"].ToString();
|
|
|
wet.workorder_code = i["workorder_code"].ToString();
|
|
|
wet.product_name = i["product_name"].ToString();
|
|
|
|
|
|
wet.material_code = i["material_code"].ToString();
|
|
|
wet.material_name = i["material_name"].ToString();
|
|
|
wet.plan_time = Convert.ToDateTime(i["plan_time"].ToString());
|
|
|
wet.bucket_code = i["bucket_code"].ToString();
|
|
|
wet.shift_desc = i["shift_desc"].ToString();
|
|
|
var inneconde= ExtractAndSort(i["prod_line_code"].ToString());
|
|
|
foreach (var item in inneconde)
|
|
|
{
|
|
|
wet.prod_line_code += "[" + eqment.Find(c=>c.EquipmentCode== item).EquipmentName + "],";
|
|
|
}
|
|
|
wet.status = i["status"].ToString();
|
|
|
wet.sync_flag = i["sync_flag"].ToString();
|
|
|
wet.processid = i["route_code"].ToString();
|
|
|
wetList.Add(wet);
|
|
|
// list_modelWareHouse.WorkOrderCode = i["WorkOrderCode"].ToString();
|
|
|
// list_modelWareHouse.OrderCode = i["OrderCode"].ToString();
|
|
|
// list_modelWareHouse.ProductName = i["ProductName"].ToString();
|
|
|
// list_modelWareHouse.ProductSpc = i["ProductSpc"].ToString();
|
|
|
// list_modelWareHouse.QuantitySplit = i["QuantitySplit"].ToString();
|
|
|
// list_modelWareHouse.BatchCode = i["BatchCode"].ToString();
|
|
|
// modelWareHouse.Add(list_modelWareHouse);
|
|
|
LogHelper.instance.log.Info(wet.prod_line_code);
|
|
|
}
|
|
|
this.WorkOrder.ItemsSource = null;
|
|
|
this.WorkOrder.ItemsSource = wetList;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
public List<string> ExtractAndSort(string input)
|
|
|
{
|
|
|
List<string> extractedData = new List<string>();
|
|
|
|
|
|
JArray jsonArray = JArray.Parse(input);
|
|
|
|
|
|
foreach (JArray subArray in jsonArray)
|
|
|
{
|
|
|
if (subArray.Count == 2)
|
|
|
{
|
|
|
string process = subArray[0].Value<string>();
|
|
|
string value = subArray[1].Value<string>();
|
|
|
|
|
|
if (process.StartsWith("GX-") && !process.Equals("GX-01"))
|
|
|
{
|
|
|
extractedData.Add(value);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return extractedData;
|
|
|
}
|
|
|
private T FindParent<T>(DependencyObject child) where T : DependencyObject
|
|
|
{
|
|
|
DependencyObject parent = VisualTreeHelper.GetParent(child);
|
|
|
|
|
|
if (parent is T)
|
|
|
{
|
|
|
return (T)parent;
|
|
|
}
|
|
|
|
|
|
if (parent != null)
|
|
|
{
|
|
|
return FindParent<T>(parent);
|
|
|
}
|
|
|
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
private void UserControl_Loaded(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
this.dateStart.SelectedDate = DateTime.Now;
|
|
|
timerDeciveState.Interval = Utils.GetAppSetting("GetDeviceStateInterval") == "" ? 15000 : Convert.ToInt32(Utils.GetAppSetting("GetDeviceStateInterval"));
|
|
|
timerDeciveState.Elapsed += TimerDeciveState_Elapsed;
|
|
|
timerDeciveState.Start();
|
|
|
InitShiftInfo();
|
|
|
GetWorkOrder();
|
|
|
}
|
|
|
|
|
|
private void TimerDeciveState_Elapsed(object sender, ElapsedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (Utils.isAnyBodyPerating) return;
|
|
|
List<WetMaterialModel> wetList = new List<WetMaterialModel>();
|
|
|
//modelWareHouse = new List<WorkOrder>();
|
|
|
//userDbWareHouse = new DBService();
|
|
|
string date = "";
|
|
|
//使用Dispatcher来在UI线程上更新UI
|
|
|
this.Dispatcher.Invoke(
|
|
|
new Action(() =>
|
|
|
{
|
|
|
date = this.dateStart.SelectedDate.ToString() == "" ? DateTime.Now.ToString() : this.dateStart.SelectedDate.ToString();
|
|
|
}
|
|
|
),
|
|
|
System.Windows.Threading.DispatcherPriority.Render);
|
|
|
|
|
|
dt = userDbWareHouse.GetWetPlanInfo(date, this.comboBoxShift.SelectedValue == null ? "" : this.comboBoxShift.SelectedValue.ToString());
|
|
|
if (dt == null) return;
|
|
|
foreach (DataRow i in dt.Rows)
|
|
|
{
|
|
|
WetMaterialModel wet = new WetMaterialModel();
|
|
|
wet.id = i["id"].ToString();
|
|
|
wet.workorder_id = i["workorder_id"].ToString();
|
|
|
wet.workorder_code = i["workorder_code"].ToString();
|
|
|
wet.product_name = i["product_name"].ToString();
|
|
|
|
|
|
wet.material_code = i["material_code"].ToString();
|
|
|
wet.material_name = i["material_name"].ToString();
|
|
|
wet.plan_time = Convert.ToDateTime(i["plan_time"].ToString());
|
|
|
wet.bucket_code = i["bucket_code"].ToString();
|
|
|
wet.shift_desc = i["shift_desc"].ToString();
|
|
|
//wet.prod_line_code = i["prod_line_code"].ToString();
|
|
|
var inneconde = ExtractAndSort(i["prod_line_code"].ToString());
|
|
|
foreach (var item in inneconde)
|
|
|
{
|
|
|
wet.prod_line_code += "[" + eqment.Find(c => c.EquipmentCode == item).EquipmentName + "],";
|
|
|
}
|
|
|
wet.status = i["status"].ToString();
|
|
|
wet.sync_flag = i["sync_flag"].ToString();
|
|
|
wet.processid = i["route_code"].ToString();
|
|
|
wetList.Add(wet);
|
|
|
LogHelper.instance.log.Info(wet.prod_line_code);
|
|
|
}
|
|
|
|
|
|
if (wetList != null)
|
|
|
{
|
|
|
//使用Dispatcher来在UI线程上更新UI
|
|
|
this.Dispatcher.Invoke(
|
|
|
new Action(() =>
|
|
|
{
|
|
|
this.WorkOrder.ItemsSource = null;
|
|
|
this.WorkOrder.ItemsSource = wetList;//dt.DefaultView;
|
|
|
}
|
|
|
),
|
|
|
System.Windows.Threading.DispatcherPriority.Render);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
private async void btnStartOrders_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
// Check user verification (commented out as per your requirement)
|
|
|
// CheckUserWin checkUserWin = new CheckUserWin();
|
|
|
// checkUserWin.ShowDialog();
|
|
|
// if (!checkUserWin.loginFlag)
|
|
|
// {
|
|
|
// CustomMessageBox.Show("请先校验用户!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
|
|
|
// return;
|
|
|
// }
|
|
|
|
|
|
if (WorkOrder.SelectedItems.Count == 0)
|
|
|
{
|
|
|
CustomMessageBox.Show("请选择要开始的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
string orderID = (WorkOrder.SelectedItem as WetMaterialModel).id;
|
|
|
string workorderID = (WorkOrder.SelectedItem as WetMaterialModel).workorder_id;
|
|
|
string material = (WorkOrder.SelectedItem as WetMaterialModel).material_code;
|
|
|
string sync_flag = (WorkOrder.SelectedItem as WetMaterialModel).sync_flag;
|
|
|
string status = (WorkOrder.SelectedItem as WetMaterialModel).status;
|
|
|
|
|
|
if (sync_flag.Equals("Y"))
|
|
|
{
|
|
|
CustomMessageBox.Show("该工单已同步,请选择其他的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (!status.Equals("w1"))
|
|
|
{
|
|
|
if (status != "")
|
|
|
{
|
|
|
CustomMessageBox.Show("该工单不符合条件,请选择其他的工单!", CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Show loading indicator
|
|
|
Dispatcher.Invoke(() =>
|
|
|
{
|
|
|
jindu.Visibility = Visibility.Visible;
|
|
|
});
|
|
|
|
|
|
// Simulate some work
|
|
|
await Task.Run(async () =>
|
|
|
{
|
|
|
// 获取湿料计划指定的成型机
|
|
|
DataTable cxjDt = userDbWareHouse.GetCXJList(workorderID);
|
|
|
|
|
|
if (cxjDt == null || cxjDt.Rows.Count == 0)
|
|
|
{
|
|
|
throw new Exception("该工单未指定料罐、成型机,请稍后再试!");
|
|
|
}
|
|
|
|
|
|
List<string> cxjList = new List<string>();
|
|
|
List<string> bucketList = new List<string>();
|
|
|
|
|
|
for (int i = 0; i < cxjDt.Rows.Count; i++)
|
|
|
{
|
|
|
string jsonStrCXJList = cxjDt.Rows[i][0].ToString();
|
|
|
string bucketNo = cxjDt.Rows[i][1].ToString();
|
|
|
bucketList.Add(bucketNo);
|
|
|
|
|
|
List<List<string>> data = JsonConvert.DeserializeObject<List<List<string>>>(jsonStrCXJList);
|
|
|
|
|
|
foreach (var innerList in data)
|
|
|
{
|
|
|
if (innerList[1].Contains("C"))
|
|
|
{
|
|
|
cxjList.Add(innerList[1]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
cxjList = cxjList.Distinct().ToList();
|
|
|
bucketList = bucketList.Distinct().ToList();
|
|
|
|
|
|
string apiUrl = Utils.GetAppSetting("WCSMaterialSyncAddress") == "" ? "http://192.168.202.28:9001/api/v1/ReceiveMesMsg/materialPlanSync" : Utils.GetAppSetting("WCSMaterialSyncAddress");
|
|
|
|
|
|
MaterialPlanModel materialPlanModel = new MaterialPlanModel();
|
|
|
List<WetMaterialModel> listWetMaterial = Utils.ToDataList<WetMaterialModel>(dt);
|
|
|
List<skuInfo> skuInfoList = new List<skuInfo>();
|
|
|
|
|
|
materialPlanModel.reqCode = CommonFunc.Common.GetUUID();
|
|
|
materialPlanModel.reqTime = DateTime.Now.ToString();
|
|
|
materialPlanModel.factory = Utils.GetAppSetting("SiteCode");
|
|
|
materialPlanModel.planNo = workorderID;
|
|
|
|
|
|
foreach (var item in bucketList)
|
|
|
{
|
|
|
skuInfo sku = new skuInfo
|
|
|
{
|
|
|
sku = material,
|
|
|
loadNo = item,
|
|
|
unLoadItems = new List<unloadNoInfo>()
|
|
|
};
|
|
|
|
|
|
foreach (var buckt in cxjList)
|
|
|
{
|
|
|
unloadNoInfo unloadNoInfo = new unloadNoInfo
|
|
|
{
|
|
|
unloadNo = buckt
|
|
|
};
|
|
|
sku.unLoadItems.Add(unloadNoInfo);
|
|
|
}
|
|
|
skuInfoList.Add(sku);
|
|
|
}
|
|
|
|
|
|
materialPlanModel.data = skuInfoList;
|
|
|
|
|
|
var jsonContent = JsonConvert.SerializeObject(materialPlanModel);
|
|
|
LogHelper.instance.log.Info("给WCS同步计划>>" + jsonContent);
|
|
|
RestHelper restClient = new RestHelper();
|
|
|
var response =await restClient.PostAsync(apiUrl, jsonContent);
|
|
|
|
|
|
WcsSyncResult result = Utils.DeJson<WcsSyncResult>(response);
|
|
|
|
|
|
if (result.message.ToLower().Equals("ok"))
|
|
|
{
|
|
|
var updatestatus = userDbWareHouse.UpdateSycnFlag(workorderID);
|
|
|
if (!updatestatus)
|
|
|
{
|
|
|
LogHelper.instance.log.Info("更新湿料计划同步状态失败!");
|
|
|
throw new Exception("推送至WCS计划失败!");
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
throw new Exception("开始工单失败!");
|
|
|
}
|
|
|
|
|
|
// Simulate delay
|
|
|
Thread.Sleep(2000);
|
|
|
});
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
CustomMessageBox.Show("同步湿料计划失败!>>>>" + ex.Message, CustomMessageBoxButton.OK, CustomMessageBoxIcon.Warning, 2000);
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
Dispatcher.Invoke(() =>
|
|
|
{
|
|
|
// Hide loading indicator
|
|
|
jindu.Visibility = Visibility.Collapsed;
|
|
|
GetWorkOrder();
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
private void InitShiftInfo()
|
|
|
{
|
|
|
DataTable dt = formingMachineService.GetShiftList();
|
|
|
if (dt == null)
|
|
|
{
|
|
|
CustomMessageBox.Show("没有查询到班次信息,请联系管理员!", CustomMessageBoxIcon.Warning);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
List<ShiftInfoModel> listShift = Utils.ToDataList<ShiftInfoModel>(dt);
|
|
|
ShiftInfoModel shiftInfoModel = new ShiftInfoModel();
|
|
|
shiftInfoModel.shift_desc = "";
|
|
|
shiftInfoModel.shift_id = null;
|
|
|
listShift.Insert(0,shiftInfoModel);
|
|
|
//comboDryRoomInfo.SelectedValuePath = "quipName";
|
|
|
//comboDryRoomInfo.DisplayMemberPath = "quipCode";
|
|
|
//comboDryRoomInfo.ItemsSource = listEquip;
|
|
|
//绑定
|
|
|
comboBoxShift.ItemsSource = listShift;
|
|
|
comboBoxShift.SelectedValuePath = "shift_id";
|
|
|
comboBoxShift.DisplayMemberPath = "shift_desc";
|
|
|
}
|
|
|
|
|
|
private void Flow_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
int index = 0;
|
|
|
Button flowButton = (Button)sender;
|
|
|
DataGridRow row = FindParent<DataGridRow>(flowButton);
|
|
|
|
|
|
if (row != null)
|
|
|
{
|
|
|
// 获取对应行的数据项对象
|
|
|
var rowDataItem = row.Item;
|
|
|
// 获取行号
|
|
|
index = row.GetIndex();
|
|
|
}
|
|
|
|
|
|
var selectedRow = WorkOrder.Items[index] as WetMaterialModel;
|
|
|
var workordercode = selectedRow.workorder_code;
|
|
|
dt = userDbWareHouse.GetFlowInfo(workordercode);
|
|
|
FlowInfoWin flowInfoWin = new FlowInfoWin(dt);
|
|
|
flowInfoWin.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
private void SOP_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
int index = 0;
|
|
|
Button sopButton = (Button)sender;
|
|
|
DataGridRow row = FindParent<DataGridRow>(sopButton);
|
|
|
|
|
|
if (row != null)
|
|
|
{
|
|
|
// 获取对应行的数据项对象
|
|
|
var rowDataItem = row.Item;
|
|
|
// 获取行号
|
|
|
index = row.GetIndex();
|
|
|
}
|
|
|
|
|
|
var selectedRow = WorkOrder.Items[index] as WetMaterialModel;
|
|
|
var processid = selectedRow.processid;
|
|
|
dt = userDbWareHouse.GetSOPInfo(processid);
|
|
|
SopInfoWin sopInfoWin = new SopInfoWin(dt);
|
|
|
sopInfoWin.ShowDialog();
|
|
|
}
|
|
|
|
|
|
private void Material_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
int index = 0;
|
|
|
Button sopButton = (Button)sender;
|
|
|
DataGridRow row = FindParent<DataGridRow>(sopButton);
|
|
|
|
|
|
if (row != null)
|
|
|
{
|
|
|
// 获取对应行的数据项对象
|
|
|
var rowDataItem = row.Item;
|
|
|
// 获取行号
|
|
|
index = row.GetIndex();
|
|
|
}
|
|
|
|
|
|
var selectedRow = WorkOrder.Items[index] as WetMaterialModel;
|
|
|
var processid = selectedRow.workorder_code;
|
|
|
dt = userDbWareHouse.GetMaterialInfo(processid);
|
|
|
LanJu_Material sopInfoWin = new LanJu_Material(dt);
|
|
|
sopInfoWin.ShowDialog();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
private void btnRefresh_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
GetWorkOrder();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 增加序号
|
|
|
/// </summary>
|
|
|
/// <param name="sender"></param>
|
|
|
/// <param name="e"></param>
|
|
|
private void USERLIST_LoadingRow(object sender, DataGridRowEventArgs e)
|
|
|
{
|
|
|
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
|
|
|
}
|
|
|
|
|
|
private void WorkOrder_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
var selectedRow = WorkOrder.SelectedItem as WetMaterialModel;
|
|
|
if (selectedRow == null) return;
|
|
|
var processid = selectedRow.workorder_code;
|
|
|
DataTable dt = userDbWareHouse.GetMaterialInfo(processid);
|
|
|
this.dgMaterialInfo.ItemsSource = dt.DefaultView;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
CustomMessageBox.Show(ex.Message,CustomMessageBoxButton.OK,CustomMessageBoxIcon.Error);
|
|
|
LogHelper.instance.log.Error("获取工单物料信息时发生异常:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void dgMaterialInfo_LoadingRow(object sender, DataGridRowEventArgs e)
|
|
|
{
|
|
|
e.Row.Header = (e.Row.GetIndex() + 1).ToString();
|
|
|
}
|
|
|
|
|
|
private void Button_MouseEnter(object sender, MouseEventArgs e)
|
|
|
{
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|