예제 #1
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp    = (CommandParameters)Element;
                string[]          elems = MetaGridServer.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);

                DateTime   weekStart = CHelper.GetRealWeekStartByDate(DateTime.Now).Date;
                List <int> entryIds  = new List <int>();

                foreach (string elem in elems)
                {
                    //int id = Convert.ToInt32(elem, CultureInfo.InvariantCulture);
                    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], CultureInfo.InvariantCulture);


                    if (type == TimeTrackingEntry.GetAssignedMetaClass().Name)
                    {
                        //if clone current week then abort
                        TimeTrackingEntry tte = MetaObjectActivator.CreateInstance <TimeTrackingEntry>(TimeTrackingEntry.GetAssignedMetaClass(), id);
                        if (weekStart == tte.StartDate)
                        {
                            throw new ArgumentException(CHelper.GetResFileString("{IbnFramework.TimeTracking:_mc_UnableToCloneMsg}"));
                        }

                        entryIds.Add(id);
                    }
                }

                if (entryIds.Count > 0)
                {
                    TimeTrackingManager.AddEntries(weekStart, Mediachase.IBN.Business.Security.CurrentUser.UserID, entryIds);
                }
            }
        }
예제 #2
0
        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();
                }
            }
        }
예제 #3
0
        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");
            }
        }