染色机计算机
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.

81 lines
3.0 KiB

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>
1 year ago
/// ParameterSetView.xaml 的交互逻辑
/// </summary>
1 year ago
public partial class ParameterSetView : UserControl
{
1 year ago
public ParameterSetView()
{
InitializeComponent();
set_sql();
//Grid.Focus();
Grid.SelectedIndex = 0;
// var row = Grid.ItemContainerGenerator.ContainerFromIndex(0) as FrameworkElement;
//if (row != null ) {row.Focus(); }
}
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(); //关闭连接
}
private void Grid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)//数据表输入事件
{
string ID;
string newValue = (e.EditingElement as TextBox).Text;//获得输入单元格信息
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
ID = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
Dictionary<string, object> datagrid_v = new Dictionary<string, object>();//缓存函数
datagrid_v.Add("Value", newValue);
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Update("Parameters",datagrid_v , "ParameterID ='"+ ID + "'", null);//更新
SQLiteHelpers.Close();//关闭数据库
}
}
}
}