Esempio n. 1
0
 /// <summary>
 /// Finds SP UserProfile by: Last Name, First Name, Middle Nam and Birthday
 /// </summary>
 /// <param name="profile">RecordUserProfile record wich is imported from 1C</param>
 /// <returns>Returns RecordUserProfile (which is imported from SP) if found, otherwise returns null</returns>
 RecordUserProfile GetProfileByPersonName(RecordUserProfile profile)
 {
     foreach (RecordUserProfile profileRecord in usersExisting.GetProfiles())
     {
         if (profileRecord.FirstName.Trim().ToLower() == profile.FirstName.Trim().ToLower() &&
             profileRecord.MiddleName.Trim().ToLower() == profile.MiddleName.Trim().ToLower() &&
             profileRecord.LastName.Trim().ToLower() == profile.LastName.Trim().ToLower() &&
             DateTime.Compare(profileRecord.BirthdayDT, profile.BirthdayDT) == 0)
         {
             return(profileRecord);
         }
     }
     return(null);
 }
Esempio n. 2
0
        protected void ShowRecords()
        {
            StringBuilder            sbCards      = new StringBuilder();
            List <RecordUserProfile> profilesSrc  = _users.GetProfiles(_strOrder, _strFilter);
            List <RecordUserProfile> profilesDest = new List <RecordUserProfile>();
            int iAllCount = profilesSrc.Count;

            if (_recordSelectionType == UserShortVerticalList.RecordSelectionType.Randomly)
            {
                var rnd   = new Random();
                int count = (_recordNumber < profilesSrc.Count) ? (_recordNumber) : (profilesSrc.Count);
                while (count > 0)
                {
                    var index = rnd.Next(profilesSrc.Count);
                    profilesDest.Add(profilesSrc[index]);
                    profilesSrc.RemoveAt(index);
                    count--;
                }
            }
            else if (_recordSelectionType == UserShortVerticalList.RecordSelectionType.FromTheEnd)
            {
                int max = (_recordNumber < profilesSrc.Count) ? (_recordNumber) : (profilesSrc.Count);
                for (int i = profilesSrc.Count - 1, cnt = 0; i >= 0 && cnt < max; i--, cnt++)
                {
                    profilesDest.Add(profilesSrc[i]);
                }
            }
            else
            {
                for (int i = 0; i < profilesSrc.Count && i < _recordNumber; i++)
                {
                    profilesDest.Add(profilesSrc[i]);
                }
            }

            foreach (RecordUserProfile profile in profilesDest)
            {
                string sProfileURL = "";
                string sPhotoURL   = "";
                string sEmail      = "";


                if (profile.ProfileURL.Trim().Length > 0)
                {
                    sProfileURL = "javascript:ShowABShortListProfileDialog('" +
                                  profile.LastName.Replace("\'", "\\\'").Replace("\"", "\\\"") + ", " +
                                  profile.FirstName.Replace("\'", "\\\'").Replace("\"", "\\\"") + "', '" +
                                  System.Web.HttpUtility.UrlEncode(profile.ProfileURL) + "')";
                }

                if (profile.PhotoURL.Trim().Length > 0)
                {
                    //_MThumb
                    string strPhotoURL = profile.PhotoURL;

                    if (_bShowBigPicture)
                    {
                        strPhotoURL = profile.PhotoURL.Replace("_MThumb.", "_LThumb.");
                    }

                    sPhotoURL = string.Format("<img  src=\"{0}\">",
                                              strPhotoURL);
                }
                else
                {
                    sPhotoURL = string.Format("<img  src=\"{0}\">",
                                              _site.Url + _sNoProfileImageFile);
                }

                if (profile.EmailWork.Trim().Length > 0)
                {
                    sEmail = string.Format("<a href=\"mailto:{0}\">{0}</a>", profile.EmailWork);
                }


                sbCards.AppendLine("<div class=\"employee_card\">");
                sbCards.AppendLine("<div class=\"card_shadow_rght\">");
                sbCards.AppendLine("<div class=\"card_body\">");
                sbCards.AppendLine("<div class=\"card_padd\">");

                if (_dataListRow[(int)dataListRowNames.rowPhoto].Visible)
                {
                    sbCards.AppendLine("<div class=\"photo_img\">");
                    sbCards.AppendLine(string.Format("<a href=\"{0}\">{1}</a>",
                                                     sProfileURL, sPhotoURL));
                    sbCards.AppendLine("</div>");
                }

                sbCards.AppendLine("<div class=\"card_txt\">");

                if (_dataListRow[(int)dataListRowNames.rowLastName].Visible ||
                    _dataListRow[(int)dataListRowNames.rowFirstName].Visible ||
                    _dataListRow[(int)dataListRowNames.rowMiddleName].Visible)
                {
                    string sName = "";

                    if (_dataListRow[(int)dataListRowNames.rowMiddleName].Visible &&
                        profile.MiddleName.Trim().Length > 0)
                    {
                        sName = string.Format("<span id=\"card_text_caption_name\"><a href=\"{0}\">{1}{2}{3}</a></span><br/>",
                                              sProfileURL,
                                              (_dataListRow[(int)dataListRowNames.rowLastName].Visible && profile.LastName.Trim().Length > 0) ? (profile.LastName.Trim() + " ") : (""),
                                              (_dataListRow[(int)dataListRowNames.rowFirstName].Visible && profile.FirstName.Trim().Length > 0) ? (profile.FirstName.Trim() + " ") : (""),
                                              (_dataListRow[(int)dataListRowNames.rowMiddleName].Visible && profile.MiddleName.Trim().Length > 0) ? (profile.MiddleName.Trim() + " ") : ("")
                                              );
                    }
                    else
                    {
                        sName = string.Format("<span id=\"card_text_caption_name\"><a href=\"{0}\">{2}{1}</a></span><br/>",
                                              sProfileURL,
                                              (_dataListRow[(int)dataListRowNames.rowLastName].Visible && profile.LastName.Trim().Length > 0) ? (profile.LastName.Trim() + " ") : (""),
                                              (_dataListRow[(int)dataListRowNames.rowFirstName].Visible && profile.FirstName.Trim().Length > 0) ? (profile.FirstName.Trim() + " ") : ("")
                                              );
                    }
                    sbCards.AppendLine(sName);
                }

                if (_dataListRow[(int)dataListRowNames.rowOrganization].Visible)
                {
                    sbCards.AppendLine("<span id=\"card_text_caption_organization\">"
                                       + profile.Organization + "</span><br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowSeparateDivision].Visible)
                {
                    sbCards.AppendLine("<span id=\"card_text_caption_sivision\">"
                                       + profile.SeparateDivision + "</span><br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowSubDivision].Visible)
                {
                    sbCards.AppendLine("<span id=\"card_text_caption_subdivision\">"
                                       + profile.SubDivision + "</span><br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowPosition].Visible)
                {
                    sbCards.AppendLine("<span id=\"card_text_caption_position\">"
                                       + profile.Position + "</span><br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowPhoneWork].Visible)
                {
                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_wphone\">Телефон (д): </span>"
                                       + profile.PhoneWork + "<br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowPhoneHome].Visible)
                {
                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_hphone\">Телефон (р): </span>"
                                       + profile.PhoneHome + "<br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowEmailWork].Visible)
                {
                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_email\">E-mail: </span>"
                                       + sEmail + "<br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowBirthday].Visible)
                {
                    string sBirthday = "";

                    if (profile.Birthday != null)
                    {
                        sBirthday = profile.BirthdayDT.ToShortDateString();
                    }

                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_birthday\">Дата народження: </span>"
                                       + sBirthday + "<br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowBirthdayShort].Visible)
                {
                    string sBirthday = "";

                    if (profile.Birthday != null)
                    {
                        sBirthday = profile.BirthdayDT.ToString("dd MMMM");
                    }


                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_birthday\">Дата народження: </span>"
                                       + sBirthday + "<br/>");
                }

                if (_dataListRow[(int)dataListRowNames.rowMerit].Visible)
                {
                    sbCards.AppendLine("<span class=\"card_text_caption\" id=\"card_text_caption_merit\">Заслуги: </span>"
                                       + profile.BestWorkerMerit + "<br/>");
                }
                sbCards.AppendLine("</div>");   // card_txt

                sbCards.AppendLine("<div style=\"clear:both\"></div>");
                sbCards.AppendLine("</div>"); // card_padd
                sbCards.AppendLine("</div>"); // card_body
                sbCards.AppendLine("</div>"); // card_shadow_rght

                sbCards.AppendLine("<div class=\"shad_bttm_lft\"></div>");
                sbCards.AppendLine("<div class=\"shad_bttm_rgt\"></div>");

                sbCards.AppendLine("</div>"); //employee_card
            }
            literalCards.Text = sbCards.ToString();

            if (_bShowNumberOfRecords)
            {
                linkButtonShowAll.Text = string.Format("{0} ({1})",
                                                       _cStrButtonShowAll, iAllCount);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Enumerates list of imported from 1C profile records and updates SP profiles
        /// </summary>
        /// <returns>true on success, false on failed</returns>
        bool UpdateProfiles()
        {
            int nAdded    = 0;
            int nModified = 0;

            try
            {
                string strSiteURL = Properties.Settings.Default.sharePointUserProfilesUrl;
                using (SPSite site = new SPSite(strSiteURL))
                {
                    SPWeb                 web     = site.OpenWeb();
                    SPServiceContext      context = SPServiceContext.GetContext(site);
                    UserProfileManager    upm     = new UserProfileManager(context);
                    ProfileSubtypeManager psm     = ProfileSubtypeManager.Get(context);

                    web.AllowUnsafeUpdates = true;

                    // choose default user profile subtype as the subtype
                    string         subtypeName = ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User);
                    ProfileSubtype subType     = psm.GetProfileSubtype(subtypeName);

                    try
                    {
                        imageUploader = new SPProfilePhotoUploader(web);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0}\nImages will not be updated", ex.ToString());
                        imageUploader = null;
                    }

                    double total   = users1C.Count;
                    double rec     = 100.0 / total;
                    double current = 0.0;

                    Console.Write("Updated 0%");
                    foreach (RecordUserProfile profile in users1C.GetProfiles())
                    {
                        RecordUserProfile profileFound       = null;
                        string            profileAccountName = "";
                        bool profileExists = false;

                        // If LDAP is refer to account name then verify if such account is existing
                        if (profile.AccountName != null &&
                            profile.AccountName.Trim().Length > 0 &&
                            Properties.Settings.Default.accountNameIsAKey == true)
                        {
                            if (upm.UserExists(profile.AccountName.Trim()))
                            {
                                profileAccountName = profile.AccountName.Trim();
                                profileExists      = true;
                            }
                        }
                        // If innIsAKey option is true and account is not found then try to find
                        // profile by INN
                        if (profileExists == false &&
                            profile.INN != null &&
                            profile.INN.Trim().Length > 0 &&
                            Properties.Settings.Default.innIsAKey)
                        {
                            profileFound = GetProfileByINN(profile);
                            if (profileFound != null)
                            {
                                profileAccountName = profileFound.AccountName;
                                profileExists      = true;
                            }
                        }
                        // Find by Last name, First name, Middle name (FIO) and Birthday
                        if (profileExists == false)
                        {
                            profileFound = GetProfileByPersonName(profile);
                            if (profileFound != null)
                            {
                                profileAccountName = profileFound.AccountName;
                                profileExists      = true;
                            }
                        }

                        if (profileExists)
                        {
                            // get existing profile
                            UserProfile p = upm.GetUserProfile(profileAccountName);

                            if (UpdateUserProfile(site, p, profile))
                            {
                                nModified++;
                            }
                        }
                        else
                        {
                            // create a user profile and set properties
                            if (CreateUserProfile(site, upm, profile, subType))
                            {
                                nAdded++;
                            }
                        }
                        current += rec;
                        Console.Write("\rUpdated {0:F}%", current);
                    }
                    Console.Write("\r");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
            Console.WriteLine("Updated {0} records.", nModified);
            Console.WriteLine("Added {0} new records.", nAdded);
            return(true);
        }
        protected void ShowGrid()
        {
            tableProfiles.Rows.Clear();

            // Draw header here
            TableHeaderRow rowHeader = new TableHeaderRow();

            foreach (ABTableColumn column in _tableColumns)
            {
                if (!column.Visible)
                {
                    continue;
                }

                TableHeaderCell cell = new TableHeaderCell();
                cell.Controls.Add(column.LinkButton);
                rowHeader.Cells.Add(cell);
            }
            tableProfiles.Rows.Add(rowHeader);

            int nRow = 0;

            foreach (RecordUserProfile profile in _users.GetProfiles(_strOrder, _strFilter))
            {
                ++nRow;
                TableRow row = new TableRow();

                string sProfileURL = "";
                string sPhotoURL   = "";
                string sEmail      = "";

                if (profile.ProfileURL.Trim().Length > 0)
                {
                    sProfileURL = "javascript:ShowABProfileDialog('" +
                                  profile.LastName.Replace("\'", "\\\'").Replace("\"", "\\\"") + ", " +
                                  profile.FirstName.Replace("\'", "\\\'").Replace("\"", "\\\"") + "', '" +
                                  System.Web.HttpUtility.UrlEncode(profile.ProfileURL) + "')";
                }

                if (_bShowPhotoIconOnly)
                {
                    if (profile.PhotoURL.Trim().Length > 0)
                    {
                        sPhotoURL = string.Format("<a onmouseover=\"ShowABPhotoDialog('{0}', '{1}'); return true;\" " +
                                                  "onmouseout=\"HideABPhotoDialog('{3}'); return true;\" " +
                                                  "href=\"javascript:ShowABPhotoDialog('{0}', '{1}')\"> " +
                                                  "<img id=\"{0}\" width=\"23\" height=\"16\" src=\"{2}\"></a>",
                                                  this.ClientID + "_photo_img_ctl_" + nRow.ToString(),
                                                  profile.PhotoURL,
                                                  _site.Url + _sPhotoImageFile,
                                                  _site.Url + _sNoProfileImageFile);
                    }
                    else
                    {
                        sPhotoURL = string.Format("<a onmouseover=\"ShowABPhotoDialog('{0}', '{1}'); return true;\" " +
                                                  "onmouseout=\"HideABPhotoDialog('{1}'); return true;\" " +
                                                  "href=\"javascript:ShowABPhotoDialog('{0}', '{1}')\"> " +
                                                  "<img id=\"{0}\" width=\"23\" height=\"16\" src=\"{2}\"></a>",
                                                  this.ClientID + "_photo_img_ctl_" + nRow.ToString(),
                                                  _site.Url + _sNoProfileImageFile,
                                                  _site.Url + _sPhotoImageFile);
                    }
                }
                else
                {
                    if (profile.PhotoURL.Trim().Length > 0)
                    {
                        sPhotoURL = string.Format("<div class=\"photo_img\"><img width=\"80\" height=\"80\" src=\"{0}\"></div>",
                                                  profile.PhotoURL);
                    }
                    else
                    {
                        sPhotoURL = string.Format("<div class=\"photo_img\"><img width=\"80\" height=\"80\" src=\"{0}\"></div>",
                                                  _site.Url + _sNoProfileImageFile);
                    }
                }

                if (profile.EmailWork.Trim().Length > 0)
                {
                    sEmail = string.Format("mailto:{0}", profile.EmailWork);
                }

                if (_tableColumns[(int)columnNames.columnPhoto].Visible)
                {
                    TableCell      cellPhoto = new TableCell();
                    LiteralControl lcPhoto   = new LiteralControl();
                    lcPhoto.Text = sPhotoURL;
                    cellPhoto.Controls.Add(lcPhoto);
                    row.Cells.Add(cellPhoto);
                }

                if (_tableColumns[(int)columnNames.columnLastName].Visible)
                {
                    TableCell cellLastName = new TableCell();
                    HyperLink linkLastName = new HyperLink();
                    linkLastName.Text        = profile.LastName;
                    linkLastName.NavigateUrl = sProfileURL;
                    cellLastName.Controls.Add(linkLastName);
                    row.Cells.Add(cellLastName);
                }

                if (_tableColumns[(int)columnNames.columnFirstName].Visible)
                {
                    TableCell cellFirstName = new TableCell();
                    HyperLink linkFirstName = new HyperLink();
                    linkFirstName.Text        = profile.FirstName;
                    linkFirstName.NavigateUrl = sProfileURL;
                    cellFirstName.Controls.Add(linkFirstName);
                    row.Cells.Add(cellFirstName);
                }

                if (_tableColumns[(int)columnNames.columnMiddleName].Visible)
                {
                    TableCell cellMiddleName = new TableCell();
                    HyperLink linkMiddleName = new HyperLink();
                    linkMiddleName.Text        = profile.MiddleName;
                    linkMiddleName.NavigateUrl = sProfileURL;
                    cellMiddleName.Controls.Add(linkMiddleName);
                    row.Cells.Add(cellMiddleName);
                }

                if (_tableColumns[(int)columnNames.columnOrganization].Visible)
                {
                    TableCell cellOrganization = new TableCell();
                    cellOrganization.Controls.Add(new LiteralControl(profile.Organization));
                    row.Cells.Add(cellOrganization);
                }

                if (_tableColumns[(int)columnNames.columnSeparateDivision].Visible)
                {
                    TableCell cellSeparateDivision = new TableCell();
                    cellSeparateDivision.Controls.Add(new LiteralControl(profile.SeparateDivision));
                    row.Cells.Add(cellSeparateDivision);
                }

                if (_tableColumns[(int)columnNames.columnSubDivision].Visible)
                {
                    TableCell cellSubDivision = new TableCell();
                    cellSubDivision.Controls.Add(new LiteralControl(profile.SubDivision));
                    row.Cells.Add(cellSubDivision);
                }

                if (_tableColumns[(int)columnNames.columnPosition].Visible)
                {
                    TableCell cellPosition = new TableCell();
                    cellPosition.Controls.Add(new LiteralControl(profile.Position));
                    row.Cells.Add(cellPosition);
                }

                if (_tableColumns[(int)columnNames.columnPhoneWork].Visible)
                {
                    TableCell cellPhoneWork = new TableCell();
                    cellPhoneWork.Controls.Add(new LiteralControl(profile.PhoneWork));
                    row.Cells.Add(cellPhoneWork);
                }

                if (_tableColumns[(int)columnNames.columnPhoneHome].Visible)
                {
                    TableCell cellHomeWork = new TableCell();
                    cellHomeWork.Controls.Add(new LiteralControl(profile.PhoneHome));
                    row.Cells.Add(cellHomeWork);
                }

                if (_tableColumns[(int)columnNames.columnEmailWork].Visible)
                {
                    TableCell cellEmail = new TableCell();
                    HyperLink linkEmail = new HyperLink();
                    linkEmail.Text        = profile.EmailWork;
                    linkEmail.NavigateUrl = sEmail;
                    cellEmail.Controls.Add(linkEmail);
                    row.Cells.Add(cellEmail);
                }

                if (_tableColumns[(int)columnNames.columnBirthday].Visible)
                {
                    string sBirthday = "";

                    if (profile.Birthday != null)
                    {
                        sBirthday = profile.BirthdayDT.ToShortDateString();
                    }

                    TableCell cellMerit = new TableCell();
                    cellMerit.Controls.Add(new LiteralControl(sBirthday));
                    row.Cells.Add(cellMerit);
                }

                if (_tableColumns[(int)columnNames.columnBirthdayShort].Visible)
                {
                    string sBirthday = "";

                    if (profile.Birthday != null)
                    {
                        sBirthday = profile.BirthdayDT.ToString("dd MMMM");
                    }

                    TableCell cellMerit = new TableCell();
                    cellMerit.Controls.Add(new LiteralControl(sBirthday));
                    row.Cells.Add(cellMerit);
                }

                if (_tableColumns[(int)columnNames.columnMerit].Visible)
                {
                    TableCell cellMerit = new TableCell();
                    cellMerit.Controls.Add(new LiteralControl(profile.BestWorkerMerit));
                    row.Cells.Add(cellMerit);
                }

                tableProfiles.Rows.Add(row);
            }
        }