예제 #1
0
        public static bool CheckUserRight(TimeTrackingBlock ttb, string rightName)
        {
            if (rightName == null)
                throw new ArgumentNullException("rightName");

            if (ttb == null)
                throw new ArgumentNullException("ttb");

            bool bRetVal = false;
            if (Mediachase.Ibn.License.TimeTrackingModule)
            {
                string key = string.Format(CultureInfo.InvariantCulture, "_ttb_{0}_right_{1}",
                    ttb.PrimaryKeyId.ToString(), rightName);

                if (HttpContext.Current == null || HttpContext.Current.Items[key] == null)
                {
                    SecurityService ss = ttb.GetService<SecurityService>();

                    if (ss != null)
                        bRetVal = ss.CheckUserRight(rightName);

                    if (HttpContext.Current != null)
                        HttpContext.Current.Items[key] = bRetVal;
                }
                else
                {
                    bRetVal = (bool)HttpContext.Current.Items[key];
                }
            }

            return bRetVal;
        }
예제 #2
0
        protected override void OnDeleted()
        {
            // Rebuild Time Tracking Block Day1, Day2, Day3, ... , Day7
            TimeTrackingBlock.RecalculateDays(this.ParentBlockId);

            base.OnDeleted();
        }
예제 #3
0
        protected override void OnSaving()
        {
            int blockId = this.ParentBlockId;

            // O.R. [2008-07-29]
            if (!SkipSecurityCheckScope.IsActive)
            {
                // Check rights
                if (!TimeTrackingBlock.CheckUserRight(blockId, Security.RightWrite))
                {
                    throw new AccessDeniedException();
                }
            }

            // O.R. [2008-08-04]: If finances are registered, set TotalApproved for new entries to zero.
            // So we can see the differences in the "Accounts" tab of info popup
            TimeTrackingBlock block = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), blockId);

            if ((bool)block.Properties["AreFinancesRegistered"].Value && this.Properties["TotalApproved"].Value == null)
            {
                this.Properties["TotalApproved"].Value = 0;
            }

            base.OnSaving();
        }
예제 #4
0
        protected override void OnDeleting()
        {
            // O.R. [2008-07-29]
            if (!SkipSecurityCheckScope.IsActive)
            {
                // Check rights
                int blockId = this.ParentBlockId;
                if (!TimeTrackingBlock.CheckUserRight(blockId, Security.RightDelete))
                {
                    throw new AccessDeniedException();
                }
            }

            base.OnDeleting();
        }
예제 #5
0
        public static bool CheckUserRight(TimeTrackingBlock ttb, string rightName)
        {
            if (rightName == null)
            {
                throw new ArgumentNullException("rightName");
            }

            if (ttb == null)
            {
                throw new ArgumentNullException("ttb");
            }

            bool bRetVal = false;

            if (Mediachase.Ibn.License.TimeTrackingModule)
            {
                string key = string.Format(CultureInfo.InvariantCulture, "_ttb_{0}_right_{1}",
                                           ttb.PrimaryKeyId.ToString(), rightName);

                if (HttpContext.Current == null || HttpContext.Current.Items[key] == null)
                {
                    SecurityService ss = ttb.GetService <SecurityService>();

                    if (ss != null)
                    {
                        bRetVal = ss.CheckUserRight(rightName);
                    }

                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.Items[key] = bRetVal;
                    }
                }
                else
                {
                    bRetVal = (bool)HttpContext.Current.Items[key];
                }
            }

            return(bRetVal);
        }
예제 #6
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");
        }
예제 #7
0
        public static bool CheckUserRight(int timeTrackingBlockId, string rightName)
        {
            if (rightName == null)
            {
                throw new ArgumentNullException("rightName");
            }

            bool bRetVal = false;

            if (Mediachase.Ibn.License.TimeTrackingModule)
            {
                string key = string.Format(CultureInfo.InvariantCulture, "_ttb_{0}_right_{1}",
                                           timeTrackingBlockId, rightName);

                if (HttpContext.Current == null || HttpContext.Current.Items[key] == null)
                {
                    TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), timeTrackingBlockId);
                    SecurityService   ss  = ttb.GetService <SecurityService>();

                    if (ss != null)
                    {
                        bRetVal = ss.CheckUserRight(rightName);
                    }

                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.Items[key] = bRetVal;
                    }
                }
                else
                {
                    bRetVal = (bool)HttpContext.Current.Items[key];
                }
            }

            return(bRetVal);
        }
예제 #8
0
 public TimeTrackingBlock(CustomTableRow row, MetaObjectOptions options)
     : base(TimeTrackingBlock.GetAssignedMetaClass(), row, options)
 {
 }
예제 #9
0
 public TimeTrackingBlock(CustomTableRow row)
     : base(TimeTrackingBlock.GetAssignedMetaClass(), row)
 {
 }
예제 #10
0
 public TimeTrackingBlock(PrimaryKeyId primaryKeyId, MetaObjectOptions options)
     : base(TimeTrackingBlock.GetAssignedMetaClass(), primaryKeyId, options)
 {
 }
예제 #11
0
 public TimeTrackingBlock(PrimaryKeyId primaryKeyId)
     : base(TimeTrackingBlock.GetAssignedMetaClass(), primaryKeyId)
 {
 }
예제 #12
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        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;
        }
예제 #13
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        public static void UnRegisterFinances(TimeTrackingBlock block)
        {
            if (!Configuration.TimeTrackingModule)
                throw new Mediachase.Ibn.LicenseRestrictionException();

            if (!(bool)block.Properties["AreFinancesRegistered"].Value)
                throw new NotSupportedException("Finances are not registered.");

            if (!TimeTrackingBlock.CheckUserRight(block, TimeTrackingManager.Right_UnRegFinances))
                throw new Mediachase.Ibn.AccessDeniedException();

            using (DbTransaction tran = DbTransaction.Begin())
            {
                ActualFinances.DeleteByBlockId(block.PrimaryKeyId.Value);

                // O.R. [2008-07-29]: We don't need to check the "Write" right for Block
                using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck())
                {
                    block.Properties["AreFinancesRegistered"].Value = false;
                    block.Save();
             				}

                // Recalculate TotalMinutes and TotalApproved
                RecalculateProjectAndObjects(block);

                tran.Commit();
            }
        }
예제 #14
0
        private static TimeTrackingBlock GetTimeTrackingBlock(int blockTypeInstanceId, DateTime startDate, int ownerId, bool createNew)
        {
            startDate = startDate.Date;

            TimeTrackingBlock block = null;
            TimeTrackingBlock[] mas = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("BlockTypeInstanceId", blockTypeInstanceId), FilterElement.EqualElement("StartDate", startDate));
            if (mas.Length > 0)
            {
                block = mas[0];
            }
            else if (createNew)
            {
                block = new TimeTrackingBlock();

                MetaObject blockInstance = MetaObjectActivator.CreateInstance<MetaObject>(GetBlockTypeInstanceMetaClass(), blockTypeInstanceId);
                int blockTypeId = (PrimaryKeyId)blockInstance.Properties["BlockTypeId"].Value;
                MetaObject blockType = MetaObjectActivator.CreateInstance<MetaObject>(GetBlockTypeMetaClass(), blockTypeId);

                MetaClass mcBlock = GetBlockMetaClass();
                int stateMachineId = (PrimaryKeyId)blockType.Properties["StateMachineId"].Value;
                string stateName = StateMachineManager.GetStateMachine(mcBlock, stateMachineId).States[0].Name;

                MetaObject stateInstance = StateMachineManager.GetState(mcBlock, stateName);

                block.mc_StateMachineId = stateMachineId;
                block.mc_StateId = stateInstance.PrimaryKeyId ?? -1;
                block.BlockTypeInstanceId = blockTypeInstanceId;
                block.OwnerId = ownerId;
                block.StartDate = startDate;
                block.Title = blockInstance.Properties["Title"].Value.ToString();
                if (blockInstance.Properties["ProjectId"].Value != null)
                    block.ProjectId = (PrimaryKeyId)blockInstance.Properties["ProjectId"].Value;
                if (!String.IsNullOrEmpty(blockType.Properties["BlockCard"].Value.ToString()))
                    block.Properties["Card"].Value = blockType.Properties["BlockCard"].Value;
                block.Save();

                // Add Owner to Block
                AddOwner(block.PrimaryKeyId.Value, ownerId);
            }

            return block;
        }
예제 #15
0
 public static TimeTrackingBlock[] List(params Mediachase.Ibn.Data.FilterElement[] filters)
 {
     return(MetaObject.List <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), filters));
 }
예제 #16
0
 public static TimeTrackingBlock[] List(params Mediachase.Ibn.Data.SortingElement[] sorting)
 {
     return(MetaObject.List <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), sorting));
 }
예제 #17
0
 public static TimeTrackingBlock[] List()
 {
     return(MetaObject.List <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass()));
 }
예제 #18
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Recalculates the project and objects TotalMinutes and TotalApproved.
        /// </summary>
        /// <param name="block">The block.</param>
        private static void RecalculateProjectAndObjects(TimeTrackingBlock block)
        {
            int projectId = GetProjectIdByTimeTrackingBlock(block);

            if (projectId > 0)
            {
                TimeTrackingEntry[] entryList = TimeTrackingEntry.List(
                    FilterElement.EqualElement("ParentBlockId", block.PrimaryKeyId.Value),
                    FilterElement.IsNotNullElement("ObjectId"),
                    FilterElement.IsNotNullElement("ObjectTypeId"));
                foreach (TimeTrackingEntry entry in entryList)
                {
                    DbTimeTracking.RecalculateObject((int)entry.Properties["ObjectId"].Value, (int)entry.Properties["ObjectTypeId"].Value, block.ProjectId.Value);
                }

                DbTimeTracking.RecalculateProject(projectId);
            }
        }
예제 #19
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
 private static int GetProjectIdByTimeTrackingBlock(TimeTrackingBlock block)
 {
     return block.Properties["ProjectId"].Value != null ? (int)(PrimaryKeyId)block.Properties["ProjectId"].Value : -1;
     //TimeTrackingBlockTypeInstance instance = new TimeTrackingBlockTypeInstance(block.BlockTypeInstanceId);
     //return base.Properties["ProjectId"].Value != null ? (int)base.Properties["ProjectId"].Value : -1;
 }
예제 #20
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Compares the time tracking block by start date.
        /// </summary>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns></returns>
        private static int CompareTimeTrackingBlockByStartDate(TimeTrackingBlock x, TimeTrackingBlock y)
        {
            if (x == null)
                throw new ArgumentNullException("x");
            if (y == null)
                throw new ArgumentNullException("y");

            return x.StartDate.CompareTo(y.StartDate);
        }
예제 #21
0
        /// <summary>
        /// Clones the week.
        /// </summary>
        /// <param name="ownerId">The owner id.</param>
        /// <param name="srcStartDate">The SRC start date.</param>
        /// <param name="destStartDate">The dest start date.</param>
        public static void CloneWeek(int ownerId, DateTime srcStartDate, DateTime destStartDate)
        {
            if (!Mediachase.Ibn.License.TimeTrackingModule)
                throw new Mediachase.Ibn.LicenseRestrictionException();

            srcStartDate = srcStartDate.Date;
            destStartDate = destStartDate.Date;

            TimeTrackingBlock[] srcBlocks = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", ownerId),
                FilterElement.EqualElement("StartDate", srcStartDate));

            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                foreach (TimeTrackingBlock srcBlock in srcBlocks)
                {
                    TimeTrackingBlock destBlock = new TimeTrackingBlock();

                    #region Copy TimeTrackingBlock Properties
                    // Set Start Date
                    destBlock.StartDate = destStartDate;

                    // Copy References
                    destBlock.BlockTypeInstanceId = srcBlock.BlockTypeInstanceId;
                    destBlock.mc_StateMachineId = srcBlock.mc_StateMachineId;
                    destBlock.OwnerId = srcBlock.OwnerId;
                    destBlock.ProjectId = srcBlock.ProjectId;

                    // Copy Card
                    destBlock.Card = srcBlock.Card;

                    // Copy Extended properties
                    foreach (MetaObjectProperty exProperty in srcBlock.ExtendedProperties)
                    {
                        if (!exProperty.IsReadOnly)
                        {
                            destBlock.Properties[exProperty.Name].Value = exProperty.Value;
                        }
                    }

                    // Copy Fields
                    destBlock.Title = srcBlock.Title;

                    destBlock.Day1 = 0;
                    destBlock.Day2 = 0;
                    destBlock.Day3 = 0;
                    destBlock.Day4 = 0;
                    destBlock.Day5 = 0;
                    destBlock.Day6 = 0;
                    destBlock.Day7 = 0;
                    #endregion

                    destBlock.Save();

                    TimeTrackingEntry[] srcEntries = TimeTrackingEntry.List(FilterElement.EqualElement("ParentBlockId", srcBlock.PrimaryKeyId.Value));

                    foreach (TimeTrackingEntry srcEntry in srcEntries)
                    {
                        TimeTrackingEntry destEntry = new TimeTrackingEntry();

                        #region Copy TimeTrackingEntry Properties
                        // Set Start Date
                        //destEntry.StartDate = destStartDate; // Referienced Field From TimeTrackingBlock

                        // Copy References
                        destEntry.ParentBlockId = destBlock.PrimaryKeyId.Value;
                        destEntry.BlockTypeInstanceId = srcEntry.BlockTypeInstanceId;
                        destEntry.OwnerId = srcEntry.OwnerId;

                        // Copy Card
                        destEntry.Card = srcEntry.Card;

                        // Copy Extended properties
                        foreach (MetaObjectProperty exProperty in srcEntry.ExtendedProperties)
                        {
                            if (!exProperty.IsReadOnly)
                            {
                                destEntry.Properties[exProperty.Name].Value = exProperty.Value;
                            }
                        }

                        // Copy Fields
                        destEntry.Title = srcEntry.Title;

                        destEntry.Day1 = 0;
                        destEntry.Day2 = 0;
                        destEntry.Day3 = 0;
                        destEntry.Day4 = 0;
                        destEntry.Day5 = 0;
                        destEntry.Day6 = 0;
                        destEntry.Day7 = 0;

                        #endregion

                        destEntry.Save();
                    }
                }

                tran.Commit();
            }
        }
예제 #22
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        /// <summary>
        /// Calculates the week status by blocks.
        /// </summary>
        /// <param name="currentWeekStart">The current week start.</param>
        /// <param name="userBlocks">The user blocks.</param>
        /// <returns></returns>
        private static WeekItemStatus CalculateWeekStatusByBlocks(DateTime currentWeekStart, TimeTrackingBlock[] userBlocks)
        {
            DateTime currentWeekEnd = currentWeekStart.AddDays(7);

            WeekItemStatus status = WeekItemStatus.NotCompleted;

            foreach (TimeTrackingBlock block in userBlocks)
            {
                // Process if block.StartDate IN [currentWeekStart, currentWeekStart)
                if (block.StartDate < currentWeekStart)
                    continue;
                if (block.StartDate >= currentWeekEnd)
                    break;

                if ((bool)block["IsRejected"] && block.mc_State == "Initial")
                {
                    // At least one block rejected
                    status = WeekItemStatus.Rejected;
                    break;
                }

                switch (block.mc_State)
                {
                    case "Initial": // Initial - At least one block not sent to approve
                        if (status == WeekItemStatus.NotCompleted ||
                            (int)status > (int)WeekItemStatus.InProcess)
                            status = WeekItemStatus.InProcess;
                        break;
                    case "Final": // Final - All blocks approved
                        if (status == WeekItemStatus.NotCompleted)
                            status = WeekItemStatus.Approved;
                        break;
                    default:
                        if (status == WeekItemStatus.NotCompleted ||
                            (int)status > (int)WeekItemStatus.Submitted)
                            status = WeekItemStatus.Submitted;
                        break;
                }
            }

            return status;
        }
예제 #23
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        public static void RegisterFinances(TimeTrackingBlock block, string rowId, DateTime regDate)
        {
            if (!Configuration.TimeTrackingModule)
                throw new Mediachase.Ibn.LicenseRestrictionException();

            if ((bool)block.Properties["AreFinancesRegistered"].Value)
                throw new NotSupportedException("Finances are already registered.");

            if (!TimeTrackingBlock.CheckUserRight(block, TimeTrackingManager.Right_RegFinances))
                throw new Mediachase.Ibn.AccessDeniedException();

            ///  TimeTrackingEntryId, UserId, ObjectTypeId, ObjectId, Title,
            ///  Day1, Day2, Day3, Day4, Day5, Day6, Day7, Total, TotalApproved, Rate, Cost
            DataTable dt = GetListTimeTrackingItemsForFinances_DataTable(block.BlockTypeInstanceId, block.StartDate, block.OwnerId);

            using (DbTransaction tran = DbTransaction.Begin())
            {
                // O.R. [2008-07-29]: We don't need to check the "Write" right for Entry and Block
                using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck())
                {
                    foreach (DataRow row in dt.Rows)
                    {
                        // O.R. [2008-07-28]: Rate and TotalApproved may contain null values, so we need do assign them
                        TimeTrackingEntry entry = MetaObjectActivator.CreateInstance<TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), (int)row["TimeTrackingEntryId"]);
                        entry.Properties["Rate"].Value = row["Rate"];
                        entry.Properties["TotalApproved"].Value = row["TotalApproved"];
                        entry.Save();

                        double cost = (double)row["Cost"];
                        if (cost == 0d)
                            continue;

                        // O.R. [2008-07-24] Now we use ProjectId
                        /*					ObjectTypes objectType = ObjectTypes.Timesheet;
                                            int objectId = (int)row["TimeTrackingEntryId"];
                         */
                        ObjectTypes objectType = ObjectTypes.Project;
                        int objectId = block.ProjectId.Value;

                        if (row["ObjectTypeId"] != DBNull.Value && row["ObjectId"] != DBNull.Value)
                        {
                            objectType = (ObjectTypes)row["ObjectTypeId"];
                            objectId = (int)row["ObjectId"];
                        }

                        // row["TotalApproved"] alwas has not null value
                        ActualFinances.Create(objectId, objectType, regDate, rowId, cost, row["Title"].ToString(), block.PrimaryKeyId.Value, (double)row["TotalApproved"], (int)block.OwnerId);
                    }

                    block.Properties["AreFinancesRegistered"].Value = true;
                    block.Save();
                }

                // Recalculate TotalMinutes and TotalApproved
                RecalculateProjectAndObjects(block);

                tran.Commit();
            }
        }
예제 #24
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        private static void CalculateDayTotal(DateTime currentWeekStart, WeekItemInfo item, TimeTrackingBlock[] userBlocks)
        {
            DateTime currentWeekEnd = currentWeekStart.AddDays(7);

            foreach (TimeTrackingBlock block in userBlocks)
            {
                // Process if block.StartDate IN [currentWeekStart, currentWeekStart)
                if (block.StartDate < currentWeekStart)
                    continue;
                if (block.StartDate >= currentWeekEnd)
                    continue;

                item.Day1 += block.Day1;
                item.Day2 += block.Day2;
                item.Day3 += block.Day3;
                item.Day4 += block.Day4;
                item.Day5 += block.Day5;
                item.Day6 += block.Day6;
                item.Day7 += block.Day7;
            }
        }
예제 #25
0
 public TimeTrackingBlock(MetaObjectOptions options)
     : base(TimeTrackingBlock.GetAssignedMetaClass(), options)
 {
 }
예제 #26
0
 public static TimeTrackingBlock[] List(Mediachase.Ibn.Data.FilterElementCollection filters, Mediachase.Ibn.Data.SortingElementCollection sorting, int start, int count)
 {
     return(MetaObject.List <TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), filters, sorting, start, count));
 }
예제 #27
0
파일: TimeTracking.cs 프로젝트: 0anion0/IBN
        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;
                }
            }
        }
예제 #28
0
        /// <summary>
        /// Add the TTEntry Item
        /// </summary>
        /// <returns></returns>
        public static TimeTrackingEntry AddEntry(int blockTypeInstanceId, DateTime startDate, int ownerId, string title)
        {
            if (!Mediachase.Ibn.License.TimeTrackingModule)
                throw new Mediachase.Ibn.LicenseRestrictionException();

            startDate = startDate.Date;

            TimeTrackingEntry retVal;
            using (TransactionScope tran = DataContext.Current.BeginTransaction())
            {
                MetaObject blockInstance = MetaObjectActivator.CreateInstance<MetaObject>(BlockTypeInstanceMetaClassName, blockTypeInstanceId);
                int blockTypeId = (PrimaryKeyId)blockInstance.Properties[BlockTypeInstanceFieldName_BlockType].Value;
                MetaObject blockType = MetaObjectActivator.CreateInstance<MetaObject>(BlockTypeMetaClassName, blockTypeId);

                TimeTrackingBlock block = null;
                TimeTrackingBlock[] mas = TimeTrackingBlock.List(FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("BlockTypeInstanceId", blockTypeInstanceId), FilterElement.EqualElement("StartDate", startDate));
                if (mas.Length > 0)
                {
                    block = mas[0];

                    if (!Security.CanWrite(block))
                        throw new AccessDeniedException();
                }
                else
                {
                    block = new TimeTrackingBlock();
                    int stateMachineId = (PrimaryKeyId)blockType.Properties[BlockTypeFieldName_StateMachine].Value;
                    string stateName = StateMachineManager.GetStateMachine(BlockMetaClassName, stateMachineId).States[0].Name;
                    MetaObject stateInstance = StateMachineManager.GetState(BlockMetaClassName, stateName);

                    block.mc_StateMachineId = stateMachineId;
                    block.mc_StateId = stateInstance.PrimaryKeyId ?? -1;
                    block.BlockTypeInstanceId = blockTypeInstanceId;
                    block.OwnerId = ownerId;
                    block.StartDate = startDate;
                    block.Title = blockInstance.Properties[BlockTypeFieldName_Title].Value.ToString();
                    if (blockInstance.Properties[BlockTypeInstanceFieldName_Project].Value != null)
                        block.ProjectId = (PrimaryKeyId)blockInstance.Properties[BlockTypeInstanceFieldName_Project].Value;
                    if (!String.IsNullOrEmpty(blockType.Properties[BlockTypeFieldName_BlockCard].Value.ToString()))
                        block.Properties["Card"].Value = blockType.Properties[BlockTypeFieldName_BlockCard].Value;
                    block.Save();

                    // Add Owner to Block
                    TimeTrackingManager.AddOwner(block.PrimaryKeyId.Value, ownerId);
                }

                TimeTrackingEntry entry = new TimeTrackingEntry();
                entry.ParentBlockId = block.PrimaryKeyId ?? -1;
                entry.Title = title;

                entry.BlockTypeInstanceId = blockTypeInstanceId;
                entry.OwnerId = ownerId;

                if (!String.IsNullOrEmpty(blockType.Properties[BlockTypeFieldName_EntryCard].Value.ToString()))
                    entry.Properties["Card"].Value = blockType.Properties[BlockTypeFieldName_EntryCard].Value;

                entry.Save();

                retVal = entry;

                tran.Commit();
            }
            return retVal;
        }
예제 #29
0
 public static int GetTotalCount(params FilterElement[] filters)
 {
     return(MetaObject.GetTotalCount(TimeTrackingBlock.GetAssignedMetaClass(), filters));
 }
예제 #30
0
        public static int GetApprovedHoursByObject(int objectId, int objectTypeId, bool currentUser)
        {
            double hours = 0;

            TimeTrackingEntry[] entryList;

            if (currentUser)
                entryList = TimeTrackingEntry.List(
                    FilterElement.EqualElement("ObjectId", objectId),
                    FilterElement.EqualElement("ObjectTypeId", objectTypeId),
                    FilterElement.EqualElement("OwnerId", Security.CurrentUserId));
            else
                entryList = TimeTrackingEntry.List(
                    FilterElement.EqualElement("ObjectId", objectId),
                    FilterElement.EqualElement("ObjectTypeId", objectTypeId));

            MetaClass mc = GetBlockMetaClass();
            Dictionary<int, bool> blockList = new Dictionary<int, bool>();

            foreach (TimeTrackingEntry entry in entryList)
            {
                int blockId = entry.ParentBlockId;

                if (!blockList.ContainsKey(blockId))
                {
                    TimeTrackingBlock block = new TimeTrackingBlock(blockId);

                    bool isInEndState = false;
                    if (StateMachineManager.GetFinalStateId(mc, block.mc_StateMachineId) == block.mc_StateId)
                        isInEndState = true;

                    blockList.Add(blockId, isInEndState);
                }

                if (blockList[blockId])
                {
                    hours += entry.Day1;
                    hours += entry.Day2;
                    hours += entry.Day3;
                    hours += entry.Day4;
                    hours += entry.Day5;
                    hours += entry.Day6;
                    hours += entry.Day7;
                }
            }

            return (int)hours;
        }
예제 #31
0
 public TimeTrackingBlock()
     : base(TimeTrackingBlock.GetAssignedMetaClass())
 {
 }