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

201 lines
5.6 KiB
C#

1 month ago
using Chloe;
using DNSD_DB;
using NewLife.Data;
using NewLife.Reflection;
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;
1 month ago
using NDSD_TouchSocket;
using NewLife;
using TouchSocket.Core;
1 month ago
namespace NDSD_Screwdriver
{
public partial class FrmSetting : Form
{
1 month ago
public FrmSetting()
{
InitializeComponent();
SqlLiteTool.CreateTable(AppTool.GetDb());
Init();
1 month ago
1 month ago
}
1 month ago
1 month ago
public void Init()
{
dataGridView1.AutoGenerateColumns = false;
var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
var list = ctx.Query<RfidSetting>().Where(x => x.IsEnable == true).ToList();
1 month ago
// dataGridView1.DataSource = list;//DataGridView的行可以添加删除只有允许添加行、删除行
1 month ago
dataGridView1.DataSource = new BindingList<RfidSetting>(list);//DataGridView的行可以添加删除只有允许添加行、删除行
dataGridView1.AllowUserToAddRows = true;
1 month ago
dataGridView1.AllowUserToDeleteRows = true;
}
private DataTable GetTable()
{
1 month ago
DataTable table = new DataTable();
table.Columns.Add("DisplayMember", typeof(string));
1 month ago
table.Columns.Add("ValueMember", typeof(string));
var dr = table.NewRow();
1 month ago
dr[0] = "绿色";
dr[1] = "1";
table.Rows.Add(dr);
dr = table.NewRow();
dr[0] = "黄色";
dr[1] = "2";
table.Rows.Add(dr);
dr = table.NewRow();
dr[0] = "红色";
dr[1] = "3";
table.Rows.Add(dr);
return table;
}
private void dataGridView1_DefaultValuesNeeded(object sender, DataGridViewRowEventArgs e)
{
e.Row.Cells[0].Value = "0";
e.Row.Cells["D1"].Value = "0";
e.Row.Cells["D2"].Value = "0";
e.Row.Cells["D3"].Value = "0";
}
private void btnSave_Click(object sender, EventArgs e)
{
List<RfidSetting> list = new List<RfidSetting>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// 检查行的类型,确保不是新行或者标题行
if (!row.IsNewRow && row.Cells[0].Value != null)
{
RfidSetting rfidSetting = new RfidSetting();
// 获取当前行的值,并添加到列表中
string rfid = row.Cells[0].Value.ToString();
string green = row.Cells[1].Value.ToString();
string yellow = row.Cells[2].Value.ToString();
string red = row.Cells[3].Value.ToString();
if (string.IsNullOrEmpty(rfid))
{
MessageBox.Show("请输入rfid标签");
return;
}
rfidSetting.IsEnable = true;
rfidSetting.CreateDateTime = DateTime.Now;
rfidSetting.RfidNo = rfid;
if (string.IsNullOrEmpty(green))
1 month ago
{
MessageBox.Show("请输入绿灯");
return;
}
else
{
if (!IsInRange(green.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
rfidSetting.Green = green;
if (string.IsNullOrEmpty(yellow))
{
MessageBox.Show("请输入黄灯");
return;
}
else
{
if (!IsInRange(yellow.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
rfidSetting.Yellow = yellow;
if (string.IsNullOrEmpty(red))
{
MessageBox.Show("请输入红灯");
return;
}
else
{
if (!IsInRange(red.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
rfidSetting.Red = red;
list.Add(rfidSetting);
}
}
if (list.Count > 0)
{
var ctx = SqlLiteTool.GetDb(AppTool.GetDb());
ctx.Update<RfidSetting>(a => a.IsEnable == true, a => new RfidSetting()
{
1 month ago
IsEnable = false
});
1 month ago
ctx.InsertRange(list);
}
MessageBox.Show("保存成功");
}
bool IsInRange(int x)
1 month ago
{
int a = 1;
int b = 16;
return x >= a && x <= b;
}
private void SetServerIPButton_Click(object sender, EventArgs e)
{
MemorySetting.ServerIP = ServerIPTextbox.Text;
MemorySetting.ServerPort = ServerPortTextbox.Text;
}
1 month ago
}
1 month ago
}