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(); } }
/// <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()); }
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) { 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(); } } }