Exemplo n.º 1
0
 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;
        }
Exemplo n.º 3
0
        // 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;
                }
            }
        }
Exemplo n.º 5
0
 public int DeleteAccountById(int id)
 {
     DBManager db = new DBManager();
     return db.DeleteAccountById(id);
 }
Exemplo n.º 6
0
 public List<AccountDB> GetAllAccounts()
 {
     DBManager db = new DBManager();
     return db.GetAllDisplayAccounts();
 }
Exemplo n.º 7
0
 public int AddNewAccount(string username, string password, int accountTypeId)
 {
     DBManager db = new DBManager();
     return db.AddNewAccount(username, password, accountTypeId);
 }
Exemplo n.º 8
0
 public List<GroupDB> SearchGroups(string search, int offset, int limitPerPage)
 {
     DBManager db = new DBManager();
     return db.SearchGroups(search, offset, limitPerPage);
 }
Exemplo n.º 9
0
 public int SetPreferredHostNameOrder(HostNameOrderDB hostOrderName)
 {
     DBManager db = new DBManager();
     return db.SetPreferredHostNameOrder(hostOrderName);
 }
Exemplo n.º 10
0
 public int DeleteGroup(int id)
 {
     DBManager db = new DBManager();
     return db.DeleteGroupById(id);
 }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        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);
                    }
                }
            }
        }
Exemplo n.º 13
0
        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;
        }
Exemplo n.º 14
0
 // fax
 public List<FaxDB> GetAllFaxByContactId(int contactId)
 {
     DBManager db = new DBManager();
     return db.GetAllFaxByContactId(contactId);
 }
Exemplo n.º 15
0
 public int DeleteGroupList(List<int> IdList)
 {
     DBManager db = new DBManager();
     return db.DeleteGroupByIdList(IdList);
 }
Exemplo n.º 16
0
 // email type
 public List<EmailTypeDB> GetAllEmailType()
 {
     DBManager db = new DBManager();
     return db.GetAllEmailType();
 }
Exemplo n.º 17
0
 // email
 public List<EmailDB> GetAllEmailByContactId(int contactId)
 {
     DBManager db = new DBManager();
     return db.GetAllEmailByContactId(contactId);
 }
Exemplo n.º 18
0
 public int AddContactBareData(ContactBareDataDB bareData)
 {
     DBManager db = new DBManager();
     return db.AddContactBareData(bareData);
 }
Exemplo n.º 19
0
 // bare data
 public ContactBareDataDB GetContactBareDataByContactId(int contactId)
 {
     DBManager db = new DBManager();
     return db.GetContactBareDataByContactId(contactId);
 }
Exemplo n.º 20
0
 public int DeleteGroupContactIdList(int groupId, List<int> IdList)
 {
     DBManager db = new DBManager();
     return db.DeleteGroupContactIdList(groupId, IdList);
 }
Exemplo n.º 21
0
 public AccountDB GetAccountById(int id)
 {
     DBManager db = new DBManager();
     return db.GetAccountById(id);
 }
Exemplo n.º 22
0
 // fax type
 public List<FaxTypeDB> GetAllFaxType()
 {
     DBManager db = new DBManager();
     return db.GetAllFaxType();
 }
Exemplo n.º 23
0
        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);
            }
        }
Exemplo n.º 24
0
 public List<FaxTypeDB> GetAllFaxTypeByAccountTypeName(string accountTypeString)
 {
     DBManager db = new DBManager();
     return db.GetAllFaxTypeByAccountTypeName(accountTypeString);
 }
Exemplo n.º 25
0
 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");
     }
 }
Exemplo n.º 26
0
 public int SetPreferredListFaxType(List<FaxTypeDB> listFaxType)
 {
     DBManager db = new DBManager();
     return db.SetPreferredListFaxType(listFaxType);
 }
Exemplo n.º 27
0
 // host name order
 
 public List<ContactNameOrderDB> GetAllNameOrder()
 {
     DBManager db = new DBManager();
     return db.GetAllNameOrder();
 }
Exemplo n.º 28
0
 public HostNameOrderDB GetHostNameOrder(string accountTypeString)
 {
     DBManager db = new DBManager();
     return db.GetHostNameOrder(accountTypeString);
 }
Exemplo n.º 29
0
        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);
            }
        }
Exemplo n.º 30
0
 // Account Type
 public List<AccountTypeDB> GetAccountTypeList()
 {
     DBManager db = new DBManager();
     return db.GetAllAccountTypeForWindow(); ;
 }