Exemplo n.º 1
0
        public Ticket(TicketModel model)
        {
            InitializeComponent();
            path              = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName;
            path             += "/bill.txt";
            this.model        = model;
            hour.Text         = DateTime.Now.ToShortTimeString();
            cashiersName.Text = model.Cashier;
            score.Text        = "100111";
            day.Text          = DateTime.Now.ToShortDateString();
            nimber.Text       = model.Products.Count.ToString();
            TotalPrice.Text   = model.price.ToString();

            lables      = new Label[model.Products.Count];
            lablesPrice = new Label[model.Products.Count];
            lablesCount = new Label[model.Products.Count];

            int y = 0;

            for (int i = 0; i < model.Products.Count; i++)
            {
                lables[i]          = new Label();
                lables[i].Location = new Point(10, 205 + y);
                lables[i].Text     = model.Products[i].Product;
                panel1.Controls.Add(lables[i]);

                lablesPrice[i]          = new Label();
                lablesPrice[i].Location = new Point(230, 205 + y);
                lablesPrice[i].Text     = model.Products[i].price.ToString();
                panel1.Controls.Add(lablesPrice[i]);


                lablesCount[i]          = new Label();
                lablesCount[i].Location = new Point(280, 205 + y);
                lablesCount[i].Text     = model.Products[i].count.ToString();
                panel1.Controls.Add(lablesCount[i]);

                y += 10;
            }
            nimber.Location     = new Point(10, 272 + y);
            label9.Location     = new Point(35, 297 + y);
            label10.Location    = new Point(3, 322 + y);
            TotalPrice.Location = new Point(117, 316 + y);
            label11.Location    = new Point(101, 348 + y);
            label12.Location    = new Point(114, 370 + y);
            Print.Location      = new Point(56, 412 + y);
            Back.Location       = new Point(188, 412 + y);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Обробник в якому створюється модель даних квиток, також видаляються з бази продані продукти
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void Check_Click(object sender, EventArgs e)
        {
            List <SoldProduct> soldProducts = new List <SoldProduct>();

            for (int i = 0; i < listViewCart.Items.Count; i++)
            {
                string productName  = listViewCart.Items[i].SubItems[0].Text;
                int    productCount = Convert.ToInt32(listViewCart.Items[i].SubItems[1].Text);
                int    productPrice = Convert.ToInt32(listViewCart.Items[i].SubItems[2].Text);
                soldProducts.Add(new SoldProduct()
                {
                    Product = productName, count = productCount, price = productPrice
                });
            }

            TicketModel model = new TicketModel()
            {
                Cashier = textBoxCashierName.Text, Products = soldProducts, price = Convert.ToInt32(textBoxTotalPrice.Text)
            };


            for (int i = 0; i < model.Products.Count; i++)
            {
                string  pName = model.Products[i].Product;
                Product p     = dbService.DB.Products.Where(x => x.Name == pName).SingleOrDefault();
                if (p != null)
                {
                    p.Count = p.Count - model.Products[i].count;
                }
            }

            dbService.DB.SaveChanges();
            listViewCart.Clear();
            LoadAllProducts();
            textBoxTotalPrice.Text = "";


            Ticket ticketForm = new Ticket(model);

            ticketForm.ShowDialog();
        }