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#

3 months ago
using Chloe;
using DNSD_DB;
using DNSD_DB.Entity;
3 months 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;
3 months ago
using NDSD_TouchSocket;
using NewLife;
using TouchSocket.Core;
3 months ago
namespace NDSD_Screwdriver
{
public partial class FrmSetting : Form
{
3 months ago
public FrmSetting()
{
InitializeComponent();
Init();
}
3 months ago
3 months ago
public void Init()
{
dataGridView1.AutoGenerateColumns = false;
3 months ago
var memorySetting = MemorySetting.Current;
var ctx = SqlLiteTool.GetDb(memorySetting.DB);
var list = ctx.Query<RFIDConfigEntity>().Where(x => x.IsEnable == true).ToList();
3 months ago
// dataGridView1.DataSource = list;//DataGridView的行可以添加删除只有允许添加行、删除行
dataGridView1.DataSource = new BindingList<RFIDConfigEntity>(list);//DataGridView的行可以添加删除只有允许添加行、删除行
3 months ago
dataGridView1.AllowUserToAddRows = true;
3 months ago
dataGridView1.AllowUserToDeleteRows = true;
3 months ago
3 months ago
3 months ago
ServerIPTextbox.Text = memorySetting.ServerIP;
ServerPortTextbox.Text=memorySetting.ServerPort;
AlarmTimeValueTextBox.Text = memorySetting.AlarmTimeValue.ToString();
txtCom.Text=memorySetting.Com;
3 months ago
}
private DataTable GetTable()
{
3 months ago
DataTable table = new DataTable();
table.Columns.Add("DisplayMember", typeof(string));
3 months ago
table.Columns.Add("ValueMember", typeof(string));
var dr = table.NewRow();
3 months 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>();
3 months ago
foreach (DataGridViewRow row in dataGridView1.Rows)
{
// 检查行的类型,确保不是新行或者标题行
if (!row.IsNewRow && row.Cells[0].Value != null)
{
RFIDConfigEntity RFIDConfigEntity = new RFIDConfigEntity();
3 months 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;
3 months ago
if (string.IsNullOrEmpty(green))
3 months ago
{
MessageBox.Show("请输入绿灯");
return;
}
else
{
if (!IsInRange(green.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Green = green;
3 months ago
if (string.IsNullOrEmpty(yellow))
{
MessageBox.Show("请输入黄灯");
return;
}
else
{
if (!IsInRange(yellow.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Yellow = yellow;
3 months ago
if (string.IsNullOrEmpty(red))
{
MessageBox.Show("请输入红灯");
return;
}
else
{
if (!IsInRange(red.ToInt()))
{
MessageBox.Show("绿灯不在有效的范围");
return;
}
}
RFIDConfigEntity.Red = red;
list.Add(RFIDConfigEntity);
3 months ago
}
}
if (list.Count > 0)
{
3 months ago
var memorySetting = MemorySetting.Current;
var ctx = SqlLiteTool.GetDb(memorySetting.DB);
ctx.Update<RFIDConfigEntity>(a => a.IsEnable == true, a => new RFIDConfigEntity()
{
3 months ago
IsEnable = false
});
3 months ago
ctx.InsertRange(list);
}
MessageBox.Show("保存成功");
}
bool IsInRange(int x)
3 months ago
{
int a = 1;
int b = 16;
return x >= a && x <= b;
}
3 months ago
private void SetServerIPButton_Click(object sender, EventArgs e)
3 months ago
{
3 months ago
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void SetAlarmTimeValueButton_Click(object sender, EventArgs e)
{
3 months 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("设置成功");
}
3 months ago
}
3 months ago
}