private void Btn_Del_Click(object sender, EventArgs e) { int index = 0; CbDeviceInfo deviceinfo = FormComm.GetDataSourceToClass <CbDeviceInfo>(dgv_DeviceInfo, ref index); if (MessageBox.Show("确认是否删除设备信息。", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { try { Dbhelper.Db.Del <CbDeviceInfo>(deviceinfo.ID); DataTable dt = dgv_DeviceInfo.DataSource as DataTable; dt.Rows.RemoveAt(index); GetDeviceInfoCount(); if (cb_AllSelected.CheckState != CheckState.Unchecked) { cb_AllSelected.CheckState = CheckState.Unchecked; btn_Export.Enabled = false; } } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Btn_Enter_Click(object sender, EventArgs e) { int devicenumber = Utils.StrToInt(tb_DeviceNumber.Text, 0); int wirelessid = Utils.StrToInt(tb_WirelessID.Text, 0); CbDeviceInfo mDeviceInfo = new CbDeviceInfo() { HostNumber = (int)ud_HostNumber.Value, IOSate = cb_IOSate.SelectedIndex, DeviceNumber = devicenumber, DeviceMode = cb_DeviceMode.SelectedIndex, FieldPartition = cb_FieldPartition.SelectedIndex, AntiSubmarineBack = cb_AntiSubmarineBack.SelectedIndex, VehicleDetection = cb_VehicleDetection.SelectedIndex, Distance = cb_Distance.SelectedIndex, EquipmentDelay = cb_EquipmentDelay.SelectedIndex, Language = cb_Language.SelectedIndex, IsLikeMachine = cb_IsLikeMachine.SelectedIndex, Frequency = (int)ud_Frequency.Value, WirelessID = wirelessid, VagueQueryNumber = cb_VagueQueryNumber.SelectedIndex }; try { mDeviceInfo.ID = Dbhelper.Db.Insert <CbDeviceInfo>(mDeviceInfo); Tag = mDeviceInfo; this.DialogResult = DialogResult.OK; } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void UpdateExitNumber(int index) { _mDeviceInfo = _mDeviceInfos[index]; string cmdtext = string.Format(" Update CBTempChargeRecord set ExitNumber={0} where ExitNumber=0 ", _mDeviceInfo.HostNumber); Dbhelper.Db.ExecuteNonQuery(cmdtext); _mDeviceInfos = null; }
private void Btn_Add_Click(object sender, EventArgs e) { using (AddDeviceInfo_Form adddeviceinfo = new AddDeviceInfo_Form()) { if (adddeviceinfo.ShowDialog() != DialogResult.OK) { return; } CbDeviceInfo mDeviceInfo = adddeviceinfo.Tag as CbDeviceInfo; FormComm.AddDgvSource <CbDeviceInfo>(mDeviceInfo, dgv_DeviceInfo); GetDeviceInfoCount(); } }
private void Btn_Edit_Click(object sender, EventArgs e) { int index = 0; CbDeviceInfo mDeviceInfo = FormComm.GetDataSourceToClass <CbDeviceInfo>(dgv_DeviceInfo, ref index); using (EditDeviceInfo_Form editdeviceinfo = new CbznSystem.EditDeviceInfo_Form(mDeviceInfo)) { if (editdeviceinfo.ShowDialog() != DialogResult.OK) { return; } mDeviceInfo = editdeviceinfo.Tag as CbDeviceInfo; FormComm.UpdateDgvDataSource <CbDeviceInfo>(mDeviceInfo, dgv_DeviceInfo, index); } }
public EditDeviceInfo_Form(CbDeviceInfo mdeviceinfo) { InitializeComponent(); _mDeviceInfo = mdeviceinfo; this.Load += AddDeviceInfo_Form_Load; this.KeyDown += EditDeviceInfo_Form_KeyDown; cb_DeviceMode.SelectedIndexChanged += Cb_DeviceMode_SelectedIndexChanged; cb_IsLikeMachine.SelectedIndexChanged += Cb_IsLikeMachine_SelectedIndexChanged; tb_DeviceNumber.KeyPress += TxtKeyPress; tb_WirelessID.KeyPress += TxtKeyPress; btn_Enter.Click += Btn_Enter_Click; }
private List <CbDeviceInfo> GetSelectRow() { List <CbDeviceInfo> mDeviceInfos = new List <CbDeviceInfo>(); for (int i = 0; i < dgv_DeviceInfo.RowCount; i++) { bool flag = Utils.StrToBool(dgv_DeviceInfo["c_Selected", i].Value, false); if (!flag) { continue; } CbDeviceInfo mDeviceInfo = FormComm.GetDataSourceToClass <CbDeviceInfo>(dgv_DeviceInfo, i); mDeviceInfos.Add(mDeviceInfo); } return(mDeviceInfos); }
private void Cb_WirelessIdList_SelectedIndexChanged(object sender, EventArgs e) { if (cb_WirelessIdList.SelectedIndex > 0) { try { CbDeviceInfo mDeviceInfo = Dbhelper.Db.FirstDefault <CbDeviceInfo>((long)cb_WirelessIdList.SelectedValue); ud_WirelessId.Value = mDeviceInfo.IsLikeMachine == 0 ? mDeviceInfo.HostNumber : mDeviceInfo.WirelessID; ud_WirelessFrequency.Value = mDeviceInfo.HostNumber > 64 ? mDeviceInfo.HostNumber - 64 : mDeviceInfo.HostNumber; } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { ud_WirelessFrequency.Value = 1; ud_WirelessId.Value = 0; } }
private void InputInfo() { CbDeviceInfo mode; List <CbDeviceInfo> deviceinfos = new List <CbDeviceInfo>(); try { StringBuilder sb = new StringBuilder(); TextFieldParser tfp; foreach (string item in _FileNames) { if (!File.Exists(item)) { continue; } string filename = Path.GetFileNameWithoutExtension(item); if (!CRegex.IsDeviceInfoFileName(filename)) { continue; } l_Title.Text = "正在导入:" + filename; pBar.PerformStep(); sb.AppendFormat("文件:{0}", filename); using (tfp = new TextFieldParser(item)) { tfp.Delimiters = new string[] { ",", "<", ">" }; tfp.TextFieldType = FieldType.Delimited; mode = new CbDeviceInfo(); while (!tfp.EndOfData) { string[] content = tfp.ReadFields(); int number = Convert.ToInt32(content[0], 16); string value = content[2]; switch (number) { case 0: mode.HostNumber = Utils.StrToInt(value.Substring(0, 2), 1); mode.Frequency = Utils.StrToInt(value.Substring(2, 2), 1); mode.WirelessID = Utils.StrToInt(value.Substring(4, 8), 0); mode.IsLikeMachine = Utils.StrToInt(value.Substring(12, 2), 0); break; case 1: mode.Distance = Utils.StrToInt(value, 1); break; case 2: mode.EquipmentDelay = Utils.StrToInt(value, 1); break; case 3: //mode.CustomerNumber = Utils.StrToInt(value, 9887); break; case 8: mode.FieldPartition = Convert.ToInt32(value, 16); break; case 9: if (!string.IsNullOrEmpty(value)) { mode.IOSate = Utils.StrToInt(value, 0); } break; case 10: mode.AntiSubmarineBack = Utils.StrToInt(value, 0); break; case 12: switch (value.Substring(value.Length - 2, 2)) { case "F0": //继电器开闸 mode.DeviceMode = 3; break; case "AA": //学习遥控器开闸 mode.DeviceMode = 2; break; case "FF": //串口开闸 mode.DeviceMode = 0; mode.DeviceNumber = Convert.ToInt32(value.Substring(0, 6), 16); break; case "55": //无线电开闸 mode.DeviceMode = 1; mode.DeviceNumber = Convert.ToInt32(value.Substring(0, 6), 16); break; } break; case 13: mode.Language = Utils.StrToInt(value, 0); break; case 15: mode.VehicleDetection = Utils.StrToInt(value, 0); break; case 17: mode.VagueQueryNumber = Utils.StrToInt(value, 0); break; } } deviceinfos.Add(mode); } } this.Invoke(new EventHandler(delegate { l_Title.Text = "正在保存数据,请勿操作。"; btn_Enter.Enabled = false; Dbhelper.Db.Insert <CbDeviceInfo>(deviceinfos.ToArray()); this.DialogResult = DialogResult.OK; })); } catch (Exception ex) { CustomExceptionHandler.GetExceptionMessage(ex); MessageBox.Show("导入失败错误数据:" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); Close(); } }