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(); } }
public void BindData(MetaClass mc, string FieldType) { using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck()) { int count = (mc == null) ? 0 : MetaObject.GetTotalCount(mc); if (count > 1) { chkUnique.Checked = false; chkUnique.Visible = false; } } }
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); }
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(); } }
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"); } }