liulb@mesnac.com 1 year ago
commit 6b05cce2d2

@ -14,6 +14,6 @@ namespace Admin.Core.IService
/// <summary>
/// 查出BASE_MATERIALINFO中存在的成品类型
/// </summary>
public Task<List<BaseMaterialInfo>> queryAsync(string search);
public Task<List<BaseMaterialInfo>> queryAsyncLike(string search);
}
}

@ -27,9 +27,9 @@ namespace Admin.Core.Service
}
/// <summary>
/// 1.查出BASE_MATERIALINFO中存在的成品类型
/// 1.条件查询使用,查出BASE_MATERIALINFO中存在的成品类型
/// </summary>
public async Task<List<BaseMaterialInfo>> queryAsync(string search)
public async Task<List<BaseMaterialInfo>> queryAsyncLike(string search)
{
List<BaseMaterialInfo> list;
if (!string.IsNullOrEmpty(search))

@ -0,0 +1,302 @@
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Model.Model_New;
using Admin.Core.Service;
using Aucma.Core.PLc;
using Aucma.Core.ProductOffLine;
using log4net;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Aucma.Core.ProductOffLine.Business
{
/// <summary>
/// 入库业务逻辑
/// </summary>
public class OffLineBusiness
{
#region 单例实现
private static readonly OffLineBusiness lazy = new OffLineBusiness();
public static OffLineBusiness Instance
{
get
{
return lazy;
}
}
#endregion
#region 接口引用
private static readonly log4net.ILog log = LogManager.GetLogger(typeof(OffLineBusiness));
private readonly IBaseOrderInfoServices _baseOrderInfoServices;
private readonly IProductPlanInfoServices? _productPlanInfoServices;
private readonly IProductOffLineServices? _productOffLineServices;
#endregion
#region 委托事件
/// <summary>
/// 扫码信息刷新
/// </summary>
/// <param name="materialCode"></param>
/// <param name="materialName"></param>
/// <param name="spaceName"></param>
/// <param name="materialType"></param>
public delegate void RefreshScanMateriaCode(string materialCode, string materialName, string spaceName, string materialType);
public event RefreshScanMateriaCode RefreshScanMateriaCodeEvent;
#endregion
#region 变量定义
/// <summary>
/// 定时器
/// </summary>
System.Timers.Timer timer = new System.Timers.Timer(1000);
#endregion
public OffLineBusiness()
{
}
public void test()
{
}
/// <summary>
/// 扫描的条码处理
/// </summary>
/// <param name="code"></param>
/// <param name="direction">扫码器方向</param>
private async void ReceiveCode(string code, int scannerNo)
{
//1.扫描的SN条码去条码系统查询GET_BARCODE_DATA 返回校验数据
// string result = await _productOffLineServices.QueryChecked(code);
string result = "Y@1104@16160030000000910780@000010034895@@ @000000@000000009000000807@BCD-160C,家电下乡@@BCD-160C@皓月白-家电下乡@161601300@160@1-00版@家电下乡产品@默认@2010-09-01";
// 如果校验失败,下发报警
if ("N".Equals(result.Substring(0, 1)))
{
sendPlcError();
// 刷新页面提示信息 result.Substring(2)
return;
}
//2.查询到的数据分割处理,结果中用"@"号分隔刷新页面显示并存到scada数据库(表待建)
string[] resultArray = result.Split('@');
// 输出结果
foreach (string item in resultArray)
{
Console.WriteLine(item);
}
//3.分垛A,B库逻辑(先左边读到的条码分A库右边读到的B库==>预留分库逻辑)
//4.下发plc信号
bool flag = SendPlcPass(scannerNo);
if (!flag)
{
log.Error("获取plc反馈失败");
return;
}
Console.WriteLine(code);
return;
//5.调条码系统保存入库接口SaveBarcodeInfo
string saveResult = await _productOffLineServices.SaveBarcodeInfo("333", "ILS_SORT", "11111", 1);
if (string.IsNullOrEmpty(saveResult) || "E".Equals(saveResult.Substring(0, 1)))
{
log.Error("条码系统保存接口出错");
sendPlcError();
return;
}
//6.更新mes数据库完成数量和时间(BASE_ORDERINFO,PRODUCT_PLANINFO) 注意:查询的字段可能需要修改,确保数据一致
//6.1截取订单号去查询更新BASE_ORDERINFO,全放到service处理
string orderCode = "11215484";
List<BaseOrderInfo> orders = await _baseOrderInfoServices.QueryAsync(x => x.OrderCode == orderCode);
BaseOrderInfo order = orders.FirstOrDefault();
if (order.CompleteAmount == 0)
{
order.CompleteAmount++;
order.BeginDate = DateTime.Now;
}
if (order.CompleteAmount == order.OrderAmount)
{
order.EndDate = DateTime.Now;
}
order.UpdatedTime = DateTime.Now;
_baseOrderInfoServices.UpdateAsync(order);
//6.2根据订单号去更新PRODUCT_PLANINFO
List<ProductPlanInfo> productInfos = await _productPlanInfoServices.QueryAsync(x => x.OrderCode == orderCode);
ProductPlanInfo productInfo = productInfos.FirstOrDefault();
if (productInfo.CompleteAmount == 0)
{
productInfo.CompleteAmount++;
productInfo.BeginTime = DateTime.Now;
}
if (productInfo.CompleteAmount == productInfo.PlanAmount)
{
productInfo.EndTime = DateTime.Now;
}
productInfo.UpdatedTime = DateTime.Now;
await _productPlanInfoServices.UpdateAsync(productInfo);
}
#region plc交互
private SemaphoreSlim semaphore = new SemaphoreSlim(0);
/// <summary>
/// 下发plc放行信号,根据接收到的scannerNo不同两条道的plc信号地址也不同
/// </summary>
/// <param name="materialType"></param>
private bool SendPlcPass(int scannerNo)
{
bool result = false;
try
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null)
{
if (obj.plc.IsConnected)
{
if (scannerNo == 1)
{
// 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D100", scannerNo);
// 往plc写入放行信号
obj.plc.WriteInt32("D102", 1);
}
else
{
// 写入入库方向两条道plc地址不同
obj.plc.WriteInt32("D200", scannerNo);
// 往plc写入放行信号
obj.plc.WriteInt32("D202", 1);
}
// 等待plc反馈信号
waitPlcSignal(scannerNo);
// semaphore.Wait();
result = true;
}
else
{
log.Info("成品下线plc连接失败请检查plc连接");
}
}
else
{
log.Info("获取plc连接对象信息为空");
}
}
catch (Exception ex)
{
log.Error("下发plc放行信号方法SendPlcPass()出现异常,ex:" + ex);
}
return result;
}
/// <summary>
/// 读取plc放行反馈
/// </summary>
/// <param name="materialType"></param>
private void waitPlcSignal(int scannerNo)
{
try
{
bool isFlag = true;
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null && obj.plc.IsConnected)
{
do
{
if (scannerNo == 1)
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D102") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D100", 0);
obj.plc.WriteInt32("D102", 0);
isFlag = false;
}
}
else
{
// 读取plc反馈信号
if (obj.plc.ReadInt32("D202") == 2)
{
Console.WriteLine("收到plc放行成功");
// 清空数据
obj.plc.WriteInt32("D200", 0);
obj.plc.WriteInt32("D202", 0);
isFlag = false;
}
}
Thread.Sleep(1000);
} while (isFlag);
// 释放信号量
//semaphore.Release();
}
else
{
log.Info("成品下线plc连接失败");
}
}
catch (Exception ex)
{
log.Error("读取plc放行反馈方法waitPlcSignal()出现异常,ex:" + ex);
}
}
/// <summary>
/// 下发plc报警信号
/// </summary>
private void sendPlcError()
{
try
{
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("成品下线Plc"));
if (obj != null)
{
if (obj.plc.IsConnected)
{
// 下发报警信号
obj.plc.WriteInt32("D104", 1);
}
else
{
log.Info("成品下线plc连接失败请检查plc连接");
}
}
else
{
log.Info("获取plc连接对象信息为空");
}
}
catch (Exception ex)
{
log.Error("下发plc放报警信号方法sendPlcError()出现异常,ex:" + ex);
}
}
#endregion
}
}

@ -2,6 +2,7 @@
using Admin.Core.Model;
using Admin.Core.Service;
using Aucma.Core.ProductOffLine.Models;
using Aucma.Core.ProductOffLine.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
@ -21,12 +22,14 @@ namespace Aucma.Core.ProductOffLine.ViewModels
public partial class DirectionEditViewModel : ObservableObject
{
public ICommand QueryCommand { get; set; }
public RelayCommand<object> MouseClickCommand { get; set; }
public ICommand SaveCommand { get; set; }
private readonly IBaseMaterialInfoServices? _baseMaterialInfoServices;
public DirectionEditViewModel() {
_baseMaterialInfoServices = App.ServiceProvider.GetService<IBaseMaterialInfoServices>();
QueryCommand = new RelayCommand(ExecuteQuery);
MouseClickCommand = new RelayCommand<object>(MouseClick);
SaveCommand = new RelayCommand(ExecuteSave);
Init();
}
@ -43,7 +46,7 @@ namespace Aucma.Core.ProductOffLine.ViewModels
{
MaterialDataGrid.Clear();
// 处理查询按钮点击事件
List<BaseMaterialInfo> materialInfoList = await _baseMaterialInfoServices.queryAsync(Search);
List<BaseMaterialInfo> materialInfoList = await _baseMaterialInfoServices.queryAsyncLike(Search);
int count = 0;
Application.Current.Dispatcher.Invoke(() =>
{
@ -53,6 +56,17 @@ namespace Aucma.Core.ProductOffLine.ViewModels
}
});
}
public void MouseClick(object obj)
{
var info = SelectedDataItem as DirectionEditModel;
if (info != null)
{
DirectionItemWindow quantityIssuedWindow = new DirectionItemWindow(info);
quantityIssuedWindow.ShowDialog();
}
}
private async void ExecuteSave()
{
@ -95,6 +109,17 @@ namespace Aucma.Core.ProductOffLine.ViewModels
}
}
private DirectionEditModel selectedDataItem;
public DirectionEditModel SelectedDataItem
{
get { return selectedDataItem; }
set
{
selectedDataItem = value;
OnPropertyChanged();
}
}
#region 初始化datagrid
private ObservableCollection<DirectionEditModel> materialDataGrid = new ObservableCollection<DirectionEditModel>();
public ObservableCollection<DirectionEditModel> MaterialDataGrid

@ -0,0 +1,128 @@
using Admin.Core.IService;
using Admin.Core.Model;
using Admin.Core.Service;
using Aucma.Core.ProductOffLine.Models;
using Aucma.Core.ProductOffLine.Views;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using NPOI.SS.Formula.Functions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Input;
namespace Aucma.Core.ProductOffLine.ViewModels
{
public partial class DirectionItemViewModel : ObservableObject
{
public RelayCommand<object> CloseWindowCommand { get; set; }
public RelayCommand SaveCommand { get; set; }
private readonly IBaseMaterialInfoServices? _baseMaterialInfoServices;
public DirectionItemViewModel(DirectionEditModel info) {
_baseMaterialInfoServices = App.ServiceProvider.GetService<IBaseMaterialInfoServices>();
CloseWindowCommand = new RelayCommand<object>(t => CloseWindow(t));
SaveCommand = new RelayCommand(updateDirection);
PlanInfo = info;
if("A".Equals(info.SpaceCode)){
IsSelectedOptionA = true;
}
else
{
IsSelectedOptionB = true;
}
}
private DirectionEditModel planInfo = new DirectionEditModel();
public DirectionEditModel PlanInfo
{
get { return planInfo; }
set {
planInfo = value;
OnPropertyChanged(nameof(PlanInfo));
}
}
#region 单选框
private bool _isSelectedOptionA;
public bool IsSelectedOptionA
{
get { return _isSelectedOptionA; }
set
{
if (_isSelectedOptionA != value)
{
_isSelectedOptionA = value;
OnPropertyChanged(nameof(IsSelectedOptionA));
// 如果选择了A选项将B选项设为false
if (_isSelectedOptionA)
{
IsSelectedOptionB = false;
}
}
}
}
private bool _isSelectedOptionB;
public bool IsSelectedOptionB
{
get { return _isSelectedOptionB; }
set
{
if (_isSelectedOptionB != value)
{
_isSelectedOptionB = value;
OnPropertyChanged(nameof(IsSelectedOptionB));
// 如果选择了B选项将A选项设为false
if (_isSelectedOptionB)
{
IsSelectedOptionA = false;
}
}
}
}
#endregion 关闭窗口
private void CloseWindow(object parameter)
{
var window = parameter as Window;
if (window != null)
{
window.Close();
}
}
private async void updateDirection()
{
BaseMaterialInfo info = await _baseMaterialInfoServices.FirstAsync(x=>x.ObjId==PlanInfo.ObjId);
if (IsSelectedOptionA)
{
info.InboundDirection = "A";
}
else
{
info.InboundDirection = "B";
}
bool result = await _baseMaterialInfoServices.UpdateAsync(info);
if (result)
{
MessageBox.Show(info.MaterialName+"入库方向修改成功");
}
}
}
}

@ -29,6 +29,7 @@ using Admin.Core.IRepository;
using Admin.Core.Service;
using System.Windows.Forms.VisualStyles;
using Microsoft.IdentityModel.Logging;
using Aucma.Core.ProductOffLine.Business;
/*
*
@ -43,9 +44,14 @@ namespace Aucma.Core.ProductOffLine.ViewModels
private readonly IProductPlanInfoServices? _productPlanInfoServices;
private readonly IProductOffLineServices ? _productOffLineServices;
System.Timers.Timer timer = new System.Timers.Timer(1000);
private OffLineBusiness offLineBusiness = OffLineBusiness.Instance;
int a = 0;
public IndexPageViewModel()
{
offLineBusiness.test();
_productOffLineServices = App.ServiceProvider.GetService<IProductOffLineServices>();
_baseOrderInfoServices = App.ServiceProvider.GetService<IBaseOrderInfoServices>();
_productPlanInfoServices = App.ServiceProvider.GetService<IProductPlanInfoServices>();
@ -450,7 +456,6 @@ namespace Aucma.Core.ProductOffLine.ViewModels
{
log.Info("成品下线plc连接失败");
}
}
catch (Exception ex)
{

@ -50,9 +50,9 @@
</DataGrid.CellStyle>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding No}" Header="序号" Width="1*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="产品编" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding MaterialCode}" Header="产品编" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding MaterialName}" Header="产品型号" Width="2*" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding SpaceCode}" Header="入库方向" Width="*"/>
<DataGridTextColumn Binding="{Binding SpaceCode}" Header="入库方向" Width="*" IsReadOnly="True" />
</DataGrid.Columns>
</DataGrid>
</Border>

@ -9,15 +9,16 @@ namespace Aucma.Core.ProductOffLine.Views
/// </summary>
public partial class DirectionEditView : Window
{
private DirectionEditViewModel directionEditViewModel = new DirectionEditViewModel();
public DirectionEditView()
{
InitializeComponent();
this.DataContext = new DirectionEditViewModel();
this.DataContext = directionEditViewModel;
}
private void dataGrid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
// planInfoEditViewModel.MouseClick(sender);
directionEditViewModel.MouseClick(sender);
}

@ -0,0 +1,94 @@
<Window x:Class="Aucma.Core.ProductOffLine.Views.DirectionItemWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Aucma.Core.ProductOffLine.Views"
mc:Ignorable="d"
Title="选择方向" Height="500" Width="500" Name="window" Background="White"
ResizeMode="NoResize" Topmost="True">
<Border Margin="5" Background="#1254AB" CornerRadius="10">
<Border.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.3" Direction="0"></DropShadowEffect>
</Border.Effect>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0" BorderBrush="#1254AB" BorderThickness="3" CornerRadius="5" Background="Transparent" Margin="5,5">
<Border.Effect>
<DropShadowEffect Color="#1254AB" Direction="270" BlurRadius="10" ShadowDepth="5" Opacity="0.5"/>
</Border.Effect>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Center" Margin="50,0,0,0">
<TextBlock Text="序 号:" FontSize="20" Foreground="#FFFFFF" Margin="10,0,0,0"/>
<TextBox x:Name="No" FontSize="20" Text="{Binding PlanInfo.No}" Foreground="#FFFFFF" Width="50" IsReadOnly="True" Margin="5,0,10,0"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Center" Margin="50,0,0,0">
<TextBlock Text="产品编码:" FontSize="20" Foreground="#FFFFFF" Margin="10,0,0,0"/>
<TextBox x:Name="MaterialCode" FontSize="20" Text="{Binding PlanInfo.MaterialCode}" Foreground="#FFFFFF" Width="260" IsReadOnly="True" Margin="5,0,10,0"/>
</StackPanel>
<StackPanel Grid.Row="2" Orientation="Horizontal" VerticalAlignment="Center" Margin="50,0,0,0">
<TextBlock Text="产品型号:" FontSize="20" Foreground="#FFFFFF" Margin="10,0,0,0"/>
<TextBox x:Name="MaterialName" FontSize="20" Text="{Binding PlanInfo.MaterialName}" Foreground="#FFFFFF" Width="260" IsReadOnly="True" Margin="5,0,10,0"/>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal" VerticalAlignment="Center" Margin="60,0,0,0" >
<!--样式-->
<StackPanel.Resources>
<Style TargetType="RadioButton">
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="20"/>
<Setter Property="Background" Value="White"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="RadioButton">
<BulletDecorator Background="Transparent">
<BulletDecorator.Bullet>
<Grid Width="20" Height="20">
<Ellipse x:Name="BulletRadio" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1"/>
</Grid>
</BulletDecorator.Bullet>
<ContentPresenter Margin="4,0,0,0" VerticalAlignment="Center" RecognizesAccessKey="True"/>
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter TargetName="BulletRadio" Property="Fill" Value="Green"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Background" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<TextBlock Text="入库方向: " FontSize="20" Foreground="#FFFFFF" />
<RadioButton Content="A" GroupName="Direction" IsChecked="{Binding IsSelectedOptionA, Mode=TwoWay}" />
<RadioButton Content="B" GroupName="Direction" IsChecked="{Binding IsSelectedOptionB, Mode=TwoWay}" Margin="10 0 0 0"/>
</StackPanel>
<StackPanel Grid.Row="4" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button Content="保 存" FontSize="20" Command="{Binding SaveCommand}" Background="#FF36B5C1" BorderBrush="#FF36B5C1" Foreground="white" Margin="0,0,10,0" Height="50" Width="100" />
<Button Content="取 消" FontSize="20" Command="{Binding CloseWindowCommand}" CommandParameter="{Binding ElementName=window}" Background="#FF9900" Foreground="white" Margin="10,0,0,0" Height="50" BorderBrush="#FF9900" Width="100" />
</StackPanel>
</Grid>
</Border>
</Grid>
</Border>
</Window>

@ -0,0 +1,33 @@
using Admin.Core.Model;
using Aucma.Core.ProductOffLine.Models;
using Aucma.Core.ProductOffLine.ViewModels;
using System;
using System.Collections.Generic;
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.Shapes;
namespace Aucma.Core.ProductOffLine.Views
{
/// <summary>
/// DirectionItemWindow.xaml 的交互逻辑
/// </summary>
public partial class DirectionItemWindow : Window
{
private DirectionItemViewModel viewModel = null;
public DirectionItemWindow(DirectionEditModel info)
{
InitializeComponent();
this.DataContext = new DirectionItemViewModel(info);
}
}
}
Loading…
Cancel
Save