private void PopulateGridviewSchedule(DateTime myDate) { List <string> workHoursList = WorkHourDB.GetWorkHoursList(); List <DateTime> daysList; //contains the list of dates starting from sunday that fall within the week relative to the myDate variable DateTimeFormatInfo dtfi; DisplayGridviewHeader(myDate, out daysList, out dtfi); int cellNumberToUse = 0; foreach (DateTime d in daysList) { cellNumberToUse = GetTheCellNumberToUse(cellNumberToUse, d); // Prevent the user from scheduling previous days // disable linkbuttons where the date is < todays date if (d < DateTime.Now.ToLocalTime().AddDays(-1)) { foreach (GridViewRow row in gviewSchedule.Rows) { row.Cells[cellNumberToUse].Text = "-"; } } // get all appointments that fall on this day // STG_ServiceWorkList stg_servWorkList = STG_ServiceWorkManager.GetListByDate(d.Date); ServiceWorkList existingServiceWorkList = ServiceWorkManager.GetListByDate(d.Date); if (existingServiceWorkList != null) { foreach (ServiceWork s in existingServiceWorkList) { // find the start time of this service work string myStartTime = s.ServiceStartTime.ToShortTimeString(); int index = workHoursList.IndexOf(myStartTime.Replace(" ", "")); // determine how long the appointment is, i.e from 10:00AM to 11:00AM and then // calculate the number of 30 minute interval from that range. int myInterval = STG_ServiceWork.CalculateNumberOfIntervals(s.ServiceStartTime, s.ServiceEndTime); if (index != -1) { //found a match for (int i = index; i < (myInterval + index); i++) { gviewSchedule.Rows[i].Cells[cellNumberToUse].Text = "Service Work ID: " + s.ServiceWorkID.ToString(); gviewSchedule.Rows[i].Cells[cellNumberToUse].ToolTip = "Service Work ID: " + s.ServiceWorkID.ToString(); } } } } } // Display the reference date in the textbox txtRefDate.Text = myDate.ToString("d", dtfi); }
protected void selectAServiceDateTime_OnCommand(object sender, CommandEventArgs e) { string whichDay = e.CommandName.ToString(); string startTime = e.CommandArgument.ToString(); // find out which day the service will be done switch (whichDay) { case "monday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForMonday].Text; break; case "tuesday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForTuesday].Text; break; case "wednesday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForWednesday].Text; break; case "thursday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForThursday].Text; break; case "friday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForFriday].Text; break; case "saturday": actualServiceDate = gviewSchedule.HeaderRow.Cells[CellNumberForSaturday].Text; break; } //load start time and end time dropdownlist List <string> workHoursList = WorkHourDB.GetWorkHoursList(); PopulateEndTimeDropdownList(workHoursList); PopulateStartTimeDropdownList(workHoursList); //get the start time based on the user's selection from the gridview ddlServiceStartTime.SelectedValue = startTime; //by default, the service end time must be 1 hour after the start time //string end = Convert.ToDateTime(startTime).AddHours(1).ToString(); ddlServiceEndTime.SelectedValue = Convert.ToDateTime(startTime).AddHours(1).ToShortTimeString().Replace(" ", ""); //display the service date selected by the user lblSelectedServiceDate.Text = actualServiceDate; LoadWorkHousInGridview(); PopulateGridviewSchedule(Convert.ToDateTime(actualServiceDate)); //show the date and time confirmation box this.mPopupSetServiceDateTime.Show(); //disable the gridview after a date and time has been selected gviewSchedule.Enabled = false; //show the panel for date and time confirmation pnlConfirmServiceWorkAppointment.Visible = true; //enable the book linkbutton lnkConfirmServiceDateTime.Enabled = true; }