Exemplo n.º 1
0
        private void Button_Click_Filter(object sender, RoutedEventArgs e)
        {
            if (cbCatagory.SelectedItem != null)
            {
                CATEGORY filterCate = (CATEGORY)cbCatagory.SelectedItem;

                var filteredProduct = db.PRODUCTs.Local
                                      .Where(x => x.PSTATUS == 1 && x.CATE == filterCate.CNAME); // pstatus = 1

                lvProduct.ItemsSource = filteredProduct.ToList();
            }
        }
Exemplo n.º 2
0
        private void Button_Click_Delete(object sender, RoutedEventArgs e)
        {
            db = new managementdbEntities();
            if (selectedCate == null)
            {
                return;
            }

            if (selectedCate.CNAME == null)
            {
                return;
            }

            CATEGORY delEntry = db.CATEGORies.Where(x => x.CNAME == selectedCate.CNAME).Select(x => x).FirstOrDefault();

            bool productOfCate = db.PRODUCTs.Where(x => x.CATE == selectedCate.CNAME).Any();

            if (productOfCate)
            {
                string message = selectedCate.CNAME + " has already contained product(s). Do you still want to delete this category? ";
                string caption = "Delete Category";
                var    result  = MessageBox.Show(message, caption, MessageBoxButton.YesNo);

                if (result == MessageBoxResult.Yes)
                {
                    delEntry.CSTATUS = 0;
                    db.SaveChanges();
                    MessageBox.Show("Deleted product");
                    this.Page_Loaded(sender, e);
                }
                else
                {
                }
            }
            else
            {
                delEntry.CSTATUS = 0;
                db.SaveChanges();
                MessageBox.Show("Deleted product");
                this.Page_Loaded(sender, e);
            }

            selectedCate = null;
        }
Exemplo n.º 3
0
        public void BtnNewPro_Click(object sender, RoutedEventArgs e)
        {
            if (!(txtBarcode.Text != "" && txtPName.Text != "" && txtPrice.Text != "" && txtQty.Text != ""))
            {
                lblNewProError.Content = "Please fill in all the required fields.";
            }

            else
            {
                bool existedBarcode = db.PRODUCTs.Where(x => x.BARCODE == txtBarcode.Text && x.PSTATUS == 1).Any();
                if (existedBarcode == true)
                {
                    lblNewProError.Content = "Barcode of this product existed!";
                }
                else if (this.DatabaseChanged != null)
                {
                    lblNewProError.Content = "";
                    CATEGORY cate = (CATEGORY)cbCatagory.SelectedItem;
                    this.DatabaseChanged(txtBarcode.Text + "," + txtPName.Text + "," + txtPrice.Text + "," + txtQty.Text + "," + cate.CNAME);
                    this.Close();
                }
            }
        }
Exemplo n.º 4
0
 // Select category
 private void getSelectedItem(object sender, MouseButtonEventArgs e)
 {
     selectedCate = (CATEGORY)lvCategory.SelectedItems[0];
 }