Hi lingers,
Refer below modified code.
protected void Page_Load(object sender, EventArgs e)
{
Panel1.Visible = true;
Panel3.Visible = false;
Panel4.Visible = false;
Panel5.Visible = false;
}
[WebMethod]
public static List<string> GetAutoCompleteData(string pid)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NER\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=kaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,pid from job where pid LIKE '%'+@SearchText+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", pid);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["pid"], dr["id"]));
}
return result;
}
}
}
[WebMethod]
public static List<string> GetAutoCompleteData1(string dieno)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=NER\\SQLEXPRESS01;Integrated Security=true;Initial Catalog=kaging;"))
{
using (SqlCommand cmd = new SqlCommand("select id,dieno from job_die where dieno LIKE '%'+@SearchText1+'%'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText1", dieno);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(string.Format("{0}/{1}", dr["dieno"], dr["id"]));
}
return result;
}
}
}
protected void TextBox9_TextChanged(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedValue == "1")
{
Panel1.Visible = true;
Panel3.Visible = false;
Panel4.Visible = false;
Panel5.Visible = false;
}
else if (DropDownList1.SelectedValue == "3")
{
Panel1.Visible = false;
Panel3.Visible = true;
Panel4.Visible = false;
Panel5.Visible = false;
}
else if (DropDownList1.SelectedValue == "4")
{
Panel1.Visible = false;
Panel3.Visible = false;
Panel4.Visible = true;
Panel5.Visible = false;
}
else if (DropDownList1.SelectedValue == "5")
{
Panel1.Visible = false;
Panel3.Visible = false;
Panel4.Visible = false;
Panel5.Visible = true;
}
}
protected void Button2_Click(object sender, EventArgs e)
{
SetSession("Select FinYear,Year,Vat FROM Settings where id= '1'", txtSearch.Text);
string insertSQL;
insertSQL = "INSERT INTO Orders (";
insertSQL += "financialyear,calendaryear,vat,month,productcode,productcodeM,purchaseorderno,supplier,dateordered,dateexpected,producttypeM,producttype,requisitioncode,posino,quantity,requirement)";
insertSQL += "VALUES('";
insertSQL += Session["1"] + "','";
insertSQL += Session["2"] + "','";
insertSQL += Session["3"] + "','";
insertSQL += "March" + "','";
insertSQL += Session["4"] + "','";
insertSQL += txtSearch.Text + "','";
insertSQL += TextBox4.Text + "','";
insertSQL += TextBox5.Text + "','";
insertSQL += TextBox6.Text + "','";
insertSQL += TextBox7.Text + "','";
insertSQL += DropDownList1.SelectedItem.ToString() + "','";
insertSQL += DropDownList1.SelectedValue.ToString() + "','";
insertSQL += TextBox9.Text + "','";
insertSQL += txtSearch1.Text + "','";
insertSQL += TextBox2.Text + "','";
insertSQL += TextBox3.Text + "')";
Insert(insertSQL);
}
protected void Button3_Click(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SetSession("Select FinYear,Year,Vat FROM Settings where id= '1'", txtSearch.Text);
if (!string.IsNullOrEmpty(TextBox24.Text))
{
string query;
query = "INSERT INTO Orders (";
query += "financialyear,calendaryear,vat,month,productcode,productcodeM,purchaseorderno,supplier,dateordered,dateexpected,producttypeM,producttype,requisitioncode,posino,quantity,requirement)";
query += "VALUES('";
query += Session["1"] + "','";
query += Session["2"] + "','";
query += Session["3"] + "','";
query += "March" + "','";
query += Session["4"] + "','";
query += txtSearch.Text + "','";
query += TextBox4.Text + "','";
query += TextBox5.Text + "','";
query += TextBox6.Text + "','";
query += TextBox7.Text + "','";
query += DropDownList1.SelectedItem.ToString() + "','";
query += DropDownList1.SelectedValue.ToString() + "','";
query += TextBox9.Text + "','";
query += TextBox24.Text + "','";
query += TextBox25.Text + "','";
query += TextBox26.Text + "')";
Insert(query);
}
if (!string.IsNullOrEmpty(TextBox27.Text))
{
string query;
query = "INSERT INTO Orders (";
query += "financialyear,calendaryear,vat,month,productcode,productcodeM,purchaseorderno,supplier,dateordered,dateexpected,producttypeM,producttype,requisitioncode,posino,quantity,requirement)";
query += "VALUES('";
query += Session["1"] + "','";
query += Session["2"] + "','";
query += Session["3"] + "','";
query += "March" + "','";
query += Session["4"] + "','";
query += txtSearch.Text + "','";
query += TextBox4.Text + "','";
query += TextBox5.Text + "','";
query += TextBox6.Text + "','";
query += TextBox7.Text + "','";
query += DropDownList1.SelectedItem.ToString() + "','";
query += DropDownList1.SelectedValue.ToString() + "','";
query += TextBox9.Text + "','";
query += TextBox27.Text + "','";
query += TextBox28.Text + "','";
query += TextBox29.Text + "')";
Insert(query);
}
if (string.IsNullOrEmpty(TextBox46.Text))
{
Response.Redirect("3.aspx");
}
else
{
string query;
query = "INSERT INTO Orders (";
query += "financialyear,calendaryear,vat,month,productcode,productcodeM,purchaseorderno,supplier,dateordered,dateexpected,producttypeM,producttype,requisitioncode,posino,quantity,requirement)";
query += "VALUES('";
query += Session["1"] + "','";
query += Session["2"] + "','";
query += Session["3"] + "','";
query += "March" + "','";
query += Session["4"] + "','";
query += txtSearch.Text + "','";
query += TextBox4.Text + "','";
query += TextBox5.Text + "','";
query += TextBox6.Text + "','";
query += TextBox7.Text + "','";
query += DropDownList1.SelectedItem.ToString() + "','";
query += DropDownList1.SelectedValue.ToString() + "','";
query += TextBox9.Text + "','";
query += TextBox46.Text + "','";
query += TextBox47.Text + "','";
query += TextBox48.Text + "')";
if (Insert(query) > 0)
{
Response.Redirect("3.aspx");
}
}
}
protected void Button4_Click(object sender, EventArgs e)
{
}
protected void Button5_Click(object sender, EventArgs e)
{
}
private int Insert(string query)
{
string connectionString = "Data Source=NER\\SQLEXPRESS01; Initial Catalog= kaging;Integrated Security=True";
SqlConnection con = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(query, con);
int added = 0;
try
{
con.Open();
added = cmd.ExecuteNonQuery();
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con.Close();
}
return added;
}
// Set Session1, Session2 and Session3.
private void SetSession(string query, string searchtext)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=NER\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
try
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Session["1"] = dr[0].ToString();
Session["2"] = dr[1].ToString();
Session["3"] = dr[2].ToString();
SetSession4(searchtext);
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con.Close();
}
}
// Set Session4.
private void SetSession4(string pId)
{
string query = "SELECT id FROM job where pid = @PId";
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=NER\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = query;
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@PId", pId.Trim());
try
{
con.Open();
object id = cmd.ExecuteScalar();
if (id != null)
{
Session["4"] = id.ToString();
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
con.Close();
}
}