コード例 #1
0
ファイル: MainForm.cs プロジェクト: fabianfroding/.net-forms
 //=============== Private Methods ===============//
 // Fyller listview för produkter med produkter. Funktionen tar emot en lista eftersom
 // listview kan filtreras med sök-funktionen, eller enkelt bara ta alla produkter från lagret.
 private void ListProducts(List <Product> products)
 {
     ListViewProducts.Items.Clear();
     ListViewProducts.BeginUpdate();
     foreach (Product product in products)
     {
         string[] productValues = new string[5];
         productValues[0] = product.name;
         productValues[1] = product.id.ToString();
         productValues[2] = product.price.ToString();
         productValues[3] = product.stock.ToString();
         productValues[4] = product.productType.ToString();
         ListViewProducts.Items.Add(new ListViewItem(productValues));
     }
     ListViewProducts.EndUpdate();
     ListViewProducts.Sort();
 }
コード例 #2
0
ファイル: SanPham.aspx.cs プロジェクト: thht95/thangweb2019
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["type"] != null)
            {
                string type = Request.QueryString["type"];
                if (type == "1")
                {
                    titleproducts.Text = "SÁCH KHOA HỌC";
                }
                else if (type == "2")
                {
                    titleproducts.Text = "SÁCH KINH TẾ";
                }
                else if (type == "3")
                {
                    titleproducts.Text = "SÁCH THIẾU NHI";
                }
                else if (type == "4")
                {
                    titleproducts.Text = "SÁCH GIÁO KHOA - GIÁO TRÌNH";
                }
                else if (type == "5")
                {
                    titleproducts.Text = "TẠP CHÍ - VĂN PHÒNG PHẨM";
                }
                else
                {
                    titleproducts.Text = "SÁCH VĂN HỌC";
                }

                List <DsSanPham> arr     = (List <DsSanPham>)Application["sanpham"];
                List <DsSanPham> arrtype = new List <DsSanPham>();
                foreach (DsSanPham sp in arr)
                {
                    if (sp.maChuDe.ToString() == type)
                    {
                        arrtype.Add(sp);
                    }
                }
                ListViewProducts.DataSource = arrtype;
                ListViewProducts.DataBind();
            }
            else
            {
                if (Request.QueryString["search"] == null)
                {
                    titleproducts.Text = "Danh sách tất cả sách";
                    List <DsSanPham> arr = (List <DsSanPham>)Application["sanpham"];
                    ListViewProducts.DataSource = arr;
                    ListViewProducts.DataBind();
                }
                else
                {
                    string search     = Request.QueryString["search"];
                    string typesearch = " ";
                    if (search == "Khoa Học")
                    {
                        typesearch = "1";
                    }
                    else if (search == "Kinh Tế")
                    {
                        typesearch = "2";
                    }
                    else if (search == "Thiếu Nhi")
                    {
                        typesearch = "3";
                    }
                    else if (search == "Giáo Khoa" || search == "Giáo Trình")
                    {
                        typesearch = "4";
                    }
                    else if (search == "Tạp Chí")
                    {
                        typesearch = "5";
                    }
                    else if (search == "Văn Học")
                    {
                        typesearch = "6";
                    }
                    else
                    {
                        titleproducts.Text = "Kết quả tìm kiếm";
                        List <DsSanPham> arr  = (List <DsSanPham>)Application["sanpham"];
                        List <DsSanPham> arr1 = new List <DsSanPham>();
                        foreach (DsSanPham sp in arr)
                        {
                            string s = sp.tensach.IndexOf(search).ToString();
                            if (s != "-1")
                            {
                                arr1.Add(sp);
                            }
                        }
                        ListViewProducts.DataSource = arr1;
                        ListViewProducts.DataBind();
                        return;
                    }
                    titleproducts.Text = "Kết quả tìm kiếm";
                    List <DsSanPham> arr2 = (List <DsSanPham>)Application["sanpham"];
                    List <DsSanPham> arr3 = new List <DsSanPham>();
                    foreach (DsSanPham sp in arr2)
                    {
                        if (sp.maChuDe.ToString() == typesearch)
                        {
                            arr3.Add(sp);
                        }
                    }
                    ListViewProducts.DataSource = arr3;
                    ListViewProducts.DataBind();
                    return;
                }
            }
        }