示例#1
0
        /// <summary>
        /// Gets the required lists.
        /// </summary>
        /// <param name="spListCollection">The sp list collection.</param>
        /// <param name="dhbField">The DHB field.</param>
        /// <param name="holidaysList">The holidays list.</param>
        /// <param name="holidaySchedulesList">The holiday schedules list.</param>
        /// <param name="resourcesList">The resources list.</param>
        /// <param name="workHoursList">The work hours list.</param>
        private static void GetRequiredLists(SPListCollection spListCollection, DaysHoursBreakdownField dhbField,
                                             out SPList holidaysList, out SPList holidaySchedulesList,
                                             out SPList resourcesList, out SPList workHoursList)
        {
            holidaySchedulesList = null;

            resourcesList = spListCollection[dhbField.ResourcePoolList];

            if (resourcesList == null)
            {
                throw new Exception("Cannot find the Resources list.");
            }

            workHoursList = spListCollection[dhbField.WorkHoursList];

            if (workHoursList == null)
            {
                throw new Exception("Cannot find the WorkHours list.");
            }

            holidaysList = spListCollection[dhbField.HolidaysList];

            if (holidaysList == null)
            {
                throw new Exception("Cannot find the Holidays list.");
            }

            SPField holidaySchedulesField = holidaysList.Fields.GetFieldByInternalName(dhbField.HolidaySchedulesField);

            if (holidaySchedulesField != null)
            {
                holidaySchedulesList =
                    spListCollection.GetList(new Guid(((SPFieldLookup)holidaySchedulesField).LookupList), false);
            }

            if (holidaySchedulesList == null)
            {
                throw new Exception("Cannot find the Holiday Schedules list.");
            }
        }
示例#2
0
        /// <summary>
        /// Loads the blocked days.
        /// </summary>
        /// <param name="dhbField">The DHB field.</param>
        private void LoadBlockedDays(DaysHoursBreakdownField dhbField)
        {
            SPWeb spWeb = SPContext.Current.Web;

            string resourcePoolUrl;

            Guid lockedWeb = CoreFunctions.getLockedWeb(spWeb);

            using (SPWeb configWeb = Utils.GetConfigWeb(spWeb, lockedWeb))
            {
                resourcePoolUrl = CoreFunctions.getConfigSetting(configWeb, "EPMLiveResourceURL", true, false);
            }

            using (var spSite = new SPSite(resourcePoolUrl))
            {
                using (SPWeb web = spSite.OpenWeb())
                {
                    SPListCollection spListCollection = web.Lists;

                    SPList holidaysList;
                    SPList holidaySchedulesList;
                    SPList resourcesList;
                    SPList workHoursList;

                    GetRequiredLists(spListCollection, dhbField, out holidaysList, out holidaySchedulesList,
                                     out resourcesList,
                                     out workHoursList);

                    _workHoursDictionary = new Dictionary <string, decimal>();
                    _holidayDictionary   = new Dictionary <string, string>();

                    bool resourceFoundInPool = false;

                    foreach (SPListItem resourceListItem in resourcesList.Items)
                    {
                        object spAccount = resourceListItem["SharePointAccount"];

                        if (spAccount == null)
                        {
                            continue;
                        }

                        var    spFieldUserValue = new SPFieldUserValue(web, (string)spAccount);
                        SPUser spUser           = spFieldUserValue.User;

                        if (spUser == null)
                        {
                            continue;
                        }

                        if (spUser.ID != web.CurrentUser.ID)
                        {
                            continue;
                        }

                        try
                        {
                            GetWorkHours(workHoursList, resourceListItem, web);
                        }
                        catch
                        {
                            throw new Exception("Your user account does not have a Work Hours schedule specified in the Resource Pool.  Please contact your Administrator to correctly associate your account with a Work Hours schedule.");
                        }

                        try
                        {
                            GetHolidays(holidaysList, resourceListItem);
                        }
                        catch
                        {
                            throw new Exception("Your user account is not associated with a Holiday Schedule in the Resource Pool.  Please contact your Administrator to correctly associate your account with a Holiday Schedule.");
                        }

                        resourceFoundInPool = true;

                        break;
                    }

                    if (!resourceFoundInPool)
                    {
                        throw new ArgumentException();
                    }
                }
            }
        }