Beispiel #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool Result = DBLayer.CHK_Origin(txtName.Text);

            if (CheckField())
            {
                try
                {
                    if (mode == 1)
                    {
                        if (Result)
                        {
                            MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            usp_SEL_tblVillageTableAdapter.Insert1(txtName.Text);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            usp_SEL_tblVillageTableAdapter.Fill(comDataSet.usp_SEL_tblVillage);
                            mode = 0;
                            DGVillage.Enabled = true;
                            btnClose.Show();
                            MessageBox.Show("Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else if (mode == 0)
                    {
                        if (Old == txtName.Text)
                        {
                            usp_SEL_tblVillageTableAdapter.Update1(txtName.Text, Old);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            usp_SEL_tblVillageTableAdapter.Fill(comDataSet.usp_SEL_tblVillage);
                            mode = 0;
                            DGVillage.Enabled = true;
                            btnClose.Show();
                            MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                        else
                        {
                            if (Result)
                            {
                                MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                            }
                            else
                            {
                                usp_SEL_tblVillageTableAdapter.Update1(txtName.Text, Old);
                                btnCancel.Enabled = false;
                                btnNew.Enabled    = true;
                                btnSave.Enabled   = false;
                                btnDelete.Enabled = true;
                                btnEdit.Enabled   = true;
                                txtName.ReadOnly  = true;
                                usp_SEL_tblVillageTableAdapter.Fill(comDataSet.usp_SEL_tblVillage);
                                mode = 0;
                                DGVillage.Enabled = true;
                                btnClose.Show();
                                MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                AcceptButton = btnNew;
            }
        }