application for appointment
I have A gridview with these columns
AppId Appdate Starttime Endtime Consumer
And 2 dropdownlists below the gridview to select start time and end time to fix the appointment.
I select the times and other values and click on insert button
Before inserting the new appointment I want to check the existing appointment on that time. if there is an appointment fixed on that time than it should give me some message. Otherwise the new appointment will be inserted
I wrote this code
protected void BtnSetApp_Click(object sender, EventArgs e)
{
int statusid = Convert.ToInt32(scheduledid());
sfid = Convert.ToInt32(Ddlsfo.SelectedValue.ToString());
DateTime starttime = Convert.ToDateTime(ddlstartdate.SelectedValue.ToString());
DateTime endtime = Convert.ToDateTime(Ddlenddate.SelectedValue.ToString());
appointmentgrid();
for (int i = 0; i < GridView1.Rows.Count; i++)
{
if (starttime == Convert.ToDateTime(ds.Tables["t"].Rows[i][2].ToString()) && endtime == Convert.ToDateTime(ds.Tables["t"].Rows[i][3].ToString()))
{
lblmessg.Text = "Appointment time has ben taken,Select New Time For Appointment";
}
else
{
cn.Close();
cmd = new SqlCommand("insert into CC_Appointment_Detail(Appointment_ID,Appointment_Date,Appointment_Desc,Appointment_Status_Id,SF_ID,User_ID,Start_Time,End_Time,Consumer_ID,Created_By,Created_Date,Updated_By,Last_Updated_Date,Valid) values (" + Txtappid.Text + ",'" + Txtappdate.Text + "','" + Txtdesc.Text + "'," + statusid + "," + sfid + "," + uid + ",'" + ddlstartdate.SelectedValue.ToString() + "','" + Ddlenddate.SelectedValue.ToString() + "'," + consumerid + ",'" + uname + "',getdate(),'" + uname + "',getdate(),'true')", cn);
cmd.CommandType = CommandType.Text;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
lblmessg.Text = "Appointment Has been Set";
Response.Redirect("callScreen.aspx");
}
public void appointmentgrid()
{
cn.Close();
da = new SqlDataAdapter("select A.Appointment_ID,A.Appointment_Date,A.Start_Time,A.End_Time,C.First_Name from CC_Appointment_Detail a,CC_Consumer_Detail C where a.Consumer_ID=c.Consumer_Id and a.SF_ID=" + Ddlsfo.SelectedValue.ToString() + " and a.Appointment_Date='" + Txtappdate.Text + "'", cn);
da.Fill(ds,"t");
GridView1.DataSource = ds.Tables["t"];
GridView1.DataBind();
}
This code not showing any error but it is inserting the appointment everytime.(only else part is getting executed).
please help.