using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DB.Entity; using DB.Service; using Tool; using Tool.Model; namespace RfidWeb.Frm { public partial class FormPlanAdd : Form { private FromPlanService fromPlanService = new FromPlanService(); private FromPlan fromPlan = null; private long id = default; public FormPlanAdd() { InitializeComponent(); this.ucCode.InputText = fromPlanService.GetMaxCode(); this.ucNo.InputText = "50"; fromPlan = new FromPlan(); fromPlan.ID = SnowflakeFactory.NewId; } public FormPlanAdd(long id) { InitializeComponent(); this.id = id; fromPlan = fromPlanService.Query(id); this.ucNo.InputText = fromPlan.Num.ToString(); this.ucCode.InputText=fromPlan.Code; } private void btnCancel_BtnClick(object sender, EventArgs e) { this.Close(); } bool IsValidNumber(string input) { // 检查是否是纯数字 if (int.TryParse(input, out int number)) { // 检查范围是否符合 return number > 0 && number < 2000; } return false; } private void btnOK_BtnClick(object sender, EventArgs e) { var code = ucNo.InputText.ToInt(); fromPlan.Num = code; fromPlan.Code=ucCode.InputText.ToString(); if (IsValidNumber(ucNo.InputText)) { MessageBox.Show("请输入0-2000 有效范围"); return; } if (id == 0) { fromPlanService.Insert(fromPlan); } else { fromPlanService.Update(fromPlan); } PlcConnect.Instance.Write(HmiPointInfo.Product_counter_CH, int.Parse(code.ToString())); this.Close(); } } }