public FrmAddCustomer(Business bus)
 {
     InitializeComponent();
     business = bus;
     newCustomer = new Customer();
     updatedCustomer = new Customer();
 }
 /// <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;
 }
 /// <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();
 }
 /// <summary>
 /// cmbCustName_SelectedIndexChanged()
 /// If customer name changes, change customer id to match;
 /// Clear error for both customer name/custId.
 /// Set customerSelected = to the customer object selected - passed to confirmation form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void cmbCustName_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (cmbCustName.SelectedIndex != -1)
     {
         int adjuster = cmbCustName.SelectedIndex;
         cmbCustID.SelectedIndex = adjuster;
         errorProvider.SetError(cmbCustID,"");
         errorProvider.SetError(cmbCustName, "");
         customerSelected = (Customer)cmbCustName.SelectedItem;
     }
 }
        //add customer to DB and call delegate
        public string UpdateCustomer(Customer cust)
        {
            String updateQuery = "UPDATE Customers "
                + "SET CustomerID = " + ((String.IsNullOrEmpty(cust.CustomerID)) ? "null" : "\"" + cust.CustomerID + "\"")
                + ", CompanyName = " + ((String.IsNullOrEmpty(cust.CompanyName)) ? "null" : "\"" + cust.CompanyName + "\"")
                + ", ContactName = " + ((String.IsNullOrEmpty(cust.ContactName)) ? "null" : "\"" + cust.ContactName + "\"")
                + ", ContactTitle = " + ((String.IsNullOrEmpty(cust.ContactTitle)) ? "null" : "'" + cust.ContactTitle + "'")
                + ", Address = " + ((String.IsNullOrEmpty(cust.Address)) ? "null" : "\"" + cust.Address + "\"")
                + ", City = " + ((String.IsNullOrEmpty(cust.City)) ? "null" : "'" + cust.City + "'")
                + ", Region = " + ((String.IsNullOrEmpty(cust.Region)) ? "null" : "\"" + cust.Region + "\"")
                + ", PostalCode = " + ((String.IsNullOrEmpty(cust.PostalCode)) ? "null" : "'" + cust.PostalCode + "'")
                + ", Country = " + ((String.IsNullOrEmpty(cust.Country)) ? "null" : "\"" + cust.Country + "\"")
                + ", Phone = " + ((String.IsNullOrEmpty(cust.Phone)) ? "null" : "'" + cust.Phone + "'")
                + ", Fax = " + ((String.IsNullOrEmpty(cust.Fax)) ? "null" : "'" + cust.Fax + "'")
                + " WHERE CustomerID = '" + cust.CustomerID + "'";

            OleDbCommand cmUpdate = new OleDbCommand(updateQuery, con);
            try
            {
                con.Open();
                cmUpdate.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                //can't display any error feedback in data access layer
                return "Customer Updated Failed";
            }
            finally
            {
                con.Close();
            }

            //raise event
            if (customerAdded_Changed != null)//check to makes sure at least one handler registered
            {
                customerAdded_Changed();
            }

            return "Customer Updated";
        }
        //add customer to DB and call delegate
        /// <summary>
        /// InsertCustomer()
        /// Takes a Customer object and adds a new record to the database table Customer
        /// </summary>
        /// <param name="p">Object of type Customer</param>
        public string InsertCustomer(Customer cust)
        {
            String insertQuery = "INSERT INTO Customers VALUES ("
                + "'" + cust.CustomerID  + "'" + ","
                + ((String.IsNullOrEmpty(cust.CompanyName)) ? "null" : "\"" + cust.CompanyName + "\"") + ","
                + ((String.IsNullOrEmpty(cust.ContactName)) ? "null" : "\"" + cust.ContactName + "\"") + ","
                + ((String.IsNullOrEmpty(cust.ContactTitle)) ? "null" : "\"" + cust.ContactTitle + "\"") + ","
                + ((String.IsNullOrEmpty(cust.Address)) ? "null" : "\"" + cust.Address + "\"") + ","
                + ((String.IsNullOrEmpty(cust.City)) ? "null" : "\"" + cust.City + "\"") + ","
                + ((String.IsNullOrEmpty(cust.Region)) ? "null" : "\"" + cust.Region + "\"") + ","
                + ((String.IsNullOrEmpty(cust.PostalCode)) ? "null" : "'" + cust.PostalCode + "'") + ","
                + ((String.IsNullOrEmpty(cust.Country)) ? "null" : "\"" + cust.Country + "\"") + ","
                + ((String.IsNullOrEmpty(cust.Phone)) ? "null" : "'" + cust.Phone + "'") + ","
                + ((String.IsNullOrEmpty(cust.Fax)) ? "null" : "'" + cust.Fax + "'") + ")";

            OleDbCommand cmInsert = new OleDbCommand(insertQuery, con);
            try
            {
                con.Open();
                cmInsert.ExecuteNonQuery();
            }
            catch (Exception)
            {
                //can't display any error feedback in data access layer
                return "Customer Added Failed";
            }
            finally
            {
                con.Close();
            }

            //raise event
            if (customerAdded_Changed != null)//check to makes sure at least one handler registered
            {
                customerAdded_Changed();
            }
            return "Customer Added";
        }
 /// <summary>
 /// updateCustomer()
 /// Updates a record in Customers Table
 /// </summary>
 /// <param name="_product">takes and object of type Customer</param>
 public string updateCustomer(Customer _customer)
 {
     string confirmation = database.UpdateCustomer(_customer);
     return confirmation;
 }
        /// <summary>
        /// fetchCustomers()
        /// Gets customer records from database and returns a copy of it
        /// </summary>
        /// <returns>List of type Customer</returns>
        public void loadCustomerData()
        {
            customers = database.FetchCustomers();

                List<Customer> copyCustomers = new List<Customer>();
                Customer copy;

                foreach (Customer c in customers)
                {
                    copy = new Customer();//create object

                    //add properties

                    copy.CustomerID = c.CustomerID;
                    copy.CompanyName = c.CompanyName;
                    copy.ContactName = c.ContactName;
                    copy.ContactTitle = c.ContactTitle;
                    copy.Address = c.Address;
                    copy.City = c.City;
                    copy.Region = c.Region;
                    copy.PostalCode = c.PostalCode;
                    copy.Country = c.Country;
                    copy.Phone = c.Phone;
                    copy.Fax = c.Fax;

                    copyCustomers.Add(copy);//add to new list
                    customers = copyCustomers;

                }
        }
 /// <summary>
 /// addCustomer()
 /// Adds new record to Customers Table
 /// </summary>
 /// <param name="_product">takes and object of type Customer</param>
 public string addCustomer(Customer _customer)
 {
     string confirmation = database.InsertCustomer(_customer);
     return confirmation;
 }