Browse Source

运行暂停按钮功能

master
sc 6 months ago
parent
commit
87bec34e0a
  1. 9
      Properties/Resources.Designer.cs
  2. 3
      Properties/Resources.en-US.resx
  3. 3
      Properties/Resources.resx
  4. 3
      Properties/Resources.zh-CN.resx
  5. 3
      Properties/Resources.zh-TW.resx
  6. 2
      UserClass/AsyncTcpServer.cs
  7. 33
      View/TechnologicalProcessView.xaml
  8. 68
      View/TechnologicalProcessView.xaml.cs
  9. 50
      ViewModel/MainWindowViewModel.cs

9
Properties/Resources.Designer.cs

@ -897,6 +897,15 @@ namespace DyeingComputer.Properties {
}
}
/// <summary>
/// 查找类似 Run/Pause 的本地化字符串。
/// </summary>
public static string R_P {
get {
return ResourceManager.GetString("R_P", resourceCulture);
}
}
/// <summary>
/// 查找类似 RapidAcidAddition 的本地化字符串。
/// </summary>

3
Properties/Resources.en-US.resx

@ -492,4 +492,7 @@
<data name="Protocols" xml:space="preserve">
<value>Protocols</value>
</data>
<data name="R_P" xml:space="preserve">
<value>Run/Pause</value>
</data>
</root>

3
Properties/Resources.resx

@ -492,4 +492,7 @@
<data name="Protocols" xml:space="preserve">
<value>Protocols</value>
</data>
<data name="R_P" xml:space="preserve">
<value>Run/Pause</value>
</data>
</root>

3
Properties/Resources.zh-CN.resx

@ -492,4 +492,7 @@
<data name="Protocols" xml:space="preserve">
<value>协议</value>
</data>
<data name="R_P" xml:space="preserve">
<value>运行/暂停</value>
</data>
</root>

3
Properties/Resources.zh-TW.resx

@ -492,4 +492,7 @@
<data name="Protocols" xml:space="preserve">
<value />
</data>
<data name="R_P" xml:space="preserve">
<value />
</data>
</root>

2
UserClass/AsyncTcpServer.cs

@ -292,7 +292,7 @@ namespace DyeingComputer.UserClass
var _TechnologicalProcessView = Application.Current.Windows.Cast<UserControl>().FirstOrDefault(window => window is TechnologicalProcessView) as TechnologicalProcessView;//跨页面
// _TechnologicalProcessView.Grid.ItemsSource = TechnologicalProcessView.sql.Tables[0].DefaultView;
_TechnologicalProcessView.Grid.SelectedIndex = -1;
_TechnologicalProcessView.GridSTEP.SelectedIndex = -1;
/**存入信息**/
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库

33
View/TechnologicalProcessView.xaml

@ -10,17 +10,24 @@
mc:Ignorable="d" Loaded="UserControl_Loaded"
KeyDown="UserControl_KeyDown"
d:DesignHeight="630" d:DesignWidth="1280">
<Grid Focusable="True">
<DataGrid x:Name="Grid" AlternationCount="2" IsReadOnly="True" SelectionChanged="Grid_SelectionChanged"
<Grid>
<DataGrid x:Name="GridSTEP" AlternationCount="2" IsReadOnly="True" SelectionChanged="Grid_SelectionChanged"
Margin="630,40,0,0" d:ItemsSource="{d:SampleData ItemCount=90}" AutoGenerateColumns="False" MinColumnWidth="30"
ItemsSource="{Binding Path=TechnologicalProcess_View,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="{x:Null}"
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False"
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
CanUserAddRows="True" CanUserDeleteRows="False" HeadersVisibility ="Column"
Background="White" SelectionMode="Single" FontSize="15" MinHeight="632" TabIndex="1" Focusable="True">
Background="White" SelectionMode="Single" FontSize="15" MinHeight="632" TabIndex="1" Focusable="True" >
<DataGrid.Resources>
<Style TargetType="ScrollViewer">
<Setter Property="PanningMode" Value="VerticalOnly"/>
</Style>
</DataGrid.Resources>
<DataGrid.RowStyle >
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="IsHitTestVisible" Value="{Binding DataContext.IsInteractive,
RelativeSource={RelativeSource AncestorType=DataGrid}}"/>
<Setter Property="Height" Value="30" />
<Setter Property="FontSize" Value="25" />
<Style.Triggers>
@ -77,7 +84,10 @@
<DataGridTextColumn Binding="{Binding DYELOT}" Width="0" MinWidth="0" MaxWidth="0"/>
</DataGrid.Columns>
</DataGrid>
<TextBlock x:Name="log" HorizontalAlignment="Left" TextWrapping="Wrap" Width="600" FontSize="25" Background="White" Text="{Binding Sys_log}" Margin="0,40,0,0"/>
<ScrollViewer HorizontalAlignment="Left" Width="600" Margin="0,40,0,0" VerticalScrollBarVisibility="Auto"
PanningMode="VerticalOnly">
<TextBlock x:Name="log" TextWrapping="Wrap" FontSize="25" Background="White" Text="{Binding Sys_log}" />
</ScrollViewer>
<TextBlock x:Name="name" HorizontalAlignment="Left" Margin="600,0,0,0" TextWrapping="Wrap" FontSize="24" Background="#FFD0D0D0" Text="{Binding Program_Name}" Height="30" Block.TextAlignment="Center">
<TextBlock.LayoutTransform>
<!--文字同样旋转90度-->
@ -89,10 +99,17 @@
<Button Content="{x:Static lang:Resources.Receipt}" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White" Click="Receipt_Click"/>
<Button Content="{x:Static lang:Resources.ParameterSet}" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White" Click="ParameterSet_Click"/>
</WrapPanel>
<WrapPanel Orientation="Horizontal" Background="#FFCCCCCC" VerticalAlignment="Top" Margin="630,0,0,0">
<Button Content="{x:Static lang:Resources.edit}" x:Name="ProgramgroupView_edit" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White" Click="ProgramgroupView_edit_Click"/>
<Button Content="{x:Static lang:Resources.Delete}" x:Name="ProgramgroupView_del" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White" Click="ProgramgroupView_del_Click"/>
<Button Content="{x:Static lang:Resources.Insert}" x:Name="ProgramgroupView_Insert" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White" Click="ProgramgroupView_Insert_Click"/>
<WrapPanel Orientation="Horizontal" Background="#FFCCCCCC" VerticalAlignment="Top" Margin="630,0,0,0">
<Button Content="{x:Static lang:Resources.edit}" x:Name="ProgramgroupView_edit" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White"
Click="ProgramgroupView_edit_Click" IsEnabled="{Binding UserButton}"/>
<Button Content="{x:Static lang:Resources.Delete}" x:Name="ProgramgroupView_del" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White"
Click="ProgramgroupView_del_Click" IsEnabled="{Binding UserButton}"/>
<Button Content="{x:Static lang:Resources.Insert}" x:Name="ProgramgroupView_Insert" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White"
Click="ProgramgroupView_Insert_Click" IsEnabled="{Binding UserButton}"/>
<Button Content="{x:Static lang:Resources.R_P}" x:Name="ProgramgroupView_run" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White"
Click="ProgramgroupView_run_Click" Command="{Binding ProgramgroupView_run}"/>
<Button Content="{x:Static lang:Resources.StopProcess}" x:Name="ProgramgroupView_stop" FontSize="20" HorizontalAlignment="Left" Height="40" VerticalAlignment="Top" Width="200" Background="White"
Click="ProgramgroupView_stop_Click" IsEnabled="{Binding UserButton}"/>
</WrapPanel>
</Grid>
</UserControl>

68
View/TechnologicalProcessView.xaml.cs

@ -33,11 +33,28 @@ namespace DyeingComputer.View
/// </summary>
public partial class TechnologicalProcessView : UserControl
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
if (propertyName != null)
{
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public TechnologicalProcessView()
{
InitializeComponent();
//Grid.DataContext = new MainWindowViewModel();
FocusManager.SetFocusedElement(Grid, Grid);
// FocusManager.SetFocusedElement(Grid, Grid);
// if (workName != null)
// {
// TechnologicalProcess_Import();
@ -45,7 +62,11 @@ namespace DyeingComputer.View
// else
// {
TechnologicalProcess_sql();
// }
// }
// ProgramgroupView_edit.IsEnabled = false;
// ProgramgroupView_del.IsEnabled = false;
// ProgramgroupView_Insert.IsEnabled = false;
}
public static object workName;
@ -108,11 +129,11 @@ namespace DyeingComputer.View
// Grid.DataContext = new MainWindowViewModel();
if (workName != null)
{
Grid.SelectedIndex = 0;
GridSTEP.SelectedIndex = 0;
}
else
{
if (MainWindowViewModel.WORK_RUN != 0) Grid.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
if (MainWindowViewModel.WORK_RUN != 0) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
}
CountDown();
}
@ -166,7 +187,7 @@ namespace DyeingComputer.View
dr.EndEdit();
dt_TP = sql.Tables[0];
Grid.SelectedIndex = -1;
GridSTEP.SelectedIndex = -1;
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
@ -208,7 +229,7 @@ namespace DyeingComputer.View
dt_TP.Rows.RemoveAt(d - 1);
Dat();
Grid.SelectedIndex = -1;
GridSTEP.SelectedIndex = -1;
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
@ -274,8 +295,17 @@ namespace DyeingComputer.View
private void Receipt_Click(object sender, RoutedEventArgs e)
{
}
private void ProgramgroupView_run_Click(object sender, RoutedEventArgs e)//运行/暂停
{
}
private void ProgramgroupView_stop_Click(object sender, RoutedEventArgs e)//结束工艺
{
}
private void ParameterSet_Click(object sender, RoutedEventArgs e)
{
@ -284,20 +314,24 @@ namespace DyeingComputer.View
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (MainWindowViewModel.WORK_RUN == 2) Grid.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (MainWindowViewModel.WORK_RUN == 2) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
int rownum = GridSTEP.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
ID = (Grid.Columns[2].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
P1 = (Grid.Columns[6].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第6列,
P2 = (Grid.Columns[7].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第7列,
P3 = (Grid.Columns[8].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第8列,
P4 = (Grid.Columns[9].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第9列,
P5 = (Grid.Columns[10].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第10列,
ID = (GridSTEP.Columns[2].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第0列,
Numder = (GridSTEP.Columns[3].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第1列,
P1 = (GridSTEP.Columns[6].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第6列,
P2 = (GridSTEP.Columns[7].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第7列,
P3 = (GridSTEP.Columns[8].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第8列,
P4 = (GridSTEP.Columns[9].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第9列,
P5 = (GridSTEP.Columns[10].GetCellContent(GridSTEP.Items[rownum]) as TextBlock).Text;//定位第10列,
ProgramgroupView_edit.IsEnabled = true;
ProgramgroupView_del.IsEnabled = true;
ProgramgroupView_Insert.IsEnabled = true;
}
}
public void CountDown()
{
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick
@ -309,7 +343,7 @@ namespace DyeingComputer.View
}
void Tick_Event_1S(object sender, EventArgs e)//Tick_Event周期执行事件1S
{
if (MainWindowViewModel.WORK_RUN == 2) Grid.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
if (MainWindowViewModel.WORK_RUN == 2) GridSTEP.SelectedIndex = MainWindowViewModel.RUN_STEPID - 1;//设定图表显示
if (sql != null)
{
dt_TP= sql.Tables[0];

50
ViewModel/MainWindowViewModel.cs

@ -29,6 +29,9 @@ using System.Diagnostics.Eventing.Reader;
using System.IO;
using System.Threading;
using TouchSocket.Sockets;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using System.Windows.Input;
using CommunityToolkit.Mvvm.Input;
namespace DyeingComputer.ViewModel
@ -79,6 +82,12 @@ namespace DyeingComputer.ViewModel
UPort(); //启动串口
CountDown(); //启动循环任务
_ = AsyncTcpServer.Main();
IsInteractive = false;
UserButton = false;
ProgramgroupView_run = new RelayCommand(
execute:ProgramgroupView_run_ );//开始/暂停事件
}
DataTable dt_con = new DataTable();
DataTable dt_sys = new DataTable();
@ -188,7 +197,46 @@ namespace DyeingComputer.ViewModel
SM02 = Convert.ToInt16(Selet_sys("SM02"));//FG
SM03 = Convert.ToInt16(Selet_sys("SM03"));//FG
}
private void ProgramgroupView_run_()////运行/暂停
{
if (WORK_RUN == 2)
{
UserButton = true;
IsInteractive = true;
}
else
if (WORK_RUN == 1)
{
UserButton = false;
IsInteractive = false;
}
else
{
UserButton = true;
IsInteractive = true;
}
}
public ICommand ProgramgroupView_run { get; }
bool _isInteractive;
public bool IsInteractive//步骤表交互选择
{
get => _isInteractive;
set
{
_isInteractive = value;
OnPropertyChanged("IsInteractive");
}
}
bool _UserButton;
public bool UserButton//步骤按钮交互选择
{
get => _UserButton;
set
{
_UserButton = value;
OnPropertyChanged("UserButton");
}
}
public string work_Temp; //显示温度
public string Work_Temp //通知UI控件参数改变
{

Loading…
Cancel
Save