染色机计算机
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

167 lines
6.4 KiB

using DyeingComputer.KEY;
using DyeingComputer.ViewModel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder;
using System.Linq;
using System.Security.Cryptography;
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
{
/// <summary>
/// ParameterSetView.xaml 的交互逻辑
/// </summary>
public partial class ParameterSetView : UserControl
{
private TextBox currentTextBox;
string ID;
private TouchKeyboard Keyboard;
public ParameterSetView()
{
InitializeComponent();
set_sql();
}
//private SQLiteHelper SQLiteHelpers = null; //定义数据库
//private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\800COMPUTER.db"; //数据库路径
public void set_sql()
{
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindowViewModel.dt_ParameterSet = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID asc", null).Tables[0]; //读取计划表写入缓存
if (MainWindowViewModel.dt_ParameterSet.Rows.Count>0) Grid.ItemsSource = MainWindowViewModel.dt_ParameterSet.DefaultView; //转换显示计划表
//SQLiteHelpers.Close(); //关闭连接
}
private void Grid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)//数据表输入事件
{
string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息
Dictionary<string, object> datagrid_v = new Dictionary<string, object>();//缓存函数
datagrid_v.Add("Value", newValue);
//SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
//SQLiteHelpers.Open(); //打开数据库
MainWindow.SQLiteHelpers.Update("Parameters", datagrid_v, "ParameterID ='" + ID + "'", null);//更新
MainWindowViewModel.dt_ParameterSet = MainWindow.SQLiteHelpers.ExecuteDataSet("select * from Parameters order by ParameterID asc", null).Tables[0]; //读取计划表写入缓存
//SQLiteHelpers.Close();//关闭数据库
MainWindowViewModel.set_ = true;
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)//打开页面时的操作
{
DataGridRow dr = (DataGridRow)Grid.ItemContainerGenerator.ContainerFromIndex(0);//取第0行单元格
DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(dr);
DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(3); //取第3列每行单元格
cell.Focus();
Grid.SelectedIndex = 0;
}
public static T GetVisualChild<T>(Visual parent) where T : Visual
{
T child = default(T);
int numVisuals = VisualTreeHelper.GetChildrenCount(parent);
for (int i = 0; i < numVisuals; i++)
{
Visual v = (Visual)VisualTreeHelper.GetChild(parent, i);
child = v as T;
if (child == null)
{
child = GetVisualChild<T>(v);
}
if (child != null)
{
break;
}
}
return child;
}
private void Grid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
ID = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
}
}
private void Grid_PreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e)
{
currentTextBox = e.EditingElement as TextBox;
if (Keyboard == null)
{
Keyboard = new TouchKeyboard();
Keyboard.KeyPressed += Keyboard_KeyPressed;
Keyboard.Closed += (s, args) => { Keyboard = null; };
}
// 显示键盘
Keyboard.Show();
// 定位键盘位置(在主窗口下方)
UpdateKeyboardPosition();
}
// 更新键盘位置
private void UpdateKeyboardPosition()
{
if (Keyboard == null) return;
// 获取主窗口的位置
var mainWindowWidth = this.Width;
var mainWindowHeight = this.Height;
// 计算键盘位置(主窗口底部中央)
Keyboard.Left = (mainWindowWidth - Keyboard.Width) / 2;
Keyboard.Top = mainWindowHeight - (Keyboard.Height+50);
}
// 键盘按键事件处理
private void Keyboard_KeyPressed(object sender, TouchKeyboard.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;
}
Keyboard.Close();
break;
case KeyType.Hide:
// 隐藏键盘处理
Keyboard.Close();
break;
}
Grid.CommitEdit();
}
}
}