Esempio n. 1
0
        /// <summary>
        /// Save a car based on inputs, proform validation check, then go back to cars page and get a list of cars
        /// </summary>
        protected void lbtnSaveCar_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) // if any validation control failed, this will be false
            {
                // inserts data into database table
                CarsBLL car = new CarsBLL();

                car.Serial       = int.Parse(lblSerial.Text);
                car.CustomerName = "(Instock)";
                car.Make         = txtMake.Text;
                car.Model        = txtModel.Text;
                car.Year         = txtYear.Text;
                car.Color        = txtColor.Text;
                car.PurchaseDate = lblPurchaseDate.Text;
                car.PurchaseFrom = txtPurchasesName.Text;
                car.PurchaseCost = decimal.Parse(txtPurchaseCost.Text);
                car.ListPrice    = decimal.Parse(txtPrice.Text);

                if (bll.InsertCar(car))
                {
                    Session["msg"] = "Car " + car.Serial + " added";
                    Response.Redirect("~/Cars.aspx");
                }
            }
            else
            {
                lblMessage.Text      = "Validation failed. Please try again";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
        /// <summary>
        /// Get a car by serial number, return a car object
        /// </summary>
        public CarsBLL GetCarBySerial(int serial)
        {
            // fetch a row from the database
            int     rowsFetched = adpCars.FillBySerial(tblCars, serial);
            CarsBLL car         = null;

            if (rowsFetched == 1)
            {
                car = new CarsBLL();
                var row = tblCars[0];

                car.Serial       = row.Serial;
                car.CustomerName = row.CustomerName;
                car.Make         = row.Make;
                car.Model        = row.Model;
                car.Year         = row.Year;
                car.Color        = row.Color;
                car.PurchaseDate = row.PurchaseDate;
                car.PurchaseFrom = row.PurchaseFrom;
                car.PurchaseCost = row.PurchaseCost;
                car.ListPrice    = row.ListPrice;
            }

            return(car);
        }
        // public methods

        /// <summary>
        /// Get all cars and return a car list to BLL from database
        /// </summary>
        public List <CarsBLL> GetAllCars()
        {
            adpCars.Fill(tblCars);
            listCars = null;

            // if table has rows
            if (tblCars.Count > 0)
            {
                // instantiate the List<>
                listCars = new List <CarsBLL>();

                // loop through the table
                foreach (var row in tblCars)
                {
                    CarsBLL car = new CarsBLL();

                    // assign the values from row to Car Business object
                    car.Serial       = row.Serial;
                    car.CustomerName = row.CustomerName;
                    car.Make         = row.Make;
                    car.Model        = row.Model;
                    car.Year         = row.Year;
                    car.Color        = row.Color;
                    car.PurchaseDate = row.PurchaseDate;
                    car.PurchaseFrom = row.PurchaseFrom;
                    car.PurchaseCost = row.PurchaseCost;
                    car.ListPrice    = row.ListPrice;

                    listCars.Add(car);
                }
            }

            return(listCars);
        }
        /// <summary>
        /// Save a sales invoice based on inputs and update car's customer name, proform validation check, then go back to sales invoices page and get a list of sales invoices
        /// </summary>
        protected void lbtnSaveSalesInvoice_Click(object sender, EventArgs e)
        {
            if (Page.IsValid) // if any validation control failed, this will be false
            {
                SalesInvoicesBLL salesInvoice = new SalesInvoicesBLL();

                salesInvoice.InvoiceId    = int.Parse(lblSalesInvoiceId.Text);
                salesInvoice.CustomerName = txtCustomerName.Text;
                salesInvoice.Serial       = int.Parse(txtSerial.Text);
                salesInvoice.SalesDate    = lblSalesDate.Text;
                salesInvoice.Salesman     = txtSalesman.Text;
                salesInvoice.NetPrice     = decimal.Parse(lblNetPrice.Text);
                salesInvoice.Tax          = decimal.Parse(lblTax.Text);
                salesInvoice.TotalPrice   = decimal.Parse(lblTotalPrice.Text);

                int num = int.Parse(txtSerial.Text);

                // get a car object by serial number and update car's customer name, then insert sals invoice into database
                CarsBLL car = bllc.GetCarBySerial(num);
                if (car != null)
                {
                    car.CustomerName = txtCustomerName.Text;
                    try
                    {
                        if (blls.InsertSalesInvoice(salesInvoice))
                        {
                            car.UpdateCar(car);
                            Session["msg"] = "Sales Invoice " + salesInvoice.InvoiceId + " added";
                            Response.Redirect("~/SalesInvoices.aspx");
                        }
                        else
                        {
                            lblMessage.Text      = "Validation failed. Please try again";
                            lblMessage.ForeColor = System.Drawing.Color.Red;
                        }
                    }
                    catch (Exception ex)
                    {
                        lblMessage.Text      = ex.Message;
                        lblMessage.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            else
            {
                lblMessage.Text      = "Validation failed. Please try again";
                lblMessage.ForeColor = System.Drawing.Color.Red;
            }
        }
 // constructor
 public AddSalesInvoice()
 {
     blls = new SalesInvoicesBLL();
     bllc = new CarsBLL();
 }
Esempio n. 6
0
 /// <summary>
 /// Update a car
 /// </summary>
 public bool UpdateCar(CarsBLL car)
 {
     return(carDAL.UpdateCar(car));
 }
Esempio n. 7
0
 /// <summary>
 /// Insert a car
 /// </summary>
 public bool InsertCar(CarsBLL car)
 {
     return(carDAL.InsertCar(car));
 }
Esempio n. 8
0
 // constructor
 public Cars()
 {
     bll = new CarsBLL();
 }
Esempio n. 9
0
 // constructor
 public AddCar()
 {
     bll = new CarsBLL();
 }
        /// <summary>
        /// Insert a  car into the database
        /// </summary>
        public bool InsertCar(CarsBLL car)
        {
            int result = adpCars.Insert(car.Serial, car.CustomerName, car.Make, car.Model, car.Year, car.Color, car.PurchaseDate, car.PurchaseFrom, car.PurchaseCost, car.ListPrice);

            return(result == 1);
        }