Exemplo n.º 1
0
        // Get existing hours and work totals
        private void PopulateExistingWorkAndNotes()
        {
            var rows = TSData.GetItemHoursByDate(_timesheetItemId.Value, _date).Rows;

            _work.Clear();
            foreach (DataRow row in rows)
            {
                _work.Add(int.Parse(row["TS_ITEM_TYPE_ID"].ToString()), float.Parse(row["TS_ITEM_HOURS"].ToString()));
            }
            if (rows.Count > 0)
            {
                _notes = rows[0]["TS_ITEM_NOTES"].ToString();
            }

            var workdoneTSItem = TSData.GetTotalItemHoursByDate(_timesheetItemId.Value, _date);

            if (workdoneTSItem != null)
            {
                var   obj = workdoneTSItem["WorkDone"];
                float f;
                if (float.TryParse(obj.ToString(), out f))
                {
                    _workDoneTSItem = f;
                }
            }
        }
Exemplo n.º 2
0
        public static Dictionary <int, string> GetWorkTypes(Guid siteId)
        {
            var tsd       = new TSData();
            var workTypes = new Dictionary <int, string>();
            var table     = tsd.GetWorkTypes(siteId);

            foreach (DataRow row in table.Rows)
            {
                workTypes.Add((int)row["TSTYPE_ID"], row["TSTYPE_NAME"].ToString());
            }
            return(workTypes);
        }
Exemplo n.º 3
0
        private void PopulateWorkTotals()
        {
            // Get Work from List if it exists
            if (_list.Fields.ContainsField("Work") && _listItem["Work"] != null)
            {
                var   obj = _listItem["Work"];
                float f;
                if (float.TryParse(obj.ToString(), out f))
                {
                    _workAllocated = f;
                }
            }

            // Get total work for this item from all users
            var workdoneListItem = TSData.GetTotalListItemHours(_list.ID, _listItem.ID);

            if (workdoneListItem != null)
            {
                var   obj = workdoneListItem["WorkDone"];
                float f;
                if (float.TryParse(obj.ToString(), out f))
                {
                    _workDoneListItem = f;
                }
            }

            // Get total work for this user on this date
            var workdoneUser = TSData.GetDailyTotalByUser(_userLoginName, _date);

            if (workdoneUser != null)
            {
                var   obj = workdoneUser["DailyWork"];
                float f;
                if (float.TryParse(obj.ToString(), out f))
                {
                    _workDoneUser = f;
                }
            }
        }
Exemplo n.º 4
0
        public bool Update()
        {
            Guid webId = SPContext.Current.Web.ID;

            if (!_timesheetId.HasValue)
            {
                // Create new timesheet
                _timesheetId = TSData.CreateTimesheet(_userLoginName, _userName, _periodId, _siteId);
            }
            if (!_timesheetItemId.HasValue)
            {
                // Create new timesheetId
                var project   = "";
                int projectId = 0;
                if (_list.Fields.ContainsField("Project"))
                {
                    var lv = new SPFieldLookupValue(_listItem["Project"].ToString());
                    project   = lv.LookupValue;
                    projectId = lv.LookupId;
                }
                _timesheetItemId = TSData.CreateTimesheetItem(_timesheetId.Value, webId, _list.ID, ItemType, _listItem.ID, _listItem.Title, project, projectId, _list.Title);
            }

            bool success = true;

            foreach (KeyValuePair <int, float> work in _work)
            {
                success = success &&
                          TSData.InsertUpdateItemHours(_timesheetItemId.Value, _date, work.Value, work.Key);
            }
            success = success &&
                      TSData.InsertUpdateNotes(_timesheetItemId.Value, _date, _notes);

            PopulateWorkTotals();
            PopulateExistingWorkAndNotes();

            return(success);
        }
Exemplo n.º 5
0
        public TSItem(Guid listId, int listItemId, DateTime date, string userLoginName, string userName)
        {
            _date = date;
            var site = SPContext.Current.Site;

            _siteId = site.ID;
            var rootWeb = site.RootWeb;

            _web           = SPContext.Current.Web;
            _userLoginName = userLoginName;
            _userName      = userName;
            _list          = _web.Lists[listId];
            _listItem      = _list.GetItemById(listItemId);

            // Get EPMLive settings
            PopulateSettings(rootWeb);

            // Check user is assigned if AllowUnassigned not set
            if (!_allowUnassigned)
            {
                CheckAssignedTo();
                if (!_authorized)
                {
                    return;
                }
            }

            // Check list is set-up for timesheets
            if (!CheckList(rootWeb))
            {
                return;
            }

            // Check date falls within a period
            _periodId = TSData.GetPeriodId(_date, _siteId);
            if (_periodId == 0)
            {
                return;
            }

            // Check current day-of-week is allowed
            if (!_daySettings.GetDaySetting(date).Allowed)
            {
                _validDay = false;
                return;
            }

            PopulateWorkTotals();

            // Get TimesheetId if timesheet exists
            _timesheetId = TSData.GetTimesheetId(_periodId, _siteId, _userLoginName);
            if (!_timesheetId.HasValue)
            {
                return;
            }

            // Get TimeSheetItemId if timesheet item exists
            _timesheetItemId = TSData.GetTimesheetItemId(_timesheetId.Value, _list.ID, _listItem.ID);
            if (!_timesheetItemId.HasValue)
            {
                return;
            }

            PopulateExistingWorkAndNotes();
        }