Ejemplo n.º 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("DO YOU WANT TO EDIT THIS DATA CONTRACT?", "EDIT CONTRACT DETAILS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbUpdateContractNumber.Text == "" || tbUpdateContractName.Text == "" || rtbUpdateContractDescription.Text == "" || dtpUpdateContractStartDate.Text == "" || dtpUpdateContractEndDate.Text == "" || cbUpdateContractTime.SelectedIndex == -1 || tbUpdateContractStatus.Text == "" || tbUpdateContractInfo.Text == "")
                    {
                        MessageBox.Show("FORM FIELD(S) CAN NOT BE LEFT EMPTY. PLEASE COMPLETE THE FORM TO EDIT DATA", "DATA UPDATE ERROR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {

                        string ContractNumber = tbUpdateContractNumber.Text;
                        string ContractName = tbUpdateContractName.Text;
                        string ContractDescription = rtbUpdateContractDescription.Text;
                        string ContractStartDate = dtpUpdateContractStartDate.Text;
                        string ContractPeriod = lblStartDate.Text + " EXTENDED " + cbUpdateContractTime.Text;
                        string ContractEndDate = dtpUpdateContractEndDate.Text;
                        string ContractInfo = tbUpdateContractInfo.Text;

                        Admin A = new Admin();
                        A.EditContractDetails(ContractNumber, ContractName, ContractDescription, ContractPeriod, ContractStartDate, ContractEndDate, ContractInfo);

                        MessageBox.Show("CONTRACT DETAILS UPDATED", "CONTRACT UPDATED", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        tbUpdateContractNumber.Clear();
                        tbUpdateContractName.Clear();
                        rtbUpdateContractDescription.Clear();
                        tbUpdateContractStatus.Clear();
                        cbUpdateContractTime.Text = "-----SELECT TIME-----";
                        tbUpdateContractInfo.Clear();

                        dtpStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpEndDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractStartDate.Text = DateTime.Today.ToShortDateString();
                        dtpUpdateContractEndDate.Text = DateTime.Today.ToShortDateString();

                        RefreshDG();
                    }
                }
            }
            catch (SqlException)
            {
                MessageBox.Show("MICROSOFT SQL SERVER DATABASE ERROR!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("INVALID OPERATION!", "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "ERROR OCCURS", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }