private void populateItem() { try { conn = new SqlConnection(connectionString); conn.Open(); DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(String.Format("SELECT * FROM AGRICULTURAL WHERE shop_ID ='{0}'", this.shop_ID), conn); adapter.Fill(ds); int count = ds.Tables[0].Rows.Count; AgrItem[] agrList = new AgrItem[count]; for (int i = 0; i < count; i++) { agrList[i] = new AgrItem(); agrList[i].Title = ds.Tables[0].Rows[i]["AGR_Name"].ToString().Trim(); agrList[i].Message = ds.Tables[0].Rows[i]["DESCRIP"].ToString().Trim(); agrList[i].AgrID = ds.Tables[0].Rows[i]["AGR_ID"].ToString().Trim(); agrList[i].Amount = ds.Tables[0].Rows[i]["amount"].ToString().Trim(); agrList[i].Price = ds.Tables[0].Rows[i]["price"].ToString().Trim(); agrList[i].Unit = ds.Tables[0].Rows[i]["unit"].ToString().Trim(); agrList[i].Instance = this.MdiParent; agrList[i].FarmerID = this.owner_ID; Byte[] data = new Byte[0]; data = (byte[])ds.Tables[0].Rows[i]["IMG"]; MemoryStream ms = new MemoryStream(data); agrList[i].Icon = Image.FromStream(ms); if (flowLayoutPanel1.Controls.Count < 0) { flowLayoutPanel1.Controls.Clear(); } else { flowLayoutPanel1.Controls.Add(agrList[i]); } } }catch (Exception e) { MessageBox.Show(e.Message); } }
private int populateItem(String name, String type, String location, String shopName) { int count = 0; try { conn = new SqlConnection(connectionString); conn.Open(); DataSet ds = new DataSet(); String sql = ""; if (name.Equals("") && type.Equals("") && location.Equals("") && shopName.Equals("")) { sql = "SELECT * FROM AGRICULTURAL ag left join AGR_RATING ar on ag.AGR_ID = ar.AGR_ID ORDER BY ar.RatePoint DESC"; } else { sql = String.Format("select * from AGRICULTURAL ag join SHOP sh on ag.Shop_ID = sh.Shop_ID where ag.AGR_Name like '{0}%' " + "and ag.AGR_Type like '{1}%' and ag.LOC_ID like '{2}%' and sh.shop_Name like '{3}%'", name, type, location, shopName); } SqlDataAdapter adapter = new SqlDataAdapter(sql, conn); adapter.Fill(ds); count = ds.Tables[0].Rows.Count; if (count == 0) { lbResultMessage.Text = String.Format("Không Tìm Thấy nông sản nào với tên: {0} loại: {1} xuất xứ: {2} tên shop: {3} !", name, type, location, shopName); return(count); } lbResultMessage.Text = String.Format("Tìm Thấy {0} nông sản với tên: {1} loại: {2} xuất xứ: {3} tên shop: {4}", count.ToString(), name, type, location, shopName); AgrItem[] agrList = new AgrItem[count]; for (int i = 0; i < count; i++) { agrList[i] = new AgrItem(); agrList[i].Title = ds.Tables[0].Rows[i]["AGR_Name"].ToString().Trim(); agrList[i].Message = ds.Tables[0].Rows[i]["DESCRIP"].ToString().Trim(); agrList[i].AgrID = ds.Tables[0].Rows[i]["AGR_ID"].ToString().Trim(); agrList[i].Amount = ds.Tables[0].Rows[i]["amount"].ToString().Trim(); agrList[i].Price = ds.Tables[0].Rows[i]["price"].ToString().Trim(); agrList[i].Unit = ds.Tables[0].Rows[i]["unit"].ToString().Trim(); agrList[i].Instance = this.MdiParent; agrList[i].FarmerID = getFarmerIDbyShopID(ds.Tables[0].Rows[i]["Shop_ID"].ToString().Trim()); agrList[i].isTraderView = true; Byte[] data = new Byte[0]; data = (byte[])ds.Tables[0].Rows[i]["IMG"]; MemoryStream ms = new MemoryStream(data); agrList[i].Icon = Image.FromStream(ms); if (flowPNMain.Controls.Count < 0) { flowPNMain.Controls.Clear(); } else { flowPNMain.Controls.Add(agrList[i]); } } } catch (Exception e) { MessageBox.Show(e.Message); } finally { conn.Close(); } return(count); }