/// <summary>
 /// The constructor for the confirmation form.
 /// </summary>
 /// <param name="b"></param>
 /// <param name="orderDetailList"></param>
 /// <param name="c"></param>
 /// <param name="emp"></param>
 public FrmConfirmation(Business businessArg, Order order, List<OrderDetail> orderDetailList, Customer cust, Employee emp)
 {
     InitializeComponent();
     currentOrder = order;
     business = businessArg;
     orderDetails = orderDetailList;
     currentCustomer = cust;
     currentEmp = emp;
 }
Exemplo n.º 2
0
 /// <summary>
 /// loadConfirmation
 /// loads confirmation form after order is placed
 /// </summary>
 /// <param name="o"></param>
 /// <param name="od"></param>
 /// <param name="c"></param>
 /// <param name="emp"></param>
 private void loadConfirmation(Order o, List<OrderDetail> od, Customer c, Employee emp)
 {
     FrmConfirmation frmConfirmation = new FrmConfirmation(business, o, od, c, emp);
     frmConfirmation.Text = "Confirmation Window ";
     frmConfirmation.ShowDialog();
 }
Exemplo n.º 3
0
        private void btn_Submit_Click(object sender, EventArgs e)
        {
            if (!validateForm())
                return;

            if (!checkQuantities())
                return;

            //create new Order Object and set properties
            Order order = new Order();
            order.CustomerID = ((Customer)cmbCustName.SelectedItem).CustomerID;
            order.EmployeeID = ((Employee)cmbClerks.SelectedItem).EmployeeID;
            order.OrderDate = System.DateTime.Now;

            //create a list of Order Details
            List<OrderDetail> orderDetails = new List<OrderDetail>(gridViewOrderDetails.Rows.Count);
            foreach (DataGridViewRow row in gridViewOrderDetails.Rows)
            {
                orderDetails.Add((OrderDetail)row.Tag);//add each orderdetail object to the list
            }

            business.addOrder(order, orderDetails);//update Database

            //load Confirmation Form
            loadConfirmation(order, orderDetails, customerSelected, clerkSelected);

            Close();
        }
Exemplo n.º 4
0
        /// <summary>
        /// InsertOrder()
        /// Takes an Order Object and inserts Order properties into Order Table.
        /// Returns OrderID as int.
        /// </summary>
        /// <param name="order"></param>
        /// <returns>int represents OrderID of Order just placed</returns>
        public int InsertOrder(Order order)
        {
            String insertQuery = "INSERT INTO Orders(CustomerID, EmployeeID, OrderDate) VALUES (\""
                + order.CustomerID.ToString() + "\",\"" + order.EmployeeID.ToString() + "\",\""
                + order.OrderDate.ToShortDateString() + "\")";
            OleDbCommand cmInsert = new OleDbCommand(insertQuery, con);

            String selectQuery = "SELECT MAX(OrderID) FROM Orders";
            OleDbCommand cmSelect = new OleDbCommand(selectQuery, con);

            int lastOrderId = 0;
            try
            {
                con.Open();
                cmInsert.ExecuteNonQuery();
                lastOrderId = (int)(cmSelect.ExecuteScalar());
            }
            catch (Exception)
            {
                //can't display any error feedback in data access layer

            }
            finally
            {
                con.Close();
            }
            return lastOrderId;
        }
Exemplo n.º 5
0
        /// <summary>
        /// addOrder()
        /// Takes an Order object and a list of Order Detail as parameters;
        /// Inserts the order into database, returns Order Id and adds it to each Order Detail object;
        /// Inserts all Order Details into Database;
        /// Updates Units In Stock in Products Table
        /// </summary>
        /// <param name="order"> Of Type Order</param>
        /// <param name="orderDetails"> of Type List<OrderDetail></param>
        public void addOrder(Order order, List<OrderDetail> orderDetails)
        {
            int newOrderId = database.InsertOrder(order);//AddOrder() adds Order record to database and returns its OrderID
            order.OrderID = newOrderId;//set the newOrderID in the Order Object

            foreach (OrderDetail od in orderDetails)
            {
                od.OrderID = newOrderId;//add newOrderID to each OrderDetail Object
                database.InsertOrderDetails(od);//add Order Detail records to Database
                database.RemoveUnitsFromStock(od.ProductID, od.Quantity);//Update the # of Units In Stock
            }
        }