Ejemplo n.º 1
0
        /// <summary>
        /// Add new contact
        /// </summary>
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            var addContact = new AddEditContactWindow();

            addContact.lblWindowHeader.Content = "Add New Contact";
            addContact.ShowDialog();

            if (addContact.DialogResult.HasValue && addContact.DialogResult.Value)
            {
                try
                {
                    pl.AddContact(addContact.FirstName, addContact.LastName, addContact.GroupID + 1, addContact.Phones);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "\nYou must insert values to all fields", "Save failed", MessageBoxButton.OK, MessageBoxImage.Stop);
                }
            }
            UpdateGrid();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Update contact details
        /// </summary>
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (dgContactsDisplay.SelectedItems.Count == 1)
            {
                var selected    = (Person)dgContactsDisplay.SelectedItem;
                var editContact = new AddEditContactWindow(selected);
                editContact.lblWindowHeader.Content = "Update a Contact";

                editContact.ShowDialog();


                if (editContact.DialogResult.HasValue && editContact.DialogResult.Value)
                {
                    // Delete unused phones
                    foreach (Phone phone in selected.Phones)
                    {
                        if (!editContact.Phones.Exists(p => p.PhoneID == phone.PhoneID))
                        {
                            if (phone.PhoneID.HasValue)
                            {
                                pl.DeletePhone(phone.PhoneID.Value);
                            }
                        }
                    }

                    // Update any changes to contact
                    pl.UpdateContact(editContact.FirstName, editContact.LastName, editContact.GroupID + 1, editContact.Phones, Convert.ToInt32(editContact.txtID.Text));
                    MessageBox.Show("Update Successfully", "Update", MessageBoxButton.OK, MessageBoxImage.Information);
                    UpdateGrid();
                }
            }
            else if (dgContactsDisplay.SelectedItems.Count > 1)
            {
                MessageBox.Show("Please select only one contact ", "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            else
            {
                MessageBox.Show("No contact has been selected", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 3
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.winAddContact = ((GUI.AddEditContactWindow)(target));
                return;

            case 2:
                this.lblWindowHeader = ((System.Windows.Controls.Label)(target));
                return;

            case 3:
                this.lblID = ((System.Windows.Controls.Label)(target));
                return;

            case 4:
                this.txtID = ((System.Windows.Controls.TextBox)(target));
                return;

            case 5:
                this.lblFirstName = ((System.Windows.Controls.Label)(target));
                return;

            case 6:
                this.txtFirstName = ((System.Windows.Controls.TextBox)(target));
                return;

            case 7:
                this.lblLastName = ((System.Windows.Controls.Label)(target));
                return;

            case 8:
                this.txtLastName = ((System.Windows.Controls.TextBox)(target));
                return;

            case 9:
                this.lblPhoneNumber = ((System.Windows.Controls.Label)(target));
                return;

            case 10:
                this.PhoneNumbersGrid = ((System.Windows.Controls.StackPanel)(target));
                return;

            case 11:
                this.phoneControl = ((GUI.PhoneControl)(target));
                return;

            case 12:
                this.lblGroupName = ((System.Windows.Controls.Label)(target));
                return;

            case 13:
                this.cmbGroupName = ((System.Windows.Controls.ComboBox)(target));
                return;

            case 14:
                this.borderMenu = ((System.Windows.Controls.Border)(target));
                return;

            case 15:
                this.btnSave = ((System.Windows.Controls.Button)(target));

            #line 57 "..\..\..\AddEditContactWindow.xaml"
                this.btnSave.Click += new System.Windows.RoutedEventHandler(this.btnSave_Click);

            #line default
            #line hidden
                return;

            case 16:
                this.btnExit = ((System.Windows.Controls.Button)(target));

            #line 58 "..\..\..\AddEditContactWindow.xaml"
                this.btnExit.Click += new System.Windows.RoutedEventHandler(this.btnExit_Click);

            #line default
            #line hidden
                return;

            case 17:
                this.btnAddAnotherPhone = ((System.Windows.Controls.Button)(target));

            #line 61 "..\..\..\AddEditContactWindow.xaml"
                this.btnAddAnotherPhone.Click += new System.Windows.RoutedEventHandler(this.btnAddAnotherPhone_Click);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }