Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private void BtnCoupon_Click(object sender, RoutedEventArgs e)
        {
            db = new managementdbEntities();
            string coupon = txtCoupon.Text;

            validCoupon = db.COUPONs.Where(x => x.CODE == coupon && x.AVAILABLE > 0).Select(x => x).SingleOrDefault();

            if (validCoupon == null)
            {
                lblCouponError.Content = "This coupon is not valid.";
            }
            else
            {
                lblCouponError.Content = "Coupon applied, " + validCoupon.VALUE + "% discount.";
                total           -= (int)validCoupon.VALUE / 100.0 * total;
                lblTotal.Content = total.ToString();
            }
        }