private void btnSave_Click(object sender, EventArgs e) { bool state; if (formHelper.inputCheck(panel1)) { #region 获取要插入信息的内容 EquipmentClass eClass = new EquipmentClass(); if (!txtValue.Text.Trim().Equals("")) { eClass.Sort = txtValue.Text.Trim(); eClass.Name = txtValue.Text.Trim(); eClass.Model = txtValue.Text.Trim(); } if (!txtRemark.Text.Trim().Equals("")) { eClass.Remark = txtRemark.Text.Trim(); } eClass.EkId = EkId; eClass.InputMan = this.userName; #endregion switch (condition) { case "新建生产设备类别": #region 增加生产设备类别 { if (eLogic.SearchKind(txtValue.Text.Trim())) { MessageBox.Show("该记录已存在,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtValue.Clear(); txtValue.Focus(); return; } state = eLogic.InsertKind(eClass); dgvEInfo.DataSource = eLogic.SearchEquipmentKindAll(); break; } #endregion case "新建生产设备名称": #region 增加生产设备名称 { // 检查要输入生产设备名称的字段是否已存在; if (eLogic.SearchName(txtValue.Text.Trim(), EkId)) { MessageBox.Show("该记录已存在,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtValue.Clear(); txtValue.Focus(); return; } state = eLogic.InsertName(eClass); dgvEInfo.DataSource = eLogic.SearchEquipmentNameAll(EkId); break; } #endregion case "新建生产设备规格": #region 增加生产设备规格 { // 检查要输入生产设备规格的字段是否已存在; if (eLogic.SearchModel(txtValue.Text.Trim())) { MessageBox.Show("该记录已存在,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtValue.Clear(); txtValue.Focus(); return; } state = eLogic.InsertModel(eClass); dgvEInfo.DataSource = eLogic.SearchEquipmentModelAll(); break; } #endregion default: state = true; break; } dgvEInfo.Columns["id"].Visible = false; dgvEInfo.Columns["inputDate"].Visible = false; dgvEInfo.Columns["inputMan"].Visible = false; dgvEInfo.Columns["备注"].Visible = false; if (state) { //MessageBox.Show("新增记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); txtValue.Clear(); txtValue.Focus(); } else { MessageBox.Show("新增记录失败,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }