master
2 years ago
parent 32ffabfb0a
commit edbf474e05

File diff suppressed because it is too large Load Diff

@ -109,10 +109,95 @@ namespace Khd.Core.Wcs.Wcs
//}; //};
//CallEmptyThread.Start(); //CallEmptyThread.Start();
Thread equipStatusThread = new Thread(EquipStatusLogic)
{
IsBackground = true
};
equipStatusThread.Start();
Console.WriteLine(DateTime.Now + ":一楼提升机线程启动成功"); Console.WriteLine(DateTime.Now + ":一楼提升机线程启动成功");
LogManager.Info("一楼提升机线程启动成功"); LogManager.Info("一楼提升机线程启动成功");
} }
private void EquipStatusLogic(object? obj)
{
using var scope = this._host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
while (true)
{
try
{
for (int i = 1; i <= 5; i++)
{
BasePlcpoint basePlcpoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == $"linesignal0{i}");
var lineSignal = StaticData.PlcDic[0].Read(basePlcpoint.plcpointAddress);
if (lineSignal != null)
{
if (Convert.ToInt32(lineSignal) == 1)
{
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == i);
if (baseEquip.equipStatus != 1)
{
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
else
{
bool hasTask = dbContext.WcsTask.Where(t => t.endPointId == i || t.currPointId == i).Any();
if (!hasTask)
{
baseEquip.equipStatus = 0;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
}
}
else
{
BaseEquip baseEquip = dbContext.BaseEquip.First(t => t.objid == i);
bool hasTask = dbContext.WcsTask.Where(t => t.endPointId == i || t.currPointId == i).Any();
if (!hasTask)
{
baseEquip.equipStatus = 0;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
else
{
baseEquip.equipStatus = 1;
dbContext.Update(baseEquip);
dbContext.SaveChanges();
}
}
}
}
}
catch (Exception ex)
{
if (ex is PlcException)
{
try
{
foreach (var item in StaticData.PlcDic)
{
if (item.Value.IP == ex.Message)
{
StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
StaticData.PlcDic[item.Key].Open();
}
}
}
catch
{
}
}
LogManager.Error(ex);
}
}
}
private void CallEmpty() private void CallEmpty()
{ {
using var scope = _host.Services.CreateScope(); using var scope = _host.Services.CreateScope();
@ -160,9 +245,27 @@ namespace Khd.Core.Wcs.Wcs
} }
} }
} }
catch catch (Exception ex)
{ {
if (ex is PlcException)
{
try
{
foreach (var item in StaticData.PlcDic)
{
if (item.Value.IP == ex.Message)
{
StaticData.PlcDic[item.Key] = new Plc.S7.Plc(item.Value.CPU, item.Value.IP, item.Value.Port, item.Value.Rack, item.Value.Slot);
StaticData.PlcDic[item.Key].Open();
}
}
}
catch
{
}
}
LogManager.Error(ex);
} }
Thread.Sleep(1000); Thread.Sleep(1000);
} }
@ -297,16 +400,46 @@ namespace Khd.Core.Wcs.Wcs
{ {
if (string.IsNullOrEmpty(task.containerNo)) if (string.IsNullOrEmpty(task.containerNo))
{ {
if (task.qty > 1)//多个托盘 if (task.useFlag == 1)
{ {
if (task.useFlag == 1) if (task.qty > 1)//多个托盘
{ {
if (task.endPointId != 1)
{
task.nextPointId = 6;
dbContext.SaveChanges();
}
}
else if (task.qty == 1)
{
if (task.endPointId != 1)
{
task.nextPointId = 6;
task.containerNo = RFID001Value;
dbContext.SaveChanges();
}
} }
} }
else if (task.qty == 1) }
else
{
MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == RFID001Value);
if (mesBasePalletInfo != null)
{ {
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createBy = null;
mesBasePalletInfo.bindAmount = null;
mesBasePalletInfo.createTime = null;
mesBasePalletInfo.materialBarcode = null;
mesBasePalletInfo.materialCode = null;
mesBasePalletInfo.materialId = null;
mesBasePalletInfo.materialName = null;
mesBasePalletInfo.updateBy = "WCS";
mesBasePalletInfo.updateTime = DateTime.Now;
dbContext.Update(mesBasePalletInfo);
dbContext.Remove(task);
dbContext.WcsTaskLog.Where(t => t.objid == task.objid).Update(t => new WcsTaskLog { taskStatus = 6 });
dbContext.SaveChanges();
} }
} }
} }
@ -377,7 +510,7 @@ namespace Khd.Core.Wcs.Wcs
continue; continue;
} }
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo); BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress)) if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress) || (string.IsNullOrEmpty(wcsTask.containerNo) && wcsTask.qty > 1))
{ {
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo) if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)
{ {
@ -413,7 +546,7 @@ namespace Khd.Core.Wcs.Wcs
if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo) if (wcsTask.taskStatus == 1 && Convert.ToInt32(reserialno06) == wcsTask.serialNo)
{ {
BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo); BasePlcpoint floorPoint = StaticData.BasePlcpointList.First(t => t.plcpointNo == "RFID00" + wcsTask.fromFloorNo);
if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress)) if (wcsTask.containerNo == this._plc.ReadRFID(floorPoint.plcpointAddress) || (string.IsNullOrEmpty(wcsTask.containerNo)&&wcsTask.qty>1))
{ {
if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层 if (Convert.ToInt32(currentfloor06Value) == wcsTask.fromFloorNo)//提升机当前楼层为初始地楼层
{ {

@ -827,20 +827,35 @@ namespace Khd.Core.Wcs.Wcs
} }
else if (item.taskType == 42) else if (item.taskType == 42)
{ {
BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35); MesBasePalletInfo? mesBasePalletInfo = dbContext.MesBasePalletInfo.FirstOrDefault(t => t.palletInfoCode == item.containerNo);
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.objid == 31); if (mesBasePalletInfo != null)
endEquip.emptyCount = 0; {
dbContext.Update(endEquip); mesBasePalletInfo.bindAmount = null;
emptyEquip.emptyCount += 1; mesBasePalletInfo.createBy = null;
emptyEquip.equipStatus = 1; mesBasePalletInfo.bindAmount = null;
emptyEquip.updateTime = DateTime.Now; mesBasePalletInfo.createTime = null;
emptyEquip.updateBy = "WCS"; mesBasePalletInfo.materialBarcode = null;
dbContext.Update(emptyEquip); mesBasePalletInfo.materialCode = null;
dbContext.Remove(wcsCmd); mesBasePalletInfo.materialId = null;
dbContext.Remove(item); mesBasePalletInfo.materialName = null;
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 }); mesBasePalletInfo.updateBy = "WCS";
dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 }); mesBasePalletInfo.updateTime=DateTime.Now;
dbContext.SaveChanges(); dbContext.Update(mesBasePalletInfo);
BaseEquip emptyEquip = dbContext.BaseEquip.First(t => t.objid == 35);
BaseEquip endEquip = dbContext.BaseEquip.First(t => t.objid == 31);
endEquip.emptyCount = 0;
dbContext.Update(endEquip);
emptyEquip.emptyCount += 1;
emptyEquip.equipStatus = 1;
emptyEquip.updateTime = DateTime.Now;
emptyEquip.updateBy = "WCS";
dbContext.Update(emptyEquip);
dbContext.Remove(wcsCmd);
dbContext.Remove(item);
dbContext.WcsTaskLog.Where(t => t.objid == item.objid).Update(t => new WcsTaskLog { taskStatus = 6 });
dbContext.WcsCmdLog.Where(t => t.objid == wcsCmd.objid).Update(t => new WcsCmdLog { cmdStatus = 6 });
dbContext.SaveChanges();
}
} }
else if (item.taskType == 43) else if (item.taskType == 43)
{ {

@ -11,7 +11,7 @@
WindowStyle="None" WindowStyle="None"
Loaded="Window_Loaded" Loaded="Window_Loaded"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
Height="450" Width="800"> Height="600" Width="800">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" /> <RowDefinition Height="*" />
@ -54,19 +54,37 @@
<Border BorderBrush="White" Grid.Column="1" BorderThickness="2" CornerRadius="5" Padding="10"> <Border BorderBrush="White" Grid.Column="1" BorderThickness="2" CornerRadius="5" Padding="10">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="*" /> <RowDefinition Height="*" />
<RowDefinition Height="6*" /> <RowDefinition Height="6*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock Text="该物料新库存信息" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/> <TextBlock Text="该物料新库存信息" FontSize="24" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="1">
<TextBox x:Name="NewBarCode" Width="250" FontSize="20" hc:InfoElement.Placeholder="请扫描条码" Style="{StaticResource TextBoxExtend}" /> <TextBox x:Name="NewBarCode" LostFocus="NewBarCode_LostFocus" Width="250" FontSize="20" hc:InfoElement.Placeholder="请扫描条码" Style="{StaticResource TextBoxExtend}" />
<RepeatButton x:Name="ScanButton" Content="添加" Style="{StaticResource RepeatButtonPrimary}" Width="100" Margin="20,0,0,0" Click="ScanButton_Click" /> <RepeatButton x:Name="ScanButton" Content="添加" Style="{StaticResource RepeatButtonPrimary}" Width="100" Margin="20,0,0,0" Click="ScanButton_Click" />
</StackPanel> </StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="2" Margin="0,20,0,0"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Grid.Row="2">
<GroupBox Height="200" Header="条码" Padding="10"> <TextBlock Text="数量:" FontSize="16" Foreground="White" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="20,0,0,0"/>
<TextBox x:Name="NewCount" Width="200" FontSize="20" hc:InfoElement.Placeholder="请输入数量" Style="{StaticResource TextBoxExtend}" />
</StackPanel>
<StackPanel Orientation="Vertical" Grid.Row="3" Margin="0,10,0,0">
<GroupBox Height="250" Header="确认" Padding="10">
<Border Background="{DynamicResource RegionBrush}" CornerRadius="4"> <Border Background="{DynamicResource RegionBrush}" CornerRadius="4">
<TextBlock x:Name="BarCodeList" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/> <Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="4*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="条码" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock Text="数量" Grid.Column="1" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock x:Name="BarCodeList" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock x:Name="CountList" Grid.Column="1" Grid.Row="1" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Border> </Border>
</GroupBox> </GroupBox>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,20,0,0"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="0,20,0,0">

@ -20,6 +20,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
private readonly string _materialName; private readonly string _materialName;
private readonly InventoryTaskForm _inventoryTaskForm; private readonly InventoryTaskForm _inventoryTaskForm;
private readonly string _locationCode; private readonly string _locationCode;
private Dictionary<string, string> _barCodeList;
public InventoryTaskEditForm(Microsoft.Extensions.Hosting.IHost _host, long materialId, string containerNo, string materialName, string locationCode, InventoryTaskForm inventoryTaskForm) public InventoryTaskEditForm(Microsoft.Extensions.Hosting.IHost _host, long materialId, string containerNo, string materialName, string locationCode, InventoryTaskForm inventoryTaskForm)
{ {
InitializeComponent(); InitializeComponent();
@ -29,6 +30,7 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
this._materialName = materialName; this._materialName = materialName;
this._inventoryTaskForm = inventoryTaskForm; this._inventoryTaskForm = inventoryTaskForm;
this._locationCode = locationCode; this._locationCode = locationCode;
_barCodeList = new Dictionary<string, string>();
} }
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
@ -77,7 +79,35 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text); var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text);
if (mesBaseBarcodeInfo != null) if (mesBaseBarcodeInfo != null)
{ {
try
{
_barCodeList.Add(mesBaseBarcodeInfo.barcodeInfo, this.NewCount.Text);
this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n";
this.CountList.Text += this.NewCount.Text + "\n";
this.NewBarCode.Text = "";
}
catch
{
MessageBoxResult messageBoxResult = MessageBox.Show("该条码已经添加过,是否更新该条码?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
if (messageBoxResult == MessageBoxResult.OK)
{
string[] barCodes = this.BarCodeList.Text.Split('\n');
string[] counts = this.CountList.Text.Split('\n');
for (int i = 0; i < barCodes.Length; i++)
{
if (this.BarCodeList.Text == barCodes[i])
{
counts[i] = this.NewCount.Text;
this.CountList.Text = string.Join("\n", counts);
this.BarCodeList.Text = string.Join("\n", barCodes);
this._barCodeList[mesBaseBarcodeInfo.barcodeInfo] = this.NewCount.Text;
break;
}
}
}
}
this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n"; this.BarCodeList.Text += mesBaseBarcodeInfo.barcodeInfo + "\n";
this.CountList.Text += this.NewCount.Text + "\n";
this.NewBarCode.Text = ""; this.NewBarCode.Text = "";
} }
else else
@ -94,9 +124,9 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
private void SaveButton_Click(object sender, RoutedEventArgs e) private void SaveButton_Click(object sender, RoutedEventArgs e)
{ {
List<string> newList = this.BarCodeList.Text.Split('\n').Distinct().ToList(); List<string> newList = this.BarCodeList.Text.Split('\n').ToList();
List<string> list = this.BarCode.Text.Split('\n').ToList(); List<string> list = this.BarCode.Text.Split('\n').ToList();
StringBuilder addStr = new StringBuilder(); StringBuilder addStr = new();
List<string> addList = newList.Where(t => !list.Contains(t)).ToList(); List<string> addList = newList.Where(t => !list.Contains(t)).ToList();
if (addList.Count > 0) if (addList.Count > 0)
{ {
@ -209,5 +239,29 @@ namespace Khd.Core.Wpf.TaskForm.Inventory
} }
this.Close(); this.Close();
} }
private void NewBarCode_LostFocus(object sender, RoutedEventArgs e)
{
try
{
using var scope = this._host.Services.CreateScope();
using var dbContext = scope.ServiceProvider.GetRequiredService<DefaultDbContext>();
var mesBaseBarcodeInfo = dbContext.MesBaseBarcodeInfo.FirstOrDefault(t => t.barcodeInfo == this.NewBarCode.Text);
if (mesBaseBarcodeInfo != null)
{
this.NewCount.Text = mesBaseBarcodeInfo.batchFlag == "1" ? mesBaseBarcodeInfo.amount.ToString() : "1";
}
else
{
MessageBox.Show("条码不存在,请重新扫码");
this.NewBarCode.Text = "";
}
}
catch
{
}
}
} }
} }

Loading…
Cancel
Save