public int DeleteAccountList(List<int> IdList) { DBManager db = new DBManager(); foreach(int id in IdList) { db.DeleteAccountById(id); } return 1; }
public void SaveDatabaseParameters(int contactLimit, int groupLimit) { DBManager db = new DBManager(); string saveData = "{"; saveData += "'contact_limit':" + contactLimit + ","; saveData += "'group_limit':" + groupLimit; saveData += "}"; SecurityManager secMng = new SecurityManager(); saveData = secMng.EncryptText(saveData); db.SaveDatabaseParameters(saveData); ContactDB.MAX_CONTACT = contactLimit; GroupDB.MAX_GROUP = groupLimit; }
// Account public AccountDB GetOrAddAccountByAccountText(string accountText) { DBManager db = new DBManager(); HostType hostType = MyUtils.GetHostTypeFromAccount(accountText); string accountTypeName = AccountTypeDB.FromTypeCodeToString(hostType); AccountDB account = db.GetAccountByUserNameAndAccountTypeName(accountText, accountTypeName); if(account.Id <= 0) // add new { AccountTypeDB type = db.GetAccountTypeByName(accountTypeName); int accountID = db.AddNewAccount(accountText, "", type.Id); account = db.GetAccountById(accountID); account.HostType = hostType; } account.AccountTypeName = accountTypeName; return account; }
public void LoadDatabaseParameters() { DBManager db = new DBManager(); string text = db.LoadDatabaseParameters(); if (!String.IsNullOrEmpty(text)) { SecurityManager secMng = new SecurityManager(); string json = secMng.DecryptText(text); if (!String.IsNullOrEmpty(json)) { JToken token = null; try { token = JObject.Parse(json); } catch (Exception e) { return; } JToken temp = token.SelectToken("contact_limit"); string contact_limit = temp != null ? temp.ToString() : ""; temp = token.SelectToken("group_limit"); string group_limit = temp != null ? temp.ToString() : ""; int limitContact = 500; Int32.TryParse(contact_limit, out limitContact); limitContact = limitContact == 0 ? 500 : limitContact; int limitGroup = 20; Int32.TryParse(group_limit, out limitGroup); limitGroup = limitGroup == 0 ? 20 : limitGroup; ContactDB.MAX_CONTACT = limitContact; GroupDB.MAX_GROUP = limitGroup; } } }
public int DeleteAccountById(int id) { DBManager db = new DBManager(); return db.DeleteAccountById(id); }
public List<AccountDB> GetAllAccounts() { DBManager db = new DBManager(); return db.GetAllDisplayAccounts(); }
public int AddNewAccount(string username, string password, int accountTypeId) { DBManager db = new DBManager(); return db.AddNewAccount(username, password, accountTypeId); }
public List<GroupDB> SearchGroups(string search, int offset, int limitPerPage) { DBManager db = new DBManager(); return db.SearchGroups(search, offset, limitPerPage); }
public int SetPreferredHostNameOrder(HostNameOrderDB hostOrderName) { DBManager db = new DBManager(); return db.SetPreferredHostNameOrder(hostOrderName); }
public int DeleteGroup(int id) { DBManager db = new DBManager(); return db.DeleteGroupById(id); }
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 int CheckUpdateAccount(int id, string user, string pass, int a_type) { DBManager db = new DBManager(); int contactCount = db.GetContactCountByAccountId(id); if (contactCount == 0) { AccountDB acc = db.GetAccountByUserNameAndAccountTypeId(user, a_type); int accId = acc.Id; accId = accId > 0 ? accId : id; return (db.UpdateAccountById(accId, user, pass, a_type) > 0 ? accId : -1); } else { AccountDB account = db.GetAccountById(id); if (account.Username.Equals(user) && account.AccountTypeId == a_type) { return (db.UpdateAccountById(id, user, pass, a_type) > 0 ? id : -1); } else { AccountDB acc = db.GetAccountByUserNameAndAccountTypeId(user, a_type); int accId = acc.Id; if (accId > 0) { return (db.UpdateAccountById(accId, user, pass, a_type) > 0 ? accId : -1); } else { return db.AddNewAccount(user, pass, a_type); } } } }
protected bool IsMaximumContactExeed(int moreContactCount) { DBManager db = new DBManager(); currentContactNumber = db.GetTotalContactCount(); if (currentContactNumber + moreContactCount > ContactDB.MAX_CONTACT) { NotifyDownloadStatus(DownloadStatus.MAXIMUM_CONTACT_EXEED, "(" + ContactDB.MAX_CONTACT + " contacts)"); return true; } return false; }
// fax public List<FaxDB> GetAllFaxByContactId(int contactId) { DBManager db = new DBManager(); return db.GetAllFaxByContactId(contactId); }
public int DeleteGroupList(List<int> IdList) { DBManager db = new DBManager(); return db.DeleteGroupByIdList(IdList); }
// email type public List<EmailTypeDB> GetAllEmailType() { DBManager db = new DBManager(); return db.GetAllEmailType(); }
// email public List<EmailDB> GetAllEmailByContactId(int contactId) { DBManager db = new DBManager(); return db.GetAllEmailByContactId(contactId); }
public int AddContactBareData(ContactBareDataDB bareData) { DBManager db = new DBManager(); return db.AddContactBareData(bareData); }
// bare data public ContactBareDataDB GetContactBareDataByContactId(int contactId) { DBManager db = new DBManager(); return db.GetContactBareDataByContactId(contactId); }
public int DeleteGroupContactIdList(int groupId, List<int> IdList) { DBManager db = new DBManager(); return db.DeleteGroupContactIdList(groupId, IdList); }
public AccountDB GetAccountById(int id) { DBManager db = new DBManager(); return db.GetAccountById(id); }
// fax type public List<FaxTypeDB> GetAllFaxType() { DBManager db = new DBManager(); return db.GetAllFaxType(); }
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); } }
public List<FaxTypeDB> GetAllFaxTypeByAccountTypeName(string accountTypeString) { DBManager db = new DBManager(); return db.GetAllFaxTypeByAccountTypeName(accountTypeString); }
public void DownloadContacts(int account_type_id, string username, string password, AccountDownloadListener notify) { DBManager db = new DBManager(); AccountDB account = db.AddOrUpdateAccountByUserPassAccTypeId(username, password, account_type_id); if (account.Id > 0) { DownloadContacts(account, notify); } else { notify.NotifyStatusByAccountId(-1, DownloadStatus.DATABASE_ERROR, "Database Error"); } }
public int SetPreferredListFaxType(List<FaxTypeDB> listFaxType) { DBManager db = new DBManager(); return db.SetPreferredListFaxType(listFaxType); }
// host name order public List<ContactNameOrderDB> GetAllNameOrder() { DBManager db = new DBManager(); return db.GetAllNameOrder(); }
public HostNameOrderDB GetHostNameOrder(string accountTypeString) { DBManager db = new DBManager(); return db.GetHostNameOrder(accountTypeString); }
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); } }
// Account Type public List<AccountTypeDB> GetAccountTypeList() { DBManager db = new DBManager(); return db.GetAllAccountTypeForWindow(); ; }