Пример #1
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            DateTime localDate     = IBN45Business.User.GetLocalDate(DateTime.UtcNow);
            DateTime destStartDate = IBN45Business.TimeTracking.GetWeekStart(localDate);

            List <int> entryIdList = new List <int>();

            foreach (DataGridItem dgi in MainGrid.Items)
            {
                CheckBox cb = (CheckBox)dgi.FindControl("chkElement");
                if (cb != null && cb.Checked && dgi.Cells[1].Text != ProjectObjectType.ToString(CultureInfo.InvariantCulture))
                {
                    entryIdList.Add(int.Parse(dgi.Cells[0].Text, CultureInfo.InvariantCulture));
                }
            }
            TimeTrackingManager.AddEntries(destStartDate, Mediachase.Ibn.Data.Services.Security.CurrentUserId, entryIdList);

            // After rebind the selected items will be disappeared.
            BindGrid();

            // Refresh parent window
            CommandParameters cp = new CommandParameters("MC_TimeTracking_CopyPrevWeekFrame");

            Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterRefreshParentFromFrameScript(this.Page, cp.ToString());
        }
Пример #2
0
        private void BindData()
        {
            int taskTime = GetTaskTime();

            TaskTimeLabel.Text = CommonHelper.GetHours(taskTime);

            SpentTimeLabel.Text = CommonHelper.GetHours(TimeTrackingManager.GetTotalHoursByObject(ObjectId, ObjectTypeId));

            TimesheetHours.Value = DateTime.MinValue;

            if (TaskId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonTaskAllowViewTaskTimeField;
            }
            if (IncidentId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonIncidentAllowViewTaskTimeField;
            }
            if (DocumentId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonDocumentAllowViewTaskTimeField;
            }
            if (ToDoId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonToDoAllowViewTaskTimeField;
            }
        }
Пример #3
0
        protected string GetPostedTime(object obj, object objectType, int timeTrackingEntryId)
        {
            string retval = "";

            if (obj != null && obj != DBNull.Value && objectType != null && objectType != DBNull.Value)
            {
                int objectId     = (int)obj;
                int objectTypeId = (int)objectType;

                if (objectTypeId == (int)ObjectTypes.CalendarEntry ||
                    objectTypeId == (int)ObjectTypes.Document ||
                    objectTypeId == (int)ObjectTypes.Issue ||
                    objectTypeId == (int)ObjectTypes.Task ||
                    objectTypeId == (int)ObjectTypes.ToDo)
                {
                    int minutes = TimeTrackingManager.GetPostedTimeByObject((int)objectId, (int)objectTypeId);
                    retval = Mediachase.UI.Web.Util.CommonHelper.GetHours(minutes);
                }
            }
            else if ((bool)block.Properties["AreFinancesRegistered"].Value)
            {
                TimeTrackingEntry entry = MetaObjectActivator.CreateInstance <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), timeTrackingEntryId);
                int minutes             = 0;
                if (entry.Properties["TotalApproved"].Value != null && entry.Properties["TotalApproved"].Value != DBNull.Value)
                {
                    minutes = Convert.ToInt32(entry.Properties["TotalApproved"].Value);
                }
                retval = Mediachase.UI.Web.Util.CommonHelper.GetHours(minutes);
            }

            return(retval);
        }
Пример #4
0
        private DataCacheInternal createCacheInternal(
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            User user,
            SearchQueryCollection queryCollection,
            IModificationNotifier modificationNotifier,
            INetworkOperationStatusListener networkOperationStatusListener,
            bool isApprovalStatusSupported)
        {
            MergeRequestManager mergeRequestManager = new MergeRequestManager(
                _cacheContext, cacheUpdater, hostname, hostProperties, queryCollection, networkOperationStatusListener,
                isApprovalStatusSupported);
            DiscussionManager discussionManager = new DiscussionManager(
                _cacheContext, hostname, hostProperties, user, mergeRequestManager,
                modificationNotifier, networkOperationStatusListener);
            TimeTrackingManager timeTrackingManager = new TimeTrackingManager(
                hostname, hostProperties, user, discussionManager, modificationNotifier, networkOperationStatusListener);

            ProjectCache projectCache = null;

            if (_cacheContext.SupportProjectCache)
            {
                IProjectListLoader loader = new ProjectListLoader(hostname, _operator);
                projectCache = new ProjectCache(loader, _cacheContext, hostname);
            }
            UserCache userCache = null;

            if (_cacheContext.SupportUserCache)
            {
                IUserListLoader userListLoader = new UserListLoader(hostname, _operator);
                userCache = new UserCache(userListLoader, _cacheContext, hostname);
            }
            return(new DataCacheInternal(mergeRequestManager, discussionManager, timeTrackingManager, projectCache, userCache));
        }
Пример #5
0
        private void BindBlocks()
        {
            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

            ddProjects.Items.Clear();

            ddProjects.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));

            ddProjects.Items.Add(new ListItem(" " + CHelper.GetResFileString("{IbnFramework.TimeTracking:NonProject}"), "-1"));

            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetNonProjectBlockTypeInstances())
            {
                ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                ddProjects.Items.Add(li);
            }

            ddProjects.Items.Add(new ListItem(" " + CHelper.GetResFileString("{IbnFramework.TimeTracking:ByProject}"), "-2"));

            // Projects
            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                ddProjects.Items.Add(li);
            }
        }
Пример #6
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            DateTime startDate     = DateTime.Parse(Request["uid"], CultureInfo.InvariantCulture);
            DateTime destStartDate = CHelper.GetWeekStartByDate(DTCWeek.SelectedDate);

            if (startDate.Date != destStartDate.Date)
            {
                TimeTrackingEntry[] mas      = TimeTrackingEntry.List(FilterElement.EqualElement("OwnerId", Mediachase.IBN.Business.Security.CurrentUser.UserID), FilterElement.EqualElement("StartDate", startDate));
                List <int>          entryIds = new List <int>();
                foreach (TimeTrackingEntry tte in mas)
                {
                    entryIds.Add((int)tte.PrimaryKeyId.Value);
                }
                if (entryIds.Count > 0)
                {
                    TimeTrackingManager.AddEntries(destStartDate, Mediachase.IBN.Business.Security.CurrentUser.UserID, entryIds);
                }
            }


            // Refresh parent window
            CommandParameters cp = new CommandParameters("MC_TT_CloneWeek");

            Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
        }
Пример #7
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            bool isProject = false;

            if (ddlSuperType.SelectedValue == "1")
            {
                isProject = true;
            }

            TimeTrackingManager.AddBlockTypeItem(txtName.Text, ddlBlockCard.SelectedValue, ddlEntryCard.SelectedValue, int.Parse(ddlStateMachine.SelectedValue), isProject);

            // Closing window
            if (RefreshButton == String.Empty)
            {
                CHelper.CloseItAndRefresh(Response);
            }
            else              // Dialog Mode
            {
                CHelper.CloseItAndRefresh(Response, RefreshButton);
            }
        }
Пример #8
0
        private void BindProjects()
        {
            ProjectList.Items.Clear();

            if (startDate == DateTime.MinValue)
            {
                return;
            }

            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

            int blockTypeInstanceFromFilter = GetProjectFromFilter();

            if (blockTypeInstanceFromFilter > 0)
            {
                TimeTrackingBlockTypeInstance inst = MetaObjectActivator.CreateInstance <TimeTrackingBlockTypeInstance>(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), blockTypeInstanceFromFilter);
                if (inst != null)
                {
                    ProjectList.Items.Add(new ListItem(inst.Properties[titledFieldName].Value.ToString(), blockTypeInstanceFromFilter.ToString()));
                }
            }
            else                // all instances
            {
                // Non-project
                bool isHeaderAdded = false;
                foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetNonProjectBlockTypeInstances())
                {
                    if (!isHeaderAdded)
                    {
                        ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByActivity").ToString(), "-1"));
                        isHeaderAdded = true;
                    }

                    ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                    ProjectList.Items.Add(li);
                }

                // Projects
                isHeaderAdded = false;
                foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetProjectBlockTypeInstances())
                {
                    if (!isHeaderAdded)
                    {
                        ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByProject").ToString(), "-2"));
                        isHeaderAdded = true;
                    }

                    ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                    ProjectList.Items.Add(li);
                }
            }

            EnsureSelectInstance();

            BindUsers();
        }
Пример #9
0
        protected void UpdateButton_Click(object sender, System.EventArgs e)
        {
            string hours = String.Format("{0:H:mm}", TimesheetHours.Value);

            if (hours == "")
            {
                hours = "0:00";
            }
            string[] parts   = hours.Split(':');
            int      minutes = 0;

            minutes = int.Parse(parts[0]) * 60;
            if (parts.Length > 1)
            {
                minutes += int.Parse(parts[1]);
            }

            if (minutes > 0)
            {
                DateTime dt        = dtc.SelectedDate;
                int      projectId = CommonHelper.GetProjectIdByObjectIdObjectType(ObjectId, ObjectTypeId);

                if (!Mediachase.IBN.Business.TimeTracking.CanUpdate(dt, projectId))
                {
                    TimesheetHoursValidator.ErrorMessage = LocRM2.GetString("tWrongDate");
                    TimesheetHoursValidator.IsValid      = false;
                    return;
                }

                string title = CommonHelper.GetObjectTitle(ObjectTypeId, ObjectId);

                try
                {
                    TimeTrackingManager.AddHoursForEntryByObject(
                        ObjectId,
                        ObjectTypeId,
                        title,
                        projectId,
                        Mediachase.IBN.Business.Security.UserID,
                        Mediachase.IBN.Business.TimeTracking.GetWeekStart(dt),
                        Mediachase.IBN.Business.TimeTracking.GetDayNum(dt),
                        minutes,
                        true);
                }
                catch (AccessDeniedException)
                {
                    TimesheetHoursValidator.ErrorMessage = LocRM2.GetString("tWrongDate");
                    TimesheetHoursValidator.IsValid      = false;
                    return;
                }

                BindData();
            }
        }
Пример #10
0
        private void BindGrid()
        {
            EnsureSelectInstance();

            if (BlockInstanceList.Items.Count > 0 && UserList.Items.Count > 0)
            {
                MainGrid.Visible = true;

                int      instanceId = int.Parse(BlockInstanceList.SelectedValue, CultureInfo.InvariantCulture);
                int      userId     = int.Parse(UserList.SelectedValue, CultureInfo.InvariantCulture);
                DateTime startDate  = DTCWeek.SelectedDate;
                //if (startDate == DateTime.MinValue)
                //    startDate = CHelper.GetWeekStartByDate(DTCWeek.Value);

                if (instanceId > 0)
                {
                    TimeTrackingBlock block = TimeTrackingManager.GetTimeTrackingBlock(instanceId, startDate, userId);
                    if (block == null || Mediachase.Ibn.Data.Services.Security.CanWrite(block))
                    {
                        MainGrid.DataSource = Mediachase.IBN.Business.TimeTracking.GetListTimeTrackingItemsForAdd_DataTable(instanceId, startDate, userId);
                        MainGrid.DataBind();
                    }
                    else
                    {
                        MainGrid.Visible = false;
                    }
                }
                else                    // All Projects
                {
                    BindAllProjectsGrid(startDate, userId);
                }
            }
            else
            {
                MainGrid.Visible = false;
            }

            foreach (DataGridItem dgi in MainGrid.Items)
            {
                if (dgi.Cells[1].Text == ProjectObjectType.ToString(CultureInfo.InvariantCulture))
                {
                    dgi.BackColor = Color.FromArgb(240, 240, 240);
                    dgi.Font.Bold = true;

                    // Add the OnClick handler
                    CheckBox cb = (CheckBox)dgi.FindControl("chkElement");
                    if (cb != null)
                    {
                        cb.Attributes.Add("onclick", String.Format(CultureInfo.InvariantCulture, "CheckChildren(this, {0})", dgi.Cells[2].Text));
                    }
                }
            }
        }
Пример #11
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            List <int>    objects            = new List <int>();
            List <int>    objectTypes        = new List <int>();
            List <string> titles             = new List <string>();
            List <int>    blockTypeInstances = new List <int>();

            foreach (DataGridItem dgi in MainGrid.Items)
            {
                CheckBox cb = (CheckBox)dgi.FindControl("chkElement");
                if (cb != null && cb.Checked && dgi.Cells[1].Text != ProjectObjectType.ToString(CultureInfo.InvariantCulture))
                {
                    objects.Add(int.Parse(dgi.Cells[0].Text, CultureInfo.InvariantCulture));
                    objectTypes.Add(int.Parse(dgi.Cells[1].Text, CultureInfo.InvariantCulture));
                    titles.Add(cb.Text);
                    blockTypeInstances.Add(int.Parse(dgi.Cells[2].Text, CultureInfo.InvariantCulture));
                }
            }

            if (objects.Count > 0)
            {
                DateTime startDate = DTCWeek.SelectedDate;
                //if (startDate == DateTime.MinValue)
                //    startDate = CHelper.GetWeekStartByDate(DTCWeek.Value);

                if (BlockInstanceList.SelectedValue != "0")
                {
                    TimeTrackingManager.AddEntries(
                        int.Parse(BlockInstanceList.SelectedValue, CultureInfo.InvariantCulture),
                        startDate,
                        int.Parse(UserList.SelectedValue, CultureInfo.InvariantCulture),
                        objects, objectTypes, titles);
                }
                else                  // Multiple projects
                {
                    TimeTrackingManager.AddEntries(
                        startDate,
                        int.Parse(UserList.SelectedValue, CultureInfo.InvariantCulture),
                        objects, objectTypes, titles, blockTypeInstances);
                }
            }

            // After rebind the selected items will be disappeared.
            BindGrid();

            // Refresh parent window
            CommandParameters cp = new CommandParameters("MC_TimeTracking_MultipleAddFrame");

            Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterRefreshParentFromFrameScript(this.Page, cp.ToString());
        }
Пример #12
0
        private void BindDD()
        {
            // Group
            GroupingList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "GroupingWeekUser").ToString(), GroupingWeekUser));
            GroupingList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "GroupingUserWeek").ToString(), GroupingUserWeek));

            // Projects
            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                ListItem li = new ListItem(bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                ProjectList.Items.Add(li);
            }

            if (ProjectList.Items.Count <= 0)
            {
                NoProjectsDiv.Visible = true;
                PanelFilters.Visible  = false;
                return;
            }
            else
            {
                NoProjectsDiv.Visible = false;
            }

            // Users
            UserList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));
            Principal[] mas = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
            foreach (Principal pl in mas)
            {
                UserList.Items.Add(new ListItem(pl.Name, pl.PrimaryKeyId.ToString()));
            }

            // Dates
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_Any}"), "[DateTimeThisAny]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisWeek}"), "[DateTimeThisWeek]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastWeek}"), "[DateTimeLastWeek]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisMonth}"), "[DateTimeThisMonth]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastMonth}"), "[DateTimeLastMonth]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisYear}"), "[DateTimeThisYear]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastYear}"), "[DateTimeLastYear]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_CustomWeek}"), "0"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_CustomPeriod}"), "-1"));

            Dtc1.SelectedDate = CHelper.GetRealWeekStartByDate(DateTime.Today);
            Dtc2.SelectedDate = CHelper.GetRealWeekStartByDate(DateTime.Today);
        }
Пример #13
0
        /// <summary>
        /// Handles the Click event of the TransitionButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void TransitionButton_Click(object sender, EventArgs e)
        {
            if (BlockId > 0 && TransitionList.Items.Count > 0 && TransitionList.SelectedItem != null)
            {
                string selectedTransition = TransitionList.SelectedValue;
                TimeTrackingManager.MakeTransitionWithComment(BlockId, new Guid(selectedTransition), TTBlockComment.Value);

                string cmd = String.Empty;
                if (Request["cmd"] != null)
                {
                    cmd = Request["cmd"];
                }
                CommandParameters cp = new CommandParameters(cmd);
                Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
            }
        }
Пример #14
0
        private void BindBlocks()
        {
            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

            ttBlock.Items.Clear();

            // Non-project
            bool isHeaderAdded = false;

            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetNonProjectBlockTypeInstances())
            {
                if (!isHeaderAdded)
                {
                    ttBlock.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "NonProject").ToString(), "-1"));
                    isHeaderAdded = true;
                }

                ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                ttBlock.Items.Add(li);
            }

            // Projects
            isHeaderAdded = false;
            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                if (!isHeaderAdded)
                {
                    ttBlock.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByProject").ToString(), "-2"));
                    isHeaderAdded = true;
                }

                ListItem li = new ListItem("   " + bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                ttBlock.Items.Add(li);
            }

            //ttBlock.DataSource = TimeTrackingManager.GetBlockTypeInstances().DefaultView;
            //ttBlock.DataTextField = "Title";
            //ttBlock.DataValueField = "PrimaryKeyId";
            //ttBlock.DataBind();

            EnsureSelectInstance();

            if (tdWeek.Visible || WeekerDiv.Visible)
            {
                ttBlock.Items.Insert(0, new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));
            }
        }
Пример #15
0
        protected void dgTimesheet_UpdateCommand(object source, DataGridCommandEventArgs e)
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            int entryId = int.Parse(e.Item.Cells[e.Item.Cells.Count - 1].Text);

            Mediachase.UI.Web.Modules.TimeControl dtc = (Mediachase.UI.Web.Modules.TimeControl)e.Item.FindControl("dtc");
            string  hours   = String.Format("{0}:{1:mm}", dtc.Value.Hour + 24 * (dtc.Value.Day - 1), dtc.Value);
            TextBox txtRate = (TextBox)e.Item.FindControl("txtRate");

            TimeTrackingManager.UpdateEntry(entryId, Mediachase.UI.Web.Util.CommonHelper.GetMinutes(hours), decimal.Parse(txtRate.Text));

            dgTimesheet.EditItemIndex = -1;
            BindDG();
        }
Пример #16
0
        private bool Process()
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return(false);
            }

            if (startDate == DateTime.MinValue)
            {
                throw new NotSupportedException("Start date is not specified");
            }

            int blockTypeInstanceId = int.Parse(ProjectList.SelectedValue);

            if (blockTypeInstanceId < 0)
            {
                lblError2.Style.Add("display", "");
                return(false);
            }

            McMetaViewPreference pref = CHelper.GetMetaViewPreference(CurrentView);
            int ownerId = int.Parse(UserList.SelectedValue, CultureInfo.InvariantCulture);

            double maxMinutes = (double)(24 * 60);

            TimeTrackingManager.AddEntryWithData(blockTypeInstanceId,
                                                 startDate,
                                                 ownerId,
                                                 txtEntry.Text,
                                                 Math.Min((new TimeSpan(Day1Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day2Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day3Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day4Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day5Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day6Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day7Time.Value.Ticks)).TotalMinutes, maxMinutes));

            BindNullValues();

            return(true);
        }
Пример #17
0
        private void BindData()
        {
            if (ProjectId > 0)
            {
                using (IDataReader reader = Project.GetProject(ProjectId))
                {
                    if (reader.Read())
                    {
                        labelTaskTime.Text  = CommonHelper.GetHours((int)reader["TaskTime"]);
                        labelSpentTime.Text = CommonHelper.GetHours((int)reader["TotalMinutes"]);
                    }
                }
            }
            else
            {
                int taskTime = GetTaskTime();
                labelTaskTime.Text = CommonHelper.GetHours(taskTime);

                labelSpentTime.Text = CommonHelper.GetHours(TimeTrackingManager.GetTotalHoursByObject(ObjectId, ObjectTypeId));
            }

            if (TaskId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonTaskAllowViewTaskTimeField;
            }
            if (IncidentId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonIncidentAllowViewTaskTimeField;
            }
            if (DocumentId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonDocumentAllowViewTaskTimeField;
            }
            if (ToDoId > 0)
            {
                tdTaskTime.Visible = PortalConfig.CommonToDoAllowViewTaskTimeField;
            }
            if (ProjectId > 0)
            {
                tdTaskTime.Visible = PortalConfig.GeneralAllowTaskTimeField;
            }
        }
Пример #18
0
        private bool Process()
        {
            Page.Validate();
            if (!Page.IsValid)
            {
                return(false);
            }

            int blockTypeInstanceId = int.Parse(ProjectList.SelectedValue);

            if (blockTypeInstanceId < 0)
            {
                lblError2.Style.Add("display", "");
                return(false);
            }

            McMetaViewPreference pref      = CHelper.GetMetaViewPreference(CurrentView);
            DateTime             startDate = CHelper.GetRealWeekStartByDate(pref.GetAttribute <DateTime>(TTFilterPopupEdit.FilterWeekAttr, TTFilterPopupEdit.FilterWeekAttr, DateTime.Today));

            if (startDate == DateTime.MinValue)
            {
                startDate = CHelper.GetRealWeekStartByDate(DateTime.Today);
            }

            double maxMinutes = (double)(24 * 60);

            TimeTrackingManager.AddEntryWithData(blockTypeInstanceId,
                                                 startDate,
                                                 Mediachase.IBN.Business.Security.CurrentUser.UserID,
                                                 txtEntry.Text,
                                                 Math.Min((new TimeSpan(Day1Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day2Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day3Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day4Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day5Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day6Time.Value.Ticks)).TotalMinutes, maxMinutes),
                                                 Math.Min((new TimeSpan(Day7Time.Value.Ticks)).TotalMinutes, maxMinutes));

            BindNullValues();

            return(true);
        }
Пример #19
0
        private DataCacheInternal createCacheInternal(
            InternalCacheUpdater cacheUpdater,
            string hostname,
            IHostProperties hostProperties,
            User user,
            DataCacheConnectionContext context)
        {
            MergeRequestManager mergeRequestManager = new MergeRequestManager(
                _dataCacheContext, cacheUpdater, hostname, hostProperties, context, _modificationNotifier);
            DiscussionManager discussionManager = new DiscussionManager(
                _dataCacheContext, hostname, hostProperties, user, mergeRequestManager, context, _modificationNotifier);
            TimeTrackingManager timeTrackingManager = new TimeTrackingManager(
                hostname, hostProperties, user, discussionManager, _modificationNotifier);

            IProjectListLoader loader = ProjectListLoaderFactory.CreateProjectListLoader(
                hostname, _operator, context, cacheUpdater);
            ProjectCache projectCache = new ProjectCache(cacheUpdater, loader, _dataCacheContext);

            return(new DataCacheInternal(mergeRequestManager, discussionManager, timeTrackingManager, projectCache));
        }
Пример #20
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp    = (CommandParameters)Element;
                string[]          elems = MetaGridServer.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);

                DateTime   weekStart = CHelper.GetRealWeekStartByDate(DateTime.Now).Date;
                List <int> entryIds  = new List <int>();

                foreach (string elem in elems)
                {
                    //int id = Convert.ToInt32(elem, CultureInfo.InvariantCulture);
                    string type = elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1];
                    if (type == MetaViewGroupUtil.keyValueNotDefined)
                    {
                        continue;
                    }

                    int id = Convert.ToInt32(elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0], CultureInfo.InvariantCulture);


                    if (type == TimeTrackingEntry.GetAssignedMetaClass().Name)
                    {
                        //if clone current week then abort
                        TimeTrackingEntry tte = MetaObjectActivator.CreateInstance <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), id);
                        if (weekStart == tte.StartDate)
                        {
                            throw new ArgumentException(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_UnableToCloneMsg}"));
                        }

                        entryIds.Add(id);
                    }
                }

                if (entryIds.Count > 0)
                {
                    TimeTrackingManager.AddEntries(weekStart, Mediachase.IBN.Business.Security.CurrentUser.UserID, entryIds);
                }
            }
        }
Пример #21
0
 protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == deleteCommand)
     {
         int id = int.Parse(e.CommandArgument.ToString());
         try
         {
             TimeTrackingManager.DeleteBlockTypeItem(id);
         }
         catch (SqlException ex)
         {
             if (ex.ErrorCode == -2146232060)
             {
                 CommandManager.GetCurrent(this.Page).InfoMessage = GetGlobalResourceObject("IbnFramework.Common", "ReferencesExists").ToString();
             }
             else
             {
                 throw ex;
             }
         }
     }
     BindGrid();
 }
Пример #22
0
        public static bool CanUpdate(DateTime startDate, int projectId)
        {
            bool retval = false;

            if (Configuration.TimeTrackingModule)
            {
                startDate = GetWeekStart(startDate);

                // O.R. [2008-07-25]
                TimeTrackingBlockTypeInstance inst = null;
                using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck())
                {
                    inst = TimeTrackingManager.GetBlockTypeInstanceByProject(projectId);
                }
                if (inst != null)
                {
                    TimeTrackingBlock[] blocks = TimeTrackingBlock.List(
                        FilterElement.EqualElement("OwnerId", Security.CurrentUser.UserID),
                        FilterElement.EqualElement("BlockTypeInstanceId", inst.PrimaryKeyId.Value),
                        FilterElement.EqualElement("StartDate", startDate)
                        );
                    if (blocks.Length > 0)                      // Block exists
                    {
                        TimeTrackingBlock block = blocks[0];
                        SecurityService   ss    = block.GetService <SecurityService>();
                        retval = ss.CheckUserRight(TimeTrackingManager.Right_Write);
                    }
                    else                        // Block doesn't exist
                    {
                        SecurityService ss = inst.GetService <SecurityService>();
                        retval = ss.CheckUserRight(TimeTrackingManager.Right_AddMyTTBlock) || ss.CheckUserRight(TimeTrackingManager.Right_AddAnyTTBlock);
                    }
                }
            }

            return(retval);
        }
Пример #23
0
        private void BindData()
        {
            ListItem li;

            // StateMachine
            Mediachase.Ibn.Data.Services.StateMachine[] smList = StateMachineManager.GetAvailableStateMachines(TimeTrackingManager.BlockMetaClassName);
            foreach (Mediachase.Ibn.Data.Services.StateMachine sm in smList)
            {
                li = new ListItem(CHelper.GetResFileString(sm.Name), sm.PrimaryKeyId.ToString());
                ddlStateMachine.Items.Add(li);
            }

            // BlockCard
            MetaClass mcBlock = TimeTrackingManager.GetBlockMetaClass();

            foreach (MetaClass card in mcBlock.GetCards())
            {
                li = new ListItem(CHelper.GetResFileString(card.FriendlyName), card.Name);
                ddlBlockCard.Items.Add(li);
            }

            // EntryCard
            MetaClass mcEntry = TimeTrackingManager.GetEntryMetaClass();

            foreach (MetaClass card in mcEntry.GetCards())
            {
                li = new ListItem(CHelper.GetResFileString(card.FriendlyName), card.Name);
                ddlEntryCard.Items.Add(li);
            }

            // SuperType
            li = new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ProjectType").ToString(), "1");
            ddlSuperType.Items.Add(li);
            li = new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "GlobalType").ToString(), "0");
            ddlSuperType.Items.Add(li);
        }
Пример #24
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                // we'll use this list to collect unique block id's taken from deleted entries
                // at the end we'll delete empty blocks
                ArrayList blocks = new ArrayList();

                int deletedItems                = 0;
                CommandParameters cp            = (CommandParameters)Element;
                string[]          elemsToDelete = MetaGridServer.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);
                using (TransactionScope tran = DataContext.Current.BeginTransaction())
                {
                    //1. All entries
                    foreach (string elem in elemsToDelete)
                    {
                        string type = elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1];
                        if (type == MetaViewGroupUtil.keyValueNotDefined)
                        {
                            deletedItems++;
                            continue;
                        }

                        int id = Convert.ToInt32(elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]);

                        //int id = int.Parse(elem);
                        if (type != TimeTrackingEntry.GetAssignedMetaClass().Name)
                        {
                            continue;
                        }

                        TimeTrackingEntry tte = MetaObjectActivator.CreateInstance <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), id);
                        if (TimeTrackingManager.DeleteEntry(tte))
                        {
                            deletedItems++;

                            if (!blocks.Contains(tte.ParentBlockId))
                            {
                                blocks.Add(tte.ParentBlockId);
                            }
                        }
                    }
                    //2. All blocks
                    foreach (string elem in elemsToDelete)
                    {
                        string type = elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1];
                        if (type == MetaViewGroupUtil.keyValueNotDefined)
                        {
                            continue;
                        }

                        int id = Convert.ToInt32(elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0]);

                        //if (id >= 0)
                        //    continue;
                        //id = -id;
                        if (type != TimeTrackingBlock.GetAssignedMetaClass().Name)
                        {
                            continue;
                        }

                        TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), id);
                        if (Mediachase.Ibn.Data.Services.Security.CanDelete(ttb))
                        {
                            ttb.Delete();
                            deletedItems++;

                            if (blocks.Contains(ttb.PrimaryKeyId))
                            {
                                blocks.Remove(ttb.PrimaryKeyId);
                            }
                        }
                    }

                    // delete empty blocks
                    using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck())
                    {
                        foreach (PrimaryKeyId blockId in blocks)
                        {
                            TimeTrackingEntry[] entries = TimeTrackingEntry.List(FilterElement.EqualElement("ParentBlockId", blockId));
                            if (entries.Length == 0)
                            {
                                TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), blockId);
                                ttb.Delete();
                            }
                        }
                    }

                    tran.Commit();
                }

                CommandManager cm = Sender as CommandManager;
                if (cm != null)
                {
                    if (deletedItems != elemsToDelete.Length)
                    {
                        cm.InfoMessage = CHelper.GetResFileString("{IbnFramework.Common:NotAllSelectedItemsWereProcessed}");
                    }
                    //    cm.InfoMessage = CHelper.GetResFileString("{IbnFramework.Common:AllSelectedItemsWereProcessed}");
                }

                //CHelper.RequireBindGrid();
                CHelper.AddToContext("NeedToClearSelector", "true");
            }
        }
Пример #25
0
        private void BindGrid()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("EntryId", typeof(int)));
            dt.Columns.Add(new DataColumn("ObjectId", typeof(int)));
            dt.Columns.Add(new DataColumn("ObjectTypeId", typeof(int)));
            dt.Columns.Add(new DataColumn("ObjectName", typeof(string)));
            dt.Columns.Add(new DataColumn("BlockTypeInstanceId", typeof(int)));
            DataRow dr;

            DateTime localDate     = IBN45Business.User.GetLocalDate(DateTime.UtcNow);
            DateTime srcStartDate  = IBN45Business.TimeTracking.GetWeekStart(localDate.AddDays(-7));
            DateTime destStartDate = IBN45Business.TimeTracking.GetWeekStart(localDate);

            TimeTrackingEntry[] srcEntries = TimeTrackingManager.GetEntriesForClone(Mediachase.Ibn.Data.Services.Security.CurrentUserId, srcStartDate, destStartDate);

            int blockTypeInstanceId = -1;

            foreach (TimeTrackingEntry srcEntry in srcEntries)
            {
                if (blockTypeInstanceId != srcEntry.BlockTypeInstanceId)
                {
                    blockTypeInstanceId = srcEntry.BlockTypeInstanceId;
                    dr                        = dt.NewRow();
                    dr["EntryId"]             = -1;
                    dr["ObjectId"]            = blockTypeInstanceId;
                    dr["ObjectTypeId"]        = ProjectObjectType;
                    dr["ObjectName"]          = srcEntry.ParentBlock;
                    dr["BlockTypeInstanceId"] = blockTypeInstanceId;
                    dt.Rows.Add(dr);
                }

                dr            = dt.NewRow();
                dr["EntryId"] = srcEntry.PrimaryKeyId;
                if (srcEntry.Properties["ObjectId"].Value != null && srcEntry.Properties["ObjectTypeId"].Value != null)
                {
                    dr["ObjectId"]     = srcEntry.Properties["ObjectId"].Value;
                    dr["ObjectTypeId"] = srcEntry.Properties["ObjectTypeId"].Value;
                }
                else
                {
                    dr["ObjectId"]     = -1;
                    dr["ObjectTypeId"] = -1;
                }
                dr["ObjectName"]          = srcEntry.Title;
                dr["BlockTypeInstanceId"] = blockTypeInstanceId;
                dt.Rows.Add(dr);
            }

            MainGrid.DataSource = dt.DefaultView;
            MainGrid.DataBind();

            foreach (DataGridItem dgi in MainGrid.Items)
            {
                CheckBox cb;
                if (dgi.Cells[1].Text == ProjectObjectType.ToString(CultureInfo.InvariantCulture))
                {
                    dgi.BackColor = Color.FromArgb(240, 240, 240);
                    dgi.Font.Bold = true;

                    // Add the OnClick handler
                    cb = (CheckBox)dgi.FindControl("chkElement");
                    if (cb != null)
                    {
                        cb.Attributes.Add("onclick", String.Format(CultureInfo.InvariantCulture, "CheckChildren(this, {0})", dgi.Cells[2].Text));
                    }
                }
            }
        }
Пример #26
0
        private void BindGrid()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("Id", typeof(int));
            dt.Columns.Add("Title", typeof(string));
            dt.Columns.Add("SuperType", typeof(string));
            dt.Columns.Add("StateMachine", typeof(string));
            dt.Columns.Add("BlockCard", typeof(string));
            dt.Columns.Add("EntryCard", typeof(string));
            dt.Columns.Add("EditLink", typeof(string));

            foreach (MetaObject mo in TimeTrackingManager.GetBlockTypeList())
            {
                DataRow row = dt.NewRow();
                row["Id"]    = mo.PrimaryKeyId;
                row["Title"] = mo.Properties["Title"].Value.ToString();
                if ((bool)mo.Properties["IsProject"].Value)
                {
                    row["SuperType"] = GetGlobalResourceObject("IbnFramework.TimeTracking", "ProjectType").ToString();
                }
                else
                {
                    row["SuperType"] = GetGlobalResourceObject("IbnFramework.TimeTracking", "GlobalType").ToString();
                }

                int stateMachineId = (Mediachase.Ibn.Data.PrimaryKeyId)mo.Properties["StateMachineId"].Value;
                Mediachase.Ibn.Data.Services.StateMachine sm = StateMachineManager.GetStateMachine(TimeTrackingManager.BlockMetaClassName, stateMachineId);
                row["StateMachine"] = CHelper.GetResFileString(sm.Name);

                if (mo.Properties["BlockCard"].Value != null)
                {
                    string    cardName = mo.Properties["BlockCard"].Value.ToString();
                    MetaClass mcCard   = MetaDataWrapper.GetMetaClassByName(cardName);
                    if (mcCard != null)
                    {
                        row["BlockCard"] = CHelper.GetResFileString(mcCard.FriendlyName);
                    }
                }
                if (mo.Properties["EntryCard"].Value != null)
                {
                    string    cardName = mo.Properties["EntryCard"].Value.ToString();
                    MetaClass mcCard   = MetaDataWrapper.GetMetaClassByName(cardName);
                    if (mcCard != null)
                    {
                        row["EntryCard"] = CHelper.GetResFileString(mcCard.FriendlyName);
                    }
                }

                dt.Rows.Add(row);
            }

            grdMain.DataSource = dt;
            grdMain.DataBind();

            foreach (GridViewRow row in grdMain.Rows)
            {
                ImageButton ib = (ImageButton)row.FindControl("ibDelete");
                if (ib != null)
                {
                    ib.Attributes.Add("onclick", "return confirm('" + GetGlobalResourceObject("IbnFramework.GlobalMetaInfo", "Delete").ToString() + "?')");
                }
            }
        }
Пример #27
0
        public string Commit(CommitObject commits, [FromUri] string token)
        {
            string apikey = string.Empty;
            string result = string.Empty;

            CurrentUser = new UserDto(new User()
            {
                ProjectGroups = new List <ProjectGroupMembership>()
                {
                    new ProjectGroupMembership()
                    {
                        ProjectGroupId = Countersoft.Gemini.Commons.Constants.GlobalGroupAdministrators, UserId = 0
                    }
                }
            });
            UserContext.User               = CurrentUser;
            PermissionsManager             = PermissionsManager.Copy(CurrentUser);
            UserContext.PermissionsManager = PermissionsManager;

            if (Request.Headers.Authorization != null && Request.Headers.Authorization.Parameter != null)
            {
                var authDetails = Encoding.Default.GetString(Convert.FromBase64String(Request.Headers.Authorization.Parameter)).Split(':');
                if (authDetails.Length == 2)
                {
                    apikey = authDetails[0];
                }
            }
            else if (token != null)
            {
                apikey = token;
            }

            if (apikey.Length == 0 || GeminiApp.Config.ApiKey.Length == 0 || !apikey.StartsWith(GeminiApp.Config.ApiKey, StringComparison.InvariantCultureIgnoreCase))
            {
                string error;

                if (GeminiApp.Config.ApiKey.Length == 0)
                {
                    error = "Web.config is missing API key";
                }
                else
                {
                    error = "Wrong API key: " + apikey;
                }

                GeminiApp.LogException(new Exception(error)
                {
                    Source = SourceControlProvider.GitHub.ToString()
                }, false);

                return(error);
            }

            if (commits == null)
            {
                try
                {
                    var body = Request.Content.ReadAsStringAsync();
                    body.Wait();
                    GeminiApp.LogException("Null CodeCommit", string.Concat("Null CodeCommit - ", body.Result), false);
                }
                catch
                {
                    try
                    {
                        GeminiApp.LogException("Null CodeCommit", "Null CodeCommit - Empty!", false);
                    }
                    catch
                    {
                    }
                }
                return(string.Empty);
            }

            foreach (var commit in commits.commits)
            {
                Regex           ex      = new Regex("GEM:(?<issueid>[0-9]+)", RegexOptions.IgnoreCase);
                MatchCollection matches = ex.Matches(commit.message);

                if (matches.Count > 0)
                {
                    var baseUrl = commits.repository.url.ReplaceIgnoreCase("https://github.com/", "https://api.github.com/");

                    List <string> filesModified = new List <string>();

                    var commitIndex = commit.url.IndexOf("commit");
                    if (commitIndex != -1)
                    {
                        var url = string.Concat(commit.url.Remove(commitIndex, commit.url.Length - commitIndex), "blob/master/");

                        for (int i = 0; i < commit.added.Length; i++)
                        {
                            filesModified.Add(string.Concat("{\"Filename\":\"", commit.added[i], "\", \"FileId\":\"", string.Empty, "\",\"PreviousFileRevisionId\":\"", string.Empty, "\" }"));
                        }

                        for (int i = 0; i < commit.modified.Length; i++)
                        {
                            filesModified.Add(string.Concat("{\"Filename\":\"", commit.modified[i], "\",\"FileId\":\"", string.Empty, "\",\"PreviousFileRevisionId\":\"", string.Empty, "\"}"));
                        }

                        for (int i = 0; i < commit.removed.Length; i++)
                        {
                            filesModified.Add(string.Concat("{\"Filename\":\"", commit.removed[i], "\",\"FileId\":\"", string.Empty, "\",\"PreviousFileRevisionId\":\"", string.Empty, "\"}"));
                        }
                    }

                    CodeCommit codeCommit = new CodeCommit();
                    codeCommit.Provider = SourceControlProvider.GitHub;
                    codeCommit.Comment  = commit.message;
                    codeCommit.Fullname = commit.author.name;
                    codeCommit.Data     = string.Concat("{\"RevisionId\":\"", commit.id, "\",\"PreviousRevisionId\":\"", string.Empty, "\",\"Files\":[", string.Join(",", filesModified.ToArray()), "],\"RepositoryName\":\"", commits.repository.name, "\",\"RepositoryUrl\":\"", baseUrl, "\",\"IsPrivate\":\"", commits.repository.PRIVATE, "\"}");

                    commit.message = ex.Replace(commit.message, string.Empty);

                    List <int> issuesAlreadyProcessed = new List <int>();

                    foreach (Match match in matches)
                    {
                        var issue = IssueManager.Get(match.ToString().Remove(0, 4).ToInt());

                        if (issue != null && !issuesAlreadyProcessed.Contains(issue.Id))
                        {
                            codeCommit.IssueId = issue.Id;
                            GeminiContext.CodeCommits.Create(codeCommit);
                            issuesAlreadyProcessed.Add(issue.Id);

                            try
                            {
                                if (match.Index + match.Length + 1 + 5 <= codeCommit.Comment.Length)
                                {
                                    var time   = codeCommit.Comment.Substring(match.Index + match.Length + 1, 5);
                                    var timeEx = new System.Text.RegularExpressions.Regex("[0-9][0-9]:[0-9][0-9]");
                                    var m      = timeEx.Match(time);
                                    if (m.Success)
                                    {
                                        // Okay, log time!
                                        var timeTypes = MetaManager.TimeTypeGetAll(issue.Project.TemplateId);
                                        if (timeTypes.Count > 0)
                                        {
                                            // Let's try and find the user
                                            var user = commit.author.email.HasValue() ? Cache.Users.Find(u => u.Username.Equals(commit.author.email, StringComparison.InvariantCultureIgnoreCase) ||
                                                                                                         u.Email.Equals(commit.author.email, StringComparison.InvariantCultureIgnoreCase) ||
                                                                                                         u.Fullname.Equals(commit.author.email, StringComparison.InvariantCultureIgnoreCase)) : null;

                                            if (user == null)
                                            {
                                                user = commit.author.name.HasValue() ? Cache.Users.Find(u => u.Username.Equals(commit.author.name, StringComparison.InvariantCultureIgnoreCase) ||
                                                                                                        u.Email.Equals(commit.author.name, StringComparison.InvariantCultureIgnoreCase) ||
                                                                                                        u.Fullname.Equals(commit.author.name, StringComparison.InvariantCultureIgnoreCase)) : null;
                                            }
                                            var timeEntry = new IssueTimeTracking();
                                            timeEntry.IssueId    = issue.Id;
                                            timeEntry.ProjectId  = issue.Entity.ProjectId;
                                            timeEntry.Comment    = codeCommit.Comment.ToMax(1990);
                                            timeEntry.EntryDate  = DateTime.Now;
                                            timeEntry.Hours      = m.Value.Substring(0, 2).ToInt();
                                            timeEntry.Minutes    = m.Value.Substring(3, 2).ToInt();
                                            timeEntry.TimeTypeId = timeTypes[0].Entity.Id;
                                            timeEntry.UserId     = user == null ? Countersoft.Gemini.Commons.Constants.SystemAccountUserId : user.Id;
                                            TimeTrackingManager.Create(timeEntry);
                                        }
                                    }
                                }
                            }
                            catch (Exception timeEx)
                            {
                                LogManager.LogError(timeEx, "GitHub - Time log");
                            }
                        }
                    }
                }
            }

            return(result);
        }
Пример #28
0
        private void BindDD()
        {
            // Group
            GroupingList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "GroupingWeekUser").ToString(), GroupingWeekUser));
            GroupingList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "GroupingUserWeek").ToString(), GroupingUserWeek));

            // Projects
            bool   isPpmExec       = Mediachase.IBN.Business.Security.IsUserInGroup(InternalSecureGroups.PowerProjectManager) || Mediachase.IBN.Business.Security.IsUserInGroup(InternalSecureGroups.ExecutiveManager);
            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

            foreach (TimeTrackingBlockTypeInstance bo in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                // Условия для того, чтобы BlockTypeInstances попал в список:
                //	- он должен быть связан с проектом
                //	- у него должны быть активны финансы
                //	- текущий пользователь - либо PPM/Exec, либо менеджер/исп.менеджер проекта

                if (bo.ProjectId.HasValue)
                {
                    int projectId = bo.ProjectId.Value;

                    if (ProjectSpreadSheet.IsActive(projectId))
                    {
                        bool add = false;
                        if (isPpmExec)
                        {
                            add = true;
                        }
                        else
                        {
                            Project.ProjectSecurity ps = Project.GetSecurity(projectId);
                            if (ps.IsManager || ps.IsExecutiveManager)
                            {
                                add = true;
                            }
                        }

                        if (add)
                        {
                            ListItem li = new ListItem(bo.Properties[titledFieldName].Value.ToString(), bo.PrimaryKeyId.ToString());
                            ProjectList.Items.Add(li);
                        }
                    }
                }
            }

            if (ProjectList.Items.Count <= 0)
            {
                NoProjectsDiv.Visible = true;
                PanelFilters.Visible  = false;
                return;
            }
            else
            {
                NoProjectsDiv.Visible = false;
            }

            // Users
            UserList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));
            Principal[] mas = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
            foreach (Principal pl in mas)
            {
                UserList.Items.Add(new ListItem(pl.Name, pl.PrimaryKeyId.ToString()));
            }

            // Dates
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_Any}"), "[DateTimeThisAny]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisWeek}"), "[DateTimeThisWeek]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastWeek}"), "[DateTimeLastWeek]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisMonth}"), "[DateTimeThisMonth]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastMonth}"), "[DateTimeLastMonth]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_ThisYear}"), "[DateTimeThisYear]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_LastYear}"), "[DateTimeLastYear]"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_CustomWeek}"), "0"));
            PeriodList.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_CustomPeriod}"), "-1"));

            Dtc1.SelectedDate = CHelper.GetRealWeekStartByDate(DateTime.Today);
            Dtc2.SelectedDate = CHelper.GetRealWeekStartByDate(DateTime.Today);
        }
Пример #29
0
        private void BindUsers()
        {
            string savedValue;

            if (!IsPostBack)
            {
                savedValue = Mediachase.IBN.Business.Security.CurrentUser.UserID.ToString();
            }
            else
            {
                savedValue = UserList.SelectedValue;
            }

            UserList.Items.Clear();

            if (ProjectList.SelectedValue == null || startDate == DateTime.MinValue)
            {
                return;
            }

            int blockTypeInstanceId = int.Parse(ProjectList.SelectedValue, CultureInfo.InvariantCulture);

            TimeTrackingBlockTypeInstance inst = MetaObjectActivator.CreateInstance <TimeTrackingBlockTypeInstance>(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), blockTypeInstanceId);

            int userFromFilter = GetUserFromFilter();

            if (userFromFilter > 0)
            {
                if (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddAnyTTBlock) ||
                    (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddMyTTBlock) && userFromFilter == Mediachase.Ibn.Data.Services.Security.CurrentUserId))
                {
                    TimeTrackingBlock block = TimeTrackingManager.GetTimeTrackingBlock(blockTypeInstanceId, startDate, userFromFilter);
                    if (block == null || Mediachase.Ibn.Data.Services.Security.CanWrite(block))
                    {
                        Principal pl = MetaObjectActivator.CreateInstance <Principal>(Principal.GetAssignedMetaClass(), userFromFilter);
                        if (pl != null)
                        {
                            UserList.Items.Add(new ListItem(pl.Name, userFromFilter.ToString()));
                        }
                    }
                }
            }
            else                // all users
            {
                if (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddAnyTTBlock))
                {
                    #region 1. Make the Dictionary of Principal
                    Dictionary <int, string> allUsers = new Dictionary <int, string>();
                    Principal[] principals            = Principal.List(new FilterElementCollection(FilterElement.EqualElement("Card", "User"), FilterElement.EqualElement("Activity", 3)), new SortingElementCollection(new SortingElement("Name", SortingElementType.Asc)));
                    foreach (Principal p in principals)
                    {
                        allUsers.Add(p.PrimaryKeyId.Value, p.Name);
                    }
                    #endregion

                    #region 2. Make the list of the Id (to pass it as array) and the Dictionary of TimeTrackingBlock
                    List <int> idList = new List <int>();
                    Dictionary <int, TimeTrackingBlock> allblocks = new Dictionary <int, TimeTrackingBlock>();
                    TimeTrackingBlock[] blocks = TimeTrackingBlock.List(FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("BlockTypeInstanceId", blockTypeInstanceId));
                    foreach (TimeTrackingBlock block in blocks)
                    {
                        idList.Add(block.PrimaryKeyId.Value);
                        allblocks.Add(block.PrimaryKeyId.Value, block);
                    }
                    #endregion

                    #region 3. Get the list of the existing blocks with rights and remove the forbidden items from allUsers
                    SerializableDictionary <int, Collection <string> > objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), idList.ToArray());
                    foreach (KeyValuePair <int, Collection <string> > item in objectRights)
                    {
                        int id = item.Key;
                        Collection <string> allowedRights = item.Value;

                        TimeTrackingBlock block = allblocks[id];
                        int ownerId             = block.OwnerId;

                        if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite))
                        {
                            allUsers.Remove(ownerId);
                        }
                    }
                    #endregion

                    #region 4. Fill in the dropdown
                    foreach (KeyValuePair <int, string> item in allUsers)
                    {
                        UserList.Items.Add(new ListItem(item.Value, item.Key.ToString()));
                    }
                    #endregion
                }
                else if (Mediachase.Ibn.Data.Services.Security.CheckObjectRight(inst, TimeTrackingManager.Right_AddMyTTBlock))
                {
                    // eliminate the block for which we don't have the "Write" right
                    TimeTrackingBlock block = TimeTrackingManager.GetTimeTrackingBlock(blockTypeInstanceId, startDate, Mediachase.Ibn.Data.Services.Security.CurrentUserId);
                    if (block == null || Mediachase.Ibn.Data.Services.Security.CanWrite(block))
                    {
                        Principal pl = MetaObjectActivator.CreateInstance <Principal>(Principal.GetAssignedMetaClass().Name, Mediachase.Ibn.Data.Services.Security.CurrentUserId);
                        UserList.Items.Add(new ListItem(pl.Name, Mediachase.Ibn.Data.Services.Security.CurrentUserId.ToString()));
                    }
                }
            }

            if (savedValue != null)
            {
                CHelper.SafeSelect(UserList, savedValue);
            }
        }
Пример #30
0
        private void BindBlockTypeInstances()
        {
            MetaClass mc = TimeTrackingBlockTypeInstance.GetAssignedMetaClass();

            // 1. Non-project
            #region 1.1. Preform the list of the Id (to pass it as array) and the Dictionary of TimeTrackingBlockTypeInstance
            List <int> idList = new List <int>();
            Dictionary <int, TimeTrackingBlockTypeInstance> blockTypeInstanceList = new Dictionary <int, TimeTrackingBlockTypeInstance>();
            foreach (TimeTrackingBlockTypeInstance blockTypeInstance in TimeTrackingManager.GetNonProjectBlockTypeInstances())
            {
                blockTypeInstanceList.Add(blockTypeInstance.PrimaryKeyId.Value, blockTypeInstance);
                idList.Add(blockTypeInstance.PrimaryKeyId.Value);
            }
            #endregion

            #region 1.2. Fillin the dropdown with elemets for which we have rights
            bool isHeaderAdded = false;
            SerializableDictionary <int, Collection <string> > objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(mc, idList.ToArray());
            foreach (KeyValuePair <int, Collection <string> > item in objectRights)
            {
                int id = item.Key;
                Collection <string> allowedRights = item.Value;
                if (allowedRights.Contains(TimeTrackingManager.Right_AddMyTTBlock) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock))
                {
                    if (!isHeaderAdded)
                    {
                        BlockInstanceList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "NonProject").ToString(), "-1"));
                        isHeaderAdded = true;
                    }

                    TimeTrackingBlockTypeInstance blockTypeInstance = blockTypeInstanceList[id];
                    ListItem li = new ListItem("   " + blockTypeInstance.Properties[titledFieldName].Value.ToString(), id.ToString());
                    BlockInstanceList.Items.Add(li);
                }
            }
            #endregion

            // 2. Projects
            #region 2.1. Preform the list of the Id (to pass it as array) and the Dictionary of TimeTrackingBlockTypeInstance
            idList = new List <int>();
            blockTypeInstanceList = new Dictionary <int, TimeTrackingBlockTypeInstance>();
            foreach (TimeTrackingBlockTypeInstance blockTypeInstance in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                blockTypeInstanceList.Add(blockTypeInstance.PrimaryKeyId.Value, blockTypeInstance);
                idList.Add(blockTypeInstance.PrimaryKeyId.Value);
            }
            #endregion

            #region 2.2. Fillin the dropdown with elemets for which we have rights
            isHeaderAdded = false;
            objectRights  = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(mc, idList.ToArray());
            foreach (KeyValuePair <int, Collection <string> > item in objectRights)
            {
                int id = item.Key;
                Collection <string> allowedRights = item.Value;

                if (allowedRights.Contains(TimeTrackingManager.Right_AddMyTTBlock) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock))
                {
                    if (!isHeaderAdded)
                    {
                        BlockInstanceList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByProject").ToString(), "-2"));
                        BlockInstanceList.Items.Add(new ListItem("   " + GetGlobalResourceObject("IbnFramework.TimeTracking", "AllProjects").ToString(), "0"));
                        isHeaderAdded = true;
                    }

                    TimeTrackingBlockTypeInstance blockTypeInstance = blockTypeInstanceList[id];
                    ListItem li = new ListItem("   " + blockTypeInstance.Properties[titledFieldName].Value.ToString(), id.ToString());
                    BlockInstanceList.Items.Add(li);
                }
            }
            #endregion

            CHelper.SafeSelect(BlockInstanceList, "0");                 // All Projects
        }