public void UpdateEmailTypeDB() { emailType = new EmailTypeDB(); emailType.Id = EmailTypeId; emailType.Name = EmailTypeName; emailType.IsPreferred = IsPreferred; }
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; } }
public List<EmailTypeDB> GetAllEmailTypeByAccountTypeName(string accountTypeName) { string query = "SELECT email_type.id as id, email_type.name as name, account_type_id, preferred, default_value" + " 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) { if (accountTypeName.Equals("File CSV, vCard")) { query = "SELECT email_type.id as id, email_type.name as name, account_type_id, preferred, default_value" + " FROM email_type, account_type where account_type.name = @type_name and account_type.id = account_type_id"; //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); cmd.Parameters.AddWithValue("@type_name", "CSV"); //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; int default_value = Int32.Parse(dataReader["default_value"].ToString()); EmailTypeDB type = new EmailTypeDB(); type.Id = id; type.Name = name; type.AccountTypeId = account_type_id; type.AccountTypeName = accountTypeName; type.IsPreferred = preferred; type.DefaultValue = default_value; list.Add(type); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } else { //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; int default_value = Int32.Parse(dataReader["default_value"].ToString()); EmailTypeDB type = new EmailTypeDB(); type.Id = id; type.Name = name; type.AccountTypeId = account_type_id; type.AccountTypeName = accountTypeName; type.IsPreferred = preferred; type.DefaultValue = default_value; list.Add(type); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } } return list; }
public EmailTypeDB GetPreferEmailFromCSVSetting() { string query = "SELECT * FROM email_type " + "WHERE account_type_id = 9 AND preferred = 1"; EmailTypeDB preferredEmail = new EmailTypeDB(); //Open connection if (this.OpenConnection() == true) { //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); //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; preferredEmail.Id = id; preferredEmail.Name = name; preferredEmail.AccountTypeId = account_type_id; preferredEmail.IsPreferred = preferred; } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return preferredEmail; }
public List<EmailTypeDB> GetEmailTypeByContactId(int contactId) { string query = "SELECT * FROM email_type " + "WHERE account_type_id = " + "(SELECT DISTINCT account_new.account_type_id " + "FROM contact LEFT JOIN email ON contact.id = email.contact_id " + "JOIN (SELECT account.id as id, account_type.id as account_type_id " + "FROM account JOIN account_type ON account_type.id = account.account_type_id) as account_new ON contact.account_id = account_new.id " + "WHERE contact.id=@contactId)"; //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("@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 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.IsPreferred = preferred; list.Add(type); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return list; }
public List<EmailTypeDB> GetAllEmailType() { string query = "SELECT email_type.id as id, email_type.name as name, account_type_id, preferred, account_type.name as type_name" + " FROM email_type, account_type where 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); //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(); string typeName = dataReader["type_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 = typeName; 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; }
private void AddOrUpdateContactsToDatabase() { if (isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int count = listContact.Count; for (int i = 0; i < count; i++) { if (!(listContact[i + 1] is ContactItem)) { continue; } 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); } CheckMaximumAndImport(list); }
// Email Type - Fax Type public EmailTypeDB GetPreferredEmailTypeByAccountTypeName(string accTypeName) { string query = "SELECT email_type.id as Id, email_type.name as Name, account_type_id as AccountTypeId, account_type.name as AccountTypeName " + "FROM account_type, email_type " + "where account_type.id = account_type_id and preferred = 1 and account_type.name = ?"; EmailTypeDB type = connection.Query<EmailTypeDB>(query, accTypeName).First(); if (type == null) { type = new EmailTypeDB(); } 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); }
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>(); EmailTypeDB preferEmailTypeFile = dbManager.GetPreferEmailFromCSVSetting(); // get email vCardEmailAddressCollection listVEmail = card.EmailAddresses; if (listVEmail != null && listVEmail.Count() > 0) { EmailDB preferEmailDB = new EmailDB(); EmailTypeDB preferEmailType = new EmailTypeDB(); //process Email1 from VCard foreach (vCardEmailAddress vEmail in listVEmail) { if (vEmail.IsPreferred == true && preferEmailTypeFile.Name.Equals("Home")) { preferEmailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; preferEmailDB.Value = vEmail.Address; preferEmailType.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.EmailType = preferEmailType; listEmail.Add(preferEmailDB); listVEmail.Remove(vEmail); break; } else if (vEmail.IsPreferred == true && preferEmailTypeFile.Name.Equals("Work")) { preferEmailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING; preferEmailDB.Value = vEmail.Address; preferEmailType.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.EmailType = preferEmailType; listEmail.Add(preferEmailDB); listVEmail.Remove(vEmail); break; } else if (vEmail.IsPreferred == true && preferEmailTypeFile.Name.Equals("Other")) { preferEmailType.Name = EmailTypeDB.VCF_EMAIL_TYPE_OTHER_STRING; preferEmailDB.Value = vEmail.Address; preferEmailType.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; preferEmailDB.EmailType = preferEmailType; listEmail.Add(preferEmailDB); listVEmail.Remove(vEmail); break; } } if (listVEmail.Count() == 1) { //process Email2 from VCard EmailDB email2DB = new EmailDB(); email2DB.Value = listVEmail[0].Address; email2DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; email2DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; EmailTypeDB email2Type = new EmailTypeDB(); switch (preferEmailTypeFile.Name) { case "Home": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING; break; case "Work": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; break; case "Other": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; break; } email2DB.EmailType = email2Type; listEmail.Add(email2DB); } else if (listVEmail.Count() == 2) { //process Email2 from VCard EmailDB email2DB = new EmailDB(); email2DB.Value = listVEmail[0].Address; email2DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; email2DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; //process Email3 from VCard EmailDB email3DB = new EmailDB(); email3DB.Value = listVEmail[1].Address; email3DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; email3DB.AccountTypeName = AccountTypeDB.TYPE_VCF_STRING; EmailTypeDB email2Type = new EmailTypeDB(); EmailTypeDB email3Type = new EmailTypeDB(); switch (preferEmailTypeFile.Name) { case "Home": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING; email3Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_OTHER_STRING; break; case "Work": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; email3Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_OTHER_STRING; break; case "Other": email2Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_HOME_STRING; email3Type.Name = EmailTypeDB.VCF_EMAIL_TYPE_WORK_STRING; break; } email2DB.EmailType = email2Type; email3DB.EmailType = email3Type; listEmail.Add(email2DB); listEmail.Add(email3DB); } } // 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>(); int count = listContact.Count; ICloudContact iContact; for (int i = 0; i < count; i++) { iContact = listContact[i]; ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_ICLOUD_STRING; contact.Id = -1; contact.FirstName = iContact.FirstName; contact.MiddleName = iContact.MiddleName; contact.LastName = iContact.LastName; // add list email List<EmailDB> listEmail = new List<EmailDB>(); List<TypeAndValue> emails = iContact.EmailAddresses; 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("HOME")) { emailType.Name = EmailTypeDB.ICLOUD_EMAIL_TYPE_HOME_STRING; } else if (type.Equals("WORK")) { emailType.Name = EmailTypeDB.ICLOUD_EMAIL_TYPE_WORK_STRING; } else { emailType.Name = EmailTypeDB.ICLOUD_EMAIL_TYPE_OTHER_STRING; } emailType.AccountTypeName = AccountTypeDB.TYPE_ICLOUD_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_ICLOUD_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); List<TypeAndValue> phones = iContact.Phones; size = phones.Count(); for (int j = 0; j < size; j++) { typeAndValue = phones[j]; string type = typeAndValue.Type; if (type.EndsWith("FAX")) { FaxDB faxDB = new FaxDB(); faxDB.Value = typeAndValue.Value; FaxTypeDB faxType = new FaxTypeDB(); if (type.Equals("HOME FAX")) { faxType.Name = FaxTypeDB.ICLOUD_FAX_TYPE_HOME_STRING; } else if (type.Equals("WORK FAX")) { faxType.Name = FaxTypeDB.ICLOUD_FAX_TYPE_WORK_STRING; } else { faxType.Name = FaxTypeDB.ICLOUD_FAX_TYPE_OTHER_STRING; } faxType.AccountTypeName = AccountTypeDB.TYPE_ICLOUD_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_ICLOUD_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } } contact.ListFax = listFax; list.Add(contact); } CheckMaximumAndImport(list); }
private void AddOrUpdateContactsToDatabase() { if (isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); 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); } CheckMaximumAndImport(list); }
public void Clone(EmailTypeDB typeDB) { if (typeDB != null) { id = typeDB.Id; name = typeDB.Name; accTypeId = typeDB.AccountTypeId; accTypeName = typeDB.AccountTypeName; isPreferred = typeDB.IsPreferred; } }
public List<EmailDB> GetAllEmailByContactIdGroupByEmailType(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 (select * from email order by id desc) as email, email_type where email.email_type_id = email_type.id and " + "contact_id = @contactId GROUP BY email.email_type_id"; //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; }
private void AddOrUpdateContactsToDatabase() { if (isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int count = listContact.Count(); LiveContact lContact; for (int i = 0; i < count; i++) { lContact = listContact[i]; ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING; contact.Id = -1; contact.FirstName = lContact.First_name; contact.LastName = lContact.Last_name; // add list email List<EmailDB> listEmail = new List<EmailDB>(); List<TypeAndValue> emails = lContact.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.LIVE_EMAIL_TYPE_PERSONAL_STRING; } else if (type.Equals("business")) { emailType.Name = EmailTypeDB.LIVE_EMAIL_TYPE_BUSINESS_STRING; } else { emailType.Name = EmailTypeDB.LIVE_EMAIL_TYPE_OTHER_STRING; } emailType.AccountTypeName = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING; emailDB.AccountTypeName = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING; emailDB.EmailType = emailType; listEmail.Add(emailDB); } contact.ListEmail = listEmail; // add list fax List<FaxDB> listFax = new List<FaxDB>(); List<TypeAndValue> phones = lContact.Phones; size = phones.Count(); for (int j = 0; j < size; j++) { typeAndValue = phones[j]; string type = typeAndValue.Type; if (type.EndsWith("fax")) { FaxDB faxDB = new FaxDB(); faxDB.Value = typeAndValue.Value; FaxTypeDB faxType = new FaxTypeDB(); if (type.Equals("home_fax")) { faxType.Name = FaxTypeDB.LIVE_FAX_TYPE_HOME_STRING; } else if (type.Equals("work_fax")) { faxType.Name = FaxTypeDB.LIVE_FAX_TYPE_WORK_STRING; } faxType.AccountTypeName = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING; faxDB.AccountTypeName = AccountTypeDB.TYPE_LIVE_HOTMAIL_STRING; faxDB.FaxType = faxType; listFax.Add(faxDB); } } contact.ListFax = listFax; list.Add(contact); } CheckMaximumAndImport(list); }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); 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); } } CheckMaximumAndImport(list); }
public List<EmailTypeDB> GetEmailType() // ttt { List<EmailTypeDB> lists = new List<EmailTypeDB>(); if (this.OpenConnection() == true) { string query = "SELECT * FROM email_type"; //Create Command SQLiteCommand cmd = new SQLiteCommand(query, connection); //Create a data reader and Execute the command SQLiteDataReader dataReader = cmd.ExecuteReader(); //Read the data and store them in the list while (dataReader.Read()) { EmailTypeDB emailTypeDB = new EmailTypeDB(); int id = Int32.Parse(dataReader["id"].ToString()); int account_type_id = Int32.Parse(dataReader["account_type_id"].ToString()); string name = dataReader["name"].ToString(); int preferred = int.Parse(dataReader["preferred"].ToString()); emailTypeDB.Id = id; emailTypeDB.AccountTypeId = account_type_id; emailTypeDB.Name = name; lists.Add(emailTypeDB); } //close Data Reader dataReader.Close(); //close Connection this.CloseConnection(); } return lists; }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); int count = listContact.Count(); 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); } CheckMaximumAndImport(list); }
private void AddOrUpdateContactsToDatabase() { if(isUserCancel) { return; } List<ContactDB> list = new List<ContactDB>(); foreach (GoogleContact gContact in listContact) { ContactDB contact = new ContactDB(); contact.AccountId = this.account.Id; contact.AccountTypeName = AccountTypeDB.TYPE_GMAIL_STRING; contact.Id = -1; contact.FirstName = gContact.GivenName; contact.MiddleName = gContact.MiddleName; contact.LastName = gContact.FamilyName; // add list email List<EmailDB> listEmail = new List<EmailDB>(); foreach (TypeAndValue email in gContact.Emails) { EmailDB emailDB = new EmailDB(); emailDB.Value = email.Value; EmailTypeDB emailType = new EmailTypeDB(); string type = email.Type; if (String.Compare(type, "home") == 0) { emailType.Name = EmailTypeDB.GMAIL_EMAIL_TYPE_HOME_STRING; } else if (String.Compare(type, "work") == 0) { 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 (TypeAndValue phone in gContact.Phones) { string type = phone.Type; if (type.EndsWith("fax")) { FaxDB faxDB = new FaxDB(); faxDB.Value = phone.Value; FaxTypeDB faxType = new FaxTypeDB(); if (String.Compare(type, "home_fax") == 0) { faxType.Name = FaxTypeDB.GMAIL_FAX_TYPE_HOME_STRING; } else if (String.Compare(type, "work_fax") == 0) { 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); } CheckMaximumAndImport(list); }