protected void nonChargeBtn_Click(object sender, EventArgs e)
    {
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            bool valid = true;
            int nCDist = Convert.ToInt32(totalDistanceLBL.Text);
            decimal nCHours = Convert.ToDecimal(totalHoursLBL.Text), nCExpense = Convert.ToDecimal(totalExpensesLBL.Text);

            TimesheetManager tm = new TimesheetManager();

            // sunday
            if (sunNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(sunNCHoursTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                         detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }

            // monday

            if (monNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(monNCHoursTB.Text, "Monday", false))
                {
                    valid = false;
                }
            }
            if (valid)
                {
                    timesheetStatusLBL.Text = tm.createNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                       detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
                }

            // tuesday

            if (tuesNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(tuesNCHoursTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
                 if (valid)
                {
                    timesheetStatusLBL.Text = tm.createNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                    detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
                }

            // wednessday
            if (wedsNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(wedsNCHoursTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }

                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // thursday
            if (thursNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(thursNCHoursTB.Text, "Thursday", false))
                {
                    valid = false;
                      }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // friday
            if (friNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(friNCHoursTB.Text, "Friday", false))
                {
                        }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
             detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // saturday
            if (satNCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(satNCHoursTB.Text, "Saturday", false))
                {
                    valid = false;
                       }
            }
                    if (valid)
        {
        timesheetStatusLBL.Text = tm.createNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
               detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
        }

            // add the totalized labels except truck which does not apply to non-chargeable
            totalHoursLBL.Text = nCHours.ToString("0.#");
            totalExpensesLBL.Text = nCExpense.ToString("0.####");
            totalDistanceLBL.Text = nCDist.ToString();
            // if hours exceed 60 throw a dialog
            if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
            {
                // throw a dialog
                dialogTitle = "Regular Hours Exceeded";
                msg = "A separate Form must be filled out to accomodate overtime";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
            }

            // update timesheet
            tm.updateTimeSheet(timesheetID, nCHours, nCDist, -1, nCExpense, "Updated", " ", " ");

            // update gridview
            summaryGV.DataBind();

            // populate generic non-chargeable drop down list elements
            specifyDDL.DataSource = tm.getWorkType();
            specifyDDL.DataBind();
            specifyDDL.Items.Insert(0, "Select");
            detailsDDL.DataSource = tm.getExpenses();
            detailsDDL.DataBind();
            detailsDDL.Items.Insert(0, "Select");

            // clear form fields
            clearNonChargeable();
            // update totals

            updateNonChargeableTotals();
            // reset drop down list to first index
            detailsDDL.SelectedIndex = 0;
            specifyDDL.SelectedIndex = 0;
            NonChargeHoursPanel.Visible = false;
            NonChargeExpensesPanel.Visible = false;
            updateNonChargeableBtn.Visible = false;
            nonChargeBtn.Visible = true;
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void chargeableBtn_Click(object sender, EventArgs e)
    {
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            bool valid = true;
            int cDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
            decimal cHours = Convert.ToDecimal(totalHoursLBL.Text), cExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text));
            TimesheetManager tm = new TimesheetManager();

            // sunday
            if (sunCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(sunCHoursTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", projectNumTB.Text, classificationDDL.SelectedValue,
                              activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // monday

            if (monCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(monCHoursTB.Text, "Monday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", projectNumTB.Text, classificationDDL.SelectedValue,
                         activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // tuesday
            if (tuesCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(tuesCHoursTB.Text, "Tuesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", projectNumTB.Text, classificationDDL.SelectedValue,
               activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // wednesday
            if (wedsCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(wedsCHoursTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", projectNumTB.Text, classificationDDL.SelectedValue,
                       activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // thursday

            if (thursCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(thursCHoursTB.Text, "Thursday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", projectNumTB.Text, classificationDDL.SelectedValue,
                           activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // friday
            if (friCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(friCHoursTB.Text, "Friday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", projectNumTB.Text, classificationDDL.SelectedValue,
                     activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // saturday
            if (satCHoursTB.Text != string.Empty)
            {
                if (!hoursValidator(satCHoursTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                timesheetStatusLBL.Text = tm.createChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", projectNumTB.Text, classificationDDL.SelectedValue,
                   activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }

            // add to totalized value labels
            totalHoursLBL.Text = cHours.ToString("0.#");
            totalExpensesLBL.Text = cExpense.ToString("0.####");
            totalDistanceLBL.Text = cDist.ToString();
            totalTruckLBL.Text = tDist.ToString();

            // if TOTAL WEEKLY hours exceed 60 throw a dialog
            if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
            {
                // throw a dialog
                dialogTitle = "Regular Weekly Hours Exceeded";
                msg = "You Worked more than 60 hrs per Week. A separate Form must be filled out to accomodate overtime";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
            }

            // update timesheet
            tm.updateTimeSheet(timesheetID, cHours, cDist, tDist, cExpense, "Updated", " ", " ");

            projectNameTB.Enabled = false;
            clientNameTB.Enabled = false;

            // clear form fields
            clearChargeable();
            // update totals
            updateChargeableTotals();
            updateLabTotals();
            updateNonChargeableTotals();
            // chargeable fields
            clientNameTB.Text = string.Empty;
            projectNameTB.Text = string.Empty;
            projectNumTB.Text = string.Empty;
            classificationDDL.Items.Clear();
            activitiesDDL.Items.Clear();

            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void labTestsBtn_Click(object sender, EventArgs e)
    {
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        bool valid = true;
        // begin to save tests if there is a timesheet id of non zero and weekending date exists
        if (weekEndingTB.Text != string.Empty && timesheetID != 0)
        {
            TimesheetManager tm = new TimesheetManager();
            // Sunday
            if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
            {
                if (!hoursValidator(sunLabTB.Text, "Sunday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, false, ref tHours);
                sunLabTB.Text = string.Empty;
                sunNuclearDensityTestTB.Text = string.Empty;
            }

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

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

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

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

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

            // Saturday
            if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
            {
                if (!hoursValidator(satLabTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, false, ref tHours);
                satLabTB.Text = string.Empty;
                satNuclearDensityTestTB.Text = string.Empty;
            }
            updateLabTotals();
            totalHoursLBL.Text = tHours.ToString("0.0");

            // update timesheet
            tm.updateTimeSheet(timesheetID, tHours, Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Updated", " ", " ");
            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            dialogTitle = "Missing Weekending Date";
            msg = "The timesheet needs a verified Weekending Date in order to proceed";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
    }
    protected void updateNonChargeableBtn_Click(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        bool result, valid = true;
        int count = 0, nCDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
        decimal nCHours = Convert.ToDecimal(totalHoursLBL.Text), nCExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text));

        //sunday
        if (sunNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(sunNCHoursTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                 detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(sunNCHoursTB.Text, sunNCAccomTB.Text, sunNCDistanceTB.Text, sunNCMiscTB.Text, "Sunday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, sunNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // monday
        if (monNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(monNCHoursTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                  detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(monNCHoursTB.Text, monNCAccomTB.Text, monNCDistanceTB.Text, monNCMiscTB.Text, "Monday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, monNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // tuesday
        if (tuesNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(tuesNCHoursTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                 detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(tuesNCHoursTB.Text, tuesNCAccomTB.Text, tuesNCDistanceTB.Text, tuesNCMiscTB.Text, "Tuesday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, tuesNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // wednessday
        if (wedsNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(wedsNCHoursTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, wedsNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(wedsNCHoursTB.Text, wedsNCAccomTB.Text, wedsNCDistanceTB.Text, wedsNCMiscTB.Text, "Wednesday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, wedsNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // thursday
        if (thursNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(thursNCHoursTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(thursNCHoursTB.Text, thursNCAccomTB.Text, thursNCDistanceTB.Text, thursNCMiscTB.Text, "Thursday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, thursNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // friday
        if (friNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(friNCHoursTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
            detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(friNCHoursTB.Text, friNCAccomTB.Text, friNCDistanceTB.Text, friNCMiscTB.Text, "Friday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, friNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // saturday
        if (satNCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(satNCHoursTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
             detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);

            if (result)
            {
                count++;
                timesheetStatusLBL.Text = count + " Row(s) Updated Successfully";
            }
            else
            {
                timesheetStatusLBL.Text = tm.createNonChargeable(satNCHoursTB.Text, satNCAccomTB.Text, satNCDistanceTB.Text, satNCMiscTB.Text, "Saturday",
                detailsDDL.SelectedValue, specifyDDL.SelectedValue, timesheetID, satNCRemarksTB.Text, ref nCHours, ref nCDist, ref nCExpense);
            }
        }

        // update the totalized labels
        totalHoursLBL.Text = nCHours.ToString("0.0");
        totalExpensesLBL.Text = nCExpense.ToString("0.00##");
        totalDistanceLBL.Text = nCDist.ToString();

        // if hours exceed 60 throw a dialog
        if (nCHours > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Weekly Hours Exceeded";
            msg = "You Worked more than 60 hours. A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }

        tm.updateTimeSheet(timesheetID, nCHours, nCDist, tDist, nCExpense, "Updated", " ", " ");
        // update gridview
        summaryGV.DataBind();
        // clear form fields
        clearNonChargeable();
        // update totals
        updateNonChargeableTotals();
        // reset drop down list to first index
        detailsDDL.SelectedIndex = 0;
        specifyDDL.SelectedIndex = 0;
        NonChargeHoursPanel.Visible = false;
        NonChargeExpensesPanel.Visible = false;

        updateNonChargeableBtn.Visible = false;
        nonChargeBtn.Visible = true;
    }
    protected void completeBtn_Click(object sender, EventArgs e)
    {
        try
        {
            // if chargeable or non chargeable are being edited prompt user to save or update changes, else execute intended code
            if (activitiesDDL.Items.Count > 0 || specifyDDL.SelectedValue != "Select" || detailsDDL.SelectedValue != "Select")
            {
                // throw a dialog
                msg = "You have Un-Saved work on this Page, Please save,update or Clear the form";
                dialogTitle = "Warning: Un-saved Work";

                ScriptManager.RegisterStartupScript(this, this.GetType(), "unsavedwork", "throwDialog();", true);
            }
            else
            {
                TimesheetManager tm = new TimesheetManager();
                TimeSheet t = tm.getTimesheetForID(timesheetID);
                // if the timesheet has been approved or completed, do not save the timesheet
                if (t.Status != "Approved" && t.Status != "Completed")
                {
                    tm.updateTimeSheet(timesheetID, Convert.ToDecimal(totalHoursLBL.Text), Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text),
                        Convert.ToDecimal(totalExpensesLBL.Text), "Completed", empCommentsTB.Text, " ");

                    // copy all of the timesheet's contents to managerial versions
                    tm.copyTimesheet(timesheetID);

                    dialogTitle = "Timesheet Complete";
                    msg = "Timesheet Completed and submitted to manager for Approval. You may view but not Re-submit this Timesheet";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
                }
                else
                {
                    dialogTitle = "Timesheet Complete";
                    msg = "Timesheet has already been Completed or Approved. It cannot be re-submitted. Please Speak to Manager";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
                }

                //  Server.Transfer("createTimeSheet.aspx");
            }
        }
        catch (Exception)
        {
            // throw a dialog
            msg = "Your TimeSheet was not Approved. Select a Weekending Date";
            dialogTitle = "TimeSheet not Approved";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "weekending", "throwDialog();", true);
        }
    }
    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;
    }
    protected void updateChargeableBtn_Click(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        bool result, valid = true;
        int count = 0, cDist = Convert.ToInt32(totalDistanceLBL.Text), tDist = Convert.ToInt32(totalTruckLBL.Text);
        decimal cHours = Convert.ToDecimal(totalHoursLBL.Text), cExpense = Convert.ToDecimal(Convert.ToDecimal(totalExpensesLBL.Text)); ;
        int id = tm.idForProjectNo(projectNumTB.Text);

        // sunday

        if (sunCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(sunCHoursTB.Text, "Sunday", true))
            {
                valid = false;
            }
        }

        if (valid)
        {
            result = tm.updateChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", id, classificationDDL.SelectedValue,
        activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(sunCHoursTB.Text, sunAccomTB.Text, sunDistTB.Text, sunTruckDistTB.Text, sunMiscTB.Text, "Sunday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, sunCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // monday

        if (monCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(monCHoursTB.Text, "Monday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", id, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(monCHoursTB.Text, monAccomTB.Text, monDistTB.Text, monTruckDistTB.Text, monMiscTB.Text, "Monday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, monCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // tuesday
        if (tuesCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(tuesCHoursTB.Text, "Tuesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", id, classificationDDL.SelectedValue,
              activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(tuesCHoursTB.Text, tuesAccomTB.Text, tuesDistTB.Text, tuesTruckDistTB.Text, tuesMiscTB.Text, "Tuesday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, tuesCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Wednesday
        if (wedsCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(wedsCHoursTB.Text, "Wednesday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", id, classificationDDL.SelectedValue,
               activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(wedsCHoursTB.Text, wedsAccomTB.Text, wedsDistTB.Text, wedsTruckDistTB.Text, wedsMiscTB.Text, "Wednesday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, wedsCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Thursday
        if (thursCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(thursCHoursTB.Text, "Thursday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", id, classificationDDL.SelectedValue,
              activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(thursCHoursTB.Text, thursAccomTB.Text, thursDistTB.Text, thursTruckDistTB.Text, thursMiscTB.Text, "Thursday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, thursCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // friday
        if (friCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(friCHoursTB.Text, "Friday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", id, classificationDDL.SelectedValue,
          activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(friCHoursTB.Text, friAccomTB.Text, friDistTB.Text, friTruckDistTB.Text, friMiscTB.Text, "Friday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, friCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // Saturday
        if (satCHoursTB.Text != string.Empty)
        {
            if (!hoursValidator(satCHoursTB.Text, "Saturday", true))
            {
                valid = false;
            }
        }
        if (valid)
        {
            result = tm.updateChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", id, classificationDDL.SelectedValue,
                 activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);

            if (result)
            {
                count++;
            }
            else
            {
                timesheetStatusLBL.Text = tm.createChargeable(satCHoursTB.Text, satAccomTB.Text, satDistTB.Text, satTruckDistTB.Text, satMiscTB.Text, "Saturday", projectNumTB.Text, classificationDDL.SelectedValue,
                activitiesDDL.SelectedValue, timesheetID, satCRemarksTB.Text, ref cHours, ref cDist, ref tDist, ref cExpense);
            }
        }

        // update the totalized labels
        totalHoursLBL.Text = cHours.ToString("0.0");
        totalExpensesLBL.Text = cExpense.ToString("0.00##");
        totalDistanceLBL.Text = cDist.ToString();
        totalTruckLBL.Text = tDist.ToString();
        // if hours exceed 60 throw a dialog
        if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Hours Exceeded";
            msg = "A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "projectNumInvalid", "throwDialog();", true);
        }
        // if hours exceed 60 throw a dialog
        if (Convert.ToDecimal(totalHoursLBL.Text) > MAX_WEEKLY_HOURS)
        {
            // throw a dialog
            dialogTitle = "Regular Hours Exceeded";
            msg = "A separate Form must be filled out to accomodate overtime";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "FillOTForm", "throwDialog();", true);
        }
        tm.updateTimeSheet(timesheetID, cHours, cDist, tDist, cExpense, "Updated", " ", " ");

        // update gridview
        summaryGV.DataBind();

        updateChargeableBtn.Visible = false;
        chargeableBtn.Visible = true;
        // update totals
        updateChargeableTotals();
        updateLabTotals();
        updateNonChargeableTotals();
        // clear form fields
        clearChargeable();

        // chargeable fields
        clientNameTB.Text = string.Empty;
        projectNameTB.Text = string.Empty;
        projectNumTB.Text = string.Empty;
        classificationDDL.Items.Clear();
        activitiesDDL.Items.Clear();
    }
    protected void labTestsBtn_Click(object sender, EventArgs e)
    {
        bool valid = true;
        decimal tHours = Convert.ToDecimal(totalHoursLBL.Text);
        if (weekEndingTB.Text != string.Empty && timesheetID > 0)
        {
            TimesheetManager tm = new TimesheetManager();
            // Sunday
            if (sunLabTB.Text != string.Empty && sunLabTB.Text != "0")
            {
                if (!hoursValidator(sunLabTB.Text, "Sunday",false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Sunday", sunNuclearDensityTestTB.Text, sunLabTB.Text, timesheetID, true, ref tHours);
                sunLabTB.Text = string.Empty;
                sunNuclearDensityTestTB.Text = string.Empty;
            }

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

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

            // Wednesday
            if (wedsLabTB.Text != string.Empty && wedsLabTB.Text != "0")
            {
                if (!hoursValidator(wedsLabTB.Text, "Wednesday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Wednesday", wedsNuclearDensityTestTB.Text, wedsLabTB.Text, timesheetID, true, ref tHours);
                wedsLabTB.Text = string.Empty;
                wedsNuclearDensityTestTB.Text = string.Empty;
            }
            // Thursday
            if (thursLabTB.Text != string.Empty && thursLabTB.Text != "0")
            {
                if (!hoursValidator(thursLabTB.Text, "Thursday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Thursday", thursNuclearDensityTestTB.Text, thursLabTB.Text, timesheetID, true, ref tHours);
                thursLabTB.Text = string.Empty;
                thursNuclearDensityTestTB.Text = string.Empty;
            }
            // Friday
            if (friLabTB.Text != string.Empty && friLabTB.Text != "0")
            {
                if (!hoursValidator(friLabTB.Text, "Friday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Friday", friNuclearDensityTestTB.Text, friLabTB.Text, timesheetID, true, ref tHours);
                friLabTB.Text = string.Empty;
                friNuclearDensityTestTB.Text = string.Empty;
            }

            // SATURDAY
            if (satLabTB.Text != string.Empty && satLabTB.Text != "0")
            {
                if (!hoursValidator(satLabTB.Text, "Saturday", false))
                {
                    valid = false;
                }
            }
            if (valid)
            {
                tm.createLabTest("Saturday", satNuclearDensityTestTB.Text, satLabTB.Text, timesheetID, true, 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", " ", " ");
            // update gridview
            summaryGV.DataBind();
        }
        else
        {
            msg = "Select Weekending date and Verify before attempting to complete Timesheet";
            dialogTitle = "Error: Weekending Date";

            ScriptManager.RegisterStartupScript(this, this.GetType(), "InvalidEntry", "throwDialog();", true);
        }
    }
    protected void completeBtn_Click(object sender, EventArgs e)
    {
        try
        {
            // if chargeable or non chargeable are being edited prompt user to save or update changes, else execute intended code
            if (activitiesDDL.Items.Count > 0 || specifyDDL.SelectedValue != "Select" || detailsDDL.SelectedValue != "Select")
            {
                // throw a dialog
                msg = "You have Un-Saved work on this Page, Please save,update or Clear the form";
                dialogTitle = "Warning: Un-saved Work";

                ScriptManager.RegisterStartupScript(this, this.GetType(), "unsavedwork", "throwDialog();", true);
            }
            else
            {
                TimesheetManager tm = new TimesheetManager();
                tm.updateTimeSheet(Convert.ToInt32(HiddenField1.Value), Convert.ToDecimal(totalHoursLBL.Text), Convert.ToInt32(totalDistanceLBL.Text), Convert.ToInt32(totalTruckLBL.Text), Convert.ToDecimal(totalExpensesLBL.Text), "Approved", empCommentsTB.Text, " ");
                //// update user status
                //AdminManager am = new AdminManager();
                //User user = tm.getEmployeeForId(timesheetID);
                //am.updateEmployee(Membership.GetUser().UserName, "Incomplete", user.branch, user.ManagedBy);
                dialogTitle = "Timesheet Approved";
                msg = "Timesheet has Been Approved.";
                ScriptManager.RegisterStartupScript(this, this.GetType(), "timesheetSubmitted", "throwDialog();", true);
            }
        }
        catch (Exception)
        {
            // throw a dialog
            msg = "Your TimeSheet was not Approved.";
            dialogTitle = "TimeSheet not Approved";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "weekending", "throwDialog();", true);

        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        TimesheetManager tm = new TimesheetManager();
        dbData = tm.getData();

        if (!IsPostBack)
        {
            statusDDL.DataSource = tm.getTimesheetStatus();
            statusDDL.DataBind();

            branchesDDL.DataSource = tm.getBranches();
            string username = Membership.GetUser().UserName;
            User user = tm.getEmployeeForId(username);
            //branchesDDL.SelectedValue = user.branch;
            branchesDDL.DataBind();
            datesDDL.DataSource = tm.getDates();
            datesDDL.DataBind();

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                if (Request.QueryString["reject"] == "reject")
                {
                    TimeSheet ts = tm.getTimesheetForID(Convert.ToInt32(Request.QueryString["time"]));
                    if (ts != null)
                    {
                        tm.updateTimeSheet(ts.TimeSheetId, ts.TotalHours.Value, ts.TotalDistance.Value, ts.TotalTruck.Value, ts.TotalExpenses.Value, "Rejected", ts.EmployeeComments, ts.ManagerComments);
                        statusDDL.SelectedValue = "Rejected";
                        statusDDL.DataBind();
                        GridView1.DataBind();
                    }
                }
                else if (Request.QueryString["sync"] == "sync")
                {
                    // create a connection to the database
                    SqlConnection conn = new SqlConnection("data source=USER;initial catalog=TIMESHEET_SYNC;user id=sa;password=PMLtest;multipleactiveresultsets=True");

                    int id = Convert.ToInt32(Request.QueryString["time"]);
                    petomaccallumModel.TimeSheet t = tm.getTimesheetForID(id);
                    if (t != null)
                    {
                        conn.Open();
                        SqlCommand tsStmt = conn.CreateCommand();
                        tsStmt.CommandText =
                        "INSERT INTO TimeSheet(TimeSheetId,TotalHours,TotalDistance, TotalExpenses, EmpNo, WeekEnding, ApprovedBy,EmployeeName, ManagerComments,EmployeeComments) VALUES(@TimeSheetId,@TotalHours, @TotalDistance, @TotalExpenses, @EmpNo, @WeekEnding, @ApprovedBy,@EmployeeName, @ManagerComments, @EmployeeComments)";

                        tsStmt.Parameters.AddWithValue("@TimeSheetId", t.TimeSheetId);
                        tsStmt.Parameters.AddWithValue("@TotalHours", t.TotalHours);
                        tsStmt.Parameters.AddWithValue("@TotalDistance", t.TotalDistance);
                        tsStmt.Parameters.AddWithValue("@TotalExpenses", t.TotalExpenses);
                        // get emp no
                        User emp = tm.getEmployeeForId(t.EmployeeId);

                        tsStmt.Parameters.AddWithValue("@EmpNo", emp.empNo);
                        tsStmt.Parameters.AddWithValue("@WeekEnding", t.WeekEnding);
                        tsStmt.Parameters.AddWithValue("@ApprovedBy", t.ApprovedBy);
                        tsStmt.Parameters.AddWithValue("@EmployeeName", t.EmployeeName);
                        tsStmt.Parameters.AddWithValue("@ManagerComments", t.ManagerComments);

                        tsStmt.Parameters.AddWithValue("@EmployeeComments", t.EmployeeComments);

                        tsStmt.ExecuteNonQuery();
                        tsStmt.Dispose();

                        // get manager chargeable data and map it
                        List<ManagerChargeable> mData = tm.getManagerChargeableForID(id);

                        if (mData != null)
                        {
                            // TODO: map the managerChargeable to the local db
                            try
                            {

                                // for each ManagerChargeable row for the timesheet, insert to temporary database
                                foreach (ManagerChargeable item in mData)
                                {
                                    SqlCommand stmt = conn.CreateCommand();
                                    //get projnum, name, client

                                    //get projnum, name, client
                                    stmt.CommandText =
                                    "INSERT INTO Chargeable(TimeSheetId,Day,PayRollHours,PayRollTravelDistance,PayRollAccomodation,PayRollMisc,BillingHours,BillingTravelDistance,BillingAccomodation,BillingMisc,ProjectNo,Classification,Activity,Remarks,BillingTruckDistance)" +
                                    "VALUES(@TimeSheetId,@Day,@PayRollHours,@PayRollTravelDistance, @PayRollAccomodation ,@PayRollMisc, @BillingHours, @BillingTravelDistance, @BillingAccomodation, @BillingMisc, @ProjectNo, @Classification, @Activity, @Remarks,@BillingTruckDistance)";
                                    stmt.Parameters.AddWithValue("@TimeSheetId", item.TimeSheetId);
                                    stmt.Parameters.AddWithValue("@Day", item.Day);
                                    // payroll
                                    if (item.PayRollHours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollHours", item.PayRollHours.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollHours", 0);
                                    }
                                    if (item.PayRollTravelDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollTravelDistance", item.PayRollTravelDistance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollTravelDistance", 0);
                                    }
                                    if (item.PayRollAccomodation.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollAccomodation", item.PayRollAccomodation.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollAccomodation", 0);
                                    }
                                    if (item.PayRollMisc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollMisc", item.PayRollMisc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@PayRollMisc", 0);
                                    }

                                    // billing
                                    if (item.BillingHours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingHours", item.BillingHours.Value);
                                    }
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTravelDistance", item.BillingTravelDistance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTravelDistance", 0);
                                    }

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingAccomodation", item.BillingAccomodation.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingAccomodation", 0);
                                    }

                                    if (item.BillingMisc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingMisc", item.BillingMisc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingMisc", 0);
                                    }
                                    // get project number
                                    string no = tm.getProjectNoForID(item.ProjectId);
                                    stmt.Parameters.AddWithValue("@ProjectNo", no);
                                    stmt.Parameters.AddWithValue("@Classification", item.Classification);
                                    stmt.Parameters.AddWithValue("@Activity", item.Activity);
                                    if (item.Remarks != null)
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", item.Remarks);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", " ");
                                    }

                                    if (item.TruckDistance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTruckDistance", item.TruckDistance);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@BillingTruckDistance", 0);
                                    }

                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        List<ManagerNonChargeable> nData = tm.getManagerNonChargeableForID(id);

                        if (nData != null)
                        {
                            try
                            {

                                // save each row of non chargeable data to the sync database
                                foreach (ManagerNonChargeable item in nData)
                                {

                                    SqlCommand stmt = conn.CreateCommand();

                                    stmt.CommandText =
                                   "INSERT INTO NonChargeable (TimeSheetId,Hours,Distance,Accomodations,Misc,TypeHours,TypeExpense,Day,Remarks)VALUES(@TimeSheetId,@Hours, @Distance, @Accomodations, @Misc, @TypeHours, @TypeExpense, @Day, @Remarks)";

                                    stmt.Parameters.AddWithValue("@TimeSheetId", t.TimeSheetId);

                                    if (item.Hours.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Hours", item.Hours.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Hours", 0);
                                    }

                                    if (item.Distance.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Distance", item.Distance.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Distance", 0);
                                    }

                                    if (item.Accomodations.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Accomodations", item.Accomodations.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Accomodations", 0);
                                    }
                                    if (item.Misc.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@Misc", item.Misc.Value);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Misc", 0);
                                    }

                                    if (item.TypeHours != null)
                                    {
                                        stmt.Parameters.AddWithValue("@TypeHours", item.TypeHours);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@TypeHours", " ");
                                    }
                                    if (item.TypeExpense != null)
                                    {
                                        stmt.Parameters.AddWithValue("@TypeExpense", item.TypeExpense);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@TypeExpense", " ");

                                    }
                                    stmt.Parameters.AddWithValue("@Day", item.Day);

                                    if (item.Remarks != null)
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", item.Remarks);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@Remarks", " ");
                                    }
                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {
                                throw;
                            }
                        }

                        // Synchronize the Lab and Density Tests
                        List<ManagerTest> tests = tm.getManagerTestsForTimeSheet(id);
                        if (tests != null)
                        {
                            try
                            {
                                foreach (ManagerTest item in tests)
                                {
                                    SqlCommand stmt = conn.CreateCommand();
                                    stmt.CommandText = "INSERT INTO ManagerTest(LabTest,DensityTest,TimeSheetId,Day) VALUES(@LabTest,@DensityTest,@TimeSheetId,@Day)";
                                    if (item.LabTest.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@LabTest", item.LabTest);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@LabTest", 0);
                                    }
                                    if (item.DensityTest.HasValue)
                                    {
                                        stmt.Parameters.AddWithValue("@DensityTest", item.DensityTest);
                                    }
                                    else
                                    {
                                        stmt.Parameters.AddWithValue("@DensityTest", 0);
                                    }

                                    if (item.TimeSheetId > 0)
                                    {
                                        stmt.Parameters.AddWithValue("@TimeSheetId", item.TimeSheetId);
                                    }

                                    if (item.Day != string.Empty)
                                    {
                                        stmt.Parameters.AddWithValue("@Day", item.Day);
                                    }

                                    stmt.ExecuteNonQuery();
                                    stmt.Dispose();
                                    stmt = null;
                                }
                            }
                            catch (Exception)
                            {

                                throw;
                            }

                        }

                        // update timesheet
                        tm.updateTimeSheet(t.TimeSheetId, t.TotalHours.Value, t.TotalDistance.Value, t.TotalTruck.Value, t.TotalExpenses.Value, "Synchronized", " ", " ");
                        conn.Close();
                    }
                }
            }
        }
    }