kalpana jaiswal

kalpana jaiswal

  • NA
  • 45
  • 9.7k

data is already in database selected by user in dropdown lis

Mar 29 2016 2:26 PM
I want to check that slot selected by user is already present in data base or not dynamically so he cant select that slot.
 
below is the code 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
public partial class ConfirmAppointment : System.Web.UI.Page
{
string s = "F";
protected void Page_Load(object sender, EventArgs e)
{
if (Session["user"] == null)
{
Response.Redirect("Login.aspx");
}
else
{
selectedDoctorDetail();
}
caltxtAppointment.StartDate = DateTime.Now;
}
private void selectedDoctorDetail()
{
int id = Convert.ToInt32(Request.QueryString["id"]);
DateTime inTime;
DateTime outTime;
DateTime value;
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DiabeticCareCenterDbConnectionString2"].ConnectionString))
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("select Fname+' '+Lname as Fullname,Qualification,Email,Fees,Intime,Outtime from Doctor where DId=@DId", con);
cmd.Parameters.AddWithValue("@DId", id);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
lblName.Text = Convert.ToString(dr.GetValue(0));
lblQualification.Text = dr.GetValue(1).ToString();
lblEmail.Text = dr.GetValue(2).ToString();
lblFees.Text = dr.GetValue(3).ToString();
lblTime.Text = dr.GetValue(4).ToString() + "-" + dr.GetValue(5).ToString();
inTime = DateTime.Parse(dr.GetValue(4).ToString());
outTime = DateTime.Parse(dr.GetValue(5).ToString());
while (true)
{
if (inTime.Hour == outTime.Hour)
{
if (inTime.Minute < outTime.Minute)
{

}
else
{
break;
}
}
else if (inTime.Hour > outTime.Hour)
{
break;
}
else
{

}
String print = inTime.Hour + ":" + inTime.Minute + "-";
value = inTime.AddMinutes(15);
print += value.Hour + ":" + value.Minute + "\n";
ListItem lst = new ListItem();
lst.Text = print;
ddlTime.Items.Add(lst);
inTime = value;
}
}
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Request.QueryString["id"]);
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DiabeticCareCenterDbConnectionString2"].ConnectionString))
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
try
{
string[] time = ddlTime.SelectedItem.Text.Trim().Split('-');
int pid = Convert.ToInt32(Session["PId"].ToString());
string sql = "insert into Appointment(PId,DId,Date,Status,InTime,OutTime)values(@PId,@DId,@Date,@Status,@InTime,@OutTime)";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.AddWithValue("@PId", pid);
cmd.Parameters.AddWithValue("@DId", id);
cmd.Parameters.AddWithValue("@Date", Convert.ToDateTime(txtAppointment.Text));
cmd.Parameters.AddWithValue("@Status", s.ToString());
cmd.Parameters.AddWithValue("@InTime", time[0].ToString());
cmd.Parameters.AddWithValue("@OutTime", time[1].ToString());
cmd.ExecuteNonQuery();
Response.Redirect("~/MailConfirmation.aspx");
}
catch(Exception ex)
{
Label1.Text = ex.Message;
}
//Label1.Text = time[0]+time[1];
}
}

Answers (1)