Exemplo n.º 1
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintInvoice printInvoice = new PrintInvoice();

            printInvoice.OrderDatepicker.Text  = ShowOrderDTO.OrderDate.ToString();
            printInvoice.txtAddress.Text       = ShowOrderDTO.Address;
            printInvoice.txtCompanyName.Text   = ShowOrderDTO.CompanyName;
            printInvoice.txtInvoiceNumber.Text = ShowOrderDTO.OrderID.ToString();
            printInvoice.txtUsername.Text      = ShowOrderDTO.UserName;
            printInvoice.txtTotalPrice.Text    = txtTotalPrice.Text;
            printInvoice.txtCustomerName.Text  = ShowOrderDTO.CustomerName;
            PrintInvoice.OrderDetails          = OrderDetailsObservalbleCollection;
            this.Content = printInvoice;
        }
Exemplo n.º 2
0
        private void btnٍSave_Click(object sender, RoutedEventArgs e)
        {
            var order = new BL.Models.Orders
            {
                CompanyId  = unitOfWork.Companies.Find(c => c.Name == txtCompanyName.Text).FirstOrDefault().ID,
                CustomerId = int.Parse(cmbCustomerName.SelectedValue.ToString()),
                UserId     = unitOfWork.Users.Find(u => u.UserName == txtUsername.Text).FirstOrDefault().ID,
                Date       = DateTime.Now,
                Address    = txtAddress.Text,
                IsDeleted  = false
            };

            unitOfWork.Orders.Add(order);
            var result = unitOfWork.Complete();

            if (result > 0)
            {
                int orderID = order.ID;

                var od = new List <BL.Models.OrderDetails>();

                foreach (var o in OrderDetails)
                {
                    od.Add(new BL.Models.OrderDetails
                    {
                        OrderId   = orderID,
                        Price     = o.Price,
                        ProductId = o.ProductId,
                        Quantity  = o.Quantity,
                    });
                }

                foreach (var item in od)
                {
                    unitOfWork.OrderDetails.Add(item);
                    unitOfWork.Complete();
                }

                MessageBox.Show("تم", "تم حفظ الطلب", MessageBoxButton.OK, MessageBoxImage.Information);;

                var startIndex   = cmbCustomerName.SelectedItem.ToString().IndexOf(',');
                var customerName = cmbCustomerName.SelectedItem.ToString().Substring(startIndex + 1);
                customerName = customerName.Remove(customerName.Length - 1);

                PrintInvoice printInvoice = new PrintInvoice();
                printInvoice.OrderDatepicker.Text  = OrderDatepicker.Text;
                printInvoice.txtAddress.Text       = txtAddress.Text;
                printInvoice.txtCompanyName.Text   = txtCompanyName.Text;
                printInvoice.txtInvoiceNumber.Text = orderID.ToString();
                printInvoice.txtUsername.Text      = txtUsername.Text;
                printInvoice.txtTotalPrice.Text    = txtTotalPrice.Text;
                printInvoice.txtCustomerName.Text  = customerName;
                PrintInvoice.OrderDetails          = OrderDetails;
                this.Content = printInvoice;
            }

            else
            {
                MessageBox.Show("فشلت العملية", "حدث خطأ أثناء حفظ الطلب", MessageBoxButton.OK, MessageBoxImage.Error);;
            }
        }