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.

267 lines
9.9 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 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.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;
using XGL.Models.Model.OrderPrepare;
using XGL.Thrift;
namespace XGL.Views
{
/// <summary>
/// LanJu_Prepare.xaml 的交互逻辑
/// </summary>
public partial class LanJu_Prepare : UserControl
{
public LanJu_Prepare()
{
InitializeComponent();
}
List<WorkOrder> modelWareHouse = new List<WorkOrder>();
DBService userDbWareHouse = new DBService();
WorkOrder list_modelWareHouse = new WorkOrder();
List<WetMaterialModel> wetList = new List<WetMaterialModel>();
WetMaterialModel wet = new WetMaterialModel();
string messageOrderCode = "";
DataTable dt;
/// <summary>
/// <summary>
/// 获取主页显示订单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void GetWorkOrder()
{
try
{
//modelWareHouse = new List<WorkOrder>();
//userDbWareHouse = new DBService();
dt = userDbWareHouse.GetWetPlanInfo();
if (dt == null) return;
foreach (DataRow i in dt.Rows)
{
wet.id = i["id"].ToString();
wet.workorder_id = i["workorder_id"].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();
wet.status = i["status"].ToString();
wet.sync_flag = i["sync_flag"].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);
}
this.WorkOrder.ItemsSource = wetList;
}
catch (Exception ex)
{
LogHelper.instance.log.Error("获取工单准备信息时发生异常:" + ex.Message);
}
}
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 WorkOrder;
var workordercode = selectedRow.WorkOrderCode;
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;
}
if (parent != null)
{
return FindParent<T>(parent);
}
return null;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
GetWorkOrder();
}
private void btnStartOrders_Click(object sender, RoutedEventArgs e)
{
CheckUserWin checkUserWin = new CheckUserWin();
checkUserWin.ShowDialog();
if (!checkUserWin.loginFlag)
{
CustomMessageBox.Show("请先校验用户!", CustomMessageBoxIcon.Warning);
return;
}
if (WorkOrder.SelectedItems.Count == 0)
{
CustomMessageBox.Show("请选择要开始的工单!", 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("该工单已同步,请选择其他的工单!", CustomMessageBoxIcon.Warning);
return;
}
if (!status.Equals("w1"))
{
if (status != "")
{
CustomMessageBox.Show("该工单不符合条件,请选择其他的工单!", CustomMessageBoxIcon.Warning);
return;
}
}
//获取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)
{
CustomMessageBox.Show("该工单未指定料罐、成型机,请稍后再试!", CustomMessageBoxIcon.Warning);
return;
}
List<string> cxjList = new List<string>();
List<string> bucketList = new List<string>();
//这扯淡的设计,根据湿料计划获取各个工单对应的工序、机台信息,这样式的,[["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)
{
if (innerList[1].Contains("C"))
{
//记录成型机列表
cxjList.Add(innerList[1]);
}
}
}
cxjList = cxjList.Distinct().ToList();//去重
bucketList = bucketList.Distinct().ToList();
//var jsonObject = JsonConvert.DeserializeObject(jsonStrCXJList);
string apiUrl = "http://192.168.202.28:9001/api/v1/ReceiveMesMsg/materialPlanSync";
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.planNo = orderID;
foreach (var item in cxjList)
{
skuInfo sku = new skuInfo();
sku.sku = material;
sku.loadNo = item;
List<unloadNoInfo> unloadNoInfoList = new List<unloadNoInfo>();
foreach (var buckt in bucketList)
{
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);
RestHelper restClient = new RestHelper();
var response = restClient.PostAsync(apiUrl, jsonContent);
Console.WriteLine(response);
//更新湿料计划同步状态
var updatestatus = userDbWareHouse.UpdateSycnFlag(orderID, workorderID);
if (!updatestatus)
LogHelper.instance.log.Info("更新湿料计划同步状态失败!");
}
private void SOP_Click(object sender, RoutedEventArgs e)
{
}
private void Material_Click(object sender, RoutedEventArgs e)
{
}
}
}