public static void Delete(Contact c) { if (c != null) { Contacts.Remove(c); } }
public static void Add(Contact e) { if (e != null) { e.Id = ContactService.Contacts.Count + 1; Contacts.Add(e); } }
//Methods //Add new contact || Edit mode turned off public void Button_AddContact(object sender, RoutedEventArgs e) { //Open Window var window = new ConnectedWindow { Owner = this }; //Set new window to Edit Mode Off window.IsEditMode = false; //Load Entry here Contact newContact = new Contact(); //Load new contact with injection function window.LoadEntry(newContact); //Open Dialog window.ShowDialog(); }
//Save currentContact || Edit mode Bool private void SavecurrentContact(Contact currentContact) { //Check input on required textboxes if (!checkTextBoxInput()) { return; } currentContact.Address1 = textBox_Address1.Text; currentContact.Address2 = textBox_Address2.Text; //Format Date correctly on Save currentContact.Birthdate = textBox_DOB.Text.ToString(); currentContact.City = textBox_City.Text; currentContact.EmailAddress = textBox_Email.Text; currentContact.FirstName = textBox_FirstName.Text; currentContact.LastName = textBox_LastName.Text; //Get State currentContact.State = ConnectedWindow_ComboBox_State.SelectedItem.ToString(); currentContact.TelephoneNumber = textBox_TelephoneNumber.Text; currentContact.Zip = textBox_Zip.Text; //Save Category if (ConnectedWinow_radioButton_None.IsChecked == true) { string input = "None"; currentContact.Category = input; MessageBox.Show(currentContact.Category); } else if (ConnectedWindow_radioButton_Work.IsChecked == true) { string input = "Work"; currentContact.Category = input; MessageBox.Show(currentContact.Category); } else if (ConnectedWindow_radioButton_General.IsChecked == true) { string input = "General"; currentContact.Category = input; MessageBox.Show(currentContact.Category); } else if (ConnectedWindow_radioButton_Personal.IsChecked == true) { string input = "Personal"; currentContact.Category = input; MessageBox.Show(currentContact.Category); } else { string input = "None"; currentContact.Category = input; MessageBox.Show(currentContact.Category); } //Edit mode bool if (IsEditMode == true) { // get a reference to the main window var mainwindow = (MainWindow)Owner; // trigger a refresh mainwindow.dataGrid_ContactList.Items.Refresh(); } //If not in edit Mode, add new currentContact else { ContactService.Add(currentContact); } //Close Window Close(); }
//Load Entry to Edit public void LoadEntry(Contact entry) { currentContact = entry; }
//***********Under Construction //Open File Code public void OpenFile() { OpenFileDialog dialog = new OpenFileDialog(); bool? openFile = dialog.ShowDialog(); if (openFile == true) { //Get the file name the user chose fileName = dialog.FileName; //open the file and read the contents into a string string myFile = File.ReadAllText(fileName); try { Contact NewList = JsonConvert.DeserializeObject<Contact>(myFile); ContactList = NewList; //Refresh the DataGrid dataGrid_ContactList.ItemsSource = null; dataGrid_ContactList.ItemsSource = ContactService.Contacts; } catch (Exception) { MessageBox.Show("Error opening file, please contact system Admin"); } } }