public void Clone(EmailDB emailDB) { if (emailDB != null) { id = emailDB.Id; accountTypeId = emailDB.AccountTypeId; accTypeName = emailDB.AccountTypeName; emailType = new EmailTypeDB(); emailType.Clone(emailDB.EmailType); value = emailDB.Value; } }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int count = listContact.Count(); if (IsMaximumContactExeed(count)) { return; } YahooContact yContact; for (int i = 0; i < count; i++) { yContact = listContact[i]; ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_YAHOO_STRING; string fullName = yContact.GivenName + " " + yContact.FamilyName + " " + yContact.MiddleName; contact.Id = -1; contact.FirstName = yContact.GivenName; contact.MiddleName = yContact.MiddleName; contact.LastName = yContact.FamilyName; // add list email List<EmailDB> listEmail = new List<EmailDB>(); List<TypeAndValue> emails = yContact.Emails; int size = emails.Count(); TypeAndValue typeAndValue; for (int j = 0; j < size; j++) { typeAndValue = emails[j]; EmailDB emailDB = new EmailDB(); emailDB.Value = typeAndValue.Value; EmailTypeDB emailType = new EmailTypeDB(); string type = typeAndValue.Type; if (type.Equals("PERSONAL")) { emailType.Name = EmailTypeDB.YAHOO_EMAIL_TYPE_HOME_STRING; } else if (type.Equals("WORK")) { emailType.Name = EmailTypeDB.YAHOO_EMAIL_TYPE_WORK_STRING; } else { emailType.Name = EmailTypeDB.YAHOO_EMAIL_TYPE_EMAIL_STRING; } emailType.AccountTypeName = AccountTypeDB.TYPE_YAHOO_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_YAHOO_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); List<TypeAndValue> phones = yContact.Phones; size = phones.Count(); for (int j = 0; j < size; j++) { typeAndValue = phones[j]; string type = typeAndValue.Type; if (type.Equals("FAX")) { FaxDB faxDB = new FaxDB(); faxDB.Value = typeAndValue.Value; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.YAHOO_FAX_TYPE_FAX_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_YAHOO_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_YAHOO_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } } contact.ListFax = listFax; list.Add(contact); } // save/update database DBManager db = new DBManager(); int res = db.AddOrUpdateContacts(list); // notify UI if (res > 0) { NotifyDownloadStatus(DownloadStatus.DONE, String.Format(AddressBook.Controller.Properties.Resources.import_num_contacts, res)); } else { NotifyDownloadStatus(DownloadStatus.INFORM, AddressBook.Controller.Properties.Resources.no_contact_added); } }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int size = listContact.Count(); if (IsMaximumContactExeed(size)) { return; } foreach (Item item in listContact) { Contact eContact = item as Contact; if (eContact != null) { ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; contact.Id = -1; contact.FirstName = eContact.GivenName; contact.MiddleName = eContact.MiddleName; contact.LastName = eContact.Surname; // add list email List<EmailDB> listEmail = new List<EmailDB>(); EmailAddressDictionary emailCollection = eContact.EmailAddresses; // email 1 EmailAddress emailAddr; emailCollection.TryGetValue(EmailAddressKey.EmailAddress1, out emailAddr); string email = emailAddr != null ? emailAddr.Address : null; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.EXCHANGE_EMAIL_TYPE_EMAIL_1_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } // email 2 emailCollection.TryGetValue(EmailAddressKey.EmailAddress2, out emailAddr); email = emailAddr != null ? emailAddr.Address : null; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.EXCHANGE_EMAIL_TYPE_EMAIL_2_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } // email 3 emailCollection.TryGetValue(EmailAddressKey.EmailAddress3, out emailAddr); email = emailAddr != null ? emailAddr.Address : null; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.EXCHANGE_EMAIL_TYPE_EMAIL_3_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); PhoneNumberDictionary phoneDictionary = eContact.PhoneNumbers; // home fax string fax; phoneDictionary.TryGetValue(PhoneNumberKey.HomeFax, out fax); if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.EXCHANGE_FAX_TYPE_HOME_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } // work fax phoneDictionary.TryGetValue(PhoneNumberKey.BusinessFax, out fax); if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.EXCHANGE_FAX_TYPE_WORK_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } // other fax phoneDictionary.TryGetValue(PhoneNumberKey.OtherFax, out fax); if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.EXCHANGE_FAX_TYPE_OTHER_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_EXCHANGE_SERVER_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } contact.ListFax = listFax; list.Add(contact); } } // save/update database DBManager db = new DBManager(); int res = db.AddOrUpdateContacts(list); // notify UI if (res > 0) { NotifyDownloadStatus(DownloadStatus.DONE, String.Format(AddressBook.Controller.Properties.Resources.import_num_contacts, res)); } else { NotifyDownloadStatus(DownloadStatus.INFORM, AddressBook.Controller.Properties.Resources.no_contact_added); } }
public void Clone(EmailTypeDB typeDB) { if (typeDB != null) { id = typeDB.Id; name = typeDB.Name; accTypeId = typeDB.AccountTypeId; accTypeName = typeDB.AccountTypeName; isPreferred = typeDB.IsPreferred; } }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int count = listContact.Count; if (IsMaximumContactExeed(count)) { return; } int realCount = 0; for (int i = 0; i < count; i++) { if (!(listContact[i + 1] is ContactItem)) { continue; } realCount++; ContactItem oContact = (ContactItem)listContact[i + 1]; ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; contact.Id = -1; contact.FirstName = oContact.FirstName; contact.MiddleName = oContact.MiddleName; contact.LastName = oContact.LastName; // add list email List<EmailDB> listEmail = new List<EmailDB>(); // email 1 string email = oContact.Email1Address; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.OUTLOOK_EMAIL_TYPE_EMAIL_1_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } // email 2 email = oContact.Email2Address; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.OUTLOOK_EMAIL_TYPE_EMAIL_2_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } // email 3 email = oContact.Email3Address; if (!String.IsNullOrEmpty(email)) { EmailDB emailDB = new EmailDB(); emailDB.Value = email; EmailTypeDB emailType = new EmailTypeDB(); emailType.Name = EmailTypeDB.OUTLOOK_EMAIL_TYPE_EMAIL_3_STRING; emailType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); // home fax string fax = oContact.HomeFaxNumber; if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.OUTLOOK_FAX_TYPE_HOME_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } // work fax fax = oContact.BusinessFaxNumber; if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.OUTLOOK_FAX_TYPE_WORK_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } // other fax fax = oContact.OtherFaxNumber; if (!String.IsNullOrEmpty(fax)) { FaxDB faxDB = new FaxDB(); faxDB.Value = fax; FaxTypeDB faxType = new FaxTypeDB(); faxType.Name = FaxTypeDB.OUTLOOK_FAX_TYPE_OTHER_STRING; faxType.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_OUTLOOK_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } contact.ListFax = listFax; list.Add(contact); } // save/update database DBManager db = new DBManager(); int res = db.AddOrUpdateContacts(list); // notify UI if (res > 0) { NotifyDownloadStatus(DownloadStatus.DONE, String.Format(AddressBook.Controller.Properties.Resources.import_num_contacts, res)); } else { NotifyDownloadStatus(DownloadStatus.INFORM, AddressBook.Controller.Properties.Resources.no_contact_added); } }
// email public List<EmailDB> GetAllEmailByContactId(int contactId) { string query = "SELECT email.id as id, email.value as value, email_type_id, email_type.name as name, email_type.preferred as preferred " + "FROM email, email_type where email.email_type_id = email_type.id and " + "contact_id = @contactId"; //Create a list to store the result List<EmailDB> list = new List<EmailDB>(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@contactId", contactId); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); int email_type_id = Int32.Parse(dataReader["email_type_id"].ToString()); string value = dataReader["value"].ToString(); string email_type_name = dataReader["name"].ToString(); bool preferred = Int32.Parse(dataReader["preferred"].ToString()) == 1; EmailDB email = new EmailDB(); email.Id = id; email.Value = value; EmailTypeDB type = new EmailTypeDB(); type.Id = email_type_id; type.Name = email_type_name; type.IsPreferred = preferred; email.EmailType = type; list.Add(email); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return list; }
public List<EmailTypeDB> GetAllEmailTypeByAccountTypeName(string accountTypeName) { string query = "SELECT email_type.id as id, email_type.name as name, account_type_id, preferred" + " FROM email_type, account_type where account_type.name = @type_name and account_type.id = account_type_id"; //Create a list to store the result List<EmailTypeDB> list = new List<EmailTypeDB>(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@type_name", accountTypeName); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); int account_type_id = Int32.Parse(dataReader["account_type_id"].ToString()); string name = dataReader["name"].ToString(); bool preferred = Int32.Parse(dataReader["preferred"].ToString()) == 1; EmailTypeDB type = new EmailTypeDB(); type.Id = id; type.Name = name; type.AccountTypeId = account_type_id; type.AccountTypeName = accountTypeName; type.IsPreferred = preferred; list.Add(type); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return list; }
// Email Type - Fax Type public EmailTypeDB GetPreferredEmailTypeByAccountTypeName(string accTypeName) { EmailTypeDB type = new EmailTypeDB(); if (this.OpenConnection() == true) { string query = "SELECT email_type.id as id, email_type.name as name, account_type_id " + "FROM account_type, email_type " + "where account_type.id = account_type_id and preferred = 1 and account_type.name = @hostName"; //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@hostName", accTypeName); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { int id = Int32.Parse(dataReader["id"].ToString()); int account_type_id = Int32.Parse(dataReader["account_type_id"].ToString()); string name = dataReader["name"].ToString(); type.Id = id; type.Name = name; type.AccountTypeId = account_type_id; type.AccountTypeName = accTypeName; type.IsPreferred = true; break; } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return type; }
public FileImportResult ImportFromVCFFile(string path) { FileImportResult result = new FileImportResult(); try { File.ReadAllText(path); } catch (Exception e) { result.errorCode = CODE_FILE_IN_USE; return result; } vCard card = null; try { card = new vCard(path); } catch (Exception ex) { result.errorCode = CODE_FILE_STRUCTURE_NOT_SUITABLE; return result; } List<EmailDB> listEmail = new List<EmailDB>(); List<FaxDB> listFax = new List<FaxDB>(); // get email vCardEmailAddressCollection listVEmail = card.EmailAddresses; if (listVEmail != null && listVEmail.Count() > 0) { foreach (vCardEmailAddress vEmail in listVEmail) { EmailDB emailDB = new EmailDB(); emailDB.Value = vEmail.Address; EmailTypeDB emailType = new EmailTypeDB(); if (vEmail.ItemType.ToString().Equals("HOME")) { emailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; } else if (vEmail.ItemType.ToString().Equals("WORK")) { emailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING; } else { emailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_OTHER_STRING; } emailType.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } } // get fax vCardPhoneCollection listVPhone = card.Phones; if (listVPhone != null && listVPhone.Count() > 0) { foreach (vCardPhone vphone in listVPhone) { if (vphone.IsFax) { FaxDB faxDB = new FaxDB(); faxDB.Value = vphone.FullNumber; FaxTypeDB faxType = new FaxTypeDB(); if (vphone.IsHome) { faxType.Name = FaxTypeDB.VCF_FAX_TYPE_HOME_STRING; } else if (vphone.IsWork) { faxType.Name = FaxTypeDB.VCF_FAX_TYPE_WORK_STRING; } else { faxType.Name = FaxTypeDB.VCF_FAX_TYPE_OTHER_STRING; } faxType.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } } } AccountDB account = dbManager.GetVCFAccount(); string accTypeName = AccountTypeDB.TYPE_VCF_STRING; List<ContactDB> listContact = new List<ContactDB>(); ContactDB contact = new ContactDB(); contact.AccountId = account.Id; contact.AccountTypeName = accTypeName; contact.Id = -1; contact.FirstName = card.GivenName; contact.MiddleName = card.AdditionalNames; contact.LastName = card.FamilyName; contact.ListEmail = listEmail; contact.ListFax = listFax; listContact.Add(contact); return AddOrUpdateContact(listContact); }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); if (IsMaximumContactExeed(listContact.Entries.Count())) { return; } foreach (Contact gContact in listContact.Entries) { ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; string title = gContact.Title; string[] names = ContactDB.GetFirstMidLastFromFullName(title, ContactDB.NAME_ORDER_FIRST_MID_LAST); contact.Id = -1; contact.FirstName = names[0]; contact.MiddleName = names[1]; contact.LastName = names[2]; // add list email List<EmailDB> listEmail = new List<EmailDB>(); foreach (EMail email in gContact.Emails) { EmailDB emailDB = new EmailDB(); emailDB.Value = email.Address; EmailTypeDB emailType = new EmailTypeDB(); if (email.Home) { emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_HOME_STRING; } else if (email.Work) { emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_WORK_STRING; } else { emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_OTHER_STRING; } emailType.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); foreach (PhoneNumber phone in gContact.Phonenumbers) { Object relObj = phone.Attributes["rel"]; string type = relObj != null ? relObj.ToString() : ""; if (type.EndsWith("fax")) { FaxDB faxDB = new FaxDB(); faxDB.Value = phone.Value; FaxTypeDB faxType = new FaxTypeDB(); if (type.EndsWith("home_fax")) { faxType.Name = FaxTypeDB.GMAIL_FAX_TYPE_HOME_STRING; } else if (type.EndsWith("work_fax")) { faxType.Name = FaxTypeDB.GMAIL_FAX_TYPE_WORK_STRING; } faxType.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } } contact.ListFax = listFax; list.Add(contact); } // save/update database DBManager db = new DBManager(); int res = db.AddOrUpdateContacts(list); // notify UI if (res > 0) { NotifyDownloadStatus(DownloadStatus.DONE, String.Format(AddressBook.Controller.Properties.Resources.import_num_contacts, res)); } else { NotifyDownloadStatus(DownloadStatus.INFORM, AddressBook.Controller.Properties.Resources.no_contact_added); } }