Exemplo n.º 1
0
        /// <summary>
        /// Only permit two selections
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void BetweenExtensionExamples_Shown(object sender, EventArgs e)
        {
            var customerNames = await CustomersTestOperations.CustomerNames();

            customerNames.ForEach(customerName => CustomerNamesCheckedListBox.Items.Add(customerName));

            ExecuteButton.Enabled = true;
        }
        /// <summary>
        /// Example for article
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void CustomersDemoButton_Click(object sender, EventArgs e)
        {
            var test = await CustomersTestOperations.GetCustomersAsync();

            var test1 = await CustomersTestOperations.GetCustomersWithProjectionAsync();

            Console.WriteLine();
        }
        private async void OrdersTestForm_Shown(object sender, EventArgs e)
        {
            var customers = await CustomersTestOperations.GetCustomerItemsForComboBox();

            CustomersComboBox.DataSource = customers;
            GetOrdersForCustomer();
            CustomersComboBox.SelectedIndexChanged += CustomersComboBox_SelectedIndexChanged;
            _ordersBindingSource.PositionChanged   += _ordersBindingSource_PositionChanged;

            OrdersWithNoDetailsButton.Enabled = true;
        }
Exemplo n.º 4
0
        private async void CustomersDataGridViewTestForm_Shown(object sender, EventArgs e)
        {
            var customerEntities = await CustomersTestOperations.AllCustomersForDataGridViewAsync();

            _customerView = new SortableBindingList <CustomerEntity>(customerEntities);
            _customerBindingSource.DataSource = _customerView;

            CountryColumn.DisplayMember    = "Name";
            CountryColumn.ValueMember      = "CountryIdentifier";
            CountryColumn.DataPropertyName = "CountryIdentifier";
            CountryColumn.DataSource       = CustomersTestOperations.CountryList();
            CountryColumn.DisplayStyle     = DataGridViewComboBoxDisplayStyle.Nothing;


            ContactTitleColumn.DisplayMember    = "ContactTitle";
            ContactTitleColumn.ValueMember      = "ContactTypeIdentifier";
            ContactTitleColumn.DataPropertyName = "ContactTypeIdentifier";
            ContactTitleColumn.DataSource       = CustomersTestOperations.ContactTypeList();
            ContactTitleColumn.DisplayStyle     = DataGridViewComboBoxDisplayStyle.Nothing;

            CustomersDataGridView.DataSource = _customerBindingSource;
            CustomersDataGridView.ExpandColumns();

            CustomersBindingNavigator.BindingSource = _customerBindingSource;
            CurrentCustomerDetails.Enabled          = true;
            SaveChangesButton.Enabled            = true;
            CompanyNameStartsWithTextBox.Enabled = true;

            CustomersDataGridView.CellValueChanged += CustomersDataGridView_CellValueChanged;
            CustomersDataGridView.UserDeletingRow  += CustomersDataGridView_UserDeletingRow;


            _customerView.ListChanged += _customerView_ListChanged;
            _customerView.AddingNew   += _customerView_AddingNew;

            DeleteCustomerBindingNavigatorButton.Enabled = true;

            CustomersDataGridView.RowPrePaint += CustomersDataGridView_RowPrePaint;
            CustomersDataGridView.ExpandColumns();
        }
Exemplo n.º 5
0
        private async void CustomersTestForm_Shown(object sender, EventArgs e)
        {
            _bindingSource.DataSource = await CustomersTestOperations.GetCustomersAsync();

            CustomersDataGridView.DataSource = _bindingSource;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Performs simple validation and setting property values so on any changes
        /// they are updated immediately.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _customerView_ListChanged(object sender, ListChangedEventArgs e)
        {
            if (e.PropertyDescriptor != null)
            {
                //
                // Get current customer in current DataGridView row
                //
                CustomerEntity currentCustomer = _customerView.CurrentCustomer(_customerBindingSource.Position);
                Console.WriteLine($" -> {e.ListChangedType.ToString()}");
                //
                // Assert if there are changes to the current row in the DataGridView
                //
                if (e.ListChangedType == ListChangedType.ItemChanged)
                {
                    //
                    // Get data residing in the database table
                    //
                    Customers customerItem = CustomersTestOperations
                                             .Context
                                             .Customers
                                             .FirstOrDefault((customer) => customer.CustomerIdentifier == currentCustomer.CustomerIdentifier);

                    if (customerItem != null)
                    {
                        /*
                         * Did contact first or last name change?
                         * If so we need to update the contact.
                         */
                        if (e.PropertyDescriptor.DisplayName == "FirstName" || e.PropertyDescriptor.DisplayName == "LastName")
                        {
                            customerItem.Contact.FirstName = currentCustomer.FirstName;
                            customerItem.Contact.LastName  = currentCustomer.LastName;
                        }

                        var test1 = currentCustomer.CompanyName;

                        EntityEntry <Customers> customerEntry = CustomersTestOperations.Context.Entry(customerItem);
                        customerEntry.CurrentValues.SetValues(currentCustomer);

                        //
                        // Setup validation on current row data
                        //
                        var validation = ValidationHelper.ValidateEntity(currentCustomer);

                        //
                        // If there are validation error present them to the user
                        //
                        if (validation.HasError)
                        {
                            var errorItems = string.Join(Environment.NewLine,
                                                         validation.Errors.Select((containerItem) => containerItem.ErrorMessage).ToArray());

                            MessageBox.Show(errorItems + Environment.NewLine + @"Customer has been reset!!!", @"Corrections needed");

                            //
                            // Read current values from database
                            //
                            Customers originalCustomer = CustomersTestOperations.CustomerFirstOrDefault(customerItem.CustomerIdentifier);

                            //
                            // reset current item both in Customer object and CustomerEntity object
                            // (there are other ways to deal with this but are dependent on business logic)
                            //
                            customerEntry.CurrentValues.SetValues(originalCustomer);
                            _customerView[_customerBindingSource.Position] = CustomersTestOperations.CustomerByIdentifier(originalCustomer.CustomerIdentifier);
                            _hasValidationErrors = true;
                        }
                        else
                        {
                            _hasValidationErrors = false;
                            CustomersTestOperations.Context.SaveChanges();
                        }
                    }
                }
            }
        }