protected override void OnDeleting() { // Remove Assigned Entry TimeTrackingEntry[] entryList = TimeTrackingEntry.List(FilterElement.EqualElement("ParentBlockId", this.PrimaryKeyId.Value)); foreach (TimeTrackingEntry entry in entryList) { entry.Delete(); } base.OnDeleting(); }
public static void AddStateFriendlyNameMetaFieldToAllMetaView() { using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass(); MetaField mf = timeTrackingEntry.Fields["StateFriendlyName"]; foreach (MetaView mv in DataContext.Current.MetaModel.MetaViews.GetByMetaClass(timeTrackingEntry)) { mv.AvailableFields.Add(mf); } scope.SaveChanges(); } }
public static void CreateStateFriendlyNameMetaField() { using (MetaClassManagerEditScope scope = DataContext.Current.MetaModel.BeginEdit()) { MetaClass timeTrackingEntry = TimeTrackingEntry.GetAssignedMetaClass(); AttributeCollection attr = new AttributeCollection(); attr.Add(McDataTypeAttribute.StringMaxLength, 255); attr.Add(McDataTypeAttribute.StringIsUnique, false); attr.Add(McDataTypeAttribute.Expression, @"SELECT TOP 1 TTBS.FriendlyName FROM cls_TimeTrackingBlock_State TTBS" + Environment.NewLine + @" JOIN cls_TimeTrackingBlock TTB ON " + Environment.NewLine + @" TTB.mc_StateId = TTBS.TimeTrackingBlock_StateId" + Environment.NewLine + @" AND" + Environment.NewLine + @" TTB.[TimeTrackingBlockId] = AAA.[ParentBlockId]"); MetaField retVal = timeTrackingEntry.CreateMetaField("StateFriendlyName", "State", MetaFieldType.Text, true, "''", attr); scope.SaveChanges(); } }
/// <summary> /// Binds the TT entry. /// </summary> /// <param name="tte">The tte.</param> void BindTTEntry(TimeTrackingEntry tte) { Day1Time.Value = DateTime.MinValue.AddMinutes(tte.Day1); Day2Time.Value = DateTime.MinValue.AddMinutes(tte.Day2); Day3Time.Value = DateTime.MinValue.AddMinutes(tte.Day3); Day4Time.Value = DateTime.MinValue.AddMinutes(tte.Day4); Day5Time.Value = DateTime.MinValue.AddMinutes(tte.Day5); Day6Time.Value = DateTime.MinValue.AddMinutes(tte.Day6); Day7Time.Value = DateTime.MinValue.AddMinutes(tte.Day7); }
public static TimeTrackingEntry[] List(params Mediachase.Ibn.Data.FilterElement[] filters) { return(MetaObject.List <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), filters)); }
/// <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(); } }
/// <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; }
public static void AddEntries(DateTime startDate, int ownerId, List<int> objects, List<int> objectTypes, List<string> titles, List<int> blockTypeInstances) { startDate = startDate.Date; // We use the dictionaries for optimization // whiteList contains the blocks for which we have the "Write" right // blackList contains the blocks for which we don't have the "Write" right // entryCardList contains card names by BlockTypeInstanceId Dictionary<int, TimeTrackingBlock> whiteList = new Dictionary<int, TimeTrackingBlock>(); Dictionary<int, TimeTrackingBlock> blackList = new Dictionary<int, TimeTrackingBlock>(); Dictionary<int, string> entryCardList = new Dictionary<int, string>(); // Get the list of existing entries TimeTrackingEntry[] existingEntries = TimeTrackingEntry.List( FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("OwnerId", ownerId), FilterElement.IsNotNullElement("ObjectId")); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { for (int i = 0; i < objects.Count; i++) { int blockTypeInstanceId = blockTypeInstances[i]; // Go to the next item if we don't have the "Write" right if (blackList.ContainsKey(blockTypeInstanceId)) continue; // Get the block TimeTrackingBlock block; if (whiteList.ContainsKey(blockTypeInstanceId)) { block = whiteList[blockTypeInstanceId]; } else // new block { block = GetTimeTrackingBlock(blockTypeInstanceId, startDate, ownerId, true); if (Security.CanWrite(block)) { whiteList.Add(blockTypeInstanceId, block); } else { blackList.Add(blockTypeInstanceId, block); continue; } } // Check for duplicates bool entryExists = false; foreach (TimeTrackingEntry existingEntry in existingEntries) { if (objects[i] == (int)existingEntry.Properties["ObjectId"].Value && objectTypes[i] == (int)existingEntry.Properties["ObjectTypeId"].Value) { entryExists = true; break; } } if (entryExists) continue; // Get the entry card string entryCard; if (entryCardList.ContainsKey(blockTypeInstanceId)) { entryCard = entryCardList[blockTypeInstanceId]; } else { entryCard = GetEntryCard(blockTypeInstanceId); entryCardList.Add(blockTypeInstanceId, entryCard); } // Adding TimeTrackingEntry entry = new TimeTrackingEntry(); entry.ParentBlockId = block.PrimaryKeyId ?? -1; entry.Title = titles[i]; entry.BlockTypeInstanceId = blockTypeInstanceId; entry.OwnerId = ownerId; entry.Properties["Card"].Value = entryCard; entry.Properties["ObjectId"].Value = objects[i]; entry.Properties["ObjectTypeId"].Value = objectTypes[i]; entry.Save(); } tran.Commit(); } }
public TimeTrackingEntry(PrimaryKeyId primaryKeyId) : base(TimeTrackingEntry.GetAssignedMetaClass(), primaryKeyId) { }
public TimeTrackingEntry(MetaObjectOptions options) : base(TimeTrackingEntry.GetAssignedMetaClass(), options) { }
public TimeTrackingEntry() : base(TimeTrackingEntry.GetAssignedMetaClass()) { }
public static int GetTotalCount(params FilterElement[] filters) { return(MetaObject.GetTotalCount(TimeTrackingEntry.GetAssignedMetaClass(), filters)); }
public static TimeTrackingEntry[] List(Mediachase.Ibn.Data.FilterElementCollection filters, Mediachase.Ibn.Data.SortingElementCollection sorting, int start, int count) { return(MetaObject.List <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), filters, sorting, start, count)); }
public static TimeTrackingEntry[] List(params Mediachase.Ibn.Data.SortingElement[] sorting) { return(MetaObject.List <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), sorting)); }
/// <summary> /// Updates the TTEntry Item /// </summary> /// <returns></returns> public static void UpdateEntry(int entryId, int totalApproved, decimal rate) { if (!Mediachase.Ibn.License.TimeTrackingModule) throw new Mediachase.Ibn.LicenseRestrictionException(); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { TimeTrackingEntry entry = new TimeTrackingEntry(entryId); TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance<TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), entry.ParentBlockId); if (!Security.CheckObjectRight(ttb, Right_RegFinances)) throw new AccessDeniedException(); using (SkipSecurityCheckScope skipSecurity = Security.SkipSecurityCheck()) { entry.Properties["TotalApproved"].Value = (double)totalApproved; entry.Properties["Rate"].Value = rate; entry.Save(); } tran.Commit(); } }
/// <summary> /// Adds the TimeTracking entries /// </summary> /// <param name="blockTypeInstanceId"></param> /// <param name="startDate"></param> /// <param name="ownerId"></param> /// <param name="objects"></param> /// <param name="objectTypes"></param> /// <param name="titles"></param> public static void AddEntries(int blockTypeInstanceId, DateTime startDate, int ownerId, List<int> objects, List<int> objectTypes, List<string> titles) { if (!Mediachase.Ibn.License.TimeTrackingModule) throw new Mediachase.Ibn.LicenseRestrictionException(); startDate = startDate.Date; // Get the list of existing entries TimeTrackingEntry[] existingEntries = TimeTrackingEntry.List( FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("BlockTypeInstanceId", blockTypeInstanceId), FilterElement.IsNotNullElement("ObjectId")); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { // Get the block TimeTrackingBlock block = GetTimeTrackingBlock(blockTypeInstanceId, startDate, ownerId, true); if (!Security.CanWrite(block)) throw new AccessDeniedException(); string entryCard = GetEntryCard(blockTypeInstanceId); // Loop by entries for (int i = 0; i < objects.Count; i++) { // Check for duplicates bool entryExists = false; foreach (TimeTrackingEntry existingEntry in existingEntries) { if (objects[i] == (int)existingEntry.Properties["ObjectId"].Value && objectTypes[i] == (int)existingEntry.Properties["ObjectTypeId"].Value) { entryExists = true; break; } } if (entryExists) continue; // Add the entry TimeTrackingEntry entry = new TimeTrackingEntry(); entry.ParentBlockId = block.PrimaryKeyId ?? -1; entry.Title = titles[i]; entry.BlockTypeInstanceId = blockTypeInstanceId; entry.OwnerId = ownerId; entry.Properties["Card"].Value = entryCard; entry.Properties["ObjectId"].Value = objects[i]; entry.Properties["ObjectTypeId"].Value = objectTypes[i]; entry.Save(); } tran.Commit(); } }
public TimeTrackingEntry(PrimaryKeyId primaryKeyId, MetaObjectOptions options) : base(TimeTrackingEntry.GetAssignedMetaClass(), primaryKeyId, options) { }
public static void AddEntries(DateTime startDate, int ownerId, List<int> entryIdList) { startDate = startDate.Date; // We use the dictionaries for optimization // whiteList contains the blocks for which we have the "Write" right // blackList contains the blocks for which we don't have the "Write" right Dictionary<int, TimeTrackingBlock> whiteList = new Dictionary<int, TimeTrackingBlock>(); Dictionary<int, TimeTrackingBlock> blackList = new Dictionary<int, TimeTrackingBlock>(); TimeTrackingEntry[] existingEntries = TimeTrackingEntry.List( FilterElement.EqualElement("StartDate", startDate), FilterElement.EqualElement("OwnerId", ownerId)); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { TimeTrackingEntry[] entryList = TimeTrackingEntry.List(new FilterElement("PrimaryKeyId", FilterElementType.In, entryIdList)); foreach (TimeTrackingEntry srcEntry in entryList) { int blockTypeInstanceId = srcEntry.BlockTypeInstanceId; // Go to the next item if we don't have the "Write" right if (blackList.ContainsKey(blockTypeInstanceId)) continue; // Get the block TimeTrackingBlock block; if (whiteList.ContainsKey(blockTypeInstanceId)) { block = whiteList[blockTypeInstanceId]; } else // the block wasn't processed yet { block = GetTimeTrackingBlock(blockTypeInstanceId, startDate, ownerId, true); if (Security.CanWrite(block)) { whiteList.Add(blockTypeInstanceId, block); } else { blackList.Add(blockTypeInstanceId, block); continue; } } // Check for duplicates bool entryExists = false; foreach (TimeTrackingEntry existingEntry in existingEntries) { if (srcEntry.Properties["ObjectId"].Value != null && existingEntry.Properties["ObjectId"].Value != null && (int)srcEntry.Properties["ObjectId"].Value == (int)existingEntry.Properties["ObjectId"].Value && (int)srcEntry.Properties["ObjectTypeId"].Value == (int)existingEntry.Properties["ObjectTypeId"].Value) { entryExists = true; break; } else if (srcEntry.Properties["ObjectId"].Value == null && existingEntry.Properties["ObjectId"].Value == null && srcEntry.Title == existingEntry.Title) { entryExists = true; break; } } if (entryExists) continue; // Add the entry string entryCard = GetEntryCard(blockTypeInstanceId); TimeTrackingEntry entry = new TimeTrackingEntry(); entry.ParentBlockId = block.PrimaryKeyId ?? -1; entry.Title = srcEntry.Title; entry.BlockTypeInstanceId = blockTypeInstanceId; entry.OwnerId = ownerId; entry.Properties["Card"].Value = entryCard; if (srcEntry.Properties["ObjectId"].Value != null && srcEntry.Properties["ObjectTypeId"].Value != null) { entry.Properties["ObjectId"].Value = srcEntry.Properties["ObjectId"].Value; entry.Properties["ObjectTypeId"].Value = srcEntry.Properties["ObjectTypeId"].Value; } entry.Save(); } tran.Commit(); } }
public TimeTrackingEntry(CustomTableRow row) : base(TimeTrackingEntry.GetAssignedMetaClass(), row) { }
public static void AddHoursForEntryByObject(int objectId, int objectTypeId, string title, int projectId, int ownerId, DateTime startDate, int dayNum, int minutes, bool summarize) { if (!Mediachase.Ibn.License.TimeTrackingModule) throw new Mediachase.Ibn.LicenseRestrictionException(); startDate = startDate.Date; // O.R. [2008-07-25] TimeTrackingBlockTypeInstance inst = null; using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck()) { inst = GetBlockTypeInstanceByProject(projectId); } if (inst == null) throw new ArgumentException("ProjectId is wrong or corresponding BlockTypeInstance does not exists."); using (TransactionScope tran = DataContext.Current.BeginTransaction()) { // O.R. [2008-07-28] TimeTrackingBlock block = null; using (SkipSecurityCheckScope scope = Mediachase.Ibn.Data.Services.Security.SkipSecurityCheck()) { block = GetTimeTrackingBlock(inst.PrimaryKeyId.Value, startDate, ownerId, true); if (block == null || !Security.CanWrite(block)) throw new AccessDeniedException(); // Get the Entry TimeTrackingEntry entry = null; TimeTrackingEntry[] entryList = TimeTrackingEntry.List( FilterElement.EqualElement("BlockTypeInstanceId", inst.PrimaryKeyId), FilterElement.EqualElement("ObjectId", objectId), FilterElement.EqualElement("ObjectTypeId", objectTypeId), FilterElement.EqualElement("OwnerId", ownerId), FilterElement.EqualElement("StartDate", startDate) ); if (entryList.Length > 0) { entry = entryList[0]; } else { string entryCard = GetEntryCard(inst.PrimaryKeyId.Value); entry = new TimeTrackingEntry(); entry.ParentBlockId = block.PrimaryKeyId ?? -1; entry.Title = title; entry.BlockTypeInstanceId = inst.PrimaryKeyId.Value; entry.OwnerId = ownerId; entry.Properties["Card"].Value = entryCard; entry.Properties["ObjectId"].Value = objectId; entry.Properties["ObjectTypeId"].Value = objectTypeId; } switch (dayNum) { case 1: if (summarize) entry.Day1 = (double)Math.Min(entry.Day1 + minutes, 1440); else entry.Day1 = (double)Math.Min(minutes, 1440); break; case 2: if (summarize) entry.Day2 = (double)Math.Min(entry.Day2 + minutes, 1440); else entry.Day2 = (double)Math.Min(minutes, 1440); break; case 3: if (summarize) entry.Day3 = (double)Math.Min(entry.Day3 + minutes, 1440); else entry.Day3 = (double)Math.Min(minutes, 1440); break; case 4: if (summarize) entry.Day4 = (double)Math.Min(entry.Day4 + minutes, 1440); else entry.Day4 = (double)Math.Min(minutes, 1440); break; case 5: if (summarize) entry.Day5 = (double)Math.Min(entry.Day5 + minutes, 1440); else entry.Day5 = (double)Math.Min(minutes, 1440); break; case 6: if (summarize) entry.Day6 = (double)Math.Min(entry.Day6 + minutes, 1440); else entry.Day6 = (double)Math.Min(minutes, 1440); break; case 7: if (summarize) entry.Day7 = (double)Math.Min(entry.Day7 + minutes, 1440); else entry.Day7 = (double)Math.Min(minutes, 1440); break; } entry.Save(); } tran.Commit(); } }
public TimeTrackingEntry(CustomTableRow row, MetaObjectOptions options) : base(TimeTrackingEntry.GetAssignedMetaClass(), row, options) { }
/// <summary> /// Delete the TTEntry Item /// </summary> /// <returns></returns> public static bool DeleteEntry(TimeTrackingEntry entry) { if (!Mediachase.Ibn.License.TimeTrackingModule) throw new Mediachase.Ibn.LicenseRestrictionException(); bool retval = false; TimeTrackingBlock ttb = MetaObjectActivator.CreateInstance<TimeTrackingBlock>(TimeTrackingBlock.GetAssignedMetaClass(), entry.ParentBlockId); if (ttb != null && Security.CanWrite(ttb)) { entry.Delete(); retval = true; } return retval; }
public static TimeTrackingEntry[] List() { return(MetaObject.List <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass())); }