Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (BlockId <= 0)
            {
                throw new ArgumentException("BlockId is wrong or not specified");
            }

            block = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), BlockId);
//			block = new TimeTrackingBlock(BlockId);

            SecurityService ss = block.GetService <SecurityService>();

            if (ss == null || !ss.CheckUserRight(TimeTrackingManager.Right_RegFinances))
            {
                throw new AccessDeniedException();
            }

            btnApprove.Text = LocRM.GetString("tApprove");
            btnCancel.Text  = LocRM.GetString("tCancel");
            if (!Page.IsPostBack)
            {
                BindAccounts();
                dtcDate.SelectedDate = Mediachase.IBN.Business.User.GetLocalDate(DateTime.UtcNow).Date;
            }

            btnApprove.CustomImage = CHelper.GetAbsolutePath("/layouts/images/accept.gif");
            btnCancel.CustomImage  = CHelper.GetAbsolutePath("/layouts/images/cancel.gif");
        }
Exemplo n.º 2
0
        public void BindData(MetaField field)
        {
            string sReferencedClass = field.Attributes[McDataTypeAttribute.ReferenceMetaClassName].ToString();

            ViewState["ReferencedClass"] = sReferencedClass;
            if (sReferencedClass == TimeTrackingEntry.GetAssignedMetaClass().Name ||
                sReferencedClass == TimeTrackingBlock.GetAssignedMetaClass().Name ||
                sReferencedClass == TimeTrackingBlockType.GetAssignedMetaClass().Name ||
                sReferencedClass == TimeTrackingBlockTypeInstance.GetAssignedMetaClass().Name ||
                sReferencedClass == Principal.GetAssignedMetaClass().Name ||
                Mediachase.IBN.Business.Security.CurrentUser == null)
            {
                tblEntity.Visible = false;
                string url = ResolveClientUrl(String.Format("~/Apps/MetaUI/Pages/Public/SelectItem.aspx?class={0}&btn={1}", sReferencedClass, Page.ClientScript.GetPostBackEventReference(btnRefresh, "xxx")));

                ibSelect.OnClientClick = String.Format("OpenPopUpWindow(\"{0}\", 640, 480, 1); return false;", url);
            }
            else
            {
                ReferenceUpdatePanel.Visible = false;
                refObjects.ObjectTypes       = sReferencedClass;
                if (Request["ContainerFieldName"] != null &&
                    field.Name == Request["ContainerFieldName"] &&
                    Request["ContainerId"] != null)
                {
                    this.Value = PrimaryKeyId.Parse(Request["ContainerId"]);
                }
            }
        }
Exemplo n.º 3
0
        private static void GetCurrentAndPrevStateIdByTimeTrackingBlock(TimeTrackingBlock block, out int curStateId, out int prevStateId)
        {
            curStateId  = -1;
            prevStateId = -1;

            StateMachineService stateMachine = block.GetService <StateMachineService>();

            if (stateMachine == null || stateMachine.StateMachine.States.Count == 0 || stateMachine.CurrentState == null)
            {
                return;
            }

            EventService eventService = block.GetService <EventService>();

            if (eventService != null)
            {
                // Detects that state is changed, find moFromStateName, toStateName
                MetaObject[] events = eventService.LoadEvents(TriggerContext.Current.TransactionId);
                StateMachineEventServiceArgs args = StateMachine.GetStateChangedEventArgs(events);
                if (args != null)
                {
                    curStateId  = StateMachineManager.GetState(TimeTrackingBlock.GetAssignedMetaClass(), args.CurrentState.Name).PrimaryKeyId.Value;
                    prevStateId = StateMachineManager.GetState(TimeTrackingBlock.GetAssignedMetaClass(), args.PrevState.Name).PrimaryKeyId.Value;
                }
            }
        }
Exemplo n.º 4
0
        private void BindStates()
        {
            ddState.Items.Add(new ListItem(CHelper.GetResFileString("{IbnFramework.Global:_mc_All}"), "0"));

            foreach (MetaObject mo in StateMachineManager.GetAvailableStates(TimeTrackingBlock.GetAssignedMetaClass()))
            {
                ddState.Items.Add(new ListItem(CHelper.GetResFileString(mo.Properties["FriendlyName"].Value.ToString()), mo.Properties["FriendlyName"].Value.ToString()));
            }
        }
Exemplo n.º 5
0
        public static void RegisterTriggers()
        {
            TriggerManager.AddTrigger(TimeTrackingBlock.GetAssignedMetaClass(),
                                      new Trigger("RecalculateProjectByTimeTrackingBlock",
                                                  "Recalculates project fields by time tracking block", false, false, true, string.Empty, "RecalculateProject"));

            TriggerManager.AddTrigger(TimeTrackingEntry.GetAssignedMetaClass(),
                                      new Trigger("RecalculateObjectByTimeTrackingEntry",
                                                  "Recalculates project fields by time tracking block", true, true, true, string.Empty, "RecalculateObject"));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Binds the data.
        /// </summary>
        private void BindData()
        {
            if (this.ClassName == TimeTrackingEntry.GetAssignedMetaClass().Name)
            {
                TimeTrackingEntry tte = MetaObjectActivator.CreateInstance <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), this.ObjectId);

                BindDayHeaders(tte.StartDate);
                BindTTEntry(tte);
                frmView.DataItem = tte;
                frmView.DataBind();

                if (TimeTrackingBlock.CheckUserRight(tte.ParentBlockId, Security.RightWrite))
                {
                    TTBlock.Visible       = false;
                    TTEntry.Visible       = true;
                    ReadOnlyBlock.Visible = false;
                }
                else
                {
                    TTBlock.Visible       = false;
                    TTEntry.Visible       = false;
                    ReadOnlyBlock.Visible = true;
                }
            }
            else if (this.ClassName == TimeTrackingBlock.GetAssignedMetaClass().Name)
            {
                TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), this.ObjectId);

                frmViewBlock.DataItem = ttb;
                frmViewBlock.DataBind();

                if (TimeTrackingBlock.CheckUserRight(ttb.PrimaryKeyId.Value, Security.RightWrite))
                {
                    TTBlock.Visible       = true;
                    TTEntry.Visible       = false;
                    ReadOnlyBlock.Visible = false;
                }
                else
                {
                    TTBlock.Visible       = false;
                    TTEntry.Visible       = false;
                    ReadOnlyBlock.Visible = true;
                }
            }
            else
            {
                TTBlock.Visible       = false;
                TTEntry.Visible       = false;
                ReadOnlyBlock.Visible = true;
            }
        }
Exemplo n.º 7
0
        private static int GetFinalStateIdByTimeTrackingBlock(TimeTrackingBlock block)
        {
            StateMachineService stateMachine = block.GetService <StateMachineService>();

            if (stateMachine == null || stateMachine.StateMachine.States.Count == 0)
            {
                return(-1);
            }

            State finalState = stateMachine.StateMachine.States[stateMachine.StateMachine.States.Count - 1];

            MetaObject stateObject = StateMachineManager.GetState(TimeTrackingBlock.GetAssignedMetaClass(), finalState.Name);

            return(stateObject.PrimaryKeyId.Value);
        }
Exemplo n.º 8
0
 public override bool CheckVisibility(object dataItem)
 {
     if (dataItem is MetaClass)
     {
         //hide list templates and timetracking classes (not entity objects)
         MetaClass mc = (MetaClass)dataItem;
         if (ListManager.MetaClassIsList(mc))
         {
             ListInfo li = ListManager.GetListInfoByMetaClassName(mc.Name);
             if (li != null && li.IsTemplate)
             {
                 return(false);
             }
         }
         else if (mc.Name == TimeTrackingEntry.GetAssignedMetaClass().Name ||
                  mc.Name == TimeTrackingBlock.GetAssignedMetaClass().Name ||
                  mc.Name == TimeTrackingBlockType.GetAssignedMetaClass().Name ||
                  mc.Name == TimeTrackingBlockTypeInstance.GetAssignedMetaClass().Name)
         {
             return(false);
         }
     }
     return(base.CheckVisibility(dataItem));
 }
Exemplo n.º 9
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");
            }
        }
Exemplo n.º 10
0
        private void ApplyStartValues()
        {
            if (BlockId > 0)
            {
                TimeTrackingBlock block = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), BlockId);
                if (block != null)
                {
                    blockInstanceId = block.BlockTypeInstanceId;
                }
            }

            BindNullValues();
        }
Exemplo n.º 11
0
        private void BindUsersByBlockTypeInstance(int blockTypeInstanceId)
        {
            string savedValue;

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

            DateTime startDate = DTCWeek.SelectedDate;

            //if (startDate == DateTime.MinValue)
            //    startDate = CHelper.GetWeekStartByDate(DTCWeek.Value);

            UserList.Items.Clear();

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

            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
            {
                Mediachase.IBN.Business.UserLight usr = Mediachase.IBN.Business.Security.CurrentUser;
                UserList.Items.Add(new ListItem(usr.LastName + ", " + usr.FirstName, usr.UserID.ToString()));
            }

            if (savedValue != null)
            {
                CHelper.SafeSelect(UserList, savedValue);
            }
        }
Exemplo n.º 12
0
        private void BindAllProjectsGrid(DateTime startDate, int userId)
        {
            DataTable dt = new DataTable();

            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;

            #region 1. Make the list of all BlockTypeInstances
            Dictionary <int, string> allList = new Dictionary <int, string>();
            bool isProject = false;
            foreach (ListItem li in BlockInstanceList.Items)
            {
                if (!isProject)
                {
                    // Check that we have reached the [ All Projects ]
                    if (li.Value == "0")
                    {
                        isProject = true;
                    }
                    continue;
                }
                allList.Add(int.Parse(li.Value, CultureInfo.InvariantCulture), li.Text);
            }
            #endregion

            #region 2. Get the list of the existing blocks by StartDate and OwnerId
            List <int> idList = new List <int>();
            Dictionary <int, TimeTrackingBlock> existingBlocks = new Dictionary <int, TimeTrackingBlock>();
            foreach (TimeTrackingBlock block in TimeTrackingBlock.List(FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("OwnerId", userId), FilterElement.IsNotNullElement("ProjectId")))
            {
                idList.Add(block.PrimaryKeyId.Value);
                existingBlocks.Add(block.PrimaryKeyId.Value, block);
            }
            #endregion

            #region 3. Get the security info by existing blocks and remove the forbidden items from allList
            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 = existingBlocks[id];
                if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite))
                {
                    allList.Remove(block.BlockTypeInstanceId);
                }
            }
            #endregion

            #region 4. Fill in the DataTable
            foreach (KeyValuePair <int, string> item in allList)
            {
                bool   isHeaderAdded = false;
                int    instanceId    = item.Key;
                string instanceName  = item.Value;
                using (IDataReader reader = Mediachase.IBN.Business.TimeTracking.GetListTimeTrackingItemsForAdd(instanceId, startDate, userId))
                {
                    while (reader.Read())
                    {
                        if (!isHeaderAdded)
                        {
                            dr                        = dt.NewRow();
                            dr["ObjectId"]            = instanceId;
                            dr["ObjectTypeId"]        = ProjectObjectType;
                            dr["ObjectName"]          = instanceName;
                            dr["BlockTypeInstanceId"] = instanceId;
                            dt.Rows.Add(dr);

                            isHeaderAdded = true;
                        }

                        dr                        = dt.NewRow();
                        dr["ObjectId"]            = reader["ObjectId"];
                        dr["ObjectTypeId"]        = reader["ObjectTypeId"];
                        dr["ObjectName"]          = reader["ObjectName"];
                        dr["BlockTypeInstanceId"] = reader["BlockTypeInstanceId"];
                        dt.Rows.Add(dr);
                    }
                }
            }
            #endregion

            MainGrid.DataSource = dt.DefaultView;
            MainGrid.DataBind();
        }
Exemplo n.º 13
0
        private void ApplyStartValues()
        {
            if (BlockId > 0)
            {
                TimeTrackingBlock block = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), BlockId);
                if (block != null)
                {
                    ownerId         = block.OwnerId;
                    startDate       = block.StartDate;
                    blockInstanceId = block.BlockTypeInstanceId;
                    return;
                }
            }

            if (ViewName == "TT_MyGroupByWeekProject")                  // My
            {
                ownerId = Mediachase.Ibn.Data.Services.Security.CurrentUserId;
            }
            else
            {
                int filterUser = GetUserFromFilter();
                if (filterUser > 0)
                {
                    ownerId = filterUser;
                }
            }

            int filterInstance = GetInstanceFromFilter();

            if (filterInstance > 0)
            {
                blockInstanceId = filterInstance;
            }

            DateTime filterDate = GetStartDateFromFilter();

            if (filterDate != DateTime.MinValue)
            {
                startDate = filterDate;
            }
        }
Exemplo n.º 14
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);
            }
        }
Exemplo n.º 15
0
        private void BindBlocks()
        {
            ProjectList.Items.Clear();

            string titledFieldName = TimeTrackingManager.GetBlockTypeInstanceMetaClass().TitleFieldName;

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

            if (startDate == DateTime.MinValue)
            {
                startDate = CHelper.GetRealWeekStartByDate(DateTime.Now);
            }
            int ownerId = Mediachase.IBN.Business.Security.CurrentUser.UserID;

            BindDayHeaders(startDate);

            // Non-project
            #region 1. Make the list of all BlockTypeInstances
            List <int> idList = new List <int>();
            Dictionary <int, string> allList = new Dictionary <int, string>();
            foreach (TimeTrackingBlockTypeInstance item in TimeTrackingManager.GetNonProjectBlockTypeInstances())
            {
                idList.Add(item.PrimaryKeyId.Value);
                allList.Add(item.PrimaryKeyId.Value, item.Title);
            }
            #endregion

            #region 2. Check the rights AddMyTTBlock and AddAnyTTBlock and remove from the allList the forbidden items
            SerializableDictionary <int, Collection <string> > objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), 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) && ownerId == Mediachase.Ibn.Data.Services.Security.CurrentUserId) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock)))
                {
                    allList.Remove(id);
                }
            }
            #endregion

            #region 3. Make the list of the TimeTrackingBlocks by OwnerId, StartDate and BlockTypeInstanceId[]
            List <string> blockTypeInstanceIdList = new List <string>();
            foreach (int id in allList.Keys)
            {
                blockTypeInstanceIdList.Add(id.ToString(CultureInfo.InvariantCulture));
            }

            List <int>            blockIdList       = new List <int>();
            Dictionary <int, int> blockInstanceList = new Dictionary <int, int>();

            TimeTrackingBlock[] blocks = TimeTrackingBlock.List(
                FilterElement.EqualElement("OwnerId", ownerId),
                FilterElement.EqualElement("StartDate", startDate),
                new FilterElement("BlockTypeInstanceId", FilterElementType.In, blockTypeInstanceIdList.ToArray())
                );
            foreach (TimeTrackingBlock block in blocks)
            {
                blockIdList.Add(block.PrimaryKeyId.Value);
                blockInstanceList.Add(block.PrimaryKeyId.Value, block.BlockTypeInstanceId);
            }
            #endregion

            #region 4. Check the right Write and remove from the allList the forbidden items
            objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), blockIdList.ToArray());
            foreach (KeyValuePair <int, Collection <string> > item in objectRights)
            {
                int id = item.Key;
                Collection <string> allowedRights = item.Value;

                if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite))
                {
                    allList.Remove(blockInstanceList[id]);
                }
            }
            #endregion

            #region 5. Fill in the dropdown
            if (allList.Count > 0)
            {
                ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByActivity").ToString(), "-1"));

                foreach (KeyValuePair <int, string> item in allList)
                {
                    ListItem li = new ListItem("   " + item.Value, item.Key.ToString());
                    ProjectList.Items.Add(li);
                }
            }
            #endregion


            // Projects
            #region 1. Make the list of all BlockTypeInstances
            idList  = new List <int>();
            allList = new Dictionary <int, string>();
            foreach (TimeTrackingBlockTypeInstance item in TimeTrackingManager.GetProjectBlockTypeInstances())
            {
                idList.Add(item.PrimaryKeyId.Value);
                allList.Add(item.PrimaryKeyId.Value, item.Title);
            }
            #endregion

            #region 2. Check the rights AddMyTTBlock and AddAnyTTBlock and remove from the allList the forbidden items
            objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlockTypeInstance.GetAssignedMetaClass(), 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) && ownerId == Mediachase.Ibn.Data.Services.Security.CurrentUserId) || allowedRights.Contains(TimeTrackingManager.Right_AddAnyTTBlock)))
                {
                    allList.Remove(id);
                }
            }
            #endregion

            #region 3. Make the list of the TimeTrackingBlocks by OwnerId, StartDate and BlockTypeInstanceId[]
            blockTypeInstanceIdList = new List <string>();
            foreach (int id in allList.Keys)
            {
                blockTypeInstanceIdList.Add(id.ToString(CultureInfo.InvariantCulture));
            }

            blockIdList       = new List <int>();
            blockInstanceList = new Dictionary <int, int>();

            blocks = TimeTrackingBlock.List(
                FilterElement.EqualElement("OwnerId", ownerId),
                FilterElement.EqualElement("StartDate", startDate),
                new FilterElement("BlockTypeInstanceId", FilterElementType.In, blockTypeInstanceIdList.ToArray())
                );
            foreach (TimeTrackingBlock block in blocks)
            {
                blockIdList.Add(block.PrimaryKeyId.Value);
                blockInstanceList.Add(block.PrimaryKeyId.Value, block.BlockTypeInstanceId);
            }
            #endregion

            #region 4. Check the right Write and remove from the allList the forbidden items
            objectRights = Mediachase.Ibn.Data.Services.Security.GetAllowedRights(TimeTrackingBlock.GetAssignedMetaClass(), blockIdList.ToArray());
            foreach (KeyValuePair <int, Collection <string> > item in objectRights)
            {
                int id = item.Key;
                Collection <string> allowedRights = item.Value;

                if (!allowedRights.Contains(Mediachase.Ibn.Data.Services.Security.RightWrite))
                {
                    allList.Remove(blockInstanceList[id]);
                }
            }
            #endregion

            #region 5. Fill in the dropdown
            if (allList.Count > 0)
            {
                ProjectList.Items.Add(new ListItem(GetGlobalResourceObject("IbnFramework.TimeTracking", "ByProject").ToString(), "-2"));

                foreach (KeyValuePair <int, string> item in allList)
                {
                    ListItem li = new ListItem("   " + item.Value, item.Key.ToString());
                    ProjectList.Items.Add(li);
                }
            }
            #endregion

            if (blockInstanceId > 0)
            {
                CHelper.SafeSelect(ProjectList, blockInstanceId.ToString());
            }

            EnsureSelectInstance();
        }
Exemplo n.º 16
0
        public static void RecalculateObject()
        {
            if (TriggerContext.Current == null)
            {
                throw new ArgumentException("TriggerContext.Current == null");
            }

            TimeTrackingEntry entry = TriggerContext.Current.Parameter.MetaObject as TimeTrackingEntry;

            if (entry == null)
            {
                return;
            }

            TimeTrackingBlock block = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), entry.ParentBlockId);

            int projectId = GetProjectIdByTimeTrackingBlock(block);

            //TimeTracking.RecalculateObject(int? objectId, int? objectTypeId, int projectId)
            //надо вызывать при создании TimeTrackingEntry (с хотя бы одним ненулевым Day1, Day2..., Day7)
            //при изменении TimeTrackingEntry (когда изменился хотя бы один Day1, Day2..., Day7) и
            // при удалении TimeTrackingEntry (с хотя бы одним ненулевым Day1, Day2..., Day7)

            // Comment conition because can n't detects that all DayX set to zero
            if (TriggerContext.Current.Parameter.State == MetaObjectState.Created && (entry.Day1 != 0 || entry.Day2 != 0 || entry.Day3 != 0 ||
                                                                                      entry.Day4 != 0 || entry.Day5 != 0 || entry.Day6 != 0 || entry.Day7 != 0) ||
                TriggerContext.Current.Parameter.State != MetaObjectState.Created)
            {
                RecalculateObjectAndProject(entry.Properties["ObjectId"].GetValue <int?>(),
                                            entry.Properties["ObjectTypeId"].GetValue <int?>(),
                                            projectId);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Handles the Click event of the btnSaveBlock 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 btnSaveBlock_Click(object sender, EventArgs e)
        {
            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), this.ObjectId);

                ProcessCollection(this.frmViewBlock.Controls, ttb);

                ttb.Save();

                tran.Commit();
            }

            CommandParameters cp = new CommandParameters("MC_TimeTracking_EditGridFrame");

            Mediachase.Ibn.Web.UI.WebControls.CommandHandler.RegisterCloseOpenedFrameScript(this.Page, cp.ToString());
        }
Exemplo n.º 18
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;

                string[] elems = null;
                if (cp.CommandArguments.ContainsKey("GridId"))
                {
                    elems = MetaGridServer.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);
                }

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

                //fix by DV: 2008-05-14
                //Esli vyzyvaetsa s grida (iconka v otklonennih listah), to primitiv v gride ustanovit etot flag
                //i togda ID budet bratsa iz parametrov, v protivnom sluchae ID - beretsa iz checkboxes
                if (!cp.CommandArguments.ContainsKey("callFromGrid"))
                {
                    foreach (string elem in elems)
                    {
                        string type = MetaViewGroupUtil.GetMetaTypeFromUniqueKey(elem);                        // elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[1];
                        if (type == MetaViewGroupUtil.keyValueNotDefined)
                        {
                            continue;
                        }

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


                        if (type == TimeTrackingEntry.GetAssignedMetaClass().Name)
                        {
                            //TimeTrackingEntry tte = MetaObjectActivator.CreateInstance<TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), id);

                            //if (!ttbIds.Contains(tte.ParentBlockId))
                            //    ttbIds.Add(tte.ParentBlockId);
                        }
                        else
                        {
                            if (!ttbIds.Contains(id))
                            {
                                ttbIds.Add(id);
                            }
                        }
                    }
                }
                else
                {
                    ttbIds.Add(Convert.ToInt32(MetaViewGroupUtil.GetIdFromUniqueKey(cp.CommandArguments["primaryKeyId"]), CultureInfo.InvariantCulture));
                }

                using (TransactionScope tran = DataContext.Current.BeginTransaction())
                {
                    foreach (int ttbId in ttbIds)
                    {
                        TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), ttbId);

                        StateMachineService sms = ((BusinessObject)ttb).GetService <StateMachineService>();

                        // process only initial state
                        if (sms.StateMachine.GetStateIndex(sms.CurrentState.Name) == 0)
                        {
                            StateTransition[] availableTransitions = sms.GetNextAvailableTransitions(true);
                            if (availableTransitions.Length > 0)
                            {
                                sms.MakeTransition(availableTransitions[0].Uid);
                                ttb.Save();
                            }
                        }
                    }
                    tran.Commit();
                }
            }
        }
Exemplo n.º 19
0
        private void BindData()
        {
            if (BlockId > 0)
            {
                TimeTrackingBlock   ttb             = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), BlockId);
                StateMachineService sms             = ttb.GetService <StateMachineService>();
                StateTransition[]   nextTransitions = sms.GetNextAvailableTransitions();
                StateTransition[]   prevTransitions = sms.GetPrevAvailableTransitions();

                ttbTitle.Text        = ttb.Title;
                TTBlockComment.Value = string.Empty;

                BindTransitions(nextTransitions, prevTransitions);
            }
        }