Example #1
0
        public Sale Create(Sale sale, User user, Customer customer)
        {
            sale.TransactionNumber = Guid.NewGuid().ToString();
            sale.UserId = user.Id;
            sale.CustomerId = customer.Id;

            var newSale = salesRepository.Add(sale);
            
            sale.SaleDetails.ToList().ForEach(sd =>
            {
                sd.SaleId = newSale.Id;
                salesRepository.Add(sd);
            });

            return newSale;
        }
Example #2
0
        public frmCharge(User user, Customer customer, Sale sale, decimal amount, decimal discount, decimal total)
        {
            InitializeComponent();

            this.User = user;
            this.Customer = customer;
            sale.Amount = amount;
            sale.Discount = discount;
            sale.Total = total;
            this.Sale = sale;

            this.salesService = new SalesService();
            this.productsService = new ProductsService();

            this.Load += (s, e) =>
            {
                txtTicket.Text = salesService.GetTicketNumber().ToString();
                txtDiscout.Text = this.Sale.Discount.ToString();
                txtTotal.Text = this.Sale.Total.ToString();

                cmbUser.DataSource = new List<User> { this.User };
                cmbUser.DisplayMember = "Username";
                cmbUser.ValueMember = "Id";

                cmbCustomer.DataSource = new List<Customer> { this.Customer };
                cmbCustomer.DisplayMember = "FullName";
                cmbCustomer.ValueMember = "Id";

                txtCash.Focus();
            };

            btnCharge.Click += (s, e) =>
            {
                var currentSale = this.Sale;

                salesService.Create(currentSale, this.User, this.Customer);

                //
                //PrintTicket
                //
                PrintTicket(this.Sale);

                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            };

            txtCash.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    var currentSale = this.Sale;

                    salesService.Create(currentSale, this.User, this.Customer);

                    //
                    //PrintTicket
                    //
                    PrintTicket(this.Sale);

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
            };

            btnCancel.Click += (s, e) =>
            {
                this.DialogResult = System.Windows.Forms.DialogResult.No;
            };
        }