Esempio n. 1
0
        private void Button_Click_DelPro(object sender, RoutedEventArgs e)
        {
            db = new managementdbEntities();
            if (selectedPro == null)
            {
                return;
            }

            if (selectedPro.BARCODE == null)
            {
                return;
            }

            PRODUCT delPro = db.PRODUCTs.Where(x => x.BARCODE == selectedPro.BARCODE).Select(x => x).SingleOrDefault();

            string message = "Do you surely want to delete this product? ";
            string caption = "Delete Product";
            var    result  = MessageBox.Show(message, caption, MessageBoxButton.YesNo);

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

            db.SaveChanges();
            this.Page_Loaded(sender, e);
            selectedPro = null;
        }
Esempio n. 2
0
        private void Button_Click_UpdPro(object sender, RoutedEventArgs e)
        {
            if (selectedPro == null)
            {
                return;
            }

            if (selectedPro.BARCODE == null)
            {
                return;
            }

            pupdform = new PUpdate(selectedPro);
            pupdform.DatabaseChanged += pupdform_DatabaseChanged;
            pupdform.ShowDialog();

            if (updPro == "" || updPro == null)
            {
                return;
            }

            var result = updPro.ToString();
            //MessageBox.Show(result);
            var tokens = updPro.Split(new string[] { "," },
                                      StringSplitOptions.RemoveEmptyEntries)
                         .Select(token => token.Trim())
                         .ToArray();

            PRODUCT updProduct = db.PRODUCTs.Where(x => x.BARCODE == selectedPro.BARCODE).Select(x => x).FirstOrDefault();

            // update = add + delete
            if (updProduct != null)
            {
                // Not edit Barcode
                if (updProduct.BARCODE != tokens[0])
                {
                    PRODUCT newProduct = new PRODUCT();
                    newProduct.BARCODE = tokens[0];
                    newProduct.PNAME   = tokens[1];
                    newProduct.PRICE   = int.Parse(tokens[2]);
                    newProduct.QTY     = int.Parse(tokens[3]);
                    newProduct.CATE    = tokens[4];
                    newProduct.PSTATUS = 1;
                    updProduct.PSTATUS = 0;
                    db.PRODUCTs.Add(newProduct);
                }
                else
                {
                    updProduct.PNAME   = tokens[1];
                    updProduct.PRICE   = int.Parse(tokens[2]);
                    updProduct.QTY     = int.Parse(tokens[3]);
                    updProduct.CATE    = tokens[4];
                    updProduct.PSTATUS = 1;
                }
            }
            db.SaveChanges();
            this.Page_Loaded(sender, e);
            selectedPro = null;
        }
Esempio n. 3
0
 private void CbProduct_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     pro = (PRODUCT)cbProduct.SelectedItem;
     if (quatity != 0)
     {
         total = (int)pro.PRICE * quatity;
     }
     lblTotal.Content = total.ToString();
 }
Esempio n. 4
0
 public PUpdate(PRODUCT selProduct)
 {
     InitializeComponent();
     db = new managementdbEntities();
     cbCatagory.ItemsSource  = db.CATEGORies.ToList();
     txtBarcode.Text         = selProduct.BARCODE;
     txtPName.Text           = selProduct.PNAME;
     txtPrice.Text           = selProduct.PRICE.ToString();
     txtQty.Text             = selProduct.QTY.ToString();
     cbCatagory.SelectedItem = db.CATEGORies.Where(x => x.CNAME == selProduct.CATE).Select(x => x).SingleOrDefault();
     selectProduct           = selProduct;
 }
Esempio n. 5
0
        private void Button_Click_AddOrder(object sender, RoutedEventArgs e)
        {
            oaddform = new OAdd();
            oaddform.DatabaseChanged += oadddform_DatabaseChanged;
            oaddform.ShowDialog();

            if (newOrd == null)
            {
                return;
            }

            var result = newOrd.ToString();
            var tokens = newOrd.Split(new string[] { "," },
                                      StringSplitOptions.RemoveEmptyEntries)
                         .Select(token => token.Trim())
                         .ToArray();

            // BARCODE, QUANTITY, DATE, TOTAL, COUPON
            db = new managementdbEntities();

            // add to transaction data
            ORDER newOrder = new ORDER();

            newOrder.BARCODE = tokens[0];
            newOrder.QTY     = int.Parse(tokens[1]);
            newOrder.DATE    = DateTime.Parse(tokens[2]);
            newOrder.TOTAL   = int.Parse(tokens[3]);
            db.ORDERs.Add(newOrder);

            // modify master data
            PRODUCT updProduct = db.PRODUCTs.Where(x => x.BARCODE == newOrder.BARCODE).Select(x => x).SingleOrDefault();

            if (updProduct != null)
            {
                updProduct.QTY = updProduct.QTY - newOrder.QTY;
            }
            //db.SaveChanges();

            // modify coupon date
            string couponCode = tokens[4].ToString();
            COUPON updCoupon  = db.COUPONs.Where(x => x.CODE == couponCode).Select(x => x).SingleOrDefault();

            if (updCoupon != null)
            {
                updCoupon.AVAILABLE = updCoupon.AVAILABLE - 1;
            }
            //db.SaveChanges();

            db.SaveChanges();
            this.Page_Loaded(sender, e);
        }
Esempio n. 6
0
        private void Button_Click_AddPro(object sender, RoutedEventArgs e)
        {
            paddform = new PAdd();
            paddform.DatabaseChanged += paddform_DatabaseChanged;
            paddform.ShowDialog();

            db = new managementdbEntities();

            if (newPro == null)
            {
                return;
            }

            //MessageBox.Show(newPro.ToString());
            var result = newPro.ToString();
            var tokens = newPro.Split(new string[] { "," },
                                      StringSplitOptions.RemoveEmptyEntries)
                         .Select(token => token.Trim())
                         .ToArray();

            string  barcode    = tokens[0].ToString();
            PRODUCT newProduct = db.PRODUCTs.Where(x => x.BARCODE == barcode).Select(x => x).FirstOrDefault();

            if (newProduct == null)
            {
                newProduct         = new PRODUCT();
                newProduct.BARCODE = tokens[0];
                newProduct.PNAME   = tokens[1];
                newProduct.PRICE   = int.Parse(tokens[2]);
                newProduct.QTY     = int.Parse(tokens[3]);
                newProduct.CATE    = tokens[4];
                newProduct.PSTATUS = 1;
                db.PRODUCTs.Add(newProduct);
            }
            else if (newProduct.PSTATUS == 0)
            {
                newProduct.PNAME   = tokens[1];
                newProduct.PRICE   = int.Parse(tokens[2]);
                newProduct.QTY     = int.Parse(tokens[3]);
                newProduct.CATE    = tokens[4];
                newProduct.PSTATUS = 1;
            }
            db.SaveChanges();
            this.Page_Loaded(sender, e);
            newPro = null;
        }
Esempio n. 7
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            pro = (PRODUCT)cbProduct.SelectedItem;

            lblError.Content = "Please fill in all the required fields.";

            // check valid form
            if (txtName.Text != "" && txtAddr.Text != "" && txtPhone.Text != "" && txtQty.Text != "" && pro != null && (rdOption1.IsChecked != false || rdOption2.IsChecked != false))
            {
                lblError.Content = "";

                if (this.DatabaseChanged != null)
                {
                    string coupon_code = (validCoupon == null) ? "#" : validCoupon.CODE.ToString();
                    this.DatabaseChanged(pro.BARCODE + "," + txtQty.Text + "," + datePicker.SelectedDate.ToString() + "," + lblTotal.Content + "," + coupon_code);
                }
                this.Close();
            }
        }
Esempio n. 8
0
        public Stats()
        {
            InitializeComponent();

            db = new managementdbEntities();
            List <PRODUCT> SaleItems = new List <PRODUCT>();
            List <ORDER>   SaleQty   = new List <ORDER>();

            productList = db.PRODUCTs.ToList();
            orderList   = db.ORDERs.ToList();
            PRODUCT Item = new PRODUCT();

            resultQry     = new List <Data>();
            salesInPeriod = new List <Data>();

            var innerJoinQuery =
                from order in orderList
                join prod in productList on order.BARCODE equals prod.BARCODE
                select new { Item = prod.PNAME, SaleQty = order.QTY };

            //this.DataContext = innerJoinQuery;
            //lvSaleProduct.ItemsSource = innerJoinQuery.ToList();


            /////////////////////////////////////////////////////////
            //var groupJoinQuery = from prod in productList
            //                     join order in orderList on prod.BARCODE equals order.BARCODE into prodGroup
            //                     select prodGroup;

            var groupJoinQuery = from order in orderList
                                 join prod in productList on order.BARCODE equals prod.BARCODE
                                 group order by order.BARCODE into g
                                 select new
            {
                Item    = g.First().PRODUCT.PNAME,
                SaleQty = g.Sum(x => x.QTY)
            };

            //////////////////////////////////////////////////////////
            this.DataContext          = groupJoinQuery;
            lvSaleProduct.ItemsSource = groupJoinQuery.ToList();
        }
Esempio n. 9
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // Category List
            db = new managementdbEntities();
            db.Configuration.ProxyCreationEnabled = false;
            db.CATEGORies.ToList();

            var filteredCate = db.CATEGORies.Local
                               .Where(x => x.CSTATUS == 1);
            List <CATEGORY> cATEGORies = filteredCate.ToList();

            lvCategory.ItemsSource = cATEGORies;

            // Product List = status == 1 && cstatus == 1
            db.Configuration.ProxyCreationEnabled = false;
            db.PRODUCTs.ToList();

            var filteredProduct = db.PRODUCTs.Local
                                  .Where(x => x.PSTATUS == 1); // pstatus = 1
            PRODUCT        newProduct = new PRODUCT();
            List <PRODUCT> pRODUCTs   = filteredProduct.ToList();

            filteredProduct = from product in pRODUCTs
                              join category in cATEGORies
                              on product.CATE equals category.CNAME
                              select product;

            lvProduct.ItemsSource = filteredProduct.ToList();

            // Order list
            db.Configuration.ProxyCreationEnabled = false;
            lvOrder.ItemsSource = db.ORDERs.ToList();

            // Category in combobox
            cbCatagory.ItemsSource = db.CATEGORies.Where(x => x.CSTATUS == 1).ToList();
        }
Esempio n. 10
0
        private void BtnReport_Click(object sender, RoutedEventArgs e)
        {
            lblChartError.Visibility = Visibility.Hidden;
            List <PRODUCT> SaleItems = new List <PRODUCT>();
            List <ORDER>   SaleQty   = new List <ORDER>();



            PRODUCT  Item = new PRODUCT();
            DateTime dateTime, begin, end;
            int      year;

            lblChooseTypeErr.Visibility = Visibility.Visible;
            if (cbOption.SelectedItem != null)
            {
                string option = ((ComboBoxItem)cbOption.SelectedItem).Content.ToString();
                lblChooseTypeErr.Visibility = Visibility.Hidden;
                if (dpDate.SelectedDate != null)
                {
                    typetime  = (int)typeOfTime.DAY;
                    dateTime  = (DateTime)dpDate.SelectedDate;
                    orderList = db.ORDERs.Where(x => x.DATE == dateTime).ToList();

                    if (option == "Products")
                    {
                        ProductType_Report(productList, orderList);
                    }
                    else
                    {
                        SaleType_Report(productList, orderList);
                    }
                    selectReport = true;
                }

                if (dpMonthYear.SelectedDate != null)
                {
                    typetime = (int)typeOfTime.MONTH;
                    dateTime = (DateTime)dpMonthYear.SelectedDate;
                    //begin = new DateTime(dateTime.Year, dateTime.Month, 1, 0, 0, 0, 0);
                    //end = new DateTime(dateTime.Year, dateTime.Month + 1, 1, 0, 0, 0, 0);
                    var query = from order in orderList
                                where (int)((DateTime)order.DATE).Month == dateTime.Month
                                select order;
                    //orderList = db.ORDERs.Where(x => x.DATE >= begin && x.DATE < end).ToList();

                    orderList = query.ToList();
                    if (option == "Products")
                    {
                        ProductType_Report(productList, orderList);
                    }
                    else
                    {
                        SaleType_Report(productList, orderList);
                    }
                    selectReport = true;
                }

                if (dpBeginDate.SelectedDate != null && dpEndDate.SelectedDate != null)
                {
                    typetime  = (int)typeOfTime.PERIOD;
                    begin     = (DateTime)dpBeginDate.SelectedDate;
                    end       = (DateTime)dpEndDate.SelectedDate;
                    orderList = db.ORDERs.Where(x => x.DATE >= begin && x.DATE < end).ToList();

                    if (option == "Products")
                    {
                        ProductType_Report(productList, orderList);
                    }
                    else
                    {
                        GetIncomeInPeriod_Report(productList, orderList);
                        SaleType_Report(productList, orderList);
                    }
                    selectReport = true;
                }

                if (txtYear.Text != "")
                {
                    typetime  = (int)typeOfTime.YEAR;
                    year      = int.Parse(txtYear.Text);
                    begin     = new DateTime(year, 1, 1, 0, 0, 0, 0);
                    end       = new DateTime(year, 12, 31, 23, 55, 55, 0);
                    orderList = db.ORDERs.Where(x => x.DATE >= begin && x.DATE < end).ToList();
                    if (option == "Products")
                    {
                        ProductType_Report(productList, orderList);
                    }
                    else
                    {
                        GetIncomeInPeriod_Report(productList, orderList);
                        SaleType_Report(productList, orderList);
                    }
                    selectReport = true;
                }
            }
        }
Esempio n. 11
0
 // Select product
 private void getSelectedItemProduct(object sender, MouseButtonEventArgs e)
 {
     selectedPro = (PRODUCT)lvProduct.SelectedItems[0];
 }