master
2 years ago
commit 56b0082ae0

@ -343,7 +343,7 @@
</Style>
</ResourceDictionary>
</Window.Resources>
<Grid Background="#172557">
<Grid>
<Grid.RowDefinitions>
@ -394,7 +394,7 @@
></Border>
<TextBox x:Name="lba_ThrifTtitle2" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="-500,-8,0,-100"></TextBox>
<Button Content="搜索" Margin="-100,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="搜索" Margin="-100,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnGetTask_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -404,8 +404,8 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="创建任务" Margin="200,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="创建任务" Margin="200,-8,0,-100" Foreground="White" Height="50" Width="132">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -415,7 +415,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="删除任务" Margin="500,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="删除任务" Margin="500,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnDelTask_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -425,7 +425,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="手动完成" Margin="800,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="手动完成" Margin="800,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnFinishTask_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -641,7 +641,7 @@
></Border>
<TextBox x:Name="lba_ThrifTtitle3" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="-1150,-8,0,-100"></TextBox>
<Button Content="搜索" Margin="-700,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="搜索" Margin="-700,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnGetEquip_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -651,7 +651,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<!-- 订单信息 -->
<Grid Width="1711" Height="1070" HorizontalAlignment="Left">
<Grid.RowDefinitions>
@ -697,7 +697,7 @@
</DataGridTemplateColumn>
<DataGridTextColumn
Width="200*"
Binding="{Binding equipmentNo}"
Binding="{Binding equipNo}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
@ -713,14 +713,7 @@
Header="设备名称"
IsReadOnly="True" />
<DataGridTextColumn
Width="180*"
Binding="{Binding equipType}"
CanUserSort="False"
ElementStyle="{StaticResource dgCell}"
FontSize="20"
Header="设备类型"
IsReadOnly="True" />
<DataGridTextColumn
Width="180*"
Binding="{Binding serverIp}"
@ -823,7 +816,7 @@
></Border>
<TextBox x:Name="lba_ThrifTtitle6" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="-550,-8,0,-100"></TextBox>
<Button Content="搜索" Margin="-100,-8,0,-100" Foreground="White" Height="50" Width="132" Click="Button_Click">
<Button Content="搜索" Margin="-100,-8,0,-100" Foreground="White" Height="50" Width="132" Click="btnGetStocK_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -1029,7 +1022,7 @@
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
<Border
></Border>
<TextBox x:Name="lba_ThrifTtitle" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
<TextBox x:Name="txtEquipNo" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50"
VerticalAlignment="Center"
HorizontalAlignment="Left"
@ -1049,7 +1042,7 @@
Margin="20,0,0,0"/>
<Border></Border>
<TextBox
x:Name="MoHuChaXunWuLiaoName"
x:Name="txtContainNo"
HorizontalAlignment="Center"
VerticalAlignment="Center"
@ -1060,7 +1053,7 @@
VerticalContentAlignment="Center"
Margin="10,0,20,0"
></TextBox>
<Button Content="搜索" Margin="20,15,0,15" Foreground="White" Width="132" Click="Button_Click">
<Button Content="搜索" Margin="20,15,0,15" Foreground="White" Width="132" Click="btnGetWcsCmd_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -1070,7 +1063,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="删除指令" Margin="20,15,0,15" Foreground="White" Width="132" Click="Button_Click">
<Button Content="删除指令" Margin="20,15,0,15" Foreground="White" Width="132" Click="btnDelCmd_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -1080,7 +1073,7 @@
</ControlTemplate>
</Button.Template>
</Button>
<Button Content="重发指令" Margin="20,15,0,15" Foreground="White" Width="132" Click="Button_Click">
<Button Content="重发指令" Margin="20,15,0,15" Foreground="White" Width="132" Click="btnReSendCmd_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
@ -1248,7 +1241,114 @@
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="PLC信息看板" FontSize="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" Width="160" Height="125" Margin="0,92,8,-92" >
<TabItem Header="物料扫描" FontSize="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" Width="160" Height="125" Margin="0,92,8,-92" >
<StackPanel x:Name="splMaterialCode" Height="1060" Width="1920" Background="#213269" Canvas.Left="175" Canvas.Top="110" Orientation="Horizontal" Margin="5,-15,0,0">
<StackPanel Orientation="Horizontal" Width="1750">
<StackPanel Orientation="Vertical" Margin="20,5,0,0">
<StackPanel Orientation="Horizontal" Margin="0" HorizontalAlignment="Left">
<Image
x:Name="img_plcmesssage1"
Width="40"
Height="35"
Margin="60,0,0,0"
Source="..\Resources\chanpintiaoma.png" Visibility="Visible"/>
<Label Content="人工叫料" Foreground="White" FontSize="20" Width="150" Height="40" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</StackPanel>
<Border Background="#213269" BorderBrush="Silver" BorderThickness="2" CornerRadius="10" Width="900" Margin="0,5,0,0">
<StackPanel Margin="0,10,10,10">
<Label
Width="152"
Height="73"
Content="数量 :"
FontSize="25" Margin="0,0,750,-60"
Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
/>
<TextBox x:Name="txtNum" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="0,0,400,0"/>
<Button Content="呼叫料箱" Margin="0,-50,10,0" Foreground="White" Height="50" Width="132" Click="btnCallBox_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
<Border.Background>#346DFF</Border.Background>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" ></ContentPresenter>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</Border>
<StackPanel Orientation="Horizontal" Margin="0">
<Image
x:Name="img_plcmesssage2"
Width="40"
Height="35"
Margin="60,0,0,0"
Source="..\Resources\chanpintiaoma.png" Visibility="Visible"/>
<Label Content="物料扫描" Foreground="White" FontSize="20" Width="150" Height="40" Margin="10,10,80,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</StackPanel>
<Border Background="#213269" BorderBrush="Silver" BorderThickness="2" CornerRadius="10" Width="900" Height="500" Margin="0,5,0,0">
<StackPanel Margin="0,10,10,10">
<Label
Width="152"
Height="73"
Content="业务类型 :"
FontSize="25" Margin="0,0,750,-60"
Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
/>
<ComboBox x:Name="cbxType" Margin="0,0,400,0" Width="180" Height="50" >
<ComboBoxItem Content="入库" />
<ComboBoxItem Content="出库" />
<ComboBoxItem Content="回库" />
</ComboBox>
<Label
Width="152"
Height="73"
Content="料箱 :"
FontSize="25" Margin="0,0,750,-60"
Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
/>
<TextBox x:Name="txtBox" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="0,0,400,0" KeyDown="txtBox_KeyDown"/>
<Label
Width="152"
Height="73"
Content="条码:"
FontSize="25" Margin="0,0,750,-60"
Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
/>
<TextBox x:Name="txtBarCode" Style="{StaticResource XingHaoBianMaYangShi}" IsEnabled="true"
Width="180" Height="50" Margin="0,0,400,0" KeyDown="txtBarCode_KeyDown"/>
<Label
Width="152"
Height="73"
Content="已扫描数量:"
FontSize="25" Margin="0,0,750,-60"
Foreground="White" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
/>
<TextBox x:Name="txtScan" Style="{StaticResource XingHaoBianMaYangShi}" IsReadOnly="True"
Width="180" Height="50" Margin="0,0,400,0" IsEnabled="False"/>
<Button Content="确认" Margin="0,-50,10,0" Foreground="White" Height="50" Width="132" Click="btnConfirmBox_Click">
<Button.Template >
<ControlTemplate TargetType="{x:Type Button}" >
<Border BorderBrush="{TemplateBinding Control.BorderBrush}" BorderThickness="1" CornerRadius="4,4,4,4">
<Border.Background>#346DFF</Border.Background>
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" ></ContentPresenter>
</Border>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
</StackPanel>
</TabItem>
<TabItem Header="PLC信息看板" FontSize="25" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" Width="160" Height="125" Margin="0,112,0,-112" >
<StackPanel x:Name="splPlcMessage" Height="1060" Width="1920" Background="#213269" Canvas.Left="175" Canvas.Top="110" Orientation="Horizontal" Margin="5,-15,0,0">
<StackPanel Orientation="Horizontal" Width="1750">
<StackPanel Orientation="Vertical" Margin="20,5,0,0">
@ -1418,8 +1518,8 @@
</Grid>
</Grid>
</Grid>
</Window>

@ -1,5 +1,6 @@
using Khd.Core.Domain.Models;
using Khd.Core.EntityFramework;
using Khd.Core.Plc.S7.Types;
using Masuit.Tools.Logging;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
@ -22,6 +23,9 @@ using Thrift.Server;
using Thrift.Transport;
using ThriftService;
using Z.EntityFramework.Plus;
using Jc.SnowId;
using Masuit.Tools;
using System.Windows.Input;
namespace Khd.Core.Wpf.Form
{
@ -40,11 +44,17 @@ namespace Khd.Core.Wpf.Form
private int UpState;//对应上件站点的状态,0为良好 1为损坏
List<BasePlcpoint> basePlcpoints = new List<BasePlcpoint>();
object timerjilu;
public class selectOrderData
public class barcodeinfo
{
public string Id { get; set; }
public string orderCode { get; set; }
public string barcode { get; set; }
public long? materialId { get; set; }
public decimal? qty { get; set; }
}
public List<barcodeinfo> barcodeLsit = new List<barcodeinfo>();
private string selectedId;
//FormShowSelect formSelect;
// public static int WeekNo = CommonHelper.WeekOfYear(DateTime.Now, new System.Globalization.CultureInfo("zh-CN"));
@ -62,7 +72,7 @@ namespace Khd.Core.Wpf.Form
{
try
{
LogManager.Info($"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;");
//LogManager.Info($"--------------------------当前时间 :{DateTime.Now} >>> 客户端启动;");
//设置显示任务栏
if (WindowState == WindowState.Normal)
{
@ -115,148 +125,6 @@ namespace Khd.Core.Wpf.Form
}
}
/// <summary>
/// 刷新日期
/// </summary>
private void SetTime()
{
new Thread(() =>
{
while (true)
{
try
{
Dispatcher.Invoke(new Action(delegate
{
LabDate.Content = DateTime.Now.ToString("yyyy年MM月dd日");
LabTime.Content = DateTime.Now.ToString("HH:mm:ss");
}));
}
catch (Exception ex)
{
}
finally
{
Thread.Sleep(1000);
}
}
}).Start();
}
public void UpMessage(object sender, EventArgs e)
{
MoHuChaXunWuLiaoName_SelectionChanged(timerjilu, null);
}
/// <summary>
/// WCS通讯方法
/// </summary>
public void StartThriftServer()
{
try
{
int point = Convert.ToInt32(ThriftConfig.JiesShouDuanKou);
WcsServer wcsServer = new WcsServer();
//wcsServer.SendCarEvent += SendCar;
// wcsServer.helloEvent += hello;
WcsThrift.Processor processor = new WcsThrift.Processor(wcsServer);
TServerTransport serverTransport = new TServerSocket(point);
TServer server = new TSimpleServer(processor, serverTransport);
server.Serve();
}
catch (Exception ex)
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
//设置图片为未到位
}));
LogManager.Error(ex);
}
}
public string hello(string name)
{
//Console.WriteLine($"hello {name}");
//return $"ServerResponse receive from client name:{name}";
try
{
if (!string.IsNullOrWhiteSpace(name))
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
//设置图片为已到位、显示挂具号
}));
}
else
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
}));
}
}
catch (Exception ex)
{
LogManager.Info($"客户端接收服务端推送的小车信息方法报错 >>> {ex.Message}");
}
return "";
}
/// <summary>
/// 发车方法
///
/// </summary>
/// <param name="carlist"></param>
/// <param name="prodCode">物料号</param>
/// <param name="amount">三轮车辆长度</param>
public void SendCar(List<string> carlist, string prodCode, string bunber, string ordercodeid)
{
TTransport transport = new TSocket(ThriftConfig.ThriftIpAddress, ThriftConfig.TuiSongDuankou);
try
{
//Console.WriteLine($"hello carlist[0]:{carlist.FirstOrDefault()}|order_code:{order_code}|amount:{amount}");
//return $"ServerResponse receive from client order_code:{order_code}";
transport.Open();
TProtocol protocol = new TBinaryProtocol(transport);
WcsThrift.Client client = new WcsThrift.Client(protocol);
// var ret = client.SendCar(carlist, prodCode, bunber, ordercodeid);
if ("1" == "1")//与服务端交互成功发车时
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
//发车成功提示反馈
this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Green);
this.lba_ThrifTtitle.Text = "发车成功!";
}));
}
else//与服务端交互失败时
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
this.lba_ThrifTtitle.Foreground = new SolidColorBrush(Colors.Red);
this.lba_ThrifTtitle.Text = $"Thrift交互失败!";
}));
}
}
catch (Exception ex)
{
LogManager.Info($"发车方法报错 >>> {ex.Message}");
}
finally
{
transport.Close();
transport.Dispose();
}
}
/// <summary>
/// 显示序号事件
/// </summary>
/// <param name="sender"></param>
@ -281,132 +149,100 @@ namespace Khd.Core.Wpf.Form
}
public int i = 0;
/// <summary>
/// 电气机柜信息面板定时器调用方法
/// 查询任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void PLCmessage(object sender, EventArgs e)
private void btnGetTask_Click(object sender, RoutedEventArgs e)
{
try
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)
{
if (i == 1000)
{
i = 0;
}
foreach (var item in basePlcpoints)
{
//通过名称找到TextBox
TextBox FoundTextBox = (TextBox)FindName(item.plcpointNo);
if (FoundTextBox == null)
{
continue;
}
string value = i.ToString();
//string value = _plc.Read(item.plcpointAddress).ToString();
//if (value.IsNullOrEmpty())
//{
// continue;
//}
//if (FoundTextBox.IsFocused == true)
//{
// continue;
//}
FoundTextBox.Text = value;
i++;
LogManager.Info(i.ToString());
}
}
catch (Exception ex)
{
LogManager.Info($"电气机柜信息面板定时器调用方法报错 >>> {ex.Message}");
MessageBox.Show("未查询到数据");
}
}
/// <summary>
/// PLC读取方法封装
/// </summary>
/// <param name="plcAddress">plc地址位</param>
/// <param name="plcDataType">plc数据类型(int类型默认为1)</param>
/// <param name="plcValueLength">plc地址位长度(string类型默认为2)</param>
/// <param name="textBoxXcid">载具号文本输入框</param>
/// <param name="textBoxGjdw">载具到位文本输入框</param>
/// <param name="textBoxClzt">PLC车辆状态文本输入框</param>
/// <param name="textBoxXcqx">载具去向文本输入框</param>
/// <param name="textBoxWcsclzt">WCS处理状态文本输入框</param>
private void ReadPlcData(string plcAddress, int plcDataType, string plcValueLength,
TextBox textBoxXcid, TextBox textBoxGjdw, TextBox textBoxClzt,
TextBox textBoxXcqx, TextBox textBoxWcsclzt)
{
try
{
// 载具号
ReadAndSetText(plcAddress, textBoxXcid);
// 载具到位
//DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 0)}";
string gjdw = $"DB4.DBW{GetOffset(plcAddress, 0)}";
ReadAndSetText(gjdw, textBoxGjdw);
// PLC处理状态
//DQXX.plcpointAddress = $"DB4.DBW{GetOffset(plcAddress, 2)}";
string plcclzt = $"DB4.DBW{GetOffset(plcAddress, 2)}";
ReadAndSetText(plcclzt, textBoxClzt);
// 小车去向
//DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 0)}";
string xcqx = $"DB5.DBW{GetOffset(plcAddress, 0)}";
ReadAndSetText(xcqx, textBoxXcqx, textBoxXcqx.IsFocused);
// WCS处理完成
//DQXX.plcpointAddress = $"DB5.DBW{GetOffset(plcAddress, 2)}";
string wcsclzt = $"DB5.DBW{GetOffset(plcAddress, 2)}";
ReadAndSetText(wcsclzt, textBoxWcsclzt, textBoxWcsclzt.IsFocused);
//-------------------------------------------------------------------------以下为方法内部嵌套方法
//嵌套方法1
void ReadAndSetText(string dw, TextBox textBox, bool checkFocus = false)
{
string value = _plc.Read(dw).ToString();
if (value != null && (!checkFocus || !textBox.IsFocused))
{
textBox.Text = value;
}
}
//嵌套方法2
int GetOffset(string PlcAddress, int baseOffset)
{
int result = int.Parse(PlcAddress.Substring(4, 1)) * 4 + baseOffset;
return result;
}
}
catch (Exception ex)
{
LogManager.Info($"PLC读取方法封装报错 >>> {ex.Message}");
}
}
/// <summary>
/// 订单导入按钮点击事件
/// 删除任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_dingdandaoru_Click(object sender, RoutedEventArgs e)
private void btnDelTask_Click(object sender, RoutedEventArgs e)
{
try
if (LoadMaterial0.SelectedIndex == -1)
{
Application.Current.Dispatcher.Invoke(new Action(
delegate
{
// 设置 EPPlus 许可上下文
ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Excel Files|*.xls;*.xlsx";
if (openFileDialog.ShowDialog() == true)
{
FileInfo fileInfo = new FileInfo(openFileDialog.FileName);
MessageBox.Show("请选择要删除的任务!");
}
else
{
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();
}
}
/// <summary>
/// 完成任务
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnFinishTask_Click(object sender, RoutedEventArgs e)
{
if (LoadMaterial0.SelectedIndex == -1)
{
MessageBox.Show("请选择要完成的任务!");
}
else
{
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();
}
}
/// <summary>
/// 查询设备信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetEquip_Click(object sender, RoutedEventArgs e)
{
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)
{
MessageBox.Show("未查询到数据");
}
}
/// <summary>
/// 查询库存信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnGetStocK_Click(object sender, RoutedEventArgs e)
{
using (ExcelPackage package = new ExcelPackage(fileInfo))
{
@ -422,12 +258,12 @@ namespace Khd.Core.Wpf.Form
// 映射数据库字段,这里需要根据你的实际需求进行调整
var columnMappings = new Dictionary<string, string>
{
// 添加映射
{columnHeaders[0],"production_sequence"},
{columnHeaders[1],"line_code"},
{columnHeaders[3],"prod_code"},
{columnHeaders[4],"Quantity"},
{columnHeaders[5],"order_code"}
// 添加映射
{columnHeaders[0],"production_sequence"},
{columnHeaders[1],"line_code"},
{columnHeaders[3],"prod_code"},
{columnHeaders[4],"Quantity"},
{columnHeaders[5],"order_code"}
};
int ordernum = 0;
// 获取实际的行数和列数
@ -486,158 +322,255 @@ namespace Khd.Core.Wpf.Form
}
catch (Exception ex)
{
MessageBox.Show($"订单导入失败 >>> {ex.Message}", "订单导入操作提示!");
LogManager.Info($"按钮订单导入事件报错 >>> {ex.Message}");
MessageBox.Show("未查询到数据");
}
}
/// <summary>
/// 接收到载具号后,清空残留信息
/// 删除指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CarNo_TextChanged(object sender, TextChangedEventArgs e)
private void btnDelCmd_Click(object sender, RoutedEventArgs e)
{
//if (!string.IsNullOrWhiteSpace(this.tBoxMessage.Text) && this.tBoxMessage.Text.Length == 17)
//{
// //清空缓存信息
// this.CarNo.Clear();
// this.tBoxMessage.Clear();
// this.lba_ThrifTtitle.Text = string.Empty;
//}
}
/// <summary>
/// 订单清空按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_ClearOrder_Click(object sender, RoutedEventArgs e)
{
try
if (LoadMaterial.SelectedIndex == -1)
{
var data = this.LoadMaterial.ItemsSource;
if (data == null)
{
MessageBox.Show($"当前订单信息为空,无需清空操作!", "订单手动清空提示!");
return;
}
if (MessageBox.Show("确认是否清空当前预存订单?",
"订单手动清空提示",
MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
string sqlQuery = @"INSERT INTO
base_production_order_split_bak
(id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence)
SELECT
id,site_code, line_code, line_name, order_code,prod_code,prod_desc,IsOver,est,Quantity,production_sequence
FROM base_production_order_split;";
string sqlDelete = @"Delete
FROM
base_production_order_split;";
var ret = dbContext.Database.ExecuteSqlRaw(sqlQuery);
dbContext.Database.ExecuteSqlRaw(sqlDelete);
string zhandianText = ThriftConfig.UpSite == "k46" ? "K46" : "K48";
string saveLog = ret == 0 ? "清空后备份任务SQL执行失败!" : "清空后备份任务SQL语句执行成功!";
if (ret != 0) MessageBox.Show($"{ret}条订单清空完毕!", "订单清空提示!");
LogManager.Info($"手动清空任务日志记录 >>> 站点:{zhandianText}{saveLog}");
this.LoadMaterial.ItemsSource = null;
//LoadMaterial_GetMessage("");
}
}
catch (Exception ex)
{
LogManager.Info($"手动清空任务方法报错 >>> {ex.Message}");
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
//
}
catch (Exception ex)
{
MessageBox.Show("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex);
LogManager.Info("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex);
}
}
/// <summary>
/// 选择事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void MoHuChaXunWuLiaoName_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
timerjilu = sender;
ComboBox comboBox = (ComboBox)sender;
var shangjiandian = comboBox.SelectedItem;
string numberPart = Regex.Match(shangjiandian.ToString(), @"\d+").Value;
try
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
//
}
catch (Exception ex)
{
MessageBox.Show("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex);
LogManager.Info("查询订单遇到错误~>>>>>>>>>>>>>>>>>>>>" + ex);
}
}
/// <summary>
/// 删除物料
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_2(object sender, RoutedEventArgs e)
{
if (LoadMaterial0.SelectedIndex == -1)
{
MessageBox.Show("请选择要删除的物料!");
MessageBox.Show("请选择要删除的指令!");
}
else
{
var quere = MessageBox.Show("确定删除吗", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
//
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();
}
}
/// <summary>
/// 刷新产线
/// 重发指令
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button_Click_3(object sender, RoutedEventArgs e)
private void btnReSendCmd_Click(object sender, RoutedEventArgs e)
{
//
if (LoadMaterial.SelectedIndex == -1)
{
MessageBox.Show("请选择要重发的指令!");
}
else
{
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();
}
}
/// <summary>
/// 物料选择事件
/// 呼叫料箱
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void shangjianwuliaocombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//
}
private void orderselect_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void Button_Click(object sender, RoutedEventArgs e)
private void btnCallBox_Click(object sender, RoutedEventArgs e)
{
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var data = dbContext.WcsTask.Where(t => t.useFlag == 0).ToList();
this.LoadMaterial0.ItemsSource = null;
this.LoadMaterial0.ItemsSource = data;
this.LoadMaterial0.Items.Refresh();
//MessageBox.Show("查询");
if (int.TryParse(txtNum.Text, out int num))
{
//目的地
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();
}
}
else
{
MessageBox.Show("请输入有效的数字");
}
}
/// <summary>
/// 料箱扫描
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
txtBarCode.Focus();
}
}
/// <summary>
/// 条码扫描
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txtBarCode_KeyDown(object sender, KeyEventArgs e)
{
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}个";
}
}
/// <summary>
/// 确认
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnConfirmBox_Click(object sender, RoutedEventArgs e)
{
var box = txtBox.Text;
if (string.IsNullOrEmpty(box))
{
MessageBox.Show("容器号不能为空!");
return;
}
if (barcodeLsit.Count==0)
{
MessageBox.Show("未扫描条码!");
return;
}
using var scope = _host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
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();
}
}
}

@ -1,4 +1,6 @@
namespace Khd.Core.Wpf
using Jc.SnowId;
namespace Khd.Core.Wpf
{
public static class PlcConfig
{
@ -31,4 +33,9 @@
/// </summary>
public static int UpFlagNum { get; set; }
}
public static class Global
{
public static JcSnowId SnowId = new JcSnowId();
}
}

@ -140,6 +140,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.10" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.32.3" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.32.3" />
<PackageReference Include="Jc.SnowId" Version="1.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Khd.Core.Domain\Khd.Core.Domain.csproj" />
@ -472,4 +473,5 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
</Project>

@ -21,13 +21,8 @@ namespace Khd.Core.Wpf
{
InitializeComponent();
this.Hide();
//IHost host = CreateHostBuilder(null).Build();
//_host = host;
//FormBoard mainWindow = new FormBoard(_host);
//mainWindow.Show();
// 通过进程名称查找进程
bool ret;
string upsite = ThriftConfig.UpSite == "k48" ? "K48" : "K46";
System.Threading.Mutex mutex = new System.Threading.Mutex(true, $"Khd.Core.Wpf", out ret);
if (ret)
{
@ -79,8 +74,6 @@ namespace Khd.Core.Wpf
Host.CreateDefaultBuilder(args)
.ConfigureServices((_, services) =>
{
//services.AddDbContext<DefaultDbContext>(options =>
// options.UseSqlServer(ConnectionStrings.ConnectionString));
services.AddDbContext<DefaultDbContext>(options =>
options.UseMySql(ConnectionStrings.ConnectionString, new MySqlServerVersion(new Version(8, 0, 31))));
});

@ -4,8 +4,7 @@
//"DefaultConnection": "server=106.12.13.113;port=3306;database=khd_jyhb;uid=root;pwd=root;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
//khd
"DefaultConnection": "server=106.12.13.113;port=3336;database=khd_jyhb;uid=khd;pwd=khd@123;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
//
//"DefaultConnection": "server=localhost;port=3306;database=khd_suspension_chain;uid=root;pwd=123456;charset='utf8';persistsecurityinfo=True;SslMode=none;Allow User Variables=True"
},
"PlcConfig": {
"IP": "127.0.0.1",

Loading…
Cancel
Save