Esempio n. 1
0
        public static List<Customer> GetCustomers()
        {
            // if the directory doesn't exist, create it
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            // create the array list for customers
            List<Customer> customers = new List<Customer>();

            // create the object for the input stream for a binary file
            BinaryReader binaryIn =
                new BinaryReader(
                new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

            // read the data from the file and store it in the List<>
            while (binaryIn.PeekChar() != -1)
            {
                Customer c = new Customer();
                c.FirstName = binaryIn.ReadString();
                c.LastName = binaryIn.ReadString();
                c.Email = binaryIn.ReadString();
                customers.Add(c);
            }

            binaryIn.Close();

            return customers;
        }
Esempio n. 2
0
        public static List<Customer> GetCustomers()
        {
            // if the directory doesn't exist, create it
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            // create the object for the input stream for a text file
            StreamReader textIn =
                new StreamReader(
                    new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

            // create the array list for customers
            List<Customer> customers = new List<Customer>();

            // read the data from the file and store it in the ArrayList
            while (textIn.Peek() != -1)
            {
                string row = textIn.ReadLine();
                string[] columns = row.Split('|');
                Customer customer = new Customer();
                customer.FirstName = columns[0];
                customer.LastName = columns[1];
                customer.Email = columns[2];
                customers.Add(customer);
            }

            textIn.Close();

            return customers;
        }
Esempio n. 3
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         customer = new Customer(txtFirstName.Text, txtLastName.Text,
             txtEmail.Text);
         this.Close();
     }
 }
 private void btnSave_Click(object sender, System.EventArgs e)
 {
     if (IsValidData())
     {
         customer = new WholesaleCustomer(txtFirstName.Text, txtLastName.Text,
             txtEmail.Text, txtCompany.Text);
         this.Close();
     }
 }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     frmAddModifyCustomer addCustomerForm = new frmAddModifyCustomer();
     addCustomerForm.addCustomer = true;
     DialogResult result = addCustomerForm.ShowDialog();
     if (result == DialogResult.OK)
     {
         customer = addCustomerForm.customer;
         txtCustomerID.Text = customer.CustomerID.ToString();
         this.DisplayCustomer();
     }
 }
 private void btnAccept_Click(object sender, EventArgs e)
 {
     if (IsValidData())
     {
         if (addCustomer)
         {
             customer = new Customer();
             this.PutCustomerData(customer);
             try
             {
                 //customer.CustomerID = CustomerDB.AddCustomer(customer);
                 this.DialogResult = DialogResult.OK;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
         else
         {
             Customer newCustomer = new Customer();
             newCustomer.CustomerID = customer.CustomerID;
             this.PutCustomerData(newCustomer);
             try
             {
                 //if (! CustomerDB.UpdateCustomer(customer, newCustomer))
                 //{
                 //    MessageBox.Show("Another user has updated or " +
                 //        "deleted that customer.", "Database Error");
                 //    this.DialogResult = DialogResult.Retry;
                 //}
                 //else
                 //{
                 //    customer = newCustomer;
                 //    this.DialogResult = DialogResult.OK;
                 //}
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, ex.GetType().ToString());
             }
         }
     }
 }
Esempio n. 7
0
        public static bool DeleteCustomer(Customer customer)
        {
            SqlConnection connection = MMABooksDB.GetConnection();

            string strDeleteStatement =
                "DELETE FROM Customers WHERE " +
                "Name = @Name " +
                "AND Address = @Address " +
                "AND City = @City " +
                "AND State = @State " +
                "and ZipCode = @ZipCode ";

            SqlCommand deleteCommand = new SqlCommand(strDeleteStatement, connection);

            deleteCommand.Parameters.AddWithValue("@Name", customer.Name);
            deleteCommand.Parameters.AddWithValue("@Address", customer.Address);
            deleteCommand.Parameters.AddWithValue("@City", customer.City);
            deleteCommand.Parameters.AddWithValue("@State", customer.State);
            deleteCommand.Parameters.AddWithValue("@ZipCode", customer.ZipCode);

            try
            {
                connection.Open();

                int count = deleteCommand.ExecuteNonQuery();

                if (count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (SqlException e)
            {
                throw e;
            }
            finally
            {
                connection.Close();
            }
        }
 public static int AddCustomer(Customer customer)
 {
     SqlConnection connection = MMABooksDB.GetConnection();
     string insertStatement =
         "INSERT Customers " +
         "(Name, Address, City, State, ZipCode) " +
         "VALUES (@Name, @Address, @City, @State, @ZipCode)";
     SqlCommand insertCommand =
         new SqlCommand(insertStatement, connection);
     insertCommand.Parameters.AddWithValue(
         "@Name", customer.Name);
     insertCommand.Parameters.AddWithValue(
         "@Address", customer.Address);
     insertCommand.Parameters.AddWithValue(
         "@City", customer.City);
     insertCommand.Parameters.AddWithValue(
         "@State", customer.State);
     insertCommand.Parameters.AddWithValue(
         "@ZipCode", customer.ZipCode);
     try
     {
         connection.Open();
         insertCommand.ExecuteNonQuery();
         string selectStatement =
             "SELECT IDENT_CURRENT('Customers') FROM Customers";
         SqlCommand selectCommand =
             new SqlCommand(selectStatement, connection);
         int customerID = Convert.ToInt32(selectCommand.ExecuteScalar());
         return customerID;
     }
     catch (SqlException ex)
     {
         throw ex;
     }
     finally
     {
         connection.Close();
     }
 }
Esempio n. 9
0
        public static List<Customer> GetCustomers()
        {
            // create the list
            List<Customer> customers = new List<Customer>();

            // create the XmlReaderSettings object
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true;

            // create the XmlReader object
            XmlReader xmlIn = XmlReader.Create(path, settings);

            // read past all nodes to the first Customer node
            xmlIn.ReadToDescendant("Customer");

            // create one Customer object for each Customer node
            do
            {
                Customer c = new Customer();
                xmlIn.ReadStartElement("Customer");
                c.FirstName =
                    xmlIn.ReadElementContentAsString();
                c.LastName =
                    xmlIn.ReadElementContentAsString();
                c.Email =
                    xmlIn.ReadElementContentAsString();
                customers.Add(c);
            }
            while (xmlIn.ReadToNextSibling("Customer"));

            // close the XmlReader object
            xmlIn.Close();

            return customers;
        }
 private void btnModify_Click(object sender, EventArgs e)
 {
     frmAddModifyCustomer modifyCustomerForm = new frmAddModifyCustomer();
     modifyCustomerForm.addCustomer = false;
     modifyCustomerForm.customer = customer;
     DialogResult result = modifyCustomerForm.ShowDialog();
     if (result == DialogResult.OK)
     {
         customer = modifyCustomerForm.customer;
         this.DisplayCustomer();
     }
     else if (result == DialogResult.Retry)
     {
         this.GetCustomer(customer.CustomerID);
         if (customer != null)
             this.DisplayCustomer();
         else
             this.ClearControls();
     }
 }
 private void GetCustomer(int customerID)
 {
     try
     {
         customer = CustomerDB.GetCustomer(customerID);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, ex.GetType().ToString());
     }
 }
        public static Customer GetCustomer(int customerID)
        {
            SqlConnection connection = MMABooksDB.GetConnection();
            string selectStatement
                = "SELECT CustomerID, Name, Address, City, State, ZipCode "
                + "FROM Customers "
                + "WHERE CustomerID = @CustomerID";
            SqlCommand selectCommand =
                new SqlCommand(selectStatement, connection);
            selectCommand.Parameters.AddWithValue("@CustomerID", customerID);

            try
            {
                connection.Open();
                SqlDataReader custReader =
                    selectCommand.ExecuteReader(CommandBehavior.SingleRow);
                if (custReader.Read())
                {
                    Customer customer = new Customer();
                    customer.CustomerID = (int)custReader["CustomerID"];
                    customer.Name = custReader["Name"].ToString();
                    customer.Address = custReader["Address"].ToString();
                    customer.City = custReader["City"].ToString();
                    customer.State = custReader["State"].ToString();
                    customer.ZipCode = custReader["ZipCode"].ToString();
                    return customer;
                }
                else
                {
                    return null;
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
 public static bool UpdateCustomer(Customer oldCustomer, 
     Customer newCustomer)
 {
     SqlConnection connection = MMABooksDB.GetConnection();
     string updateStatement =
         "UPDATE Customers SET " +
         "Name = @NewName, " +
         "Address = @NewAddress, " +
         "City = @NewCity, " +
         "State = @NewState, " +
         "ZipCode = @NewZipCode " +
         "WHERE Name = @OldName " +
         "AND Address = @OldAddress " +
         "AND City = @OldCity " +
         "AND State = @OldState " +
         "AND ZipCode = @OldZipCode";
     SqlCommand updateCommand =
         new SqlCommand(updateStatement, connection);
     updateCommand.Parameters.AddWithValue(
         "@NewName", newCustomer.Name);
     updateCommand.Parameters.AddWithValue(
         "@NewAddress", newCustomer.Address);
     updateCommand.Parameters.AddWithValue(
         "@NewCity", newCustomer.City);
     updateCommand.Parameters.AddWithValue(
         "@NewState", newCustomer.State);
     updateCommand.Parameters.AddWithValue(
         "@NewZipCode", newCustomer.ZipCode);
     updateCommand.Parameters.AddWithValue(
         "@OldName", oldCustomer.Name);
     updateCommand.Parameters.AddWithValue(
         "@OldAddress", oldCustomer.Address);
     updateCommand.Parameters.AddWithValue(
         "@OldCity", oldCustomer.City);
     updateCommand.Parameters.AddWithValue(
         "@OldState", oldCustomer.State);
     updateCommand.Parameters.AddWithValue(
         "@OldZipCode", oldCustomer.ZipCode);
     try
     {
         connection.Open();
         int count = updateCommand.ExecuteNonQuery();
         if (count > 0)
             return true;
         else
             return false;
     }
     catch (SqlException ex)
     {
         throw ex;
     }
     finally
     {
         connection.Close();
     }
 }
 private void PutCustomerData(Customer customer)
 {
     customer.Name = txtName.Text;
     customer.Address = txtAddress.Text;
     customer.City = txtCity.Text;
     customer.State = cboStates.SelectedValue.ToString();
     customer.ZipCode = txtZipCode.Text;
 }
Esempio n. 15
0
 public void Remove(Customer customer)
 {
     customers.Remove(customer);
     Changed(this);
 }
Esempio n. 16
0
 public void Add(Customer customer)
 {
     customers.Add(customer);
     Changed(this);
 }