private void UpdateMasterAccountActorComboBox(object sender)
        {
            ASPxCallbackPanel panel = sender as ASPxCallbackPanel;
            GridViewEditItemTemplateContainer itemContainer = (GridViewEditItemTemplateContainer)panel.NamingContainer;
            ASPxGridView grid = itemContainer.Grid;
            //Get allocation
            ASPxComboBox allocationComboBox =
                (ASPxComboBox)grid.FindEditRowCellTemplateControl(grid.Columns["Allocation!Key"] as GridViewDataColumn, "cboAllocation");

            if (allocationComboBox.Value == null)
            {
                return;
            }
            Guid       allocationId = (Guid)allocationComboBox.Value;
            Allocation allocation   = session.GetObjectByKey <Allocation>(allocationId);
            //Get account actor type
            AllocationAccountActorType masterAllocationAccountActorType =
                allocation.AllocationAccountActorTypes.FirstOrDefault(r => r.IsMaster);

            if (masterAllocationAccountActorType == null)
            {
                throw new Exception("Invalid allocation. Make sure that the allocation has a master account actor type.");
            }
            AccountActorType accountActorType = masterAllocationAccountActorType.AccountActorTypeId;

            AccountActorTypeEnum accountActorTypeEnum =
                (AccountActorTypeEnum)Enum.Parse(typeof(AccountActorTypeEnum), accountActorType.Code);
            //Get account actor combobox
            AccountActorComboBox accountActorComboBox =
                (AccountActorComboBox)panel.FindControl("accountActorComboBox"); //FindEditRowCellTemplateControl(grid.Columns["MasterAccountActor"] as GridViewDataColumn, "accountActorComboBox");

            //Validation setting
            accountActorComboBox.ComboBox.ValidationSettings.ErrorDisplayMode         = ErrorDisplayMode.ImageWithTooltip;
            accountActorComboBox.ComboBox.ValidationSettings.RequiredField.IsRequired = true;
            accountActorComboBox.ComboBox.ValidationSettings.RequiredField.ErrorText  =
                (string)HttpContext.GetGlobalResourceObject("MessageResource", "Msg_Required_Select");
            //Set account actor combobox strategy
            accountActorComboBox.SetAccountActorComboBoxStrategy(
                AccountActorComboBoxStrategyCreators.GetCreator(accountActorTypeEnum).Create());
        }
Ejemplo n.º 2
0
        public bool AllocationEditing_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "SAVE":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutAllocationEditingForm))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid             selectedAllocationTypeId;
                        Guid             selectedAccountActorTypeId;
                        AllocationType   selectedAllocationType   = null;
                        AccountActorType selectedAccountActorType = null;
                        Allocation       allocation = null;
                        bool             isParseSuccess;

                        //Get selected allocation type
                        isParseSuccess = Guid.TryParse(cboAllocationType.Value.ToString(), out selectedAllocationTypeId);
                        if (!isParseSuccess)
                        {
                            throw new Exception("The string is invalid for parsing to GUID");
                        }
                        selectedAllocationType = uow.GetObjectByKey <AllocationType>(selectedAllocationTypeId);

                        //Update allocation
                        allocation                  = uow.GetObjectByKey <Allocation>(AllocationId);
                        allocation.Code             = txtCode.Text;
                        allocation.Name             = txtName.Text;
                        allocation.Description      = txtDescription.Text;
                        allocation.AllocationTypeId = selectedAllocationType;

                        //Get selected IsMaster AccountActorType
                        isParseSuccess =
                            Guid.TryParse(cbIsMasterAccountActorType.Value.ToString()
                                          , out selectedAccountActorTypeId);
                        if (!isParseSuccess)
                        {
                            throw new Exception("The string is invalid for parsing to GUID");
                        }
                        selectedAccountActorType = uow.GetObjectByKey <AccountActorType>(selectedAccountActorTypeId);

                        //Update isMaster AllocationAccountActorType
                        AllocationAccountActorType isMasterAllocationAccountActorType =
                            allocation.AllocationAccountActorTypes.FirstOrDefault(r => r.IsMaster);
                        if (isMasterAllocationAccountActorType != null)
                        {
                            isMasterAllocationAccountActorType.AccountActorTypeId = selectedAccountActorType;
                        }
                        else
                        {
                            //Create new IsMaster AllocationAccountActorType
                            AllocationAccountActorType allocationAccountActorType
                                = new AllocationAccountActorType(uow)
                                {
                                AccountActorTypeId = selectedAccountActorType,
                                AllocationId       = allocation,
                                IsMaster           = true
                                };
                        }

                        //Get selected ids in gridlookupAccountActorType
                        var relatedAccountActorTypeIds = gridlookupAccountActorType.GridView
                                                         .GetSelectedFieldValues("AccountActorTypeId")
                                                         .Select(r => Guid.Parse(r.ToString()));
                        List <AllocationAccountActorType> relatedAccountActorTypes =
                            allocation.AllocationAccountActorTypes.Where(r => !r.IsMaster).ToList();
                        uow.Delete(relatedAccountActorTypes);

                        //Create new related AllocationAccountActorTypes
                        foreach (var relatedAccountActorTypeId in relatedAccountActorTypeIds)
                        {
                            AllocationAccountActorType relatedAllocationAccountActorType
                                = new AllocationAccountActorType(uow)
                                {
                                AccountActorTypeId = uow.GetObjectByKey <AccountActorType>(relatedAccountActorTypeId),
                                AllocationId       = allocation,
                                IsMaster           = false
                                };
                            relatedAllocationAccountActorType.Save();
                        }

                        //Set new Id to session variable
                        AllocationId = allocation.AllocationId;
                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool AllocationCreating_PreTransitionCRUD(string transition)
        {
            switch (transition.ToUpper())
            {
            case "SAVE":
                if (ASPxEdit.ValidateEditorsInContainer(formlayoutAllocationEditingForm))
                {
                    using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
                    {
                        Guid             selectedAllocationTypeId;
                        Guid             selectedAccountActorTypeId;
                        AllocationType   selectedAllocationType   = null;
                        AccountActorType selectedAccountActorType = null;
                        Allocation       allocation = null;
                        bool             isParseSuccess;

                        //Get selected allocation type
                        isParseSuccess = Guid.TryParse(cboAllocationType.Value.ToString(), out selectedAllocationTypeId);
                        if (!isParseSuccess)
                        {
                            throw new Exception("The string is invalid for parsing to GUID");
                        }
                        selectedAllocationType = uow.GetObjectByKey <AllocationType>(selectedAllocationTypeId);

                        //Create new allocation
                        allocation = new Allocation(uow)
                        {
                            AllocationId     = Guid.NewGuid(),
                            AllocationTypeId = selectedAllocationType,
                            Code             = txtCode.Text,
                            Description      = txtDescription.Text,
                            Name             = txtName.Text,
                            RowStatus        = Utility.Constant.ROWSTATUS_ACTIVE
                                               //OwnerOrgId
                        };

                        //Get selected IsMaster AccountActorType
                        isParseSuccess =
                            Guid.TryParse(cbIsMasterAccountActorType.Value.ToString()
                                          , out selectedAccountActorTypeId);
                        if (!isParseSuccess)
                        {
                            throw new Exception("The string is invalid for parsing to GUID");
                        }
                        selectedAccountActorType = uow.GetObjectByKey <AccountActorType>(selectedAccountActorTypeId);

                        //Create new IsMaster AllocationAccountActorType
                        AllocationAccountActorType allocationAccountActorType
                            = new AllocationAccountActorType(uow)
                            {
                            AccountActorTypeId = selectedAccountActorType,
                            AllocationId       = allocation,
                            IsMaster           = true
                            };

                        //Get selected ids in gridlookupAccountActorType
                        var relatedAccountActorTypeIds = gridlookupAccountActorType.GridView
                                                         .GetSelectedFieldValues("AccountActorTypeId")
                                                         .Select(r => Guid.Parse(r.ToString()));
                        //Create new related AllocationAccountActorTypes
                        foreach (var relatedAccountActorTypeId in relatedAccountActorTypeIds)
                        {
                            AllocationAccountActorType relatedAllocationAccountActorType
                                = new AllocationAccountActorType(uow)
                                {
                                AccountActorTypeId = uow.GetObjectByKey <AccountActorType>(relatedAccountActorTypeId),
                                AllocationId       = allocation,
                                IsMaster           = false
                                };
                            relatedAllocationAccountActorType.Save();
                        }

                        //Set new Id to session variable
                        AllocationId = allocation.AllocationId;
                        uow.CommitChanges();
                    }
                }
                else
                {
                    return(false);
                }
                break;

            default:
                break;
            }
            return(true);
        }