Пример #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool Result = DBLayer.CHK_Area(txtName.Text);

            if (CheckField())
            {
                try
                {
                    if (mode == 1)
                    {
                        tblEventsTableAdapter.AddEvent(txtName.Text);
                        btnCancel.Enabled = false;
                        btnNew.Enabled    = true;
                        btnSave.Enabled   = false;
                        btnDelete.Enabled = true;
                        btnEdit.Enabled   = true;
                        txtName.ReadOnly  = true;
                        tblEventsTableAdapter.Fill(dataset2.tblEvents);
                        mode = 0;
                        btnClose.Show();
                        DGArea.Enabled = true;
                        MessageBox.Show("Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    else if (mode == 0)
                    {
                        tblEventsTableAdapter.UpdateEvent(txtName.Text, Convert.ToInt32(txtID.Text));
                        btnCancel.Enabled = false;
                        btnNew.Enabled    = true;
                        btnSave.Enabled   = false;
                        btnDelete.Enabled = true;
                        btnEdit.Enabled   = true;
                        txtName.ReadOnly  = true;
                        tblEventsTableAdapter.Fill(dataset2.tblEvents);
                        mode = 0;
                        btnClose.Show();
                        DGArea.Enabled = true;
                        MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                AcceptButton = btnSave;
            }
        }
Пример #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool Result = DBLayer.CHK_Area(txtName.Text);

            if (CheckField())
            {
                try
                {
                    if (mode == 1)
                    {
                        if (Result)
                        {
                            MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                        }
                        else
                        {
                            usp_SEL_tblAreaTableAdapter.Insert1(txtName.Text);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            usp_SEL_tblAreaTableAdapter.Fill(comDataSet.usp_SEL_tblArea);
                            mode = 0;
                            btnClose.Show();
                            lbl.Text       = header;
                            DGArea.Enabled = true;
                            MessageBox.Show("Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else if (mode == 0)
                    {
                        if (Old == txtName.Text)
                        {
                            usp_SEL_tblAreaTableAdapter.Update1(txtName.Text, Old);
                            btnCancel.Enabled = false;
                            btnNew.Enabled    = true;
                            btnSave.Enabled   = false;
                            btnDelete.Enabled = true;
                            btnEdit.Enabled   = true;
                            txtName.ReadOnly  = true;
                            usp_SEL_tblAreaTableAdapter.Fill(comDataSet.usp_SEL_tblArea);
                            mode     = 0;
                            lbl.Text = header;
                            btnClose.Show();
                            DGArea.Enabled = true;
                            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_tblAreaTableAdapter.Update1(txtName.Text, Old);
                                btnCancel.Enabled = false;
                                btnNew.Enabled    = true;
                                btnSave.Enabled   = false;
                                btnDelete.Enabled = true;
                                btnEdit.Enabled   = true;
                                txtName.ReadOnly  = true;
                                lbl.Text          = header;
                                usp_SEL_tblAreaTableAdapter.Fill(comDataSet.usp_SEL_tblArea);
                                mode = 0;
                                btnClose.Show();
                                DGArea.Enabled = true;
                                MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                AcceptButton = btnSave;
            }
        }