Browse Source

通讯修改

master
pry 2 years ago
parent
commit
983a182213
5 changed files with 466 additions and 163 deletions
  1. +37
    -2
      BPASmartClient.CustomResource/Pages/Model/MessageLog.cs
  2. +20
    -1
      BPASmartClient.CustomResource/Pages/View/PromptView.xaml
  3. +29
    -0
      BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs
  4. +53
    -17
      BPASmartClient.Modbus/ModbusTcp.cs
  5. +327
    -143
      FryPot_DosingSystem/View/NewRecipeView.xaml

+ 37
- 2
BPASmartClient.CustomResource/Pages/Model/MessageLog.cs View File

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows;
using BPASmartClient.Model;
using System.Windows.Media;
using BPASmartClient.CustomResource.Pages.View;

namespace BPASmartClient.CustomResource.Pages.Model
{
@@ -44,7 +45,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
{
lock (userlock)
{
if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString())&& !string.IsNullOrEmpty(info))
if (!string.IsNullOrEmpty(Global.userInfo.UserName) && !string.IsNullOrEmpty(Global.userInfo.permission.ToString()) && !string.IsNullOrEmpty(info))
{
UserLog userLog = new UserLog()
{
@@ -76,7 +77,7 @@ namespace BPASmartClient.CustomResource.Pages.Model
RunLog?.Invoke(info);
}
}
int AlarmID;
public void ShowAlarmLog(string info, string AlarmNumber = "_", AlarmLevel level = AlarmLevel.一般报警)
{
@@ -97,5 +98,39 @@ namespace BPASmartClient.CustomResource.Pages.Model
AlarmLog?.Invoke(info);
}
}

public bool ShowDialog(string info, DialogType dialogType = DialogType.Information)
{
PromptView PV = new PromptView();
switch (dialogType)
{
case DialogType.Warning:
PV.TextBlockIcon = "";
PV.TextBlockForeground = Brushes.Yellow;
PV.TextBlockInfo = $"警告:{info}";
break;
case DialogType.Error:
PV.TextBlockIcon = "";
PV.TextBlockForeground = Brushes.Red;
PV.TextBlockInfo = $"错误:{info}";
break;
case DialogType.Information:
PV.TextBlockIcon = "";
PV.TextBlockForeground = Brushes.DeepSkyBlue;
PV.TextBlockInfo = $"提示:{info}";
break;
default:
break;
}
var res = PV.ShowDialog();
return res == null ? false : (bool)res;
}
}

public enum DialogType
{
Warning,
Error,
Information,
}
}

+ 20
- 1
BPASmartClient.CustomResource/Pages/View/PromptView.xaml View File

@@ -13,6 +13,21 @@
WindowStartupLocation="CenterScreen"
WindowStyle="None"
mc:Ignorable="d">

<Window.Resources>
<Style x:Key="buttonStyle" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Grid>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<Grid.Background>
<ImageBrush ImageSource="/BPASmartClient.CustomResource;component/Image/弹窗.png" Stretch="Fill" />
@@ -34,8 +49,12 @@
<ColumnDefinition />
</Grid.ColumnDefinitions>

<TextBlock Text="&#xe657;" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="Red" FontFamily="../../Fonts/#iconfont"/>
<TextBlock Name="icon" Text="&#xe61f;" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="DeepSkyBlue" FontFamily="../../Fonts/#iconfont"/>
<TextBlock Name="info" Text="警告:" Grid.Column="1" TextWrapping="Wrap" VerticalAlignment="Center" Foreground="DeepSkyBlue"/>
</Grid>

<Grid Grid.Row="1">
<Button/>
</Grid>

<Grid.RowDefinitions>


+ 29
- 0
BPASmartClient.CustomResource/Pages/View/PromptView.xaml.cs View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
@@ -24,6 +25,34 @@ namespace BPASmartClient.CustomResource.Pages.View
InitializeComponent();
}

public string TextBlockIcon
{
get { return this.icon.Text.Trim(); }
set { this.icon.Text = Regex.Unescape(StringToUnicode(value.ToString())); }
}

public Brush TextBlockForeground
{
get { return this.icon.Foreground; }
set { this.icon.Foreground = value; this.info.Foreground = value; }
}

public string TextBlockInfo
{
get { return this.info.Text.Trim(); }
set { this.info.Text = value; }
}

private string StringToUnicode(string s)
{
if (!string.IsNullOrEmpty(s))
{
//这里把格式&#xe625; 转为 \ue625
return s.Replace(@"&#x", @"\u").Replace(";", "");
}
return s;
}

private void Button_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;


+ 53
- 17
BPASmartClient.Modbus/ModbusTcp.cs View File

@@ -1,5 +1,5 @@
using BPASmartClient.Helper;
using BPASmartClient.Message;
//using BPASmartClient.Message;
using NModbus;
using System;
using System.Collections.Generic;
@@ -25,6 +25,8 @@ namespace BPASmartClient.Modbus
private ManualResetEvent mre = new ManualResetEvent(false);
public string IPAdress;
public int Port;
public Action<string> Show { get; set; }
public Action<string> ShowEx { get; set; }

/// <summary>
/// 连接plc 原料设备成功
@@ -49,7 +51,7 @@ namespace BPASmartClient.Modbus
/// <param name="port">端口号,默认502</param>
public void ModbusTcpConnect(string ip, int port = 502)
{
MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接中。。。。");
Show?.Invoke($"设备【{ip}:{port}】连接中。。。。");
IPAdress = ip;
Port = port;
modbusFactory = new ModbusFactory();
@@ -60,7 +62,7 @@ namespace BPASmartClient.Modbus
master.Transport.WriteTimeout = 2000;//写入超时时间
master.Transport.Retries = 10;//重试次数
ConnectOk?.Invoke();
MessageLog.GetInstance.Show($"设备【{ip}:{port}】连接成功");
Show?.Invoke($"设备【{ip}:{port}】连接成功");
}
else
{
@@ -94,15 +96,15 @@ namespace BPASmartClient.Modbus
{
if (!ErrorFlag)
{
MessageLog.GetInstance.ShowEx($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
MessageLog.GetInstance.ShowEx(ex.ToString());
ShowEx?.Invoke($"ModbusTcp 连接失败,IP = {IPAdress},Port = {Port}");
ShowEx?.Invoke(ex.ToString());
ErrorFlag = true;
}
if (!IsReconnect) break;
Thread.Sleep(3000);
}
}
if (ErrorFlag && IsReconnect) MessageLog.GetInstance.Show("ModbusTcp 重连成功!");
if (ErrorFlag && IsReconnect) Show?.Invoke("ModbusTcp 重连成功!");
}

/// <summary>
@@ -244,18 +246,54 @@ namespace BPASmartClient.Modbus
}
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}");
ShowEx?.Invoke($"读取地址:【{address}:= {startAddress}】,读取类型:【{commandType.ToString()}】出错,{ex.ToString()}");
ExceptionHandling(ex);
}
return default(object);
}


/// <summary>
/// 写入数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="address">写入地址</param>
/// <param name="value">写入值</param>
/// <param name="Retries">重试次数</param>
/// <param name="slaveAddress">从站地址</param>
/// <returns></returns>
public bool Write<T>(string address, T value, int Retries = 1, byte slaveAddress = 1)
{
int count = 0;
if (Retries == 1 || Retries == 0)
{
return TempWrite(address, value, slaveAddress);
}
else if (Retries > 1)
{
bool isok = false;
while (count < Retries)
{
count++;
TempWrite(address, value, slaveAddress);
var res = Read(address);
if (res != null && res.ToString() == value.ToString())
{
isok = true;
break;
}
}
return isok;
}
return false;
}

public string Write<T>(string address, T value, byte slaveAddress = 1)
private bool TempWrite<T>(string address, T value, byte slaveAddress = 1)
{
if (address == null || tcpClient == null) return "失败,地址为空或断开连接";
if (address == null || tcpClient == null)
{
Show?.Invoke("写入失败,地址为空或断开连接");
return false;
}
ushort startAddress = (ushort)GetAddress(address);
CommandType commandType = CommandType.Coils;
try
@@ -305,16 +343,14 @@ namespace BPASmartClient.Modbus
{
commandType = CommandType.Inputs;
}
return $"成功,地址:{address},值:{value}";
Show?.Invoke($"成功,地址:{address},值:{value}");
return true;
}
catch (Exception ex)
{
MessageLog.GetInstance.ShowEx($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}");

ShowEx?.Invoke($"写入地址:【{address}:= {startAddress}】,写入类型:【{commandType.ToString()}】出错,{ex.ToString()}");
ExceptionHandling(ex);

return $"异常,地址:{address},值:{value},发送异常";
return false;
}
}



+ 327
- 143
FryPot_DosingSystem/View/NewRecipeView.xaml View File

@@ -1,21 +1,27 @@
<Window x:Class="FryPot_DosingSystem.View.NewRecipeView"
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:FryPot_DosingSystem.View"
xmlns:vm="clr-namespace:FryPot_DosingSystem.ViewModel" xmlns:Themes1="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
mc:Ignorable="d"
Title="NewRecipeView" Height="550" Width="800"
WindowStyle="None" WindowStartupLocation="CenterScreen" AllowsTransparency="True">
<Window
x:Class="FryPot_DosingSystem.View.NewRecipeView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Themes1="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Classic"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:FryPot_DosingSystem.View"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="clr-namespace:FryPot_DosingSystem.ViewModel"
Title="NewRecipeView"
Width="800"
Height="550"
AllowsTransparency="True"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
mc:Ignorable="d">
<Window.DataContext>
<vm:NewRecipeViewModel></vm:NewRecipeViewModel>
<vm:NewRecipeViewModel />
</Window.DataContext>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/GenricStyle.xaml" />
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml"/>
<ResourceDictionary Source="/BPASmartClient.CustomResource;component/Themes/MyStyle.xaml" />

<ResourceDictionary>
<!--#region ListBox样式-->
@@ -40,35 +46,44 @@
<!--#endregion-->
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3"/>
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA"/>
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5"/>
<SolidColorBrush x:Key="TextBox.Static.Border" Color="#FFABAdB3" />
<SolidColorBrush x:Key="TextBox.MouseOver.Border" Color="#FF7EB4EA" />
<SolidColorBrush x:Key="TextBox.Focus.Border" Color="#FF569DE5" />
<Style x:Key="TextBoxStyle" TargetType="{x:Type TextBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
<Setter Property="BorderBrush" Value="{StaticResource TextBox.Static.Border}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="AllowDrop" Value="true" />
<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Border x:Name="border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="True">
<ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
<Border
x:Name="border"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="True">
<ScrollViewer
x:Name="PART_ContentHost"
Focusable="false"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Opacity" TargetName="border" Value="0.56"/>
<Setter TargetName="border" Property="Opacity" Value="0.56" />
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.MouseOver.Border}"/>
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource TextBox.MouseOver.Border}" />
</Trigger>
<Trigger Property="IsKeyboardFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{StaticResource TextBox.Focus.Border}"/>
<Setter TargetName="border" Property="BorderBrush" Value="{StaticResource TextBox.Focus.Border}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -77,51 +92,83 @@
<Style.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true"/>
<Condition Property="IsSelectionActive" Value="false"/>
<Condition Property="IsInactiveSelectionHighlightEnabled" Value="true" />
<Condition Property="IsSelectionActive" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}"/>
<Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />
</MultiTrigger>
</Style.Triggers>
</Style>
<SolidColorBrush x:Key="foreground" Color="#a2c2e8"/>
<SolidColorBrush x:Key="borderBrush" Color="Aqua"/>
<SolidColorBrush x:Key="foreground" Color="#a2c2e8" />
<SolidColorBrush x:Key="borderBrush" Color="Aqua" />
<Style x:Key="ComboBoxStyle1" TargetType="{x:Type ComboBox}">
<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}"/>
<Setter Property="Foreground" Value="{DynamicResource foreground}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{DynamicResource borderBrush}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="Margin" Value="0,0,0,0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Height" Value="24"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="IsTextSearchCaseSensitive" Value="true"/>
<Setter Property="IsEditable" Value="true"/>
<Setter Property="StaysOpenOnEdit" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ComboBoxFocusVisual}" />
<Setter Property="Foreground" Value="{DynamicResource foreground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="BorderBrush" Value="{DynamicResource borderBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Margin" Value="0,0,0,0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Height" Value="24" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.CanContentScroll" Value="true" />
<Setter Property="ScrollViewer.PanningMode" Value="Both" />
<Setter Property="Stylus.IsFlicksEnabled" Value="False" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="IsTextSearchCaseSensitive" Value="true" />
<Setter Property="IsEditable" Value="true" />
<Setter Property="StaysOpenOnEdit" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" SnapsToDevicePixels="true">
<Border
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="true">
<Grid>
<Themes1:ClassicBorderDecorator x:Name="Border" BorderStyle="None" BorderBrush="{x:Static Themes1:ClassicBorderDecorator.ClassicBorderBrush}" BorderThickness="2">
<Popup x:Name="PART_Popup" AllowsTransparency="true" Focusable="False" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<Themes1:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MinWidth="{Binding ActualWidth, ElementName=Border}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1">
<Themes1:ClassicBorderDecorator
x:Name="Border"
BorderBrush="{x:Static Themes1:ClassicBorderDecorator.ClassicBorderBrush}"
BorderStyle="None"
BorderThickness="2">
<Popup
x:Name="PART_Popup"
AllowsTransparency="true"
Focusable="False"
IsOpen="{TemplateBinding IsDropDownOpen}"
Placement="Bottom"
PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}">
<Themes1:SystemDropShadowChrome
x:Name="Shdw"
MinWidth="{Binding ActualWidth, ElementName=Border}"
MaxHeight="{TemplateBinding MaxDropDownHeight}"
Color="Transparent">
<Border
x:Name="DropDownBorder"
BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}"
BorderThickness="1">
<Border.Background>
<SolidColorBrush Color="#264c73"></SolidColorBrush>
<SolidColorBrush Color="#264c73" />
</Border.Background>
<ScrollViewer x:Name="DropDownScrollViewer">
<Grid RenderOptions.ClearTypeHint="Enabled">
<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
<Canvas
Width="0"
Height="0"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<Rectangle
x:Name="OpaqueRect"
Width="{Binding ActualWidth, ElementName=DropDownBorder}"
Height="{Binding ActualHeight, ElementName=DropDownBorder}"
Fill="{Binding Background, ElementName=DropDownBorder}" />
</Canvas>
<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<ItemsPresenter
x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Grid>
</ScrollViewer>
</Border>
@@ -129,42 +176,58 @@
</Popup>
</Themes1:ClassicBorderDecorator>
<DockPanel Margin="2">
<FrameworkElement DockPanel.Dock="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}"/>
<FrameworkElement Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}" DockPanel.Dock="Right" />
<Border x:Name="SelectedItemBorder" Margin="{TemplateBinding Padding}">
<ContentPresenter ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" Content="{TemplateBinding SelectionBoxItem}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="1,1,1,1" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<ContentPresenter
Margin="1,1,1,1"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding SelectionBoxItem}"
ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
</Border>
</DockPanel>
<ToggleButton ClickMode="Press" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Margin="2" MinWidth="0" MinHeight="0" Style="{StaticResource ComboBoxTransparentButtonStyle}" Width="Auto"/>
<ToggleButton
Width="Auto"
MinWidth="0"
MinHeight="0"
Margin="2"
ClickMode="Press"
Focusable="false"
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
Style="{StaticResource ComboBoxTransparentButtonStyle}" />
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsDropDownOpen" Value="false"/>
<Condition Property="IsDropDownOpen" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}" />
</MultiTrigger>
<Trigger Property="HasItems" Value="false">
<Setter Property="MinHeight" TargetName="DropDownBorder" Value="95"/>
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsGrouping" Value="true"/>
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
<Condition Property="IsGrouping" Value="true" />
<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false" />
</MultiTrigger.Conditions>
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="false" />
</MultiTrigger>
<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
<Trigger SourceName="PART_Popup" Property="HasDropShadow" Value="true">
<Setter TargetName="Shdw" Property="Margin" Value="0,0,5,5" />
<Setter TargetName="Shdw" Property="Color" Value="#71000000" />
</Trigger>
<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
<Trigger SourceName="DropDownScrollViewer" Property="ScrollViewer.CanContentScroll" Value="false">
<Setter TargetName="OpaqueRect" Property="Canvas.Top" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}" />
<Setter TargetName="OpaqueRect" Property="Canvas.Left" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -172,9 +235,9 @@
</Setter>
<Style.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
<Setter Property="IsTabStop" Value="false" />
<Setter Property="Padding" Value="1" />
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
@@ -183,70 +246,160 @@
<Border Name="br">
<Border.Background>
<!--<ImageBrush ImageSource="/BPASmartClient.CustomResource;component/Image/bg.png"></ImageBrush>-->
<SolidColorBrush Color="#264c73">

</SolidColorBrush>
<SolidColorBrush Color="#264c73" />
</Border.Background>
<Grid >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="80"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition Height="50" />
<RowDefinition Height="80" />
<RowDefinition Height="40" />
<RowDefinition />
</Grid.RowDefinitions>

<TextBlock Text="配方信息" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#FF2AB2E7" FontSize="25" Margin="0,10"></TextBlock>
<TextBlock
Margin="0,10"
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="25"
Foreground="#FF2AB2E7"
Text="配方信息" />
<UniformGrid Grid.Row="1" Columns="2">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Margin="0,8">
<TextBlock Text="请输入配方名称:" Foreground="#FF2AB2E7" FontSize="18" Margin="10,0,5,0" VerticalAlignment="Center"></TextBlock>
<TextBox Style="{DynamicResource TextBoxStyle}" Text="{Binding RecipeName}" Width="230" Height="30" BorderThickness="1" Background="Transparent" Foreground="Orange"
VerticalContentAlignment="Center"
BorderBrush="#FF2AB2E7" VerticalAlignment="Center" FontSize="16" ></TextBox>
<StackPanel Margin="0,8" Orientation="Horizontal">
<TextBlock
Margin="10,0,5,0"
VerticalAlignment="Center"
FontSize="18"
Foreground="#FF2AB2E7"
Text="请输入配方名称:" />
<TextBox
Width="230"
Height="30"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Background="Transparent"
BorderBrush="#FF2AB2E7"
BorderThickness="1"
FontSize="16"
Foreground="Orange"
Style="{DynamicResource TextBoxStyle}"
Text="{Binding RecipeName}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="请输入桶的数量:" Foreground="#FF2AB2E7" FontSize="18" Margin="10,0,5,0" VerticalAlignment="Center"></TextBlock>
<TextBox Style="{DynamicResource TextBoxStyle}" Text="{Binding RecipeRollerNum}" InputMethod.IsInputMethodEnabled="False" Width="230" Height="30" BorderThickness="1" Background="Transparent" Foreground="Orange"
VerticalContentAlignment="Center"
BorderBrush="#FF2AB2E7" VerticalAlignment="Center" FontSize="16" TextChanged="TextBox_TextChanged"></TextBox>
<TextBlock
Margin="10,0,5,0"
VerticalAlignment="Center"
FontSize="18"
Foreground="#FF2AB2E7"
Text="请输入桶的数量:" />
<TextBox
Width="230"
Height="30"
VerticalAlignment="Center"
VerticalContentAlignment="Center"
Background="Transparent"
BorderBrush="#FF2AB2E7"
BorderThickness="1"
FontSize="16"
Foreground="Orange"
InputMethod.IsInputMethodEnabled="False"
Style="{DynamicResource TextBoxStyle}"
Text="{Binding RecipeRollerNum}"
TextChanged="TextBox_TextChanged" />
</StackPanel>
</StackPanel>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="添加原料" Width="180" Margin="0,0,10,0" Height="30" Background="Transparent" BorderBrush="#FF2AB2E7" Foreground="#FF2AB2E7" Cursor="Hand" Command="{Binding AddRecipe}" ></Button>
<Button Content="确认更新" Height="30" Width="180" Background="Transparent" BorderBrush="#FF2AB2E7" Foreground="#FF2AB2E7" Command="{Binding Comfirm}"></Button>
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal">
<Button
Width="180"
Height="30"
Margin="0,0,10,0"
Background="Transparent"
BorderBrush="#FF2AB2E7"
Command="{Binding AddRecipe}"
Content="添加原料"
Cursor="Hand"
Foreground="#FF2AB2E7" />
<Button
Width="180"
Height="30"
Background="Transparent"
BorderBrush="#FF2AB2E7"
Command="{Binding Comfirm}"
Content="确认更新"
Foreground="#FF2AB2E7" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
<Button Content="另存为" Height="30" Width="180" Margin="0,0,10,0" Command="{Binding SaveAs}" Cursor="Hand"/>
<Button Click="Button_Click" Content="取消" Height="30" FontSize="20" Background="Transparent" BorderBrush="#FF2AB2E7" Foreground="#FF2AB2E7" Width="180" Cursor="Hand"></Button>
<StackPanel
Grid.Row="1"
HorizontalAlignment="Center"
Orientation="Horizontal">
<Button
Width="180"
Height="30"
Margin="0,0,10,0"
Command="{Binding SaveAs}"
Content="另存为"
Cursor="Hand" />
<Button
Width="180"
Height="30"
Background="Transparent"
BorderBrush="#FF2AB2E7"
Click="Button_Click"
Content="取消"
Cursor="Hand"
FontSize="20"
Foreground="#FF2AB2E7" />
</StackPanel>
</Grid>
</UniformGrid>
<Grid Grid.Row="2" Background="#FF2AB2E7" Margin="0,0,0,10">
<Grid
Grid.Row="2"
Margin="0,0,0,10"
Background="#FF2AB2E7">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="210"/>
<ColumnDefinition Width="225"/>
<ColumnDefinition Width="225"/>
<ColumnDefinition/>
<ColumnDefinition Width="210" />
<ColumnDefinition Width="225" />
<ColumnDefinition Width="225" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="原料名称" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
<GridSplitter></GridSplitter>
<TextBlock Grid.Column="1" Text="原料桶号" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
<GridSplitter Grid.Column="1"></GridSplitter>
<TextBlock Grid.Column="2" Text="原料重量" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"></TextBlock>
<GridSplitter Grid.Column="2"></GridSplitter>
<TextBlock Grid.Column="3" Text="操作" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White"/>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="White"
Text="原料名称" />
<GridSplitter />
<TextBlock
Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="White"
Text="原料桶号" />
<GridSplitter Grid.Column="1" />
<TextBlock
Grid.Column="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="White"
Text="原料重量" />
<GridSplitter Grid.Column="2" />
<TextBlock
Grid.Column="3"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Foreground="White"
Text="操作" />
</Grid>
<ScrollViewer Grid.Row="3" VerticalScrollBarVisibility="Hidden">
<ItemsControl ItemsSource="{Binding materials}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
<StackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
@@ -256,42 +409,73 @@
<ControlTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="210"/>
<ColumnDefinition Width="210" />

<ColumnDefinition Width="210"></ColumnDefinition>
<ColumnDefinition Width="225"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition Width="210" />
<ColumnDefinition Width="225" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<ComboBox ItemsSource="{Binding DataContext.materialNames,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}" Text="{Binding MaterialName}" Margin="10,0,0,10" Width="190" FontSize="14" KeyUp="ComboBox_KeyUp" LostFocus="ComboBox_LostFocus" Style="{StaticResource ComboBoxStyle1}" Height="30">
<ComboBox
Width="190"
Height="30"
Margin="10,0,0,10"
FontSize="14"
ItemsSource="{Binding DataContext.materialNames, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
KeyUp="ComboBox_KeyUp"
LostFocus="ComboBox_LostFocus"
Style="{StaticResource ComboBoxStyle1}"
Text="{Binding MaterialName}">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Background" Value="White" />
<Setter Property="Foreground" Value="#e69519"/>
<Setter Property="Foreground" Value="#e69519" />


</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
<StackPanel Grid.Column="1" Orientation="Horizontal" >
<TextBox Text="{Binding MaterialLoc}" Background="Transparent" FontSize="14" Height="30"
BorderBrush="#e69519" Foreground="LightGray" Width="170" Margin="35,0,0,10" ></TextBox>
<StackPanel Grid.Column="1" Orientation="Horizontal">
<TextBox
Width="170"
Height="30"
Margin="35,0,0,10"
Background="Transparent"
BorderBrush="#e69519"
FontSize="14"
Foreground="LightGray"
Text="{Binding MaterialLoc}" />

</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="2">
<TextBox Text="{Binding MaterialWeight}" Background="Transparent" FontSize="14" Height="30"
BorderBrush="#e69519" Foreground="LightGray" Width="170" Margin="35,0,0,10" ></TextBox>
<TextBlock VerticalAlignment="Center" FontSize="14" Margin="4,0,0,10" Text="g" Foreground="#e69519" ></TextBlock>
</StackPanel>
<Button Grid.Column="3"
Content="删除"
Width="94"
<StackPanel Grid.Column="2" Orientation="Horizontal">
<TextBox
Width="170"
Height="30"
FontSize="14"
Margin="0,0,20,10"
Margin="35,0,0,10"
Background="Transparent"
BorderBrush="#e69519" Foreground="LightGray" HorizontalAlignment="Right"
Command="{Binding DataContext.RemoveRecipe,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=ItemsControl}}"
CommandParameter="{Binding MaterialCode}"></Button>
BorderBrush="#e69519"
FontSize="14"
Foreground="LightGray"
Text="{Binding MaterialWeight}" />
<TextBlock
Margin="4,0,0,10"
VerticalAlignment="Center"
FontSize="14"
Foreground="#e69519"
Text="g" />
</StackPanel>
<Button
Grid.Column="3"
Width="94"
Height="30"
Margin="0,0,20,10"
HorizontalAlignment="Right"
Background="Transparent"
BorderBrush="#e69519"
Command="{Binding DataContext.RemoveRecipe, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ItemsControl}}"
CommandParameter="{Binding MaterialCode}"
Content="删除"
FontSize="14"
Foreground="LightGray" />
</Grid>
</ControlTemplate>
</RadioButton.Template>


Loading…
Cancel
Save