Exemple #1
0
        private void CustomerEditor_Load(System.Object sender, System.EventArgs e)
        {
            // ----- Prepare the form.

            // ----- Create the context. It will remain during the entire program.
            try
            {
                ActiveContext = new SalesOrderEntities(GetConnectionString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error connecting to database: " + ex.Message);
                Application.Exit();
            }

            // ----- Display the existing customers.
            try
            {
                foreach (Customer scanCustomer in ActiveContext.Customers)
                {
                    AllCustomers.Items.Add(new ItemData(scanCustomer.FullName, scanCustomer.ID));
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error loading customers: " + ex.Message);
            }
        }
Exemple #2
0
 public bool EditCustomer(ref Customer oneCustomer, SalesOrderEntities context)
 {
     // ----- Prompt the user to edit a new or existing customer.
     this.ActiveCustomer = oneCustomer;
     this.ActiveContext  = context;
     if (this.ShowDialog() == DialogResult.OK)
     {
         if (oneCustomer == null)
         {
             oneCustomer = this.ActiveCustomer;
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }