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();
    }