private void Birthdate_LostFocus(object sender, RoutedEventArgs e) { var box = sender as TextBox; if (box != null && !box.Text.Equals(string.Empty)) { box.Text = AddressBookControl.FormatBirthdate(box.Text); } ValidateField(box); }
private string FixedUidOf(Contact contact) { if (contact == null) { return(null); } var uid = contact.Uid; Log.WriteLine("uid: {0}", uid); contact.Birthdate = AddressBookControl.FormatBirthdate(contact.Birthdate); var validUid = contact.GenerateUid(); if (uid == null || uid.Equals(string.Empty) || !validUid.Equals(uid)) { uid = validUid; } Log.WriteLine("uid: {0}", uid); return(uid); }
private void ImportContacts() { var filepath = this._csvFilepath; if (filepath == null || !File.Exists(filepath)) { return; } var contacts = new List <Contact>(); if (_contacts.Count > 0) // cached { Log.WriteLine("cached"); contacts = _contacts; } else { Log.WriteLine("loaded"); using (TextFieldParser parser = new TextFieldParser(filepath)) { parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); var i = 0; Dictionary <string, int> keys = new Dictionary <string, int>(); while (!parser.EndOfData) { string[] fields = parser.ReadFields(); // Log.WriteLine("Fields (Length): {0}", fields.Length); if (fields.Length < 60) // default keys count 61 { return; } if (i < 1) { var j = 0; // NOTE: // exported csv from (as Outlook format CSV) // // * https://outlook.live.com/people // * https://contacts.google.com // // ## Header // // Default (no change by user) Headers // // (from outlook.live.com) // First Name,Middle Name,Last Name,Title,Suffix,Nickname,Given Yomi,Surname Yomi,E-mail Address,E-mail 2 Address,E-mail 3 Address,Home Phone,Home Phone 2,Business Phone,Business Phone 2,Mobile Phone,Car Phone,Other Phone,Primary Phone,Pager,Business Fax,Home Fax,Other Fax,Company Main Phone,Callback,Radio Phone,Telex,TTY/TDD Phone,IMAddress,Job Title,Department,Company,Office Location,Manager's Name,Assistant's Name,Assistant's Phone,Company Yomi,Business Street,Business City,Business State,Business Postal Code,Business Country/Region,Home Street,Home City,Home State,Home Postal Code,Home Country/Region,Other Street,Other City,Other State,Other Postal Code,Other Country/Region,Personal Web Page,Spouse,Schools,Hobby,Location,Web Page,Birthday,Anniversary,Notes // // (from google.com) // First Name,Middle Name,Last Name,Title,Suffix,Initials,Web Page,Gender,Birthday,Anniversary,Location,Language,Internet Free Busy,Notes,E-mail Address,E-mail 2 Address,E-mail 3 Address,Primary Phone,Home Phone,Home Phone 2,Mobile Phone,Pager,Home Fax,Home Address,Home Street,Home Street 2,Home Street 3,Home Address PO Box,Home City,Home State,Home Postal Code,Home Country,Spouse,Children,Manager's Name,Assistant's Name,Referred By,Company Main Phone,Business Phone,Business Phone 2,Business Fax,Assistant's Phone,Company,Job Title,Department,Office Location,Organizational ID Number,Profession,Account,Business Address,Business Street,Business Street 2,Business Street 3,Business Address PO Box,Business City,Business State,Business Postal Code,Business Country,Other Phone,Other Fax,Other Address,Other Street,Other Street 2,Other Street 3,Other Address PO Box,Other City,Other State,Other Postal Code,Other Country,Callback,Car Phone,ISDN,Radio Phone,TTY/TDD Phone,Telex,User 1,User 2,User 3,User 4,Keywords,Mileage,Hobby,Billing Information,Directory Server,Sensitivity,Priority,Private,Categorie foreach (var text in fields) { // first match priority if (!keys.ContainsKey("GivenName") && (text.Equals("First Name") || text.Equals("Middle Name"))) { keys.Add("GivenName", j); } else if (text.Equals("Last Name")) { keys.Add("FamilyName", j); } else if (!keys.ContainsKey("Address") && (text.Equals("Home Address") || text.Equals("Home Street"))) { keys.Add("Address", j); } else if (!keys.ContainsKey("City") && (text.Equals("Home City") || text.Equals("Home State"))) { keys.Add("City", j); } else if (text.Equals("Home Postal Code")) { keys.Add("Zip", j); } else if (!keys.ContainsKey("Country") && (text.Equals("Home Country/Region") || text.Equals("Home Country"))) { keys.Add("Country", j); } else if (!keys.ContainsKey("Phone") && (text.Equals("Home Phone") || text.Equals("Mobile Phone"))) { keys.Add("Phone", j); } else if (!keys.ContainsKey("Email") && (text.Equals("E-mail Address") || text.Equals("E-mail 2 Address") || text.Equals("E-mail 3 Address"))) { keys.Add("Email", j); } else if (text.Equals("Birthday")) { keys.Add("Birthdate", j); } j++; } i++; continue; } var contact = new Contact(); if (keys.ContainsKey("GivenName")) { contact.GivenName = fields[keys["GivenName"]]; } if (keys.ContainsKey("FamilyName")) { contact.FamilyName = fields[keys["FamilyName"]]; } if (keys.ContainsKey("Address")) { contact.Address = fields[keys["Address"]]; } if (keys.ContainsKey("City")) { contact.City = fields[keys["City"]]; } if (keys.ContainsKey("Zip")) { contact.Zip = fields[keys["Zip"]]; } if (keys.ContainsKey("Country")) { contact.Country = fields[keys["Country"]]; } if (keys.ContainsKey("Phone")) { contact.Phone = fields[keys["Phone"]]; } if (keys.ContainsKey("Email")) { contact.Email = fields[keys["Email"]]; } if (keys.ContainsKey("Birthdate")) { contact.Birthdate = AddressBookControl.FormatBirthdate(fields[keys["Birthdate"]]); } if (contact.HasName) { contact.Id = i; contacts.Add(contact); } i++; } } } Log.WriteLine("contacts: {0}", contacts.Count); this._contacts = contacts; this._openCsvFile = true; this.CsvFileName.Text = Path.GetFileName(filepath); EnableFileBar(true); var clone = _contacts.Select(c => c.Clone()).ToList(); _patientDb.UpdateContactList(clone); }
private async void SaveButton_Click(object sender, RoutedEventArgs e) { Log.WriteLine(sender.GetType().Name); bool result = ValidateFields(); Contact contact = null; if (result) { Dictionary <string, string> values = GetContactValues(); contact = CurrentEntry; if (contact == null || contact.Uid == null || contact.Uid.Equals(string.Empty)) { contact = _patientDb.InitContact(values); } foreach (var v in values) { string val = v.Value; if (v.Key.Equals("Birthdate")) { val = AddressBookControl.FormatBirthdate(val); } contact[v.Key] = val; } if (contact.Uid != null && !contact.Uid.Equals(string.Empty) && contact.Uid.Equals(contact.GenerateUid())) { await _patientDb.UpdateContact(contact); await _patientDb.LoadAllContacts(); // need reload all :'( } else { // NEW Entry or `Contact.Uid` has been changed long?id = await _patientDb.InsertContact(contact); if (id != null && id.Value > 0) { contact.Id = id.Value; this.SearchPatientBox.Text = ""; } else { // TODO need another message? (already exists) ShowMessage(true); } await _patientDb.LoadAllContacts(); this.RawContactsCount = _patientDb.Count; } } if (contact == null || contact.Uid == null || !result) { return; } else { this.CurrentEntry = contact; _patientDb.UpdateContactList(); if (_openCsvFile) { this._openCsvFile = false; EnableFileBar(false); EnableButton("PlusButton", true); EnableButton("MinusButton", true); } // See ContactList_ItemStatusChanged this.ContactList.ItemContainerGenerator.StatusChanged += ContactList_ItemStatusChanged; } e.Handled = true; }