protected void btnSave_Click(object sender, EventArgs e) { try { if (txtDate.Text == string.Empty) { divError.Visible = true; lblError.Visible = true; lblError.Text = "Please select date to set time slots."; return; } DateTime dt = DateTime.Today; if (txtDate.Text == Convert.ToString(dt.ToShortDateString())) { divError.Visible = true; lblError.Visible = true; lblError.Text = "Please select date greater than today's date."; return; } if (Convert.ToDateTime(txtDate.Text).DayOfWeek == DayOfWeek.Sunday) { divError.Visible = true; lblError.Visible = true; lblError.Text = "Selected date is sunday.Please select another date."; return; } Appointment objApp = new Appointment(); DataSet DS = new DataSet(); DS = objApp.GetAppointmentslots(Convert.ToDateTime(txtDate.Text)); if (DS.Tables[0].Rows.Count > 0) { divError.Visible = true; lblError.Visible = true; lblError.Text = "Time slots are already allocated to selected date."; return; } else { foreach (DataListItem item in dtlTime.Items) { Label lblTimeId = (Label)item.FindControl("lblTimeId"); CheckBox chkTime = (CheckBox)item.FindControl("chkTime"); if (chkTime.Checked) { objApp.AddAppointmentslots(Convert.ToDateTime(txtDate.Text), Convert.ToInt32(lblTimeId.Text)); } } divError.Visible = true; lblError.Visible = true; lblError.ForeColor = System.Drawing.Color.Green; lblError.Text = "Time slots allocated sucessfully."; } //Response.Redirect("AppointmentSettings.aspx"); } catch { } }
protected void btnSave_Click(object sender, EventArgs e) { try { Appointment objApp = new Appointment(); objApp.DeleteAppointmentslots(Convert.ToDateTime(dt)); foreach (DataListItem item in dtlTime.Items) { Label lblTimeId = (Label)item.FindControl("lblTimeId"); CheckBox chkTime = (CheckBox)item.FindControl("chkTime"); if (chkTime.Checked) { objApp.AddAppointmentslots(Convert.ToDateTime(txtDate.Text), Convert.ToInt32(lblTimeId.Text)); } } Response.Redirect("AppointmentSettings.aspx"); } catch { } }