protected void Page_Load(object sender, EventArgs e)
    {
        dbData = new string[7] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
        // Fields to populate when user visits this page: Employee ID, Employee Name, and Branch
        TimesheetManager tm = new TimesheetManager();

        // re-highlight rows if possible
        HighLightDeletedRows();
        if (!IsPostBack)
        {

            verifyBtn.Enabled = true;
            // get and populate user information
            MembershipUser loggedInUser = Membership.GetUser();
            User employee = tm.getEmployeeForId(loggedInUser.UserName);
            empIdTB.Text = employee.empNo;
            nameTB.Text = employee.FirstName + " " + employee.MiddleName + " " + employee.LastName;
            departmentTB.Text = employee.branch;

            // 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");

            // sub-menu's of non-chargeable section
            NonChargeExpensesPanel.Visible = false;
            NonChargeHoursPanel.Visible = false;
            detailsDDL.SelectedIndex = 0;
            specifyDDL.SelectedIndex = 0;

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                string timesheet = Request.QueryString["time"];
                string expense = Request.QueryString["expense"];
                string hours = Request.QueryString["hours"];
                string project = Request.QueryString["project"];
                string classification = Request.QueryString["class"];
                string activity = Request.QueryString["activity"];
                string delete = Request.QueryString["delete"];
                int chID = Convert.ToInt32(Request.QueryString["charge"]);
                int nonChID = Convert.ToInt32(Request.QueryString["nonCh"]);
                int lab = Convert.ToInt32(Request.QueryString["test"]);
                // reset weekending dates
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);

                int id = Convert.ToInt32(timesheet);
                timesheetID = id;
                HiddenField1.Value = id.ToString();

                // VIEW ONLY from a MANAGER's perspective.
                if (Request.QueryString["view"] == "view") {
                    verifyBtn.Enabled = false;
                    chargeableBtn.Enabled = false;
                    nonChargeBtn.Enabled = false;
                    labTestsBtn.Enabled = false;
                    // disable edit and delete columns
                    summaryGV.Columns[0].Visible = false;
                    summaryGV.Columns[1].Visible = false;
                    summaryGV.Columns[0].Visible = false;
                    summaryGV.Columns[1].Visible = false;
                    string username = Membership.GetUser().UserName;

                    TimeSheet ts = tm.getTimesheetForID(timesheetID);
                    User user = tm.getEmployeeForId(ts.EmployeeId);
                    departmentTB.Text = user.branch;
                    empIdTB.Text = user.empNo;
                    nameTB.Text = user.FirstName + " " + user.MiddleName + " " + user.LastName;
                }
                // display lab test hours
                if (lab > 0 && delete != "delete")
                {
                    List<EmpTest> tests = tm.getEmpTestsForTimeSheet(id);
                    updateLabTestsBtn.Visible = true;
                    labTestsBtn.Visible = false;
                    aID = 1;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    foreach (EmpTest item in tests)
                    {
                        if (item.Day == "Sunday")
                        {
                            sunLabTB.Text = item.LabTest.ToString();
                            sunNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Monday")
                        {
                            monLabTB.Text = item.LabTest.ToString();
                            monNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Tuesday")
                        {
                            tuesLabTB.Text = item.LabTest.ToString();
                            tuesNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Wednesday")
                        {
                            wedsLabTB.Text = item.LabTest.ToString();
                            wedsNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Thursday")
                        {
                            thursLabTB.Text = item.LabTest.ToString();
                            thursNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Friday")
                        {
                            friLabTB.Text = item.LabTest.ToString();
                            friNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Saturday")
                        {
                            satLabTB.Text = item.LabTest.ToString();
                            satNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                    }
                }

                // set static properties on the webpage
                weekEndingTB.Text = tm.getWeekendingForTimeSheet(id);

                // delete summary non-chargeable and chargeable
                if (delete == "delete")
                {
                    rowIDs.Add(summaryGV.SelectedIndex);
                    HighLightDeletedRows();
                    //tm.deleteSummary(nonChID, chID, id, lab, false);

                    summaryGV.Focus();
                }
                // if there is a query string, load the totals from the corresponding timesheet
                updateTimeSheetTotals();
                // this conditional structure determines what module to load based on query string values
                // Project Only
                if (Request.QueryString["projectOnly"] != null)
                {
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    projectNumTB.Text = p.ProjectNo;
                    projectNameTB.Text = p.ProjectName;
                    clientNameTB.Text = p.ClientName;
                    classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                    classificationDDL.DataBind();
                    classificationDDL.SelectedValue = classification;

                    projectNumTB.Enabled = true;
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                }
                // chargeable
                else if (project != null && project != "0")
                {
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);

                    // populate the project information fields
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    if (p != null)
                    {
                        projectNumTB.Text = p.ProjectNo;
                        projectNameTB.Text = p.ProjectName;
                        clientNameTB.Text = p.ClientName;
                        classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                        classificationDDL.DataBind();
                        classificationDDL.SelectedValue = classification;
                        activitiesDDL.DataSource = tm.getActivityForClassification(classification);
                        activitiesDDL.DataBind();
                        activitiesDDL.SelectedValue = activity;
                        projectNumTB.Enabled = true;

                        // populate the chargeable fields based on the classification and activity selected
                        List<ChargeableJob> cJobs = tm.getChargeableJobsForTimesheetID(timesheetID);

                        if (chID > 0)
                        {
                            cJobs.Add(tm.getChargeForID(chID));
                        }

                        if (cJobs != null)
                        {
                            chargeableBtn.Visible = false;
                            updateChargeableBtn.Visible = true;

                            foreach (var item in cJobs)
                            {
                                if (item.Day == "Sunday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        sunAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    sunCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    sunDistTB.Text = item.TravelDistance.ToString();
                                    sunTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        sunMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    sunCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Monday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        monAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    monCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    monDistTB.Text = item.TravelDistance.ToString();
                                    monTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        monMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    monCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Tuesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        tuesAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    tuesCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    tuesDistTB.Text = item.TravelDistance.ToString();
                                    tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        tuesMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    tuesCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Wednesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        wedsAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    wedsCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    wedsDistTB.Text = item.TravelDistance.ToString();
                                    wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        wedsMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    wedsCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Thursday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        thursAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    thursCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    thursDistTB.Text = item.TravelDistance.ToString();
                                    thursTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        thursMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    thursCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Friday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        friAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    friCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    friDistTB.Text = item.TravelDistance.ToString();
                                    friTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        friMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    friCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Saturday" && item.Classification == classification && item.Activity == activity)
                                {
                                    if (item.Accomodations.HasValue)
                                    {
                                        satAccomTB.Text = item.Accomodations.Value.ToString("0.00##");
                                    }
                                    satCHoursTB.Text = item.EmpHours.ToString("0.0");
                                    satDistTB.Text = item.TravelDistance.ToString();
                                    satTruckDistTB.Text = item.TruckDistance.ToString();
                                    if (item.Misc.HasValue)
                                    {
                                        satMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                    }
                                    satCRemarksTB.Text = item.Remarks;
                                }
                            }
                        }
                    }
                }
                // Non-Chargeable
                else if (expense != "Select" || hours != "Select")
                {
                    aID = 2;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    // set the dropdownlists and display the different panels accordingly
                    if (hours != string.Empty)
                    {
                        specifyDDL.SelectedValue = hours;
                        NonChargeHoursPanel.Visible = true;
                    }
                    else
                    {
                        specifyDDL.SelectedIndex = 0;
                        NonChargeHoursPanel.Visible = false;
                    }

                    if (expense != string.Empty)
                    {
                        detailsDDL.SelectedValue = expense;
                        NonChargeExpensesPanel.Visible = true;
                    }
                    else
                    {
                        detailsDDL.SelectedIndex = 0;
                        NonChargeExpensesPanel.Visible = false;
                    }

                    List<NonChargeable> nCh = tm.getNonChargeableForTimesheetID(timesheet, expense, hours);
                    if (nCh != null)
                    {
                        // adjust buttons
                        nonChargeBtn.Visible = false;
                        updateNonChargeableBtn.Visible = true;
                        // populate the non chargeable text fields based on the expense and type of hours selected
                        foreach (var item in nCh)
                        {
                            if (item.Day == "Sunday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    sunNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                sunNCHoursTB.Text = item.Hours.ToString("0.0");
                                sunNCDistanceTB.Text = item.Distance.ToString();
                                sunTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    sunNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                sunNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Monday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    monNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                monNCHoursTB.Text = item.Hours.ToString("0.0");
                                monNCDistanceTB.Text = item.Distance.ToString();
                                monTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    monNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                monNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Tuesday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    tuesNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                tuesNCHoursTB.Text = item.Hours.ToString("0.0");
                                tuesNCDistanceTB.Text = item.Distance.ToString();
                                tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    tuesNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }

                                tuesNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Wednesday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    wedsNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                wedsNCHoursTB.Text = item.Hours.ToString("0.0");
                                wedsNCDistanceTB.Text = item.Distance.ToString();
                                wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    wedsNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                wedsNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Thursday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    thursNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                thursNCHoursTB.Text = item.Hours.ToString("0.0");
                                thursNCDistanceTB.Text = item.Distance.ToString();
                                thursTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    thursNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                thursNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Friday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    friNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                friNCHoursTB.Text = item.Hours.ToString("0.0");
                                friNCDistanceTB.Text = item.Distance.ToString();
                                friTruckDistTB.Text = item.TruckDistance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    friNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                                friNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Saturday")
                            {
                                if (item.Accomodation.HasValue)
                                {
                                    satNCAccomTB.Text = item.Accomodation.Value.ToString("0.00##");
                                }
                                satNCHoursTB.Text = item.Hours.ToString("0.0");
                                satNCDistanceTB.Text = item.Distance.ToString();
                                satTruckDistTB.Text = item.TruckDistance.ToString();
                                satNCRemarksTB.Text = item.Remarks;
                                if (item.Misc.HasValue)
                                {
                                    satNCMiscTB.Text = item.Misc.Value.ToString("0.00##");
                                }
                            }
                        }
                    }
                }
            }
        }
        // check to see if weekending is specified, if it is get timesheetID set it and update the gridviews
        if (weekEndingTB.Text != string.Empty)
        {
            // re-populate the dates
            ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
            // try and get the timesheet for the logged in user
            int id = tm.idForDate(weekEndingTB.Text, tm.idForUsername(Membership.GetUser().UserName));
            if (id != 0)
            {
                timesheetID = id;
                HiddenField1.Value = id.ToString();
                // update totals
                updateTimeSheetTotals();
                summaryGV.DataBind();
            }
        }
        // populate the predictive text arrays
        projectNoDB = tm.getProjectNumbers();
    }
    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 Page_Load(object sender, EventArgs e)
    {
        dbData = new string[7] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
        weekEndingTB.Enabled = false;
        // Fields to populate when user visits this page: Employee ID, Employee Name, and Branch
        TimesheetManager tm = new TimesheetManager();
        projectNumTB.Enabled = true;
        if (!IsPostBack)
        {
            // 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");

            // sub-menu's of non-chargeable section
            NonChargeExpensesPanel.Visible = false;
            NonChargeHoursPanel.Visible = false;

            // check query strings for form data to be populated
            if (Request.QueryString.Count > 0)
            {
                string timesheet = Request.QueryString["time"];
                string expense = Request.QueryString["expense"];
                string hours = Request.QueryString["hours"];
                string project = Request.QueryString["project"];
                string classification = Request.QueryString["class"];
                string activity = Request.QueryString["activity"];
                int chID = Convert.ToInt32(Request.QueryString["charge"]);
                int nonChID = Convert.ToInt32(Request.QueryString["nonCh"]);
                string delete = Request.QueryString["delete"];
                int lab = Convert.ToInt32(Request.QueryString["test"]);

                // reset weekending dates
                ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);

                int id = Convert.ToInt32(timesheet);
                timesheetID = id;
                HiddenField1.Value = id.ToString();

                // handle lab hours
                if (lab > 0 && delete != "delete")
                {
                    List<ManagerTest> tests = tm.getManagerTestsForTimeSheet(id);
                    updateLabTestsBtn.Visible = true;
                    labTestsBtn.Visible = false;
                    aID = 1;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    foreach (ManagerTest item in tests)
                    {
                        if (item.Day == "Sunday")
                        {
                            sunLabTB.Text = item.LabTest.ToString();
                            sunNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Monday")
                        {
                            monLabTB.Text = item.LabTest.ToString();
                            monNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Tuesday")
                        {
                            tuesLabTB.Text = item.LabTest.ToString();
                            tuesNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Wednesday")
                        {
                            wedsLabTB.Text = item.LabTest.ToString();
                            wedsNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Thursday")
                        {
                            thursLabTB.Text = item.LabTest.ToString();
                            thursNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Friday")
                        {
                            friLabTB.Text = item.LabTest.ToString();
                            friNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                        else if (item.Day == "Saturday")
                        {
                            satLabTB.Text = item.LabTest.ToString();
                            satNuclearDensityTestTB.Text = item.DensityTest.ToString();
                        }
                    }
                }

                // set static properties on the webpage
                weekEndingTB.Text = tm.getWeekendingForTimeSheet(id);
                // if there is a query string, load the totals from the corresponding timesheet

                if (delete == "delete")
                {

                   tm.deleteSummary(nonChID, chID, id, lab, true);
                    summaryGV.Focus();
                }
                // update Timesheet Totals
                updateTimeSheetTotals();
                TimeSheet t = tm.getTimesheetForID(timesheetID);
                // get and populate user information
                User emp = tm.getEmployeeForId(t.EmployeeId);
                empIdTB.Text = emp.empNo;
                nameTB.Text = emp.FirstName + " " + emp.MiddleName + " " + emp.LastName;
                departmentTB.Text = emp.branch;
                if (Request.QueryString["projectOnly"] != null)
                {
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    projectNumTB.Text = p.ProjectNo;
                    projectNameTB.Text = p.ProjectName;
                    clientNameTB.Text = p.ClientName;
                    classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                    classificationDDL.DataBind();
                    classificationDDL.SelectedValue = classification;

                    projectNumTB.Enabled = true;
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                }
                // Chargeable
                else if (project != null && project != "0" && project != string.Empty)
                {
                    // adjust accordion panels
                    aID = 0;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);
                    // populate the project information fields
                    int projectID = Convert.ToInt32(project);
                    Project p = tm.getProjectForID(projectID);
                    if (p != null)
                    {
                        projectNumTB.Text = p.ProjectNo;
                        projectNameTB.Text = p.ProjectName;
                        clientNameTB.Text = p.ClientName;
                        classificationDDL.DataSource = tm.getClassificationForProject(p.ProjectNo);
                        classificationDDL.DataBind();
                        classificationDDL.SelectedValue = classification;

                        activitiesDDL.DataSource = tm.getActivityForClassification(classification);
                        activitiesDDL.DataBind();
                        activitiesDDL.SelectedValue = activity;

                        // adjust buttons
                        chargeableBtn.Visible = false;
                        updateChargeableBtn.Visible = true;

                        // populate the chargeable fields based on the classification and activity selected
                        List<ManagerChargeable> cJobs = tm.getManagerChargeableForID(timesheetID);

                        if (chID > 0)
                        {
                            cJobs.Add(tm.getManagerChargeForID(chID));
                        }

                        if (cJobs != null)
                        {
                            foreach (var item in cJobs)
                            {
                                if (item.Day == "Sunday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        sunBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        sunBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        sunBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }

                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        sunTruckDistTB.Text = item.TruckDistance.ToString();
                                    }

                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        sunBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }

                                    sunCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Monday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        monBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        monBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        monBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        monTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        monBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    monCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Tuesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        tuesBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        tuesBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        tuesBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        tuesTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        tuesBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    tuesCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Wednesday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        wedsBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours

                                    if (item.BillingHours.HasValue)
                                    {
                                        wedsBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        wedsBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        wedsTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        wedsBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    wedsCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Thursday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation

                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        thursBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        thursBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        thursBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        thursTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        thursBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    thursCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Friday" && item.Classification == classification && item.Activity == activity)
                                {    // Accomodation
                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        friBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        friBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance

                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        friBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        friTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc

                                    if (item.BillingMisc.HasValue)
                                    {
                                        friBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    friCRemarksTB.Text = item.Remarks;
                                }
                                else if (item.Day == "Saturday" && item.Classification == classification && item.Activity == activity)
                                {
                                    // Accomodation
                                    if (item.BillingAccomodation.HasValue)
                                    {
                                        satBAccomTB.Text = item.PayRollAccomodation.Value.ToString("0.00##");
                                    }

                                    // Hours
                                    if (item.BillingHours.HasValue)
                                    {
                                        satBCHoursTB.Text = item.BillingHours.Value.ToString("0.0");
                                    }
                                    // Distance
                                    if (item.BillingTravelDistance.HasValue)
                                    {
                                        satBDistTB.Text = item.BillingTravelDistance.ToString();
                                    }
                                    // truck distance
                                    if (item.TruckDistance.HasValue)
                                    {
                                        satTruckDistTB.Text = item.TruckDistance.ToString();
                                    }
                                    // Misc
                                    if (item.BillingMisc.HasValue)
                                    {
                                        satBMiscTB.Text = item.BillingMisc.Value.ToString("0.00##");
                                    }
                                    satCRemarksTB.Text = item.Remarks;
                                }
                            }
                        }
                    }
                }
                // Non-Chargeable
                else if (expense != string.Empty && expense != null || hours != string.Empty && hours != null)
                {
                    // activate corresponding accordion panel
                    aID = 2;
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "toggleAccordion", "accordionToggle();", true);

                    // set the dropdownlists and display the different panels accordingly
                    if (hours != string.Empty)
                    {
                        specifyDDL.SelectedValue = hours;
                        NonChargeHoursPanel.Visible = true;
                    } if (expense != string.Empty)
                    {
                        detailsDDL.SelectedValue = expense;
                        NonChargeExpensesPanel.Visible = true;
                    }

                    // adjust buttons
                    nonChargeBtn.Visible = false;
                    updateNonChargeableBtn.Visible = true;

                    List<ManagerNonChargeable> nonCh = tm.getManagerNonChargeableForTimesheetID(timesheet, expense, hours);
                    if (nonCh != null)
                    {
                        // populate the non chargeable text fields based on the expense and type of hours selected
                        foreach (var item in nonCh)
                        {
                            if (item.Day == "Sunday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    sunNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                sunNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                sunNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    sunNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                sunNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Monday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    monNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                monNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                monNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    monNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                monNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Tuesday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    tuesNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                tuesNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                tuesNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    tuesNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }

                                tuesNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Wednesday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    wedsNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                wedsNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                wedsNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    wedsNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                wedsNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Thursday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    thursNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                thursNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                thursNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    thursNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                thursNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Friday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    friNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                friNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                friNCDistanceTB.Text = item.Distance.ToString();
                                if (item.Misc.HasValue)
                                {
                                    friNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                                friNCRemarksTB.Text = item.Remarks;
                            }
                            else if (item.Day == "Saturday")
                            {
                                if (item.Accomodations.HasValue)
                                {
                                    satNCAccomTB.Text = item.Accomodations.Value.ToString("0.####");
                                }
                                satNCHoursTB.Text = item.Hours.Value.ToString("0.#");
                                satNCDistanceTB.Text = item.Distance.ToString();
                                satNCRemarksTB.Text = item.Remarks;
                                if (item.Misc.HasValue)
                                {
                                    satNCMiscTB.Text = item.Misc.Value.ToString("0.####");
                                }
                            }
                        }
                    }
                }
            }
        }
        // check to see if weekending is specified update the gridviews
        if (weekEndingTB.Text != string.Empty)
        {
            // re-populate the dates
            ScriptManager.RegisterStartupScript(this, this.GetType(), "populate", "populate();", true);
            // Get the timesheet id for the users whos timesheet we are managing
            string username = tm.getUsernameForEmpNo(empIdTB.Text);
            int id = tm.idForDate(weekEndingTB.Text, tm.idForUsername(username));

            if (id != 0)
            {
                timesheetID = id;
                HiddenField1.Value = id.ToString();
                // update totals
                updateTimeSheetTotals();
                summaryGV.DataBind();
            }
        }
        // populate the predictive text arrays
        projectNoDB = tm.getProjectNumbers();
    }