Ejemplo n.º 1
0
        private void MitCompanies_Click(object sender, RoutedEventArgs e)
        {
            // Invokes the window to show the companies list.
            CompanyList companyList = new CompanyList();

            companyList.DataContext = Companies;
            companyList.Owner       = this;
            companyList.ShowDialog();
        }
Ejemplo n.º 2
0
        private void BtnOperation_Click(object sender, RoutedEventArgs e)
        {
            CompanyList = (CompanyList)Owner;

            if (Verb == "Add")
            {
                if (ValidateFields())
                {
                    // Form validated as correct and will be saved as a new company.
                    CompanyList.Dashboard.Companies.List.Add(new Company()
                    {
                        Id            = FindId(),
                        Name          = txtCompanyName.Text,
                        ContactPerson = txtContactPerson.Text,
                        Phone         = txtPhone.Text,
                        Email         = txtEmail.Text,
                        Website       = txtWebsite.Text,
                        Address       = txtAddress.Text,
                        City          = txtCity.Text,
                        State         = txtState.Text,
                        PostCode      = txtPostCode.Text,
                        Country       = cboCountry.Text
                    });
                    CompanyList.Dashboard.Modified = true;
                }
            }
            else if (Verb == "Edit")
            {
                if (ValidateFields())
                {
                    // Form validated as correct and will save changes made to the company
                    Company Company = (Company)this.DataContext;
                    Company.Name          = txtCompanyName.Text;
                    Company.ContactPerson = txtContactPerson.Text;
                    Company.Phone         = txtPhone.Text;
                    Company.Email         = txtEmail.Text;
                    Company.Website       = txtWebsite.Text;
                    Company.Address       = txtAddress.Text;
                    Company.City          = txtCity.Text;
                    Company.State         = txtState.Text;
                    Company.PostCode      = txtPostCode.Text;
                    Company.Country       = cboCountry.Text;

                    CompanyList.Dashboard.Modified = true;
                }
            }
            else if (Verb == "Delete")
            {
                // Ensure that user is serious about deleting the company.
                MessageBoxResult MessageBoxResult = MessageBox.Show(
                    "Are you sure you want to delete this Company?",
                    "Confirm",
                    MessageBoxButton.YesNo,
                    MessageBoxImage.Warning
                    );

                // User is serious.
                if (MessageBoxResult == MessageBoxResult.Yes)
                {
                    Company Company = (Company)this.DataContext;
                    CompanyList.Dashboard.Companies.List.Remove(Company);

                    CompanyList.Dashboard.Modified = true;
                }
            }

            // Refresh companies list as the company list window itemsource for the listview is not bound.
            if (Valid)
            {
                CompanyList.RefreshCompaniesList();
                this.Close();
            }
        }