Ejemplo n.º 1
0
        private void BtnNewSale_Click(object sender, RoutedEventArgs e)
        {
            NewSale saleForm = new NewSale();

            saleForm.ShowDialog();
            if (saleForm.saved)
            {
                string firstName;
                string lastName;

                try
                {
                    //Add a customer
                    if ((bool)saleForm.chkExisting.IsChecked)
                    {
                        _customerManager.addNewCustomer(saleForm.cust);
                    }

                    //New Bill
                    List <BillingLineItem> lineItems = new List <BillingLineItem>();
                    firstName = saleForm.cust.getFirstName();
                    lastName  = saleForm.cust.getLastName();
                    int c = _customerManager.getCustomerIDByCustomerName(firstName, lastName);

                    //New billing line item
                    lineItems.Add(new BillingLineItem(0, saleForm.sale.getSaleAmount()));
                    _billingManager.newBill(new Bill(0, c,
                                                     saleForm.sale.getSaleAmount(), 0, DateTime.Now, DateTime.Now.AddDays(30), lineItems));

                    //New sale
                    firstName = saleForm.cust.getFirstName();
                    lastName  = saleForm.cust.getLastName();
                    string vin = saleForm.availableCars[saleForm.cboCar.SelectedIndex].getVIN();
                    saleForm.sale.addEmployee(_employee.getEmployeeID());
                    saleForm.sale.setBillingLineItemID(_billingManager.getLastestBillingLineItem());
                    saleForm.sale.setCustomerID(_customerManager.getCustomerIDByCustomerName(firstName, lastName));
                    _saleManager.addNewSale(saleForm.sale, vin);

                    lblStatusMessage.Content = "Update success";
                }
                catch (Exception ex)
                {
                    lblStatusMessage.Content = ex.Message;
                }
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateLineItems2(string data)
        {
            try
            {
                //Declare variables
                Repair        repair        = (Repair)Session["repair"];
                List <string> serialNumbers = data.Split(',').ToList();
                List <PartVM> parts         = _partsManager.getAllParts();

                //Add line items to the repair
                foreach (string serialNumber in serialNumbers)
                {
                    Part part = parts.Find(x => x.SerialNumber == serialNumber);
                    repair.LineItems.Add(new RepairLineItem()
                    {
                        SerialNumber = part.SerialNumber,
                        Amount       = part.Cost,
                        Type         = part.PartType
                    });
                }

                //Create a new bill
                Bill bill = new Bill()
                {
                    CustomerID = repair.CustomerID,
                    AmountDue  = repair.getAmount(),
                    AmountPaid = 0M,
                    IssueDate  = DateTime.Now,
                    DueDate    = DateTime.Now.AddDays(30),
                    LineItems  = new List <BillingLineItem>()
                };
                bill.LineItems.Add(new BillingLineItem()
                {
                    Amount = repair.getAmount()
                });

                //Add everything to the database
                _billingManager.newBill(bill);
                repair.BillingLineItemID = _billingManager.getLastestBillingLineItem();
                _repairsManager.addNewRepair(repair);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Redirect("~/Home/Error?error=" + ex.Message));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Sale sale, string customerName, string vin,
                                   string isChecked, string firstName, string lastName,
                                   string address, string emailAddress, string phoneNumber)
        {
            try
            {
                if (vin == "")
                {
                    throw new ApplicationException("VIN field cannot be blank");
                }

                if (null != isChecked)
                {
                    if (firstName == "")
                    {
                        throw new ApplicationException("First name cannot be blank");
                    }
                    else if (lastName == "")
                    {
                        throw new ApplicationException("Last name cannot be blank");
                    }
                    else if (address == "")
                    {
                        throw new ApplicationException("Address cannot be blank");
                    }
                    else if (emailAddress == "")
                    {
                        throw new ApplicationException("Email address cannot be blank");
                    }
                    else if (phoneNumber == "")
                    {
                        throw new ApplicationException("Phone number cannot be blank");
                    }
                }

                //Choose whether to add a new customer
                if (null != isChecked)
                {
                    Customer customer = new Customer()
                    {
                        FirstName    = firstName,
                        LastName     = lastName,
                        Address      = address,
                        EmailAddress = emailAddress,
                        PhoneNumber  = phoneNumber
                    };

                    customerManager.addNewCustomer(customer);

                    customerName = firstName + " " + lastName;
                }

                //Set the customer ID and employee ID
                sale.EmployeeID = 1000000;
                sale.CustomerID = customerManager.getCustomerIDByCustomerName(
                    customerName.Split(' ')[0],
                    customerName.Split(' ')[1]
                    );

                //Add a new bill to the database
                Bill bill = new Bill()
                {
                    CustomerID = sale.CustomerID,
                    AmountDue  = sale.SaleAmount,
                    AmountPaid = 0M,
                    IssueDate  = DateTime.Now,
                    DueDate    = DateTime.Now.AddDays(30),
                    LineItems  = new List <BillingLineItem>()
                };
                bill.LineItems.Add(new BillingLineItem()
                {
                    Amount = sale.SaleAmount
                });
                billingManager.newBill(bill);

                //Add the sale to the database
                sale.SaleDate          = DateTime.Now;
                sale.BIllingLineItemID = billingManager.getLastestBillingLineItem();
                manager.addNewSale(sale, vin);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Redirect("~/Home/Error?error=" + ex.Message));
            }
        }