Example #1
0
        private void addCustomerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var form = new CustomerForm();

            if (form.ShowDialog() == DialogResult.OK)
            {
                db.Customers.Add(form.Customer);
                db.SaveChanges();
            }
        }
Example #2
0
        public decimal Dequeue()
        {
            decimal sum = 0; // сумма покупки

            if (Queue.Count == 0)
            {
                return(0);
            }
            var card = Queue.Dequeue();

            if (card != null)
            {
                var check = new Check()
                {
                    SellerID   = Seller.SellerId,
                    Seller     = Seller,
                    CustomerId = card.Customer.CustomerId,
                    Customer   = card.Customer,
                    Created    = DateTime.Now,
                };

                if (!IsModel)
                {
                    db.Checks.Add(check);
                    db.SaveChanges();
                }
                else
                {
                    check.CheckId = 0;
                }

                var sells = new List <Sell>();    //вспомогательный список

                foreach (Product product in card) // достаем из корзины
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = check.CheckId,
                            Check     = check,
                            ProductId = product.ProductId,
                            Product   = product
                        };

                        sells.Add(sell);  // добавляем продажу

                        if (!IsModel)
                        {
                            db.Sells.Add(sell);
                        }

                        product.Count--;      // уменьшаем кол-во товара
                        sum += product.Price; // формируем тоговую стоимость
                    }
                }

                check.Price = sum;

                if (!IsModel)
                {
                    db.SaveChanges();
                }

                CheckClosed?.Invoke(this, check); // генерируем событие (? - проверка на null)
            }
            return(sum);
        }
Example #3
0
        public decimal Dequeue()
        {
            decimal sum = 0;

            if (Queue.Count == 0)
            {
                return(0);
            }

            var card = Queue.Dequeue();

            if (card != null)
            {
                //Создаем чек
                var check = new Check()
                {
                    SellerId   = Seller.SellerId,
                    Seller     = Seller,
                    CustomerId = card.Customer.CustomerId,
                    Customer   = card.Customer,
                    Created    = DateTime.Now
                };

                if (!IsModel)
                {
                    db.Checks.Add(check);
                    db.SaveChanges();
                }
                else
                {
                    check.CheckId = 0;
                }

                var sells = new List <Sell>();

                //Считаем товар
                foreach (Product product in card)
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = check.CheckId,
                            Check     = check,
                            ProductId = product.ProductId,
                            Product   = product
                        };


                        sells.Add(sell);

                        if (!IsModel)
                        {
                            db.Sells.Add(sell);
                        }
                        product.Count--;
                        sum += product.Price;
                    }
                }

                check.Price = sum;

                if (!IsModel)
                {
                    db.SaveChanges();
                }
                CheckClosed?.Invoke(this, check);
            }
            return(sum);
        }
Example #4
0
        public decimal Dequeue()
        {
            decimal sum = 0;

            if (Queue.Count == 0)
            {
                return(0);
            }
            var cart = Queue.Dequeue();

            if (cart != null)
            {
                var check = new Check()
                {
                    SellerId    = Seller.Id,
                    Seller      = this.Seller,
                    CustomerId  = cart.Customer.Id,
                    Customer    = cart.Customer,
                    DateCreated = DateTime.Now
                };

                if (!IsModel)
                {
                    _db.Checks.Add(check);
                    _db.SaveChanges();
                }
                else
                {
                    check.Id = 0;
                }

                var sells = new List <Sell>();
                foreach (Product product in cart)
                {
                    if (product.Count > 0)
                    {
                        var sell = new Sell()
                        {
                            CheckId   = check.Id,
                            Check     = check,
                            ProductId = product.Id,
                            Product   = product
                        };
                        sells.Add(sell);

                        if (!IsModel)
                        {
                            _db.Sells.Add(sell);
                        }

                        product.Count--;
                        sum += product.Price;
                    }
                }
                check.Price = sum;

                if (!IsModel)
                {
                    _db.SaveChanges();
                }

                ExitCustomer++;
                CheckClosed?.Invoke(this, check);
            }
            return(sum);
        }