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.

268 lines
10 KiB
C#

2 years ago
using CentralControl.DBDAO;
2 years ago
using CommonFunc;
2 years ago
using CommonFunc.Tools;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
2 years ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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;
2 years ago
using XGL.Models.Model.OrderPrepare;
2 years ago
using XGL.Thrift;
namespace XGL.Views
{
/// <summary>
/// LanJu_Prepare.xaml 的交互逻辑
/// </summary>
public partial class LanJu_Prepare : UserControl
{
public LanJu_Prepare()
{
InitializeComponent();
2 years ago
}
2 years ago
List<WorkOrder> modelWareHouse = new List<WorkOrder>();
DBService userDbWareHouse = new DBService();
WorkOrder list_modelWareHouse = new WorkOrder();
2 years ago
2 years ago
List<WetMaterialModel> wetList = new List<WetMaterialModel>();
WetMaterialModel wet = new WetMaterialModel();
string messageOrderCode = "";
2 years ago
DataTable dt;
2 years ago
/// <summary>
/// <summary>
/// 获取主页显示订单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GetWorkOrder()
{
try
{
2 years ago
//modelWareHouse = new List<WorkOrder>();
//userDbWareHouse = new DBService();
2 years ago
dt = userDbWareHouse.GetWetPlanInfo();
if (dt == null) return;
2 years ago
foreach (DataRow i in dt.Rows)
2 years ago
{
2 years ago
wet.id = i["id"].ToString();
wet.workorder_id = i["workorder_id"].ToString();
wet.product_name = i["product_name"].ToString();
2 years ago
wet.material_code = i["material_code"].ToString();
2 years ago
wet.material_name = i["material_name"].ToString();
2 years ago
wet.plan_time = Convert.ToDateTime(i["plan_time"].ToString());
wet.bucket_code = i["bucket_code"].ToString();
wet.shift_desc = i["shift_desc"].ToString();
2 years ago
wet.prod_line_code = i["prod_line_code"].ToString();
2 years ago
wet.status = i["status"].ToString();
wet.sync_flag = i["sync_flag"].ToString();
2 years ago
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);
2 years ago
}
2 years ago
this.WorkOrder.ItemsSource = wetList;
2 years ago
}
catch (Exception ex)
{
2 years ago
LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message);
2 years ago
}
}
2 years ago
2 years ago
private void Flow_Click(object sender, RoutedEventArgs e)
{
2 years ago
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 WorkOrder;
2 years ago
var workordercode = selectedRow.WorkOrderCode;
2 years ago
dt = userDbWareHouse.GetFlowInfo(workordercode);
}
private T FindParent<T>(DependencyObject child) where T : DependencyObject
{
DependencyObject parent = VisualTreeHelper.GetParent(child);
if (parent is T)
{
return (T)parent;
}
2 years ago
if (parent != null)
{
return FindParent<T>(parent);
}
return null;
2 years ago
}
2 years ago
2 years ago
2 years ago
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
GetWorkOrder();
}
private void btnStartOrders_Click(object sender, RoutedEventArgs e)
{
2 years ago
CheckUserWin checkUserWin = new CheckUserWin();
checkUserWin.ShowDialog();
if (!checkUserWin.loginFlag)
{
CustomMessageBox.Show("请先校验用户!", CustomMessageBoxIcon.Warning);
return;
}
2 years ago
if (WorkOrder.SelectedItems.Count == 0)
{
CustomMessageBox.Show("请选择要开始的工单!", CustomMessageBoxIcon.Warning);
return;
}
string orderID = (WorkOrder.SelectedItem as WetMaterialModel).id;
2 years ago
string workorderID = (WorkOrder.SelectedItem as WetMaterialModel).workorder_id;
string material = (WorkOrder.SelectedItem as WetMaterialModel).material_code;
2 years ago
string sync_flag = (WorkOrder.SelectedItem as WetMaterialModel).sync_flag;
string status = (WorkOrder.SelectedItem as WetMaterialModel).status;
2 years ago
if (sync_flag.Equals("Y"))
2 years ago
{
CustomMessageBox.Show("该工单已同步,请选择其他的工单!", CustomMessageBoxIcon.Warning);
return;
}
2 years ago
if (!status.Equals("w1"))
2 years ago
{
2 years ago
if (status != "")
{
CustomMessageBox.Show("该工单不符合条件,请选择其他的工单!", CustomMessageBoxIcon.Warning);
return;
}
2 years ago
}
2 years ago
//获取WMS齐套率湿料计划先不用
//var wmsState = userDbWareHouse.GetWorkOrderQitaoLv(orderID);
//if (wmsState == null || wmsState.Rows[0][0].Equals("0"))
//{
// CustomMessageBox.Show("该工单未准备好,请稍后再试!", CustomMessageBoxIcon.Warning);
// return;
//}
//获取湿料计划指定的成型机
var cxjDt = userDbWareHouse.GetCXJList(orderID);
if (cxjDt == null || cxjDt.Rows.Count == 0)
{
2 years ago
CustomMessageBox.Show("该工单未指定料罐、成型机,请稍后再试!", CustomMessageBoxIcon.Warning);
return;
}
List<string> cxjList = new List<string>();
List<string> bucketList = new List<string>();
2 years ago
//这扯淡的设计,根据湿料计划获取各个工单对应的工序、机台信息,这样式的,[["GX01","C1"],["GX01","C5"],["GX01","C3"],["GX01","C6"],["GX01","C8"],["GX02","H2"],["GX02","H3"],["GX02","H4"],["GX02","H5"],["GX02","H6"],["GX03","X3"],["GX03","X6"]]
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);
// 解析JSON字符串为嵌套的列表结构
List<List<string>> data = JsonConvert.DeserializeObject<List<List<string>>>(jsonStrCXJList);
// 输出嵌套列表的值
foreach (var innerList in data)
{
2 years ago
if (innerList[1].Contains("C"))
{
//记录成型机列表
cxjList.Add(innerList[1]);
}
2 years ago
}
}
cxjList = cxjList.Distinct().ToList();//去重
2 years ago
bucketList = bucketList.Distinct().ToList();
//var jsonObject = JsonConvert.DeserializeObject(jsonStrCXJList);
2 years ago
2 years ago
string apiUrl = "http://192.168.202.28:9001/api/v1/ReceiveMesMsg/materialPlanSync";
2 years ago
2 years ago
2 years ago
MaterialPlanModel materialPlanModel = new MaterialPlanModel();
2 years ago
2 years ago
List<WetMaterialModel> listWetMaterial = Utils.ToDataList<WetMaterialModel>(dt);
2 years ago
List<skuInfo> skuInfoList = new List<skuInfo>();
2 years ago
materialPlanModel.reqCode = CommonFunc.Common.GetUUID();
materialPlanModel.reqTime = DateTime.Now.ToString();
materialPlanModel.factory = Utils.GetAppSetting("SiteCode");
2 years ago
materialPlanModel.planNo = orderID;
foreach (var item in cxjList)
{
2 years ago
skuInfo sku = new skuInfo();
sku.sku = material;
sku.loadNo = item;
2 years ago
2 years ago
List<unloadNoInfo> unloadNoInfoList = new List<unloadNoInfo>();
foreach (var buckt in bucketList)
{
2 years ago
unloadNoInfo unloadNoInfo = new unloadNoInfo();
unloadNoInfo.unloadNo = buckt;
unloadNoInfoList.Add(unloadNoInfo);
}
sku.unLoadItems = unloadNoInfoList;
skuInfoList.Add(sku);
}
materialPlanModel.data = skuInfoList;
// 将要发送的数据序列化为JSON格式
var jsonContent = JsonConvert.SerializeObject(materialPlanModel);
2 years ago
2 years ago
RestHelper restClient = new RestHelper();
var response = restClient.PostAsync(apiUrl, jsonContent);
2 years ago
Console.WriteLine(response);
2 years ago
//更新湿料计划同步状态
2 years ago
var updatestatus = userDbWareHouse.UpdateSycnFlag(orderID, workorderID);
2 years ago
if (!updatestatus)
LogHelper.instance.log.Info("更新湿料计划同步状态失败!");
2 years ago
}
2 years ago
private void SOP_Click(object sender, RoutedEventArgs e)
{
}
private void Material_Click(object sender, RoutedEventArgs e)
{
}
2 years ago
}
}