change - 货道信息设置箱型并下发至PLC

dev
wenjy 1 year ago
parent 1f0d917cc3
commit 9e7210f6b3

@ -24,6 +24,9 @@ using System.Windows.Documents;
using static Npgsql.Replication.PgOutput.Messages.RelationMessage;
using System.Windows.Media;
using log4net;
using System.Windows.Forms;
using Aucma.Core.HwPLc;
using Aucma.Core.PLc;
namespace Aucma.Core.OldBoxFoam.ViewModels
{
@ -267,6 +270,7 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
ListItems.Add(new OldBoxFoamTypeModel()
{
ObjId = spaceInfoLeft[i].ObjId,
SpaceName = $"{i + 1}#货道",
Local = spaceInfo.Local,
Status = spaceInfoLeft[i].StoreAmount == 3 ? "1" : "0",
@ -293,6 +297,7 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
ListItems.Add(new OldBoxFoamTypeModel()
{
ObjId = spaceInfoRight[i].ObjId,
SpaceName = $"{i + 1}#货道",
Local = spaceInfo.Local,
Status = spaceInfoRight[i].StoreAmount == 3 ? "1" : "0",
@ -437,5 +442,92 @@ namespace Aucma.Core.OldBoxFoam.ViewModels
}
}
private OldBoxFoamTypeModel selectedDataItem;
public OldBoxFoamTypeModel SelectedDataItem
{
get => selectedDataItem;
set => SetProperty(ref selectedDataItem, value);
}
/// <summary>
/// 设置夹具箱型
/// </summary>
/// <param name="obj"></param>
public void MouseClick(object obj)
{
var info = SelectedDataItem as OldBoxFoamTypeModel;
if (info != null)
{
SetBoxTypeView setBoxTypeView = new SetBoxTypeView(info.Boxtype);
setBoxTypeView.ShowDialog();
if(setBoxTypeView.boxTypeResult != info.Boxtype)
{
if (!string.IsNullOrEmpty(setBoxTypeView.boxTypeResult))
{
HwPLc.PlcModel plc = null;
//下发给PLC
var address = GetSpaceBoxTypeAddress(Convert.ToInt32(info.ObjId));
if (info.ObjId <= 4)
{
plc = HwPLc.PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc1"));
}
else
{
plc = HwPLc.PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("OldMelsecPlc3"));
}
if(plc != null)
{
bool isFlag = plc.plc.WriteInt16(address, setBoxTypeView.boxTypeResult);
if (isFlag)
{
System.Windows.MessageBox.Show("货道型号设置成功");
}
else
{
System.Windows.MessageBox.Show("货道型号设置失败");
}
}
}
}
}
}
private string GetSpaceBoxTypeAddress(int spaceCode)
{
string address = string.Empty;
switch(spaceCode)
{
case 1:
address = "D2010";
break;
case 2:
address = "D2020";
break;
case 3:
address = "D2030";
break;
case 4:
address = "D2040";
break;
case 5:
address = "D2010";
break;
case 6:
address = "D2020";
break;
case 7:
address = "D2030";
break;
case 8:
address = "D2040";
break;
}
return address;
}
}
}

@ -226,8 +226,9 @@
RowHeight="50" AutoGenerateColumns="False" RowHeaderWidth="0"
GridLinesVisibility="None" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto" BorderThickness="0" CanUserAddRows="False" SelectionMode="Single" IsReadOnly="True"
Foreground="White">
Foreground="White" SelectedItem="{Binding SelectedDataItem}" MouseLeftButtonDown="dgvMH_MouseLeftButtonDown_1">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ObjId}" Header="序号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding Local}" Header="位置" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTextColumn Binding="{Binding SpaceName}" Header="货道号" Width="1*" ElementStyle="{StaticResource DataGridTextColumnCenterSytle}"/>
<DataGridTemplateColumn Width="*" Header="状态">

@ -22,10 +22,17 @@ namespace Aucma.Core.OldBoxFoam.Views
/// </summary>
public partial class RealRoadPageView : UserControl
{
private RealRoadPageViewModel realRoadPageView = null;
public RealRoadPageView()
{
InitializeComponent();
this.DataContext = new RealRoadPageViewModel();
realRoadPageView = new RealRoadPageViewModel();
this.DataContext = realRoadPageView;
}
private void dgvMH_MouseLeftButtonDown_1(object sender, MouseButtonEventArgs e)
{
realRoadPageView.MouseClick(sender);
}
}
}

@ -0,0 +1,80 @@
<Window x:Class="Aucma.Core.OldBoxFoam.Views.SetBoxTypeView"
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.OldBoxFoam.Views"
mc:Ignorable="d"
Background="#1152AC"
Title="箱型设置" FontFamily="Microsoft YaHei" Height="300" Width="500"
d:DesignHeight="200" WindowStartupLocation="CenterScreen"
d:DesignWidth="400" ResizeMode="NoResize" Topmost="True" >
<Window.Resources>
<Style x:Key="CustomTextBoxStyle" TargetType="TextBox">
<Setter Property="BorderThickness" Value="1" />
<Setter Property="BorderBrush" Value="#CCCCCC" />
<Setter Property="Background" Value="#F2F2F2" />
<Setter Property="Padding" Value="5" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Foreground" Value="#333333" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="Margin" Value="5" />
<Setter Property="MinWidth" Value="120" />
<Setter Property="MinHeight" Value="30" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<ScrollViewer x:Name="PART_ContentHost" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value="0.5" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<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.RowDefinitions>
<RowDefinition Height="6*"/>
<RowDefinition Height="2*"/>
</Grid.RowDefinitions>
<Border Grid.Row="0" BorderBrush="#1254AB" BorderThickness="2" Margin="5">
<Border.Effect>
<DropShadowEffect Color="#1254AB" ShadowDepth="0" BlurRadius="5" Opacity="0.5" Direction="0"></DropShadowEffect>
</Border.Effect>
<Grid>
<StackPanel Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Center" Orientation="Horizontal">
<TextBox x:Name="BoxType" FontSize="20" BorderBrush="#FFFFFF" Foreground="#FFFFFF" Height="30px" Width="100px" Margin="10,0,0,0"/>
</StackPanel>
</Grid>
</Border>
<Border Grid.Row="1" BorderBrush="#1254AB" BorderThickness="2" Margin="5">
<Border.Effect>
<DropShadowEffect Color="Gray" ShadowDepth="0" BlurRadius="5" Opacity="0.5" Direction="0"></DropShadowEffect>
</Border.Effect>
<StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="10 0">
<Button Content="保 存" Margin="5 0" Click="Button_Click" />
<Button Content="取 消" Background="#FF9900" BorderBrush="#FF9900" Margin="5 0" Click="Button_Click_1" />
</StackPanel>
</Border>
</Grid>
</Border>
</Window>

@ -0,0 +1,43 @@
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.OldBoxFoam.Views
{
/// <summary>
/// SetBoxTypeView.xaml 的交互逻辑
/// </summary>
public partial class SetBoxTypeView : Window
{
public string boxTypeResult = string.Empty;
public SetBoxTypeView(string boxType)
{
boxTypeResult = boxType ;
InitializeComponent();
this.BoxType.Text = boxType;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.boxTypeResult = this.BoxType.Text;
this.Close();
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Loading…
Cancel
Save