//保存 private void Btn_Save_Click(object sender, EventArgs e) { if (!Function.IsRegEx(@"^\d+(\.\d+)?$", this.Tb_DetectStart.Text.Trim())) { Function.MessageWarning("检测起点类型不正确!"); return; } if (!Function.IsRegEx(@"^[1-9]\d*$|^0$", this.Tb_FullBalance.Text.Trim())) { Function.MessageWarning("最大秤值类型不正确!"); return; } C_Meter MeterItem = new C_Meter(); MeterItem.Serial = Convert.ToInt32(this.Cmb_Serial.SelectedValue); MeterItem.MeterType = this.Cmb_MeterType.SelectedValue.ToString(); MeterItem.BaudRate =Convert.ToInt32(this.Cmb_BaudRate.SelectedValue); MeterItem.Unit = this.Cmb_Unit.SelectedValue.ToString(); MeterItem.DetectStart =Convert.ToSingle(this.Tb_DetectStart.Text.Trim()); MeterItem.FullBalance =Convert.ToInt32(this.Tb_FullBalance.Text.Trim()); if (MeterItem.Unit == "t"){MeterItem.Digit = 3; } else{MeterItem.Digit = 0;} if (MeterBLL.Update(MeterItem)) { Function.Message("修改成功!"); } }
/// <summary> /// 显示信息 /// </summary> /// <returns>返回数据源</returns> public static void DataShow(C_Meter Item) { try { PublicFun.IniFile Ini = new PublicFun.IniFile(WSV.Model.FilePath.Config); if (Ini.ExistIniFile()) { Item.Serial =Convert.ToInt32(Ini.IniReadValue("Meter", "Serial")); Item.MeterType = Ini.IniReadValue("Meter", "MeterType"); Item.BaudRate =Convert.ToInt32(Ini.IniReadValue("Meter", "BaudRate")); Item.Unit = Ini.IniReadValue("Meter", "Unit"); Item.DetectStart =Convert.ToSingle(Ini.IniReadValue("Meter", "DetectStart")); Item.FullBalance =Convert.ToInt32(Ini.IniReadValue("Meter", "FullBalance")); Item.Digit =Convert.ToInt32(Ini.IniReadValue("Meter","Digit")); } } catch (Exception ex) { throw ex; } }
/// <summary> /// 修改数据 /// </summary> /// <param name="Item">model</param> /// <returns></returns> public static bool Update(C_Meter Item) { bool Flag = false; try { PublicFun.IniFile Ini = new PublicFun.IniFile(WSV.Model.FilePath.Config); if (Ini.ExistIniFile()) { Ini.IniWriteValue("Meter", "Serial", Item.Serial); Ini.IniWriteValue("Meter", "MeterType", Item.MeterType); Ini.IniWriteValue("Meter", "BaudRate", Item.BaudRate); Ini.IniWriteValue("Meter", "Unit", Item.Unit); Ini.IniWriteValue("Meter", "DetectStart", Item.DetectStart); Ini.IniWriteValue("Meter", "FullBalance", Item.FullBalance); Ini.IniWriteValue("Meter", "Digit", Item.Digit); } Flag = true; } catch (Exception ex) { throw ex; } return Flag; }
//窗体加载 private void Meter_Load(object sender, EventArgs e) { My_RunCode = BLL.MyLog.DL_Run.Insert(this.Text); C_Meter MeterItem=new C_Meter(); MeterBLL.DataShow(MeterItem); this.Cmb_Serial.SelectedByValue(MeterItem.Serial); this.Cmb_MeterType.SelectedByValue(MeterItem.MeterType); this.Cmb_BaudRate.SelectedByValue(MeterItem.BaudRate); this.Cmb_Unit.SelectedByValue(MeterItem.Unit); this.Tb_DetectStart.Text = MeterItem.DetectStart.ToString(); this.Tb_FullBalance.Text = MeterItem.FullBalance.ToString(); }