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.

233 lines
6.5 KiB
C#

1 month ago
using Chloe;
using DNSD_DB;
using DNSD_DB.Entity;
1 month ago
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();
Init();
}
1 month ago
1 month ago
public void Init()
{
dataGridView1.AutoGenerateColumns = false;
1 month ago
var memorySetting = MemorySetting.Current;
var ctx = SqlLiteTool.GetDb(memorySetting.DB);
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
1 month ago
// dataGridView1.DataSource = list;//DataGridView的行可以添加删除只有允许添加行、删除行
dataGridView1.DataSource = new BindingList<RFIDConfigEntity>(list);//DataGridView的行可以添加删除只有允许添加行、删除行
1 month ago
dataGridView1.AllowUserToAddRows = true;
1 month ago
dataGridView1.AllowUserToDeleteRows = true;
1 month ago
1 month ago
1 month ago
ServerIPTextbox.Text = memorySetting.ServerIP;
ServerPortTextbox.Text=memorySetting.ServerPort;
AlarmTimeValueTextBox.Text = memorySetting.AlarmTimeValue.ToString();
txtCom.Text=memorySetting.Com;
1 month ago
}
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<RFIDConfigEntity> list = new List<RFIDConfigEntity>();
1 month ago
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// 检查行的类型,确保不是新行或者标题行
if (!row.IsNewRow && row.Cells[0].Value != null)
{
RFIDConfigEntity RFIDConfigEntity = new RFIDConfigEntity();
1 month ago
// 获取当前行的值,并添加到列表中
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;
}
RFIDConfigEntity.IsEnable = true;
RFIDConfigEntity.CreateDateTime = DateTime.Now;
RFIDConfigEntity.RfidNo = rfid;
1 month ago
if (string.IsNullOrEmpty(green))
1 month ago
{
MessageBox.Show("请输入绿灯");
return;
}
else
{
if (!IsInRange(green.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Green = green;
1 month ago
if (string.IsNullOrEmpty(yellow))
{
MessageBox.Show("请输入黄灯");
return;
}
else
{
if (!IsInRange(yellow.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Yellow = yellow;
1 month ago
if (string.IsNullOrEmpty(red))
{
MessageBox.Show("请输入红灯");
return;
}
else
{
if (!IsInRange(red.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Red = red;
list.Add(RFIDConfigEntity);
1 month ago
}
}
if (list.Count > 0)
{
1 month ago
var memorySetting = MemorySetting.Current;
var ctx = SqlLiteTool.GetDb(memorySetting.DB);
ctx.Update<RFIDConfigEntity>(a => a.IsEnable == true, a => new RFIDConfigEntity()
{
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;
}
1 month ago
private void SetServerIPButton_Click(object sender, EventArgs e)
1 month ago
{
1 month ago
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void SetAlarmTimeValueButton_Click(object sender, EventArgs e)
{
1 month ago
var memorySetting = MemorySetting.Current;
memorySetting.ServerIP = ServerIPTextbox.Text;
memorySetting.ServerPort = ServerPortTextbox.Text;
memorySetting.AlarmTimeValue = Convert.ToInt32(AlarmTimeValueTextBox.Text);
memorySetting.Com = txtCom.Text;
memorySetting.Save();
MessageBox.Show("设置成功");
}
1 month ago
}
1 month ago
}