示例#1
0
        /// <summary>
        /// Imports records (list of RecordUserProfile) from SharePoint site
        /// </summary>
        /// <returns>true on success, false on failed</returns>
        bool ReadSPRecords()
        {
            try
            {
                string strSiteURL = Properties.Settings.Default.sharePointUrl;
                using (SPSite site2 = new SPSite(strSiteURL))
                {
                    using (SPWeb web = site2.OpenWeb())
                    {
                        web.AllowUnsafeUpdates = true;
                        SPServiceContext   sc  = SPServiceContext.GetContext(site2);
                        UserProfileManager upm = new UserProfileManager(sc);
                        foreach (UserProfile profile in upm)
                        {
                            // TODO: Figure out how to filter the list and skill all service accounts
                            if (profile["AccountName"].Value != null &&
                                (profile["AccountName"].Value.ToString().ToUpper().IndexOf("\\SM_") >= 0 ||
                                 profile["AccountName"].Value.ToString().ToUpper().IndexOf("\\SP_") >= 0))
                            {
                                continue;
                            }
                            if (profile["AccountName"].Value != null &&
                                profile["AccountName"].Value.ToString() == profile.DisplayName)
                            {
                                continue;
                            }

                            usersExisting.Add(profile);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string sError = string.Format("ReadSPRecords(): Error was occured while reading user profiles:\n{0}",
                                              ex.ToString());

                TextWriter errorWriter = Console.Error;
                Console.WriteLine(sError);
                errorWriter.WriteLine(sError);
                return(false);
            }
            return(true);
        }
示例#2
0
        protected void Page_Init(object sender, EventArgs e)
        {
            if (_webPart != null)
            {
                if (_webPart.TableProfiles != null)
                {
                    _users.Add(_webPart.TableProfiles);
                }

                _bShowRefreshShowAll = _webPart.EnableRefreshShowAll;
                _sNoProfileImageFile = _webPart.NoProfileImageFile;

                _dataListRow[(int)dataListRowNames.rowPhoto].Visible            = _webPart.ShowColumnPhoto;
                _dataListRow[(int)dataListRowNames.rowLastName].Visible         = _webPart.ShowColumnLastName;
                _dataListRow[(int)dataListRowNames.rowFirstName].Visible        = _webPart.ShowColumnFirstName;
                _dataListRow[(int)dataListRowNames.rowMiddleName].Visible       = _webPart.ShowColumnMiddleName;
                _dataListRow[(int)dataListRowNames.rowOrganization].Visible     = _webPart.ShowColumnOrganization;
                _dataListRow[(int)dataListRowNames.rowSeparateDivision].Visible = _webPart.ShowColumnSeparateDivision;
                _dataListRow[(int)dataListRowNames.rowSubDivision].Visible      = _webPart.ShowColumnSubDivision;
                _dataListRow[(int)dataListRowNames.rowPosition].Visible         = _webPart.ShowColumnPosition;
                _dataListRow[(int)dataListRowNames.rowPhoneWork].Visible        = _webPart.ShowColumnWorkPhone;
                _dataListRow[(int)dataListRowNames.rowPhoneHome].Visible        = _webPart.ShowColumnHomePhone;
                _dataListRow[(int)dataListRowNames.rowEmailWork].Visible        = _webPart.ShowColumnEmail;
                _dataListRow[(int)dataListRowNames.rowBirthday].Visible         = _webPart.ShowColumnBirthday;
                _dataListRow[(int)dataListRowNames.rowBirthdayShort].Visible    = _webPart.ShowColumnBirthdayShort;
                _dataListRow[(int)dataListRowNames.rowMerit].Visible            = _webPart.ShowColumnMerit;

                _bShowBigPicture = _webPart.ShowBigPhoto;

                _recordNumber        = _webPart.NumberOfRecords;
                _recordSelectionType = _webPart.SelectionType;
                _users.GetBestEmployeesWeeklyOnly   = _webPart.ShowBestWorkersWeeklyOnly;
                _users.GetBestEmployeesOnly         = _webPart.ShowBestWorkersOnly;
                _users.GetNewEmployeesOnly          = _webPart.ShowNewEmployeesOnly;
                _users.NewEmployeeDays              = _webPart.NewEmployeesDays;
                _users.GetEmployeesWithBirthdayOnly = _webPart.ShowWhosBirthdayOnly;
                if (_users.GetEmployeesWithBirthdayOnly)
                {
                    DateTime  now  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                    DayOfWeek day  = now.DayOfWeek;
                    int       days = day - DayOfWeek.Monday;

                    if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.Today)
                    {
                        _users.BirthdayStart = now;
                        _users.BirthdayEnd   = now;
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.Yesterday)
                    {
                        _users.BirthdayStart = now.AddDays(-1);
                        _users.BirthdayEnd   = _users.BirthdayStart;
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.Tomorrow)
                    {
                        _users.BirthdayStart = now.AddDays(1);
                        _users.BirthdayEnd   = _users.BirthdayStart;
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.ThisWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.LastWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days - 7);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.NextWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days + 7);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.ThisMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.LastMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1).AddMonths(-1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                    else if (_webPart.BirthdayTimeframe == UserShortVerticalList.Timeframe.NextMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1).AddMonths(1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                }
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            if (_webPart != null)
            {
                if (_webPart.TableProfiles != null)
                {
                    _users.Add(_webPart.TableProfiles);
                }

                _bShowCaptionPanel   = _webPart.EnableCaption;
                _sCaptionText        = _webPart.CaptionText;
                _bShowSearchPanel    = _webPart.EnableSearch;
                _sPhotoImageFile     = _webPart.PhotoImageFile;
                _sNoProfileImageFile = _webPart.NoProfileImageFile;

                _bShowPhotoIconOnly = _webPart.ShowColumnPhotoIcon;

                _tableColumns[(int)columnNames.columnPhoto].Visible            = _webPart.ShowColumnPhoto;
                _tableColumns[(int)columnNames.columnLastName].Visible         = _webPart.ShowColumnLastName;
                _tableColumns[(int)columnNames.columnFirstName].Visible        = _webPart.ShowColumnFirstName;
                _tableColumns[(int)columnNames.columnMiddleName].Visible       = _webPart.ShowColumnMiddleName;
                _tableColumns[(int)columnNames.columnOrganization].Visible     = _webPart.ShowColumnOrganization;
                _tableColumns[(int)columnNames.columnSeparateDivision].Visible = _webPart.ShowColumnSeparateDivision;
                _tableColumns[(int)columnNames.columnSubDivision].Visible      = _webPart.ShowColumnSubDivision;
                _tableColumns[(int)columnNames.columnPosition].Visible         = _webPart.ShowColumnPosition;
                _tableColumns[(int)columnNames.columnPhoneWork].Visible        = _webPart.ShowColumnWorkPhone;
                _tableColumns[(int)columnNames.columnPhoneHome].Visible        = _webPart.ShowColumnHomePhone;
                _tableColumns[(int)columnNames.columnEmailWork].Visible        = _webPart.ShowColumnEmail;
                _tableColumns[(int)columnNames.columnBirthday].Visible         = _webPart.ShowColumnBirthday;
                _tableColumns[(int)columnNames.columnBirthdayShort].Visible    = _webPart.ShowColumnBirthdayShort;
                _tableColumns[(int)columnNames.columnMerit].Visible            = _webPart.ShowColumnMerit;

                _users.GetBestEmployeesOnly         = _webPart.ShowBestWorkersOnly;
                _users.GetBestEmployeesWeeklyOnly   = _webPart.ShowBestWorkersWeeklyOnly;
                _users.GetNewEmployeesOnly          = _webPart.ShowNewEmployeesOnly;
                _users.NewEmployeeDays              = _webPart.NewEmployeesDays;
                _users.GetEmployeesWithBirthdayOnly = _webPart.ShowWhosBirthdayOnly;
                if (_users.GetEmployeesWithBirthdayOnly)
                {
                    DateTime  now  = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                    DayOfWeek day  = now.DayOfWeek;
                    int       days = day - DayOfWeek.Monday;

                    if (_webPart.BirthdayTimeframe == UserList.Timeframe.Today)
                    {
                        _users.BirthdayStart = now;
                        _users.BirthdayEnd   = now;
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.Yesterday)
                    {
                        _users.BirthdayStart = now.AddDays(-1);
                        _users.BirthdayEnd   = _users.BirthdayStart;
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.Tomorrow)
                    {
                        _users.BirthdayStart = now.AddDays(1);
                        _users.BirthdayEnd   = _users.BirthdayStart;
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.ThisWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.LastWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days - 7);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.NextWeek)
                    {
                        _users.BirthdayStart = DateTime.Now.AddDays(-days + 7);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddDays(6);
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.ThisMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.LastMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1).AddMonths(-1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                    else if (_webPart.BirthdayTimeframe == UserList.Timeframe.NextMonth)
                    {
                        _users.BirthdayStart = new DateTime(now.Year, now.Month, 1).AddMonths(1);
                        _users.BirthdayEnd   = _users.BirthdayStart.AddMonths(1).AddDays(-1);
                    }
                }
            }

            // Create table buttons
            int col = 0;

            foreach (ABTableColumn column in _tableColumns)
            {
                col++;

                if (column.Visible == false)
                {
                    continue;
                }

                column.LinkButton             = new LinkButton();
                column.LinkButton.ID          = string.Format("lbCellHeader{0}", col);
                column.LinkButton.Text        = column.Caption;
                column.LinkButton.CommandName = column.SortCommand;
                column.LinkButton.Command    += new CommandEventHandler(lbCell_Command);
            }
        }