@ -1,8 +1,10 @@
using DyeingComputer.ViewModel ;
using DyeingComputer.KEY ;
using DyeingComputer.ViewModel ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Net ;
using System.Security.Cryptography ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows ;
@ -28,75 +30,140 @@ namespace DyeingComputer.View
{
InitializeComponent ( ) ;
}
// private SQLiteHelper SQLiteHelpers = null; //定义数据库
string ID ;
private TextBox currentTextBox ;
private TouchKeyboardNumeral numeralKeyboard ;
// private SQLiteHelper SQLiteHelpers = null; //定义数据库
//private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
private void Grid_D_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
int rownum = Grid_D . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_D . Columns [ 0 ] . GetCellContent ( Grid_D . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
}
}
private void Grid_A_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
int rownum = Grid_A . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_A . Columns [ 0 ] . GetCellContent ( Grid_A . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
}
}
private void Grid_M_SelectionChanged ( object sender , SelectionChangedEventArgs e )
{
}
private void Grid_D_CellEditEnding ( object sender , DataGridCellEditEndingEventArgs e )
private void Grid_D_BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
{
string ID ;
string newValue = ( e . EditingElement as TextBox ) . Text ; //获得输入单元格信息
int rownum = Grid_D . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
MainWindowViewModel . D_view = false ;
}
private void Grid_D_PreparingCellForEdit ( object sender , DataGridPreparingCellForEditEventArgs e )
{
currentTextBox = e . EditingElement as TextBox ;
if ( numeralKeyboard = = null )
{
ID = ( Grid_D . Columns [ 0 ] . GetCellContent ( Grid_D . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
Dictionary < string , object > datagrid_v = new Dictionary < string , object > ( ) ; //缓存函数
datagrid_v . Add ( "PLC" , newValue ) ;
// SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
MainWindow . SQLiteHelpers . Update ( "IOName" , datagrid_v , "ID ='" + ID + "'" , null ) ; //更新
//SQLiteHelpers.Close();//关闭数据库
numeralKeyboard = new TouchKeyboardNumeral ( ) ;
numeralKeyboard . KeyPressed + = NumeralKeyboard_KeyPressed ;
numeralKeyboard . Closed + = ( s , args ) = > { numeralKeyboard = null ; } ;
}
// 显示键盘
numeralKeyboard . Show ( ) ;
// 定位键盘位置(在主窗口下方)
UpdateKeyboardPosition ( ) ;
}
private void Grid_D_CellEditEnding ( object sender , DataGridCellEditEndingEventArgs e )
{
string newValue = ( e . EditingElement as TextBox ) . Text ; //获得输入单元格信息
Dictionary < string , object > datagrid_v = new Dictionary < string , object > ( ) ; //缓存函数
datagrid_v . Add ( "PLC" , newValue ) ;
// SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
// SQLiteHelpers.Open(); //打开数据库
MainWindow . SQLiteHelpers . Update ( "IOName" , datagrid_v , "ID ='" + ID + "'" , null ) ; //更新
//SQLiteHelpers.Close();//关闭数据库
MainWindowViewModel . SQL_data ( ) ; //重新获得io表
MainWindowViewModel . D_view = true ;
MainWindowViewModel . D_view = true ;
}
private void Grid_D_BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
private void Grid_A _BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
{
MainWindowViewModel . D_view = false ;
MainWindowViewModel . A_view = false ;
}
private void Grid_A_PreparingCellForEdit ( object sender , DataGridPreparingCellForEditEventArgs e )
{
currentTextBox = e . EditingElement as TextBox ;
if ( numeralKeyboard = = null )
{
numeralKeyboard = new TouchKeyboardNumeral ( ) ;
numeralKeyboard . KeyPressed + = NumeralKeyboard_KeyPressed ;
numeralKeyboard . Closed + = ( s , args ) = > { numeralKeyboard = null ; } ;
}
// 显示键盘
numeralKeyboard . Show ( ) ;
// 定位键盘位置(在主窗口下方)
UpdateKeyboardPosition ( ) ;
}
private void Grid_A_CellEditEnding ( object sender , DataGridCellEditEndingEventArgs e )
{
string ID ;
string newValue = ( e . EditingElement as TextBox ) . Text ; //获得输入单元格信息
Dictionary < string , object > datagrid_v = new Dictionary < string , object > ( ) ; //缓存函数
datagrid_v . Add ( "PLC" , newValue ) ;
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindow . SQLiteHelpers . Update ( "IOName" , datagrid_v , "ID ='" + ID + "'" , null ) ; //更新
//SQLiteHelpers.Close();//关闭数据库
int rownum = Grid_A . SelectedIndex ; //获取鼠标选中行并定义变量
if ( rownum ! = - 1 ) //判断鼠标定位是否有效
{
ID = ( Grid_A . Columns [ 0 ] . GetCellContent ( Grid_A . Items [ rownum ] ) as TextBlock ) . Text ; //定位第0列,
Dictionary < string , object > datagrid_v = new Dictionary < string , object > ( ) ; //缓存函数
datagrid_v . Add ( "PLC" , newValue ) ;
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindow . SQLiteHelpers . Update ( "IOName" , datagrid_v , "ID ='" + ID + "'" , null ) ; //更新
//SQLiteHelpers.Close();//关闭数据库
}
MainWindowViewModel . SQL_data ( ) ; //重新获得io表
MainWindowViewModel . A_view = true ;
}
private void Grid_A_BeginningEdit ( object sender , DataGridBeginningEditEventArgs e )
// 更新键盘位置
private void UpdateKeyboardPosition ( )
{
MainWindowViewModel . A_view = false ;
if ( numeralKeyboard = = null ) return ;
// 获取主窗口的位置
var mainWindowWidth = this . Width ;
var mainWindowHeight = this . Height ;
// 计算键盘位置(主窗口底部中央)
numeralKeyboard . Left = ( mainWindowWidth - numeralKeyboard . Width ) / 2 ;
numeralKeyboard . Top = mainWindowHeight / 2 ;
}
// 键盘按键事件处理
private void NumeralKeyboard_KeyPressed ( object sender , TouchKeyboardNumeral . KeyPressedEventArgs e )
{
switch ( e . KeyType )
{
/ * case KeyType . Character :
currentTextBox . Text + = e . KeyValue ;
break ;
case KeyType . Backspace :
if ( currentTextBox . Text . Length > 0 )
{
currentTextBox . Text = currentTextBox . Text . Substring ( 0 , currentTextBox . Text . Length - 1 ) ;
}
break ; * /
case KeyType . Enter :
// 回车键处理
if ( ! String . IsNullOrEmpty ( e . KeyValue ) )
{
currentTextBox . Text = e . KeyValue ;
}
numeralKeyboard . Close ( ) ;
break ;
case KeyType . Hide :
// 隐藏键盘处理
numeralKeyboard . Close ( ) ;
break ;
}
Grid_D . CommitEdit ( ) ;
Grid_A . CommitEdit ( ) ;
}
}
}