Ejemplo n.º 1
0
        private void btnUpdateContract_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("UPDATE CONTRACT STATUS TO COMPLETED?", "UPDATE CONTRACT STATUS", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    if (tbEditContractNumber.Text == "" || tbEditContractName.Text == "" || tbEditContractTimePeriod.Text == "" || tbEditContractEndDate.Text == "" || tbEditContractStatus.Text == "")
                    {
                        MessageBox.Show("PLEASE SELECT CONTRACT TO COMPLETE FIRST", "ERROR UPDATING CONTRACT STATUS", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {

                        string TodayDate = DateTime.Today.ToShortDateString();
                        string OneDayAfter = DateTime.Today.AddDays(-1).ToShortDateString();
                        string TwoDayAfter = DateTime.Today.AddDays(-2).ToShortDateString();
                        string ThreeDayAfter = DateTime.Today.AddDays(-3).ToShortDateString();
                        string FourDayAfter = DateTime.Today.AddDays(-4).ToShortDateString();
                        string FiveDayAfter = DateTime.Today.AddDays(-5).ToShortDateString();
                        string SixDayAfter = DateTime.Today.AddDays(-6).ToShortDateString();
                        string SevenDayAfter = DateTime.Today.AddDays(-7).ToShortDateString();

                        if(tbEditContractEndDate.Text == TodayDate || tbEditContractEndDate.Text == OneDayAfter || tbEditContractEndDate.Text == TwoDayAfter || tbEditContractEndDate.Text == ThreeDayAfter || tbEditContractEndDate.Text == FourDayAfter || tbEditContractEndDate.Text == FiveDayAfter || tbEditContractEndDate.Text == SixDayAfter || tbEditContractEndDate.Text == SevenDayAfter)
                        {
                            string ContractNumber = tbEditContractNumber.Text;
                            Admin A = new Admin();
                            A.UpdateContractStatus(ContractNumber);

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

                            tbEditContractNumber.Clear();
                            tbEditContractName.Clear();
                            tbEditContractTimePeriod.Clear();
                            tbEditContractEndDate.Clear();
                            tbEditContractStatus.Clear();

                            RefreshDG();
                        }
                        else
                        {
                            MessageBox.Show("CONTRACT IS NOT DONE YET, CAN'T UPDATE CONTRACT STATUS", "CONTRACT STILL ONGOING", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            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);
            }
        }