Exemplo n.º 1
0
        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();
            }
        }
Exemplo n.º 2
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.º 3
0
        public bool IsEnable(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;

                if (!cp.CommandArguments.ContainsKey("parentBlockId"))
                {
                    return(false);
                }

                MetaObject          ttb = MetaObjectActivator.CreateInstance <BusinessObject>(MetaDataWrapper.ResolveMetaClassByNameOrCardName("TimeTrackingBlock"), Convert.ToInt32(cp.CommandArguments["parentBlockId"]));
                StateMachineService sms = ((BusinessObject)ttb).GetService <StateMachineService>();

                bool canWrite       = TimeTrackingBlock.CheckUserRight((Mediachase.IbnNext.TimeTracking.TimeTrackingBlock)ttb, Security.RightWrite);
                bool isInitialState = sms.StateMachine.GetStateIndex(sms.CurrentState.Name) == 0;

                return(canWrite && isInitialState);
            }

            return(false);
        }
Exemplo n.º 4
0
        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();
            }
        }