コード例 #1
0
ファイル: frmTypeWork.cs プロジェクト: nizarkhatri/mckj-app
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool Result = DBLayer.CHK_Type(txtName.Text);

            if (CheckField())

            {
                try
                {
                    if (mode == 1)
                    {
                        if (Result)
                        {
                            MessageBox.Show(txtName.Text + " Already Exist!", "Error");
                        }
                        else
                        {
                            usp_SEL_tblWorkTypeTableAdapter.Insert1(txtName.Text);
                            usp_SEL_tblWorkTypeTableAdapter.Fill(comDataSet.usp_SEL_tblWorkType);
                            MessageBox.Show("Saved Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            mode           = 0;
                            DGType.Enabled = true;
                        }
                    }
                    else if (mode == 0)
                    {
                        if (txtName.Text == Old)
                        {
                            usp_SEL_tblWorkTypeTableAdapter.Update1(txtName.Text, Old);
                            usp_SEL_tblWorkTypeTableAdapter.Fill(comDataSet.usp_SEL_tblWorkType);
                            MessageBox.Show("Modified Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            mode           = 0;
                            DGType.Enabled = true;
                        }
                        else
                        {
                            if (Result)
                            {
                                MessageBox.Show(txtName.Text + " Already Exist!", "Error");
                            }
                            else
                            {
                                usp_SEL_tblWorkTypeTableAdapter.Update1(txtName.Text, Old);
                                usp_SEL_tblWorkTypeTableAdapter.Fill(comDataSet.usp_SEL_tblWorkType);
                                MessageBox.Show("Modified Successfully!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                                btnCancel.Enabled = false;
                                btnNew.Enabled    = true;
                                btnSave.Enabled   = false;
                                btnDelete.Enabled = true;
                                btnEdit.Enabled   = true;
                                txtName.ReadOnly  = true;
                                mode           = 0;
                                DGType.Enabled = true;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                AcceptButton = btnNew;
            }
        }