Example #1
0
 public MainUIWindow(string role, int cusID)
 {
     InitializeComponent();
     bll = new MainUIBLL();
     this.role = role;
     this.cusID = cusID;
     DetailBLL bllDetail = new DetailBLL();
     textBlockTotalQuantity.Text = bllDetail.ShowTotalProCate(this.cusID).ToString();
     List<Book> bookList = new List<Book>();
     List<Magazine> magaList = new List<Magazine>();
     bookList = bll.getallBookUI();
     magaList = bll.getallMagaUI();
     Separator separator = new Separator();
     separator.Width = 795;
     DisplayBookUI.Children.Add(separator);
     List<ProductDisplay> proList = new List<ProductDisplay>();
     proList = getAllProduct(bookList, magaList);
     proList.Sort(
         delegate (ProductDisplay p1, ProductDisplay p2)
         {
             return p2.Date.CompareTo(p1.Date);
         }
     );
     if (this.role == "Manager")
     {
         manage.Visibility = Visibility.Visible;
         manage.IsEnabled = true;
     }
     getallProUI(proList, "All");
     ProType.SelectionChanged += ProType_SelectionChanged;
     Instock.SelectionChanged += Instock_SelectionChanged;
     Search.Click += Search_click;
     ProSort.SelectionChanged += ProSort_SelectionChanged;
     SearchTaskBar.KeyDown += Search_KeyDown;
 }
Example #2
0
        private void ProSort_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            bll = new MainUIBLL();
            search_string = SearchTaskBar.Text;
            List<Magazine> magaList = new List<Magazine>();
            List<Book> bookList = new List<Book>();
            magaList = bll.getallMagaUI();
            bookList = bll.getallBookUI();
            List<Magazine> magaToDisplay = new List<Magazine>();
            List<Book> bookToDisplay = new List<Book>();

            if (Instock.SelectedIndex == 0)
            {
                foreach (var i in magaList)
                {
                    if (i.Quantiy > 0)
                    {
                        magaToDisplay.Add(i);
                    }
                }
                foreach (var i in bookList)
                {
                    if (i.Quantiy > 0)
                    {
                        bookToDisplay.Add(i);
                    }
                }
            }
            else
            {
                foreach (var i in magaList)
                {
                    magaToDisplay.Add(i);
                }
                foreach (var i in bookList)
                {
                    bookToDisplay.Add(i);
                }
            }
            List<Magazine> magaToSearch = new List<Magazine>();
            List<Book> bookToSearch = new List<Book>();
            foreach (var i in magaToDisplay)
            {
                if ((i.SeriName.Name + " No." + i.No).Contains(search_string, StringComparison.OrdinalIgnoreCase))
                {
                    magaToSearch.Add(i);
                }
            }
            foreach (var i in bookToDisplay)
            {
                if (i.Name.Contains(search_string, StringComparison.OrdinalIgnoreCase))
                {
                    bookToSearch.Add(i);
                }
            }
            string proType;
            if (ProType.SelectedIndex == 0)
            {
                proType = "Book";
            }
            else if (ProType.SelectedIndex == 1)
            {
                proType = "Magazine";
            }
            else
            {
                proType = "All";
            }

            DisplayBookUI.Children.Clear();
            Separator separator = new Separator();
            separator.Width = 795;
            DisplayBookUI.Children.Add(separator);
            List<ProductDisplay> proList = new List<ProductDisplay>();

            proList = getAllProduct(bookToSearch, magaToSearch);
            switch (ProSort.SelectedIndex)
            {
                case 0:
                    proList.Sort(
                        delegate (ProductDisplay p1, ProductDisplay p2)
                        {
                            return p2.Date.CompareTo(p1.Date);
                        }
                    );
                    break;
                case 1:
                    proList.Sort(
                        delegate (ProductDisplay p1, ProductDisplay p2)
                        {
                            return p1.Date.CompareTo(p2.Date);
                        }
                    );
                    break;
                case 2:
                    proList.Sort(
                        delegate (ProductDisplay p1, ProductDisplay p2)
                        {
                            return p2.Price.CompareTo(p1.Price);
                        }
                    );
                    break;
                case 3:
                    proList.Sort(
                        delegate (ProductDisplay p1, ProductDisplay p2)
                        {
                            return p1.Price.CompareTo(p2.Price);
                        }
                    );
                    break;
            }
            getallProUI(proList, proType);
        }