コード例 #1
0
    protected void updateLabTestsBtn_Click(object sender, EventArgs e)
    {
        bool valid = true;
        TimesheetManager tm = new TimesheetManager();
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        // try to update, if cannot update, then create new lab test
        if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
        {
            if (!hoursValidator(sunLabTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours);
            }
            sunLabTB.Text = string.Empty;
            sunNuclearDensityTestTB.Text = string.Empty;
        }

        if (monLabTB.Text != string.Empty && monLabTB.Text != "0")
        {
            if (!hoursValidator(monLabTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Monday", monNuclearDensityTestTB.Text, monLabTB.Text, timesheetID, false, ref tHours);
            }
            monLabTB.Text = string.Empty;
            monNuclearDensityTestTB.Text = string.Empty;
        }

        if (tuesLabTB.Text != string.Empty && tuesLabTB.Text != "0")
        {
            if (!hoursValidator(tuesLabTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Tuesday", tuesNuclearDensityTestTB.Text, tuesLabTB.Text, timesheetID, false, ref tHours);
            }
            tuesLabTB.Text = string.Empty;
            tuesNuclearDensityTestTB.Text = string.Empty;
        }

        if (wedsLabTB.Text != string.Empty && wedsLabTB.Text != "0")
        {
            if (!hoursValidator(wedsLabTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, false, ref tHours);
            }
            wedsLabTB.Text = string.Empty;
            wedsNuclearDensityTestTB.Text = string.Empty;
        }

        if (thursLabTB.Text != string.Empty && thursLabTB.Text != "0")
        {
            if (!hoursValidator(thursLabTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, false, ref tHours);
            }
            thursLabTB.Text = string.Empty;
            thursNuclearDensityTestTB.Text = string.Empty;
        }

        if (friLabTB.Text != string.Empty && friLabTB.Text != "0")
        {
            if (!hoursValidator(friLabTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, false, ref tHours);
            }
            friLabTB.Text = string.Empty;
            friNuclearDensityTestTB.Text = string.Empty;
        }

        if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
        {
            if (!hoursValidator(satLabTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            if (!tm.updateLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours))
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours);
            }
            satLabTB.Text = string.Empty;
            satNuclearDensityTestTB.Text = string.Empty;
        }

        totalHoursLBL.Text = tHours.ToString("0.0");
        updateLabTotals();
        // update timesheet
        tm.updateTimeSheet(timesheetID, tHours, Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Updated", " ", " ");

        summaryGV.DataBind();
        updateLabTestsBtn.Visible = false;
        labTestsBtn.Visible = true;
    }