Browse Source

添加一个新类DataGridHelper,用于更新datagrid

master
sc 2 years ago
parent
commit
d8f1c487d5
  1. 13
      MainWindow.xaml
  2. 52
      UserClass/DataGridHelper.cs
  3. 2
      ViewModel/MainWindowViewModel.cs
  4. 1
      formula_manage.csproj

13
MainWindow.xaml

@ -71,7 +71,7 @@
<TextBox x:Name="Anew" HorizontalAlignment="Left" Height="30" Margin="300,35,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="30" FontSize="20" <TextBox x:Name="Anew" HorizontalAlignment="Left" Height="30" Margin="300,35,0,0" TextWrapping="Wrap" Text="0" VerticalAlignment="Top" Width="30" FontSize="20"
MaxLines="1" MaxLength="2" PreviewTextInput="Tb_KeyPress" InputMethod.IsInputMethodEnabled="False" Focusable ="False"/> MaxLines="1" MaxLength="2" PreviewTextInput="Tb_KeyPress" InputMethod.IsInputMethodEnabled="False" Focusable ="False"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="95,105,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsTabStop="False"/> <TextBox HorizontalAlignment="Left" Height="30" Margin="95,105,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="200" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsTabStop="False"/>
<ComboBox x:Name="Machine" DisplayMemberPath="Name" ItemsSource="{Binding mac_Machine, Source={StaticResource MainWindowViewModel}}" <ComboBox x:Name="Machine" DisplayMemberPath="Name" ItemsSource="{Binding mac_Machine, Source={StaticResource MainWindowViewModel}}" StaysOpenOnEdit="True"
HorizontalAlignment="Left" Height="30" Margin="95,140,0,0" VerticalAlignment="Top" Width="120" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsEditable="True"/> HorizontalAlignment="Left" Height="30" Margin="95,140,0,0" VerticalAlignment="Top" Width="120" FontSize="20" KeyUp="SearchBox_OnKeyDownd" IsEditable="True"/>
<ComboBox x:Name="OrderType" Text="正常单" HorizontalAlignment="Left" Height="30" Margin="95,175,0,0" VerticalAlignment="Top" Width="120" FontSize="20" IsTabStop="True" KeyUp="SearchBox_OnKeyDownd" IsEditable="True"> <ComboBox x:Name="OrderType" Text="正常单" HorizontalAlignment="Left" Height="30" Margin="95,175,0,0" VerticalAlignment="Top" Width="120" FontSize="20" IsTabStop="True" KeyUp="SearchBox_OnKeyDownd" IsEditable="True">
<ComboBoxItem Content="正常单"></ComboBoxItem> <ComboBoxItem Content="正常单"></ComboBoxItem>
@ -98,7 +98,7 @@
<Button Content="-" HorizontalAlignment="Left" Height="15" Width="20" Margin="140,20,0,0" VerticalAlignment="Top" FontSize="10" <Button Content="-" HorizontalAlignment="Left" Height="15" Width="20" Margin="140,20,0,0" VerticalAlignment="Top" FontSize="10"
Background="#FFF1F1F1" BorderBrush="#FFC5C5C5" Padding="0,0,0,0" IsTabStop="False" Click="Button_StepDow" Focusable ="False"/> Background="#FFF1F1F1" BorderBrush="#FFC5C5C5" Padding="0,0,0,0" IsTabStop="False" Click="Button_StepDow" Focusable ="False"/>
<TextBlock HorizontalAlignment="Left" Height="35" Margin="170,5,0,0" TextWrapping="Wrap" Text="流程:" VerticalAlignment="Top" Width="45" FontSize="20"/> <TextBlock HorizontalAlignment="Left" Height="35" Margin="170,5,0,0" TextWrapping="Wrap" Text="流程:" VerticalAlignment="Top" Width="45" FontSize="20"/>
<ComboBox Name="Workflow" DisplayMemberPath="DissolveName" ItemsSource="{Binding flow_Workflow, Source={StaticResource MainWindowViewModel}}" <ComboBox Name="Workflow" DisplayMemberPath="DissolveName" ItemsSource="{Binding flow_Workflow, Source={StaticResource MainWindowViewModel}}" StaysOpenOnEdit="True"
HorizontalAlignment="Left" Height="30" Margin="225,5,0,0" Text="" VerticalAlignment="Top" Width="175" FontSize="20" IsEditable="True" Grid.ColumnSpan="2"/> HorizontalAlignment="Left" Height="30" Margin="225,5,0,0" Text="" VerticalAlignment="Top" Width="175" FontSize="20" IsEditable="True" Grid.ColumnSpan="2"/>
<TextBlock HorizontalAlignment="Left" Height="35" Margin="0,40,0,0" TextWrapping="Wrap" Text="配方代码:" VerticalAlignment="Top" Width="90" FontSize="20"/> <TextBlock HorizontalAlignment="Left" Height="35" Margin="0,40,0,0" TextWrapping="Wrap" Text="配方代码:" VerticalAlignment="Top" Width="90" FontSize="20"/>
<TextBox HorizontalAlignment="Left" Height="30" Margin="90,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="125" FontSize="20" KeyUp="SearchBox_OnKeyDownd"/> <TextBox HorizontalAlignment="Left" Height="30" Margin="90,40,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="125" FontSize="20" KeyUp="SearchBox_OnKeyDownd"/>
@ -168,9 +168,8 @@
<ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0" <ComboBox x:Name="CP_PRODUCT_CODE" BorderThickness="0,0,0,0"
ItemsSource="{Binding stuff_Product, Source={StaticResource MainWindowViewModel}}" ItemsSource="{Binding stuff_Product, Source={StaticResource MainWindowViewModel}}"
DisplayMemberPath="ProductCode" DisplayMemberPath="ProductCode"
Text="{Binding PRODUCT_CODE}" Text="{Binding PRODUCT_CODE}" IsTextSearchEnabled="True" StaysOpenOnEdit="True"
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" KeyDown="CP_PRODUCT_CODE_KeyUp"> BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" KeyDown="CP_PRODUCT_CODE_KeyUp">
</ComboBox> </ComboBox>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
@ -178,14 +177,16 @@
<DataGridTemplateColumn Header="目标饱和度(%)" Width="200" MaxWidth="400" MinWidth="100" > <DataGridTemplateColumn Header="目标饱和度(%)" Width="200" MaxWidth="400" MinWidth="100" >
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<TextBox x:Name="CP_CONC" BorderThickness="0,0,0,0" Text="{Binding CONC}" BorderBrush="{x:Null}" Background="{x:Null}" KeyDown="CP_CONC_KeyUp"/> <TextBox x:Name="CP_CONC" BorderThickness="0,0,0,0" Text="{Binding CONC}"
BorderBrush="{x:Null}" Background="{x:Null}" KeyDown="CP_CONC_KeyUp"/>
</DataTemplate> </DataTemplate>
</DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> </DataGridTemplateColumn>
<DataGridTemplateColumn Header="计算单位" Width="80" MaxWidth="80" MinWidth="80" CellStyle="{StaticResource CellStyle}"> <DataGridTemplateColumn Header="计算单位" Width="80" MaxWidth="80" MinWidth="80" CellStyle="{StaticResource CellStyle}">
<DataGridTemplateColumn.CellTemplate> <DataGridTemplateColumn.CellTemplate>
<DataTemplate> <DataTemplate>
<ComboBox x:Name="CP_SHIFT" BorderThickness="0,0,0,0" Text="{Binding SHIFT}" BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False"> <ComboBox x:Name="CP_SHIFT" BorderThickness="0,0,0,0" Text="{Binding SHIFT}"
BorderBrush="{x:Null}" Background="{x:Null}" IsEditable="True" IsReadOnly="True" Focusable="True" IsTabStop="False">
<ComboBoxItem Content="%"></ComboBoxItem> <ComboBoxItem Content="%"></ComboBoxItem>
<ComboBoxItem Content="g/L"></ComboBoxItem> <ComboBoxItem Content="g/L"></ComboBoxItem>
</ComboBox> </ComboBox>

52
UserClass/DataGridHelper.cs

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;
namespace formula_manage.UserClass
{
public static class DataGridHelper
{
public static void SetRealTimeCommit(DataGrid dataGrid, bool isRealTime)
{
dataGrid.SetValue(RealTimeCommitProperty, isRealTime);
}
public static bool GetRealTimeCommit(DataGrid dataGrid)
{
return (bool)dataGrid.GetValue(RealTimeCommitProperty);
}
public static readonly DependencyProperty RealTimeCommitProperty =
DependencyProperty.RegisterAttached("RealTimeCommit", typeof(bool),
typeof(DataGridHelper),
new PropertyMetadata(false, RealTimeCommitCallBack));
private static void RealTimeCommitCallBack(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var dg = d as DataGrid;
if (dg == null)
return;
EventHandler<DataGridCellEditEndingEventArgs> ceHandler = delegate (object xx, DataGridCellEditEndingEventArgs yy)
{
var flag = GetRealTimeCommit(dg);
if (!flag)
return;
var cellContent = yy.Column.GetCellContent(yy.Row);
if (cellContent != null && cellContent.BindingGroup != null)
cellContent.BindingGroup.CommitEdit();
};
dg.CellEditEnding += ceHandler;
RoutedEventHandler eh = null;
eh = (xx, yy) =>
{
dg.Unloaded -= eh;
dg.CellEditEnding -= ceHandler;
};
dg.Unloaded += eh;
}
}
}

2
ViewModel/MainWindowViewModel.cs

@ -170,7 +170,7 @@ namespace formula_manage.ViewModel
{ {
DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event DispatcherTimer timer = new DispatcherTimer//初始化循环,每0.5秒调用一次Tick_Event
{ {
Interval = TimeSpan.FromSeconds(0.1) Interval = TimeSpan.FromSeconds(0.5)
}; };
timer.Tick += Tick_Event; timer.Tick += Tick_Event;
timer.Start(); timer.Start();

1
formula_manage.csproj

@ -176,6 +176,7 @@
<DependentUpon>Login.xaml</DependentUpon> <DependentUpon>Login.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="SQLModels\STUFF_Product.cs" /> <Compile Include="SQLModels\STUFF_Product.cs" />
<Compile Include="UserClass\DataGridHelper.cs" />
<Compile Include="UserClass\IniFile.cs" /> <Compile Include="UserClass\IniFile.cs" />
<Compile Include="UserClass\PressKey.cs" /> <Compile Include="UserClass\PressKey.cs" />
<Compile Include="UserClass\DataTableForToObservableCollection.cs" /> <Compile Include="UserClass\DataTableForToObservableCollection.cs" />

Loading…
Cancel
Save