149 lines
5.3 KiB
C#
149 lines
5.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using WindowsFormsApp1.db;
|
|
using WindowsFormsApp1.mod;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace WindowsFormsApp1.form
|
|
{
|
|
public partial class LinePLC_Manage : Form
|
|
{
|
|
public LinePLC_Manage()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void 查询_Click(object sender, EventArgs e)
|
|
{
|
|
GetInfo();
|
|
}
|
|
|
|
private void 关闭_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void LINE_Manage_Load(object sender, EventArgs e)
|
|
{
|
|
dataGridView1.AutoGenerateColumns = false;
|
|
|
|
// 添加修改按钮列
|
|
DataGridViewButtonColumn modifyColumn = new DataGridViewButtonColumn();
|
|
modifyColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
modifyColumn.Name = "ModifyColumn";
|
|
modifyColumn.HeaderText = "修改";
|
|
modifyColumn.Text = "修改";
|
|
modifyColumn.UseColumnTextForButtonValue = true;
|
|
dataGridView1.Columns.Add(modifyColumn);
|
|
|
|
// 添加删除按钮列
|
|
DataGridViewButtonColumn deleteColumn = new DataGridViewButtonColumn();
|
|
deleteColumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
deleteColumn.Name = "DeleteColumn";
|
|
deleteColumn.HeaderText = "删除";
|
|
deleteColumn.Text = "删除";
|
|
deleteColumn.UseColumnTextForButtonValue = true;
|
|
dataGridView1.Columns.Add(deleteColumn);
|
|
|
|
dataGridView1.CellContentClick += DataGridView1_CellContentClick;
|
|
GetInfo();
|
|
}
|
|
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
|
{
|
|
// 检查点击的是否为按钮列
|
|
if (e.RowIndex >= 0)
|
|
{
|
|
DataGridView dataGridView = (DataGridView)sender;
|
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
|
|
|
int selectid = int.Parse(row.Cells[0].Value.ToString());
|
|
if (e.ColumnIndex == 3)
|
|
{
|
|
LinePLC_Insert fLOW_Insert = new LinePLC_Insert();
|
|
fLOW_Insert.dataid = selectid;
|
|
fLOW_Insert.Operation = OperationType.Edit;
|
|
fLOW_Insert.ShowDialog();
|
|
GetInfo();
|
|
|
|
}
|
|
else if (e.ColumnIndex == 4)
|
|
{
|
|
DialogResult result = MessageBox.Show("你确定要删除数据吗?", "确认提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
|
|
|
|
if (result == DialogResult.OK)
|
|
{
|
|
SQLiteHelper<t_lineplc> sQLiteHelper = new db.SQLiteHelper<t_lineplc>();
|
|
var delresult = sQLiteHelper.Delete(selectid);
|
|
if (delresult.Success)
|
|
{
|
|
MessageBox.Show("删除成功");
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("删除失败");
|
|
}
|
|
GetInfo();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
public void GetInfo()
|
|
{
|
|
try
|
|
{
|
|
SQLiteHelper<t_plc> sQLiteHelper = new db.SQLiteHelper<t_plc>();
|
|
SQLiteHelper<t_line> sQLiteHelper1 = new db.SQLiteHelper<t_line>();
|
|
SQLiteHelper<t_lineplc> sQLiteHelper2 = new db.SQLiteHelper<t_lineplc>();
|
|
var result_plc = sQLiteHelper.QueryAll();
|
|
var result_line = sQLiteHelper1.QueryAll();
|
|
var result_lineplc = sQLiteHelper2.QueryAll();
|
|
|
|
|
|
if (!result_line.Success || !result_plc.Success || !result_lineplc.Success)
|
|
{
|
|
MessageBox.Show("查询失败!");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
List<object> list = new List<object>();
|
|
foreach (var line in result_lineplc.Data)
|
|
{
|
|
var linename = result_line.Data.FirstOrDefault(a=>a.id == line.lineid);
|
|
var plcname = result_plc.Data.FirstOrDefault(a => a.id == line.plcid);
|
|
list.Add( new
|
|
{
|
|
id = line.id,
|
|
lineid = line.lineid,
|
|
plcid = line.plcid,
|
|
linename = linename.linename,
|
|
plcname = plcname.plcname,
|
|
});
|
|
}
|
|
|
|
dataGridView1.DataSource = null;
|
|
dataGridView1.DataSource = list;
|
|
dataGridView1.Refresh();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
}
|
|
}
|
|
|
|
private void 新增_Click(object sender, EventArgs e)
|
|
{
|
|
LinePLC_Insert fLOW_Insert = new LinePLC_Insert();
|
|
fLOW_Insert.ShowDialog();
|
|
GetInfo();
|
|
}
|
|
}
|
|
}
|