Merge branch 'master' of http://www.scserverddns.top:13000/sc/DyeingComputer
This commit is contained in:
commit
c1bb703b03
4 files changed
+127
-6
No files matched your search
@@ -91,6 +91,7 @@
|
||||
<Compile Include="UserClass\LogDataRead.cs" />
|
||||
<Compile Include="UserClass\LogGing.cs" />
|
||||
<Compile Include="UserClass\MD5check.cs" />
|
||||
<Compile Include="UserClass\NumericTextColumn .cs" />
|
||||
<Compile Include="UserClass\PressKey.cs" />
|
||||
<Compile Include="UserClass\SqliteHelper.cs" />
|
||||
<Compile Include="UserClass\StrToInt.cs" />
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows;
|
||||
|
||||
namespace DyeingComputer.UserClass
|
||||
{
|
||||
/// <summary>
|
||||
/// DataGrid中只能输入数字的列
|
||||
/// </summary>
|
||||
/// local:DataGridNumericColumn Binding = "{Binding NumericProperty}"
|
||||
///
|
||||
public class NumericTextColumn : DataGridTextColumn
|
||||
{
|
||||
protected override object PrepareCellForEdit(FrameworkElement editingElement, RoutedEventArgs editingEventArgs)
|
||||
{
|
||||
var edit = editingElement as TextBox;
|
||||
edit.PreviewTextInput += Edit_PreviewTextInput;
|
||||
DataObject.AddPastingHandler(edit, OnPaste);
|
||||
//限制输入法切换,可避免中文输入添加到列中
|
||||
InputMethod.SetIsInputMethodEnabled(edit, false);
|
||||
return base.PrepareCellForEdit(editingElement, editingEventArgs);
|
||||
}
|
||||
|
||||
private void OnPaste(object sender, DataObjectPastingEventArgs e)
|
||||
{
|
||||
var data = e.SourceDataObject.GetData(DataFormats.Text);
|
||||
if (!IsDataValid(data)) e.CancelCommand();
|
||||
}
|
||||
|
||||
private void Edit_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
e.Handled = !IsDataValid(e.Text);
|
||||
}
|
||||
|
||||
bool IsDataValid(object data)
|
||||
{
|
||||
try
|
||||
{
|
||||
Convert.ToInt32(data);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,16 +5,17 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:DyeingComputer.View"
|
||||
xmlns:lang="clr-namespace:DyeingComputer.Properties"
|
||||
xmlns:localUserClass="clr-namespace:DyeingComputer.UserClass"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="630" d:DesignWidth="1280" VerticalAlignment="Top">
|
||||
<Grid>
|
||||
<DataGrid x:Name="Grid" AlternationCount="2" IsReadOnly="True"
|
||||
Margin="0,0,0,0" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
<DataGrid x:Name="Grid" AlternationCount="2" Margin="0,0,0,0" d:ItemsSource="{d:SampleData ItemCount=99}" AutoGenerateColumns="False"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="#CCCCCC"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2" AllowDrop="False"
|
||||
CanUserReorderColumns="False" CanUserSortColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False"
|
||||
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column"
|
||||
Background="White" SelectionMode="Single" FontSize="15" >
|
||||
CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility ="Column" InputMethod.IsInputMethodEnabled ="False"
|
||||
RowEditEnding="Grid_RowEditEnding"
|
||||
Background="White" SelectionMode="Single" FontSize="15" Cursor="AppStarting" >
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Setter Property="Height" Value="30" />
|
||||
@@ -43,13 +44,12 @@
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
|
||||
<DataGrid.Columns>
|
||||
<!--列信息绑定-->
|
||||
<DataGridTextColumn Header="{x:Static lang:Resources.Type}" Width="200" Binding="{Binding Category}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:Resources.Code}" Width="200" Binding="{Binding ParameterID}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:Resources.Directives}" Width="*" Binding="{Binding ParameterName}" IsReadOnly="True"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:Resources.ParameterSet}" Width="200" Binding="{Binding Value}" IsReadOnly="True"/>
|
||||
<localUserClass:NumericTextColumn Header="{x:Static lang:Resources.ParameterSet}" Width="200" Binding="{Binding Value}"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
</Grid>
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using static DyeingComputer.UserClass.SqliteHelper;
|
||||
|
||||
namespace DyeingComputer.View
|
||||
{
|
||||
@@ -23,6 +29,67 @@ namespace DyeingComputer.View
|
||||
public ParameterSetView()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
set_sql();
|
||||
// Grid.CurrentCell = new DataGridCellInfo(Grid.Items[1], Grid.Columns[3]);
|
||||
|
||||
FocusManager.SetFocusedElement(Grid, Grid);
|
||||
Grid.CurrentCell = new DataGridCellInfo(Grid.Items[Grid.Items.Count-1], Grid.Columns[3]);
|
||||
Grid.BeginEdit();
|
||||
//FocusManager.SetFocusedElement(Grid, Grid);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private SQLiteHelper SQLiteHelpers = null; //定义数据库
|
||||
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
|
||||
DataSet sql; //内存数据缓存
|
||||
|
||||
public void set_sql()
|
||||
{
|
||||
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
|
||||
SQLiteHelpers.Open(); //打开数据库
|
||||
|
||||
string sql_script = "select * from Parameters";
|
||||
|
||||
if (sql != null) sql.Clear(); //清空缓存
|
||||
sql = SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取计划表写入缓存
|
||||
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
|
||||
|
||||
SQLiteHelpers.Close(); //关闭连接
|
||||
|
||||
//sql.Clear(); //清除缓存
|
||||
//System.GC.Collect();
|
||||
}
|
||||
|
||||
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)//表格选择事件
|
||||
{
|
||||
string ID;
|
||||
string Numder;
|
||||
|
||||
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
ID = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
||||
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
||||
}
|
||||
}
|
||||
|
||||
private void Grid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
|
||||
{
|
||||
string ID;
|
||||
string Numder;
|
||||
|
||||
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
ID = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
|
||||
Numder = (Grid.Columns[3].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user