protected void HospitalDropDownList_SelectedIndexChanged(object sender, EventArgs e) { //set opening and closing label to visible if (HospitalDropDownList.SelectedItem.ToString() != "-Select a Hospital-") { lb_openingHrs.Visible = true; lb_closingHrs.Visible = true; lblHospital.Visible = false; } else { lb_openingHrs.Visible = false; lb_closingHrs.Visible = false; } lblTime.Text = ""; DepartmentDropDownList.DataSource = DepartmentManagementSystem.getDepartments(HospitalDropDownList.SelectedValue.ToString()); DepartmentDropDownList.DataTextField = "departmentName"; DepartmentDropDownList.DataValueField = "departmentID"; DepartmentDropDownList.DataBind(); DepartmentDropDownList.Items.Insert(0, new ListItem("(Select a Department)", "-1")); //get opening hours and set it if (HospitalDropDownList.SelectedValue.ToString() != "-1") { Facility f = FacilityManagementSystem.getOpeningHrs(HospitalDropDownList.SelectedValue.ToString()); HourChange("AM"); AMPMDropDownList.ClearSelection(); AMPMDropDownList.Items.FindByText(f.openingHrs.Substring(4, 2)).Selected = true; lb_actualOpening.Text = f.generalInfo; lb_actualClosing.Text = f.region; lb_actualClosing.Visible = true; lb_actualOpening.Visible = true; } else { HourDropDownList.Items.Clear(); HourDropDownList.Items.Insert(0, new ListItem("-Hr-", "-1")); MinDropDownList.Items.Clear(); MinDropDownList.Items.Insert(0, new ListItem("-Min-", "-1")); AMPMDropDownList.ClearSelection(); lb_actualClosing.Visible = false; lb_actualOpening.Visible = false; } }
void MinChange(int hour) { Facility f = FacilityManagementSystem.getOpeningHrs(HospitalDropDownList.SelectedValue.ToString()); int openHours = Convert.ToInt32(f.openingHrs.Substring(0, 2)); int closeHours = Convert.ToInt32(f.closingHrs.Substring(0, 2)); int openMins = Convert.ToInt32(f.openingHrs.Substring(2, 2)); int closeMins = Convert.ToInt32(f.closingHrs.Substring(2, 2)); MinDropDownList.Items.Clear(); MinDropDownList.Items.Insert(0, new ListItem("-Min-", "-1"));//add heading in dropdownlist if (hour == openHours) { for (int min = openMins; min <= 45; min = min + 15) { MinDropDownList.Items.Add(new ListItem(min.ToString(), min.ToString())); } } else if (hour == closeHours - 1) { for (int min = 0; min <= closeMins; min = min + 15) { MinDropDownList.Items.Add(new ListItem(min.ToString(), min.ToString())); } } else if (hour == -1) { //do nothing~ } else { for (int i = 0; i <= 45; i = i + 15) { MinDropDownList.Items.Add(new ListItem(i.ToString(), i.ToString())); } } //set selected min to first index MinDropDownList.ClearSelection(); if (hour != -1) { MinDropDownList.SelectedIndex = 1; } //change the text "0" to "00" if (MinDropDownList.SelectedItem.ToString() == "0") { MinDropDownList.SelectedItem.Text = "00"; } }
void HourChange(string AMPM) { Facility f = FacilityManagementSystem.getOpeningHrs(HospitalDropDownList.SelectedValue.ToString()); int openHours = Convert.ToInt32(f.openingHrs.Substring(0, 2)); int closeHours = Convert.ToInt32(f.closingHrs.Substring(0, 2)); HourDropDownList.Items.Clear(); if (AMPM == "AM") { if (openHours > 12)//if opening time after 12pm no time slot in am { HourDropDownList.Items.Add(new ListItem("No time slot!", "-1")); } else { for (openHours = openHours + 0; openHours < closeHours && openHours < 12; openHours++)//add time slot in dropdownlist { HourDropDownList.Items.Add(new ListItem(openHours.ToString(), openHours.ToString())); } } } else if (AMPM == "PM") { if (closeHours < 12)//if closing time before 12pm no slot for pm slot { HourDropDownList.Items.Add(new ListItem("No time slot!", "-1")); } else { if (openHours < 12)//if opening time before 12pm set open to 12pm for pm slot { openHours = 12; } for (openHours = openHours + 0; openHours < closeHours; openHours++) { if (openHours != 12) { HourDropDownList.Items.Add(new ListItem((openHours - 12).ToString(), openHours.ToString()));//minus 12 cos time is in 24 hr format. 12pm dunnid minus } else { HourDropDownList.Items.Add(new ListItem((openHours).ToString(), openHours.ToString())); } } } } HourDropDownList.ClearSelection(); //add "0" to single digit number. e.g. "8" becomes "08" foreach (ListItem li in HourDropDownList.Items) { if (Convert.ToInt32(li.Value) < 10) { li.Text = "0" + li.Text; li.Value = li.Text; } } HourDropDownList.Items.Insert(0, new ListItem("-Hr-", "-1"));//add heading in dropdownlist //set default value of hour HourDropDownList.ClearSelection(); HourDropDownList.SelectedIndex = 1; openHours = Convert.ToInt32(f.openingHrs.Substring(0, 2)); //reset open time if (AMPM == "PM" && openHours < 12) //if opening time before 12pm set open to 12pm for pm slot { openHours = 12; } MinChange(openHours);//set mins }