Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int eId;

            DialogResult strDelete = MessageBox.Show("确定要删除吗?", "提示", MessageBoxButtons.YesNo);

            if (strDelete.ToString().Equals("No"))
            {
                return;
            }

            try
            {
                if (dgvEInfo.CurrentRow != null)
                {
                    eId = Convert.ToInt32(dgvEInfo.CurrentRow.Cells[0].Value.ToString());

                    switch (condition)
                    {
                    case "新建生产设备类别":
                    {
                        if (eLogic.DeleteKind(eId))
                        {
                            //MessageBox.Show("删除记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dgvEInfo.DataSource = eLogic.SearchEquipmentKindAll();
                        }
                        else
                        {
                            MessageBox.Show("删除记录失败,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    }

                    case "新建生产设备名称":
                    {
                        if (eLogic.DeleteName(eId))
                        {
                            //MessageBox.Show("删除记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dgvEInfo.DataSource = eLogic.SearchEquipmentNameAll(EkId);
                        }
                        else
                        {
                            MessageBox.Show("删除记录失败,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    }

                    case "新建生产设备规格":
                    {
                        if (eLogic.DeleteModel(eId))
                        {
                            //MessageBox.Show("删除记录成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            dgvEInfo.DataSource = eLogic.SearchEquipmentModelAll();
                        }
                        else
                        {
                            MessageBox.Show("删除记录失败,请从新操作!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        break;
                    }

                    default:
                        break;
                    }

                    dgvEInfo.Columns["id"].Visible        = false;
                    dgvEInfo.Columns["inputDate"].Visible = false;
                    dgvEInfo.Columns["inputMan"].Visible  = false;
                    dgvEInfo.Columns["备注"].Visible        = false;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("记录正在使用,删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            finally
            {
            }
        }