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.

578 lines
24 KiB
C#

2 years ago
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
2 years ago
using Khd.Core.Plc.S7.Types;
2 years ago
using Masuit.Tools.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Win32;
using OfficeOpenXml;
using System;
2 years ago
using System.Collections.Generic;
using System.Data;
2 years ago
using System.IO;
2 years ago
using System.Linq;
2 years ago
using System.Text.RegularExpressions;
2 years ago
using System.Threading;
2 years ago
using System.Windows;
2 years ago
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
2 years ago
using Thrift.Protocol;
2 years ago
using Thrift.Server;
using Thrift.Transport;
using ThriftService;
using Z.EntityFramework.Plus;
2 years ago
using Jc.SnowId;
using Masuit.Tools;
using System.Windows.Input;
2 years ago
namespace Khd.Core.Wpf.Form
{
/// <summary>
/// FormBoardT.xaml 的交互逻辑
/// </summary>
public partial class FormBoardT : Window
{
private readonly IHost _host;
private Khd.Core.Plc.S7.Plc _plc;
private DispatcherTimer ShowTimer;//刷新时间
private DispatcherTimer PLCMessage;//呈现PLC机柜信息
private DispatcherTimer UPMessageTimer;//刷新上件记录
private DispatcherTimer ShowOrderMessage;//呈现PLC机柜信息
private object order_code;
private int UpState;//对应上件站点的状态,0为良好 1为损坏
List<BasePlcpoint> basePlcpoints = new List<BasePlcpoint>();
object timerjilu;
2 years ago
public class barcodeinfo
2 years ago
{
2 years ago
public string barcode { get; set; }
public long? materialId { get; set; }
public decimal? qty { get; set; }
2 years ago
}
2 years ago
public List<barcodeinfo> barcodeLsit = new List<barcodeinfo>();
2 years ago
private string selectedId;
//FormShowSelect formSelect;
// public static int WeekNo = CommonHelper.WeekOfYear(DateTime.Now, new System.Globalization.CultureInfo("zh-CN"));
public FormBoardT(IHost host)
{
InitializeComponent();
this._host = host;
}
/// <summary>
/// 页面加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FormBoard_Loaded(object sender, RoutedEventArgs e)
{
try
{
2 years ago
//LogManager.Info($"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;");
2 years ago
//设置显示任务栏
if (WindowState == WindowState.Normal)
{
MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
WindowState = WindowState.Maximized;
}
//加载dategrid信息
//LoadMaterial_GetMessage("");
//连接PLC判断
2 years ago
// var plc = new Khd.Core.Plc.S7.Plc((CpuType)PlcConfig.CpuType, PlcConfig.IP, PlcConfig.Port,
// PlcConfig.Rack, PlcConfig.Slot);
// //plc.Open();
// //if (!plc.IsConnected)
// //{
// // MessageBox.Show("PLC连接失败,重新连接");
// //}
// //else
// //{
// // this._plc = plc;
// //}
// using var scope = _host.Services.CreateScope();
// using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
// basePlcpoints = dbContext.BasePlcpoint.Where(t => t.isDelete == 0).ToList();
// //var baseMaterials = dbContext.BaseMaterial.Where(t => t.IsDelete == 0).ToList();
////
// PLCMessage = new DispatcherTimer();
// PLCMessage.Tick += new EventHandler(PLCmessage); //委托获取点位方法
// PLCMessage.Interval = new TimeSpan(0, 0, 0, 0, 1000);
// PLCMessage.Start();
// UPMessageTimer = new DispatcherTimer();
// UPMessageTimer.Tick += new EventHandler(UpMessage); //委托刷新上件记录
// UPMessageTimer.Interval = new TimeSpan(0, 0, 0, 0, 2000);
// UPMessageTimer.Start();
// Button_Click_1(null, null);
// SetTime();
// List<string> list = new List<string>
// {
// "101上件点",
// "102上件点",
// "103上件点"
// };
2 years ago
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// 显示序号事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgData_LoadingRow(object sender, DataGridRowEventArgs e)
{ e.Row.Header = e.Row.GetIndex() + 1; }
/// <summary>
/// 点击退出按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExit_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否确认关闭程序", "提示信息", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
{
System.Environment.Exit(System.Environment.ExitCode);
}
}
private void Close(object sender, EventArgs e)
{
System.Environment.Exit(System.Environment.ExitCode);
}
public int i = 0;
/// <summary>
2 years ago
/// 查询任务
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnGetTask_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
GetTask();
}
private void GetTask()
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var equipCode = lba_ThrifTtitle1.Text;
var palletNo = lba_ThrifTtitle2.Text;
var data = dbContext.WcsTask.Where(t => t.useFlag == 1 && t.containerNo.Contains(palletNo) && t.equipmentNo.Contains(equipCode)).ToList();
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = data;
this.LoadMaterial0.Items.Refresh();
if (data.Count == 0)
2 years ago
{
2 years ago
MessageBox.Show("未查询到数据");
2 years ago
}
}
/// <summary>
2 years ago
/// 删除任务
2 years ago
/// </summary>
2 years ago
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnDelTask_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
if (LoadMaterial0.SelectedIndex == -1)
2 years ago
{
2 years ago
MessageBox.Show("请选择要删除的任务!");
2 years ago
}
2 years ago
else
2 years ago
{
2 years ago
var Currentselected = LoadMaterial0.SelectedItem as WcsTask;
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
Currentselected.useFlag = 0;
dbContext.WcsTask.Update(Currentselected);
dbContext.SaveChanges();
GetTask();
2 years ago
}
}
/// <summary>
2 years ago
/// 完成任务
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnFinishTask_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
if (LoadMaterial0.SelectedIndex == -1)
2 years ago
{
2 years ago
MessageBox.Show("请选择要完成的任务!");
2 years ago
}
2 years ago
else
2 years ago
{
2 years ago
var Currentselected = LoadMaterial0.SelectedItem as WcsTask;
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
Currentselected.taskStatus = 5;
dbContext.WcsTask.Update(Currentselected);
dbContext.SaveChanges();
GetTask();
2 years ago
}
}
/// <summary>
2 years ago
/// 查询设备信息
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnGetEquip_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var equipCode = lba_ThrifTtitle3.Text;
var data = dbContext.BaseEquip.Where(t => t.useFlag == 1 && t.equipNo.Contains(equipCode)).ToList();
this.LoadMaterial3.ItemsSource = null;
this.LoadMaterial3.ItemsSource = data;
this.LoadMaterial3.Items.Refresh();
if (data.Count == 0)
2 years ago
{
2 years ago
MessageBox.Show("未查询到数据");
}
2 years ago
}
/// <summary>
2 years ago
/// 查询库存信息
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnGetStocK_Click(object sender, RoutedEventArgs e)
2 years ago
{
using (ExcelPackage package = new ExcelPackage(fileInfo))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();
if (worksheet != null)
{
// 获取 Excel 表头
var columnHeaders = worksheet.Cells[1, 1, 1, worksheet.Dimension.End.Column]
.Select(cell => cell.Text)
.ToList();
BaseProductionOrderSplit orderMoedel = new();
// 映射数据库字段,这里需要根据你的实际需求进行调整
var columnMappings = new Dictionary<string, string>
{
2 years ago
// 添加映射
{columnHeaders[0],"production_sequence"},
{columnHeaders[1],"line_code"},
{columnHeaders[3],"prod_code"},
{columnHeaders[4],"Quantity"},
{columnHeaders[5],"order_code"}
2 years ago
};
int ordernum = 0;
// 获取实际的行数和列数
int rowCount = worksheet.Dimension.Rows;
int colCount = worksheet.Dimension.Columns;
// 遍历 Excel 数据行
for (int row = 2; row <= rowCount; row++)
{
// 创建 SQL 插入语句
//string insertCommand = $"INSERT INTO YourTableName ({string.Join(", ", columnMappings.Values)}) VALUES (";
List<string> values = new();
// 遍历 Excel 数据列
for (int col = 1; col <= colCount; col++)
{
string columnName = columnHeaders[col - 1];
string databaseColumnName;
// 映射 Excel 列名到数据库列名
if (columnMappings.TryGetValue(columnName, out databaseColumnName))
{
// 获取 Excel 单元格的值
var cellValue = worksheet.Cells[row, col].Text;
// 添加值到插入语句
values.Add(cellValue);
//values.Add($"'{cellValue.Replace("'", "''")}'");
//if (!string.IsNullOrWhiteSpace(cellValue))
//{
// values.Add(cellValue);
//}
}
}
// 使用 LINQ 查询空值
bool containsNull = values.Any(item => item == "" || item == null);
if (containsNull)
{
//MessageBox.Show("Excel表格中存在空值,不执行导入操作!", "订单导入操作提示!");
//LogManager.Info($"订单导入按钮事件错误 >>> Excel表格中存在空值!不执行导入操作!");
break;
}
// 获得插入语句
//string fullInsertCommand = $"{insertCommand} {string.Join(", ", values)} )";
var xianbiename = Char.GetNumericValue(values[1][values[1].Length - 1]).ToString();
int orderSequence = int.Parse(values[0].Trim());
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
2 years ago
// var orderModel = dbContext.BaseProductionOrderSplit.OrderBy(t => t.productionSequence).ToList();
///var data = orderModel.Find(t => t.orderCode == values[4].Trim().ToUpper());
//
2 years ago
}
MessageBox.Show($"{ordernum}条订单导入系统!", "订单导入操作提示!");
//LoadMaterial_GetMessage("");
}
}
}
}));
}
catch (Exception ex)
{
2 years ago
MessageBox.Show("未查询到数据");
2 years ago
}
}
/// <summary>
2 years ago
/// 删除指令
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnDelCmd_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
if (LoadMaterial.SelectedIndex == -1)
2 years ago
{
2 years ago
MessageBox.Show("请选择要删除的指令!");
2 years ago
}
2 years ago
else
2 years ago
{
2 years ago
var Currentselected = LoadMaterial.SelectedItem as WcsCmd;
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
Currentselected.useFlag = 0;
dbContext.WcsCmd.Update(Currentselected);
dbContext.SaveChanges();
GetWcsCmd();
2 years ago
}
}
/// <summary>
2 years ago
/// 重发指令
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnReSendCmd_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
if (LoadMaterial.SelectedIndex == -1)
2 years ago
{
2 years ago
MessageBox.Show("请选择要重发的指令!");
2 years ago
}
2 years ago
else
2 years ago
{
2 years ago
var Currentselected = LoadMaterial.SelectedItem as WcsCmd;
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
Currentselected.sendFlag = 0;
dbContext.WcsCmd.Update(Currentselected);
dbContext.SaveChanges();
GetWcsCmd();
2 years ago
}
}
/// <summary>
2 years ago
/// 呼叫料箱
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnCallBox_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
if (int.TryParse(txtNum.Text, out int num))
2 years ago
{
2 years ago
//目的地
var endEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault();
//所有辅料库位
var wmsBaseLocation = dbContext.WmsBaseLocation.Where(t=> t.warehouseId== 5).ToList(); //五楼辅料库
//有库存的库位
var wmsStock = dbContext.WcsStock.Where(t => t.useFlag == 1).Select(t=>t.locationCode).ToList();
var EmptyBox = wmsBaseLocation.Where(t => !t.locationCode.Contains(wmsStock)).ToList();
for (int i = 0; i < num; i++)
{
var wcsTask = new WcsTask()
{
objid = Global.SnowId.NextId(),
startPointId = EmptyBox[i].locationId,
startPointNo = EmptyBox[i].agvPositionCode,
currPointId = EmptyBox[i].locationId,
currPointNo = EmptyBox[i].agvPositionCode,
nextPointId = endEquip.objid,
nextPointNo = endEquip.equipNo,
endPointId = endEquip.objid,
endPointNo = endEquip.equipNo,
taskType = 13,
taskStatus = 0,
floorNo = 5,
containerNo = EmptyBox[i].containerCode,
equipmentNo = endEquip.equipNo,
createBy = "5楼呼叫料箱任务",
createTime = System.DateTime.Now,
};
dbContext.Add(wcsTask);
dbContext.SaveChanges();
}
2 years ago
}
else
{
2 years ago
MessageBox.Show("请输入有效的数字");
}
2 years ago
}
2 years ago
2 years ago
/// <summary>
2 years ago
/// 料箱扫描
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void txtBox_KeyDown(object sender, KeyEventArgs e)
2 years ago
{
2 years ago
if (e.Key == Key.Enter)
2 years ago
{
2 years ago
txtBarCode.Focus();
2 years ago
}
}
/// <summary>
2 years ago
/// 条码扫描
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
2 years ago
{
2 years ago
if (e.Key == Key.Enter)
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var mesInfo = dbContext.MesBaseBarcodeInfo.Where(t => t.barcodeInfo == txtBarCode.Text).FirstOrDefault();
if (mesInfo == null)
{
MessageBox.Show("请扫描正确的条码");
return;
}
barcodeinfo barcodeinfo = new barcodeinfo();
barcodeinfo.barcode=txtBarCode.Text;
barcodeinfo.materialId = mesInfo.materialId;
barcodeinfo.qty = mesInfo.amount;
barcodeLsit.Add(barcodeinfo);
txtBarCode.SelectAll();
txtBarCode.Focus();
txtScan.Text = $"已扫描{barcodeLsit.Count}个";
}
2 years ago
}
/// <summary>
2 years ago
/// 确认
2 years ago
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
2 years ago
private void btnConfirmBox_Click(object sender, RoutedEventArgs e)
2 years ago
{
2 years ago
var box = txtBox.Text;
if (string.IsNullOrEmpty(box))
{
MessageBox.Show("容器号不能为空!");
return;
}
if (barcodeLsit.Count==0)
{
MessageBox.Show("未扫描条码!");
return;
}
2 years ago
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
2 years ago
if (cbxType.Text == "入库")
{
//写入wms_raw_instock
var wmsRawInstock = new WmsRawInstock()
{
rawInstockId = Global.SnowId.NextId(),
warehouseId = 5,
operationType = "3",
instockType = "9",
materialId = barcodeLsit.FirstOrDefault().materialId,
palletInfoCode = txtBox.Text,
instockAmount = barcodeLsit.Sum(t=>t.qty),
executeStatus="0",
applyBy="扫描入库",
applyDate=System.DateTime.Now
};
dbContext.WmsRawInstock.Add(wmsRawInstock);
dbContext.SaveChanges();
var startEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault();
var warehouse = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == 5).FirstOrDefault();
//写入wcs任务
var wcsTask = new WcsTask()
{
objid = Global.SnowId.NextId(),
startPointId = startEquip.objid,
startPointNo = startEquip.agvPositionCode,
currPointId = startEquip.objid,
currPointNo = startEquip.agvPositionCode,
nextPointId = warehouse.warehouseId,
nextPointNo = warehouse.warehouseCode,
endPointId = warehouse.warehouseId,
endPointNo = warehouse.warehouseCode,
taskType = 4,
taskStatus = 0,
floorNo = 5,
containerNo = txtBox.Text,
equipmentNo = startEquip.equipNo,
createBy = "5楼入库任务",
createTime = System.DateTime.Now,
};
dbContext.Add(wcsTask);
dbContext.SaveChanges();
}
if (cbxType.Text == "出库")
{
//从料箱里拿出来
}
if (cbxType.Text == "回库")
{
//写入wms_raw_instock
var wmsRawInstock = new WmsRawInstock()
{
rawInstockId = Global.SnowId.NextId(),
warehouseId = 5,
operationType = "3",
instockType = "9",
materialId = barcodeLsit.FirstOrDefault().materialId,
palletInfoCode = txtBox.Text,
instockAmount = barcodeLsit.Sum(t => t.qty),
executeStatus = "0",
applyBy = "扫描回库",
applyDate = System.DateTime.Now
};
dbContext.WmsRawInstock.Add(wmsRawInstock);
dbContext.SaveChanges();
var startEquip = dbContext.BaseEquip.Where(t => t.equipNo == "FL05").FirstOrDefault();
var warehouse = dbContext.WmsBaseWarehouse.Where(t => t.warehouseId == 5).FirstOrDefault();
//写入wcs任务
var wcsTask = new WcsTask()
{
objid = Global.SnowId.NextId(),
startPointId = startEquip.objid,
startPointNo = startEquip.agvPositionCode,
currPointId = startEquip.objid,
currPointNo = startEquip.agvPositionCode,
nextPointId = warehouse.warehouseId,
nextPointNo = warehouse.warehouseCode,
endPointId = warehouse.warehouseId,
endPointNo = warehouse.warehouseCode,
taskType = 4,
taskStatus = 0,
floorNo = 5,
containerNo = txtBox.Text,
equipmentNo = startEquip.equipNo,
createBy = "5楼回库任务",
createTime = System.DateTime.Now,
};
dbContext.Add(wcsTask);
dbContext.SaveChanges();
}
2 years ago
}
2 years ago
2 years ago
}
}