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