Exemple #1
0
        /// <summary>
        /// One method to edit the current customer in the DataGridView
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// *
        /// * Another method is to data bind customer properties to controls on the edit form.
        /// </remarks>
        private void cmdEditCurrent_Click(object sender, EventArgs e)
        {
            EditorForm f = new EditorForm(bsCustomers.Customer(), ContactTitles);

            try
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    Customer  customer  = blCustomers.FirstOrDefault(cust => cust.CustomerIdentifier == bsCustomers.CustomerIdentifier());
                    Customers customers = new Customers();
                    if (customers.UpdateCustomer(customer))
                    {
                        bsCustomers.ResetCurrentItem();
                    }
                    else
                    {
                        MessageBox.Show(customers.ValidationMessage);
                    }
                }
            }
            finally
            {
                f.Dispose();
            }
        }
Exemple #2
0
        private void EditCurrentRow()
        {
            Customer   customer = blCustomers.FirstOrDefault(cust => cust.CustomerIdentifier == bsCustomers.CustomerIdentifier());
            EditorForm f        = new EditorForm(customer, ContactTitles);

            try
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    bsCustomers.ResetCurrentItem();
                }
            }
            finally
            {
                f.Dispose();
            }
        }
Exemple #3
0
        private void AddNewCustomer()
        {
            Customer   customer = new Customer();
            EditorForm f        = new EditorForm(customer, ContactTitles);

            try
            {
                if (f.ShowDialog() == DialogResult.OK)
                {
                    blCustomers.Add(customer);
                    blCustomers.ResetBindings();

                    /*
                     * Here we are changing the sort to show the new customer in a-z order
                     * rather than sitting at the bottom of the DataGridView.
                     */
                    dataGridView1.Sort(dataGridView1.Columns["CompanyName"], ListSortDirection.Ascending);
                }
            }
            finally
            {
                f.Dispose();
            }
        }