private void ShowDataList() { string name = Request.QueryString["name"]; string category = Request.QueryString["category"]; string fromPrice = Request.QueryString["fromPrice"]; string toPrice = Request.QueryString["toPrice"]; decimal priceTo = -1; try { priceTo = decimal.Parse(toPrice); } catch (Exception) { } decimal priceFrom = -1; try { priceFrom = decimal.Parse(fromPrice); } catch (Exception) { } SqlConnection conn = new SqlConnection(@"Data Source=THE-HIEN;Initial Catalog=CSharpAssignment;Integrated Security=SSPI"); string sql = "SELECT [ID] ,[Quantity] ,[Price] ,[Usage] ,[Name] ,[StatusID] ,[CateID] ,[ImageLink] FROM [Product] Where StatusID = 1 "; if (name != null && name.Length > 0) { sql += "and Name like @name "; } if (priceTo > 0 && priceTo >= priceFrom) { sql += "and Price >= @lowerPrice and Price <= @upperPrice "; } if (category != null && category.Length > 0) { sql += "and (Select Name FROM Category WHERE ID = CateID) = @cateName "; } SqlDataAdapter da = new SqlDataAdapter(sql, conn); if (name != null && name.Length > 0) { da.SelectCommand.Parameters.Add("@name", SqlDbType.NVarChar).Value = "%" + name + "%"; } if (priceFrom > 0 && priceTo >= priceFrom) { da.SelectCommand.Parameters.Add("@upperPrice", SqlDbType.Decimal).Value = priceTo; da.SelectCommand.Parameters.Add("@lowerPrice", SqlDbType.Decimal).Value = priceFrom; } if (category != null && category.Length > 0) { da.SelectCommand.Parameters.Add("@cateName", SqlDbType.NVarChar).Value = category; } DataSet ds = new DataSet(); da.Fill(ds, "tblProduct"); DLProduct.DataSourceID = null; DLProduct.DataSource = ds; DLProduct.DataMember = "tblProduct"; DLProduct.DataBind(); }
private void ShowDataList() { string name = Request.QueryString["name"]; string category = Request.QueryString["category"]; string fromPrice = Request.QueryString["fromPrice"]; string toPrice = Request.QueryString["toPrice"]; PanelSearch.Visible = true; if (category != null && name == null && fromPrice == null && toPrice == null) { PanelInfo.Visible = true; PanelSearch.Visible = false; CategoryName.Text = category; CategoryDetail.Text = GetCategoryDisription(category); } decimal priceTo = -1; try { priceTo = decimal.Parse(toPrice); } catch (Exception) { } decimal priceFrom = -1; try { priceFrom = decimal.Parse(fromPrice); } catch (Exception) { } SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["CSharpAssignmentConnectionString"].ConnectionString); string sql = "SELECT [ID] ,[Quantity] ,[Price] ,[Usage] ,[Name] ,[StatusID] ,[CateID] ,[ImageLink] FROM [Product] Where StatusID = 1 "; if (name != null && name.Length > 0) { sql += "and Name like @name "; } if (priceTo > 0 && priceTo >= priceFrom) { sql += "and Price >= @lowerPrice and Price <= @upperPrice "; } if (category != null && category.Length > 0) { sql += "and (Select Name FROM Category WHERE ID = CateID) = @cateName "; } SqlDataAdapter da = new SqlDataAdapter(sql, conn); if (name != null && name.Length > 0) { da.SelectCommand.Parameters.Add("@name", SqlDbType.NVarChar).Value = "%" + name + "%"; } if (priceFrom > 0 && priceTo >= priceFrom) { da.SelectCommand.Parameters.Add("@upperPrice", SqlDbType.Decimal).Value = priceTo; da.SelectCommand.Parameters.Add("@lowerPrice", SqlDbType.Decimal).Value = priceFrom; } if (category != null && category.Length > 0) { da.SelectCommand.Parameters.Add("@cateName", SqlDbType.NVarChar).Value = category; } DataSet ds = new DataSet(); da.Fill(ds, "tblProduct"); DLProduct.DataSourceID = null; DLProduct.DataSource = ds; DLProduct.DataMember = "tblProduct"; DLProduct.DataBind(); }
public BLProduct() { dl = new DLProduct(); }