public bool IsEnable(object Sender, object Element)
        {
            bool retval = true;

            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;

                if (cp.CommandArguments["primaryKeyId"] == null)
                {
                    throw new ArgumentException("PrimaryKeyId is null for SetDefaultOrgAddressEnableHandler");
                }

                PrimaryKeyId pk     = PrimaryKeyId.Parse(cp.CommandArguments["primaryKeyId"]);
                EntityObject entity = BusinessManager.Load(AddressEntity.GetAssignedMetaClassName(), pk);
                retval = !(bool)entity.Properties["IsDefaultOrganizationElement"].Value;
            }

            return(retval);
        }
Ejemplo n.º 2
0
        public void Invoke(object Sender, object Element)
        {
            if (Element is CommandParameters)
            {
                CommandParameters cp = (CommandParameters)Element;
                string[]          selectedElements = EntityGrid.GetCheckedCollection(((CommandManager)Sender).Page, cp.CommandArguments["GridId"]);

                if (selectedElements != null)
                {
                    string addressClassName = AddressEntity.GetAssignedMetaClassName();
                    int    errorCount       = 0;
                    using (TransactionScope tran = DataContext.Current.BeginTransaction())
                    {
                        foreach (string elem in selectedElements)
                        {
                            string       id  = elem.Split(new string[] { "::" }, StringSplitOptions.RemoveEmptyEntries)[0];
                            PrimaryKeyId key = PrimaryKeyId.Parse(id);

                            try
                            {
                                BusinessManager.Delete(addressClassName, key);
                            }
                            catch (Exception ex)
                            {
                                CHelper.GenerateErrorReport(ex);
                                errorCount++;
                            }
                        }

                        tran.Commit();
                    }

                    if (errorCount > 0)
                    {
                        ((CommandManager)Sender).InfoMessage = CHelper.GetResFileString("{IbnFramework.Common:NotAllSelectedItemsWereProcessed}");
                    }
                }
            }
        }