private void btn_save_device_Click(object sender, EventArgs e) { try { device device = new device(); device.IP = txtbox_IP.Text.Trim(); device.mask = txtbox_mask.Text.Trim(); device.gate = txtbox_gate.Text.Trim(); device.model = cboModel.SelectedItem.ToString(); device.name = txtbox_name.Text.Trim(); device.type = txtbox_type.Text.Trim(); device.size = txtbox_size.Text.Trim(); device.Num = txtbox_Num.Text.Trim(); device.note = txtbox_note.Text.Trim(); this.config.listDevice.RemoveAt(this.config.num); this.config.listDevice.Add(device); DataTable dataTable = Common.FillDataTable <device>(this.config.listDevice); DBSet.dataTableToCsvT(dataTable, @"..\device.csv"); MessageBox.Show("保存成功"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public bool check_device(device device) { if (string.IsNullOrEmpty(device.IP)) { MessageBox.Show("IP地址不能为空"); return(false); } if (string.IsNullOrEmpty(device.mask)) { MessageBox.Show("子网掩码不能为空"); return(false); } if (string.IsNullOrEmpty(device.gate)) { MessageBox.Show("网关不能为空"); return(false); } if (string.IsNullOrEmpty(device.name)) { MessageBox.Show("名称不能为空"); return(false); } if (string.IsNullOrEmpty(device.type)) { MessageBox.Show("型号不能为空"); return(false); } if (string.IsNullOrEmpty(device.Num)) { MessageBox.Show("编号不能为空"); return(false); } if (string.IsNullOrEmpty(device.size)) { MessageBox.Show("大小不能为空"); return(false); } if (string.IsNullOrEmpty(device.model)) { MessageBox.Show("使用模式不能为空"); return(false); } return(true); }
//设备管理--新增 #region 设备管理 private void btn_add_device_Click(object sender, EventArgs e) { try { //表格新增 //int index = this.dataGridView_device.Rows.Add(); //this.dataGridView_device.Rows[index].Cells[1].Value = txtbox_IP.Text; //this.dataGridView_device.Rows[index].Cells[2].Value = txtbox_mask.Text; //this.dataGridView_device.Rows[index].Cells[3].Value = txtbox_gate.Text; //this.dataGridView_device.Rows[index].Cells[4].Value = cboModel.SelectedText; //this.dataGridView_device.Rows[index].Cells[5].Value = txtbox_name.Text; //this.dataGridView_device.Rows[index].Cells[6].Value = txtbox_type.Text; //this.dataGridView_device.Rows[index].Cells[7].Value = txtbox_size.Text; //this.dataGridView_device.Rows[index].Cells[8].Value = txtbox_Num.Text; //this.dataGridView_device.Rows[index].Cells[9].Value = txtbox_note.Text; //this.dataGridView_device.Refresh(); //数据库新增 device device = new device(); device.IP = txtbox_IP.Text.Trim(); device.mask = txtbox_mask.Text.Trim(); device.gate = txtbox_gate.Text.Trim(); device.model = cboModel.SelectedItem == null?"":cboModel.SelectedItem.ToString(); device.name = txtbox_name.Text.Trim(); device.type = txtbox_type.Text.Trim(); device.size = txtbox_size.Text.Trim(); device.Num = txtbox_Num.Text.Trim(); device.note = txtbox_note.Text.Trim(); if (check_device(device)) { //listDevice = new List<device>(); listDevice.Add(device); DataTable dataTable = Common.FillDataTable <device>(listDevice); this.dataGridView_device.DataSource = dataTable; DBSet.dataTableToCsvT(dataTable, @"..\device.csv"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }