Exemplo n.º 1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                string username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

                int i = username.IndexOf(@"\");
                if (i != -1)
                {
                    username = username.Substring(i + 1, username.Length - i - 1);
                }
                txtUsername.Text = username;

                CommonLibrary.AppConfig appConfig = new CommonLibrary.AppConfig(Constants.GetConfigFilePath());
                contactManagement = new CommonLibrary.ActiveDirectory.ContactManagement("LDAP://" + appConfig.GetValue("DomainName"));
                contact           = contactManagement.GetUserProfile(username);
                contact.Username  = username;

                txtHomePhone.Text     = contact.HomePhone;
                txtMobilePhone.Text   = contact.MobilePhone;
                txtBusinessPhone.Text = contact.BusinessPhone;
                txtBusinessFax.Text   = contact.BusinessFax;
                txtEmail.Text         = contact.Email;
                txtAddress.Text       = contact.Address;
                txtIPPhone.Text       = contact.IPPhone;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve all user
        /// </summary>
        /// <param name="filter"> (&(objectCategory=person)(objectClass=user)(sAMAccountName=*)) </param>
        /// <returns> List of User</returns>
        public Dictionary <string, Model.Contact> RetrieveAllContact(string filter)
        {
            Dictionary <string, Model.Contact> dictionary = new Dictionary <string, Model.Contact>();

            _DirectorySearcher.Filter = filter;
            _DirectorySearcher.PropertiesToLoad.Add("displayName");
            _DirectorySearcher.PropertiesToLoad.Add("telephoneNumber");
            _DirectorySearcher.PropertiesToLoad.Add("Mobile");


            SearchResultCollection allUsers = _DirectorySearcher.FindAll();

            foreach (SearchResult result in allUsers)
            {
                if (result.Properties["displayName"].Count > 0 &&
                    !result.Properties["displayName"][0].ToString().Contains("CN=") &&
                    !result.Properties["displayName"][0].ToString().Contains("System"))
                {
                    Model.Contact contact = new CommonLibrary.Model.Contact();
                    contact.FullName    = result.Properties["displayName"][0].ToString();
                    contact.HomePhone   = result.Properties["telephoneNumber"].Count == 0? "" : result.Properties["telephoneNumber"][0].ToString();
                    contact.MobilePhone = result.Properties["Mobile"].Count == 0? "" : result.Properties["Mobile"][0].ToString();

                    if (!dictionary.ContainsKey(contact.FullName))
                    {
                        dictionary.Add(contact.FullName, contact);
                    }
                }
            }

            return(dictionary);
        }
Exemplo n.º 3
0
        public Model.Contact GetUserProfile(string username)
        {
            //Dictionary<string, Model.Contact> user=RetrieveAllContact("(sAMAccountName="+username+")",true);

            // return user[username];
            Model.Contact contact = new CommonLibrary.Model.Contact();

            _DirectorySearcher.Filter      = "(SAMAccountName=" + username + ")";
            _DirectorySearcher.SearchScope = SearchScope.Subtree;
            SearchResult result = _DirectorySearcher.FindOne();

            if (result != null)
            {
                contact.FullName      = result.Properties["displayName"][0].ToString();
                contact.BusinessPhone = result.Properties["telephoneNumber"].Count == 0 ? "" : result.Properties["telephoneNumber"][0].ToString();
                contact.BusinessFax   = result.Properties["facsimileTelephoneNumber"].Count == 0 ? "" : result.Properties["facsimileTelephoneNumber"][0].ToString();
                contact.MobilePhone   = result.Properties["Mobile"].Count == 0 ? "" : result.Properties["Mobile"][0].ToString();
                contact.Address       = result.Properties["homePostalAddress"].Count == 0 ? "" : result.Properties["homePostalAddress"][0].ToString();
                contact.HomePhone     = result.Properties["homePhone"].Count == 0 ? "" : result.Properties["homePhone"][0].ToString();
                contact.Email         = result.Properties["mail"].Count == 0 ? "" : result.Properties["mail"][0].ToString();
                contact.IPPhone       = result.Properties["ipPhone"].Count == 0 ? "" : result.Properties["ipPhone"][0].ToString();
            }

            return(contact);
        }
Exemplo n.º 4
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!txtFullname.Text.Trim().Equals(""))
                {
                    CommonLibrary.Model.Contact contact = new CommonLibrary.Model.Contact();
                    CommonLibrary.OutlookContact.ContactManagement contactManagment = new CommonLibrary.OutlookContact.ContactManagement();

                    contact.FullName      = txtFullname.Text;
                    contact.HomePhone     = txtHomePhone.Text;
                    contact.MobilePhone   = txtMobilePhone.Text;
                    contact.BusinessPhone = txtBusinessPhone.Text;
                    contact.BusinessFax   = txtBusinessFax.Text;
                    contact.Address       = txtAddress.Text;
                    contact.Email         = txtEmail.Text;

                    contactManagment.AddNewContact(contact);

                    // this.Close();

                    MessageBox.Show("Save Successful");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Fail to save.");
            }
        }
Exemplo n.º 5
0
        public static Dictionary <string, Model.Contact> RetreiveAllContact()
        {
            Application outLook   = new Application();
            NameSpace   outLookNS = outLook.GetNamespace("MAPI");
            MAPIFolder  cf        = outLookNS.GetDefaultFolder(OlDefaultFolders.olFolderContacts);
            Items       ctcItems  = cf.Items;

            Dictionary <string, Model.Contact> contacts = new Dictionary <string, CommonLibrary.Model.Contact>();

            for (int j = 1; j < (ctcItems.Count + 1); j++)
            {
                ContactItem ctc = (ContactItem)ctcItems[j];

                Model.Contact contact = new CommonLibrary.Model.Contact();
                contact.FullName = ctc.FullName.ToString();

                contact.Address     = ctc.HomeAddress == null? "" : ctc.HomeAddress.ToString();
                contact.HomePhone   = ctc.HomeTelephoneNumber == null? "" : ctc.HomeTelephoneNumber.ToString();
                contact.MobilePhone = ctc.MobileTelephoneNumber == null? "" : ctc.MobileTelephoneNumber.ToString();

                if (!contacts.ContainsKey(contact.FullName))
                {
                    contacts.Add(contact.FullName, contact);
                }
            }

            return(contacts);
        }
Exemplo n.º 6
0
        public static Dictionary <string, Model.Contact> RetreiveAllContact()
        {
            Dictionary <string, Model.Contact> contacts = new Dictionary <string, CommonLibrary.Model.Contact>();

            NKTWABLib.NKTWAB NKT        = new NKTWABLib.NKTWAB();
            NKTWABLib.Folder rootFolder = NKT.RootFolder;

            NKTWABLib.ContactContainer contCont = (NKTWABLib.ContactContainer)NKT.get_Item(rootFolder.Folders.get_Item(1).EntryID);
            //ComctlLib.Node tvItem = new ComctlLib.Node();

            for (int i = 1; i <= contCont.Contacts.Count; i++)
            {
                Model.Contact contact = new CommonLibrary.Model.Contact();

                NKTWABLib.Contact item = contCont.Contacts.get_Item(i);
                contact.FullName = item.Name;

                contact.Address     = item.HomeAddressCity;
                contact.HomePhone   = item.HomeTelephoneNumber;
                contact.MobilePhone = item.MobileTelephoneNumber;
                contact.Email       = item.Email1Address;

                contact.BusinessPhone = item.BusinessTelephoneNumber;
                contact.BusinessFax   = item.BusinessFaxNumber;
                contact.IPPhone       = "";


                if (!contacts.ContainsKey(contact.FullName))
                {
                    contacts.Add(contact.FullName, contact);
                }
            }

            return(contacts);
        }