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.
 
 
 

193 lines
8.6 KiB

using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
namespace SunlightCentralizedControlManagement_SCCM_.View
{
/// <summary>
/// ProgramgroupView.xaml 的交互逻辑
/// </summary>
public partial class ProgramgroupView : UserControl
{
public ProgramgroupView()
{
InitializeComponent();
Programgroup_sql();
Group.Text = "ALL";
}
DataSet sql; //内存数据缓存
public void Programgroup_sql()
{
string sql_script = "select * from ProgramName order by ProgramID desc";
string sql_ProgramGroup = "select * from ProgramGroup order by ID desc";
if (sql != null) sql.Clear(); //清空缓存
sql = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet(sql_script, null); //读取计划表写入缓存
if (sql != null) Grid.ItemsSource = sql.Tables[0].DefaultView; //转换显示计划表
DataTable GROUP = MainWindowViewModel.SQLiteHelpers.ExecuteDataSet(sql_ProgramGroup, null).Tables[0]; //获得程序组
List<string> result = new List<string>();
result.Add("ALL");
for (int i =0; i<GROUP.Rows.Count;i++)
{
result.Add (GROUP.Rows[i][1].ToString());
}
Group.ItemsSource = result.ToArray();
}
public static string Programgroup_Numder { get; set; }
public static string Programgroup_ID { get; set; }
private void Grid_PreviewMouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)//表格选择事件
{
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
Programgroup_ID = (Grid.Columns[0].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
Programgroup_Numder = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
}
edit.IsHitTestVisible = true;
Rename.IsHitTestVisible = true;
Remark.IsHitTestVisible = true;
Delete.IsHitTestVisible = true;
}
private void Grid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)//双击表格编辑事件
{
int rownum = Grid.SelectedIndex;//获取鼠标选中行并定义变量
if (rownum != -1)//判断鼠标定位是否有效
{
Programgroup_ID = (Grid.Columns[0].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第0列,
Programgroup_Numder = (Grid.Columns[1].GetCellContent(Grid.Items[rownum]) as TextBlock).Text;//定位第1列,
container.Content = new ProgramstepsView();//打开步设置
}
}
private void ListViewItem_New(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
InputBox frm = new InputBox();
frm.Accept += new EventHandler(InputBox_new_accept);
frm.ShowDialog();
}
void InputBox_new_accept(object sender, EventArgs e)//新建按钮窗口返回
{
//事件的接收者通过一个简单的类型转换得到InputBox的引用
InputBox frm = (InputBox)sender;
//接收到InputBox的TextBox值
string VALUE = frm.InputValue;
string ID = DateTime.Now.ToString("yyMMddHHmmss"); //id为时间合
Dictionary<string, object> Program_new = new Dictionary<string, object>();//缓存函数
Program_new.Add("ProgramName", VALUE);
Program_new.Add("ProgramID", ID);
Program_new.Add("Groups", Group.Text);
Program_new.Add("Step", "0");
Program_new.Add("Time", "0:00");
Program_new.Add("Notes", null);
MainWindowViewModel.SQLiteHelpers.InsertData("ProgramName", Program_new);// 执行插入
Programgroup_Numder = VALUE;
Programgroup_ID = ID;
Programgroup_sql();
}
private void ListViewItem_edit(object sender, System.Windows.Input.MouseButtonEventArgs e)//编辑事件
{
edit.IsHitTestVisible = false;
Rename.IsHitTestVisible = false;
Remark.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
if (Programgroup_ID == null) return;
container.Content = new ProgramstepsView();
}
private void ListViewItem_Rename(object sender, System.Windows.Input.MouseButtonEventArgs e)//重命名
{
edit.IsHitTestVisible = false;
Rename.IsHitTestVisible = false;
Remark.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
if (Programgroup_ID == null) return;
InputBox frm = new InputBox();
frm.Accept += new EventHandler(InputBox_Rename_accept);
frm.ShowDialog();
}
void InputBox_Rename_accept(object sender, EventArgs e)//重命名按钮窗口返回
{
//事件的接收者通过一个简单的类型转换得到InputBox的引用
InputBox frm = (InputBox)sender;
//接收到InputBox的TextBox值
string VALUE = frm.InputValue;
Dictionary<string, object> Program_Rename = new Dictionary<string, object>();//缓存函数
Program_Rename.Add("ProgramName", VALUE);
Program_Rename.Add("Groups", Group.Text);
MainWindowViewModel.SQLiteHelpers.Update("ProgramName", Program_Rename, "ProgramID='" + Programgroup_ID + "'", null);
Dictionary<string, object> Program_Steps = new Dictionary<string, object>();//缓存函数
Program_Steps.Add("Program", VALUE);
MainWindowViewModel.SQLiteHelpers.Update("ProgramSteps", Program_Steps, "ProgramID='" + Programgroup_ID + "'", null);
Programgroup_sql();
Programgroup_Numder = null;
Programgroup_ID = null;
}
private void ListViewItem_Remark(object sender, System.Windows.Input.MouseButtonEventArgs e)//备注
{
edit.IsHitTestVisible = false;
Rename.IsHitTestVisible = false;
Remark.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
if (Programgroup_ID == null) return;
InputBox frm = new InputBox();
frm.Accept += new EventHandler(InputBox_Remark_accept);
frm.ShowDialog();
}
void InputBox_Remark_accept(object sender, EventArgs e)//备注按钮窗口返回
{
//事件的接收者通过一个简单的类型转换得到InputBox的引用
InputBox frm = (InputBox)sender;
//接收到InputBox的TextBox值
string VALUE = frm.InputValue;
Dictionary<string, object> Program_Remark = new Dictionary<string, object>();//缓存函数
Program_Remark.Add("Notes", VALUE);
MainWindowViewModel.SQLiteHelpers.Update("ProgramName", Program_Remark, "ProgramID='" + Programgroup_ID + "'", null);
Programgroup_sql();
Programgroup_Numder = null;
Programgroup_ID = null;
}
private void ListViewItem_Delete(object sender, System.Windows.Input.MouseButtonEventArgs e)//删除
{
edit.IsHitTestVisible = false;
Rename.IsHitTestVisible = false;
Remark.IsHitTestVisible = false;
Delete.IsHitTestVisible = false;
if (Programgroup_Numder == null) return;
///弹窗提示确认删除
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Delete + Programgroup_Numder, "Delete ",
System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
{
///执行删除
MainWindowViewModel.SQLiteHelpers.Delete("ProgramName", "ProgramID='" + Programgroup_ID + "'", null);
MainWindowViewModel.SQLiteHelpers.Delete("ProgramSteps", "ProgramID='" + Programgroup_ID + "'", null);
Programgroup_sql();
}
Programgroup_Numder = null;
Programgroup_ID = null;
}
}
}