001.
using
System;
002.
using
System.Collections;
003.
using
System.Configuration;
004.
using
System.Data;
005.
using
System.Data.SqlClient;
006.
using
System.Linq;
007.
using
System.Text;
008.
using
System.Web;
009.
using
System.Web.Security;
010.
using
System.Web.UI;
011.
using
System.Web.UI.HtmlControls;
012.
using
System.Web.UI.WebControls;
013.
using
System.Web.UI.WebControls.WebParts;
014.
using
System.Xml.Linq;
015.
016.
public
partial
class
AdminCustSearch : System.Web.UI.Page
017.
{
018.
DataSet ds =
new
DataSet();
019.
020.
protected
void
Page_Load(
object
sender, EventArgs e)
021.
{
022.
if
(!IsPostBack)
023.
{
024.
string
strConn1 =
"Data Source=MIXAR-PC;Initial Catalog=StockProductInfo;Integrated Security=True"
;
025.
026.
SqlConnection Conn1 =
new
SqlConnection(strConn1);
027.
if
(Conn1.State == ConnectionState.Open)
028.
{
029.
Conn1.Close();
030.
}
031.
Conn1.ConnectionString = strConn1;
032.
Conn1.Open();
033.
034.
string
sqlCustType;
035.
sqlCustType =
"SELECT DISTINCT CustType_ID, CustType_Name "
;
036.
sqlCustType +=
"FROM tabCustomerType "
;
037.
sqlCustType +=
"WHERE (CustType_Status LIKE 'yes')"
;
038.
sqlCustType +=
"ORDER BY CustType_Name"
;
039.
040.
SqlDataAdapter da1 =
new
SqlDataAdapter(sqlCustType, Conn1);
041.
DataSet ds1 =
new
DataSet();
042.
da1.Fill(ds1,
"CustType"
);
043.
ddlCustomerType.DataSource = ds1.Tables[
"CustType"
];
044.
ddlCustomerType.DataValueField =
"CustType_Name"
;
045.
ddlCustomerType.DataTextField =
"CustType_Name"
;
046.
ddlCustomerType.DataBind();
047.
ListItem firstItem =
new
ListItem(
"Select..."
,
"Select..."
);
048.
ddlCustomerType.Items.Insert(0, firstItem);
049.
050.
Conn1.Close();
051.
}
052.
}
053.
054.
protected
void
btnSearch_Click(
object
sender, EventArgs e)
055.
{
056.
string
strConn2 =
"Data Source=MIXAR-PC;Initial Catalog=StockProductInfo;Integrated Security=True"
;
057.
058.
SqlConnection Conn2 =
new
SqlConnection(strConn2);
059.
if
(Conn2.State == ConnectionState.Open)
060.
{
061.
Conn2.Close();
062.
}
063.
Conn2.ConnectionString = strConn2;
064.
Conn2.Open();
065.
066.
string
sqlCustSearch;
067.
sqlCustSearch =
"SELECT DISTINCT masCustomer.Cust_ID AS CustID, "
;
068.
sqlCustSearch +=
"masCustomer.Cust_FName AS Firstname, "
;
069.
sqlCustSearch +=
"masCustomer.Cust_LName AS Lastname, "
;
070.
sqlCustSearch +=
"masCustomer.Cust_Tel AS Telephone, "
;
071.
sqlCustSearch +=
"tabCustomerType.CustType_Name AS Type "
;
072.
sqlCustSearch +=
"FROM masCustomer, tabCustomerType "
;
073.
sqlCustSearch +=
"WHERE (masCustomer.CustType_ID = tabCustomerType.CustType_ID)"
;
074.
075.
if
(ddlCustomerType.SelectedItem.Value !=
"Select..."
)
076.
{
077.
sqlCustSearch +=
"AND (tabCustomerType.CustType_Name = '"
+ ddlCustomerType.SelectedItem.Text +
"')"
;
078.
}
079.
if
(txtCustID.Text !=
""
)
080.
{
081.
sqlCustSearch +=
"AND (masCustomer.Cust_ID LIKE '"
+ txtCustID.Text +
"%')"
;
082.
}
083.
if
(txtFirstname.Text !=
""
)
084.
{
085.
sqlCustSearch +=
"AND (masCustomer.Cust_FName LIKE '"
+ txtFirstname.Text +
"%')"
;
086.
}
087.
if
(txtLastname.Text !=
""
)
088.
{
089.
sqlCustSearch +=
"AND (masCustomer.Cust_LName LIKE '"
+ txtLastname.Text +
"%')"
;
090.
}
091.
if
(txtTelephone.Text !=
""
)
092.
{
093.
sqlCustSearch +=
"AND (masCustomer.Cust_Tel LIKE '"
+ txtTelephone.Text +
"%')"
;
094.
}
095.
096.
SqlDataAdapter da3 =
new
SqlDataAdapter(sqlCustSearch, Conn2);
097.
da3.Fill(ds,
"Customers"
);
098.
099.
dgvCustResult.DataSource = ds.Tables[
"Customers"
];
100.
dgvCustResult.DataBind();
101.
102.
if
(dgvCustResult.Rows.Count <= 0)
103.
{
104.
Response.Write(
"<script type='text/javascript'>alert('Search not found!!');</script>"
);
105.
ddlCustomerType.SelectedValue =
"Select..."
;
106.
txtCustID.Text =
""
;
107.
txtFirstname.Text =
""
;
108.
txtLastname.Text =
""
;
109.
txtTelephone.Text =
""
;
110.
}
111.
else
112.
{
113.
dgvCustResult.Visible =
true
;
114.
}
115.
116.
Conn2.Close();
117.
}
118.
119.
120.
protected
void
dgvCustResult_SelectedIndexChanged(
object
sender, EventArgs e)
121.
{
122.
string
custID, custFName, custLName, custName;
123.
custID = dgvCustResult.SelectedRow.Cells[0].Text;
124.
custFName = dgvCustResult.SelectedRow.Cells[1].Text;
125.
custLName = dgvCustResult.SelectedRow.Cells[2].Text;
126.
custName = custFName +
" "
+ custLName;
127.
128.
Session[
"custFullName"
] = custName;
129.
Session[
"custID"
] = custID;
130.
131.
Response.Redirect(
"AdminNewOrder.aspx"
);
132.
}
133.
}