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());
        }
Example #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);
        }
Example #3
0
File: Util.cs Project: ewin66/dev
        /// <summary>
        /// Populate default data to database
        /// </summary>
        public static void Populate()
        {
            try
            {
                ////NAS.DAL.Accounting.AccountChart
                NAS.DAL.BI.Accounting.Account.CorrespondFinancialAccountDim.Populate();
                NAS.DAL.BI.Accounting.Account.FinancialAccountDim.Populate();
                Account.Populate();
                AccountType.Populate();
                AccountCategory.Populate();
                Currency.Populate();

                ////NAS.DAL.Accounting.Configure
                AllocationType.Populate();

                ////NAS.DAL.CMS.ObjectDocument
                ObjectType.Populate();
                CustomFieldType.Populate();
                ObjectTypeCustomField.Populate();

                ////NAS.DAL.Inventory.Item
                RecordedType.Populate();

                ////NAS.DAL.Inventory.Operation
                CommanderStockCartStatus.Populate();
                CommanderStockCartType.Populate();

                ////NAS.DAL.Inventory.StockCart
                StockCartActorType.Populate();

                ////NAS.DAL.Invoice
                TaxType.Populate();
                PromotionType.Populate();

                ////NAS.DAL.Nomenclature.Inventory
                Nomenclature.Inventory.Inventory.Populate();
                InventoryUnit.Populate();

                ////NAS.DAL.Nomenclature.Item
                ItemUnitRelationType.Populate();
                UnitType.Populate();
                Unit.Populate();
                ItemUnit.Populate();
                ItemTradingType.Populate();
                ItemCustomType.Populate();

                ////NAS.DAL.Nomenclature.Organization
                TradingCategory.Populate();
                AuthenticationProvider.Populate();
                DepartmentType.Populate();
                OrganizationType.Populate();
                Person.Populate();
                Organization.Populate();
                OwnerOrg.Populate();
                CustomerOrg.Populate();
                SupplierOrg.Populate();
                ManufacturerOrg.Populate();
                Department.Populate();
                DepartmentPerson.Populate();

                //NAS.DAL.Staging.Accounting.Journal
                AccountActorType.Populate();

                ////NAS.DAL.Vouches
                VouchesType.Populate();
                VouchesActorType.Populate();
                ReceiptVouchesType.Populate();
                PaymentVouchesType.Populate();
                ForeignCurrency.Populate();

                ////NAS.DAL.Accounting.Journal
                AccountingPeriod.Populate();
                //SalesInvoicePickingStockCart.Populate();

                ////NAS.DAL.System.ArtifactCode
                ArtifactType.Populate();
                CodeRuleDataType.Populate();
                CodeRuleDataFormat.Populate();
                RuleRepeaterType.Populate();

                //NAS.DAL.Sales.Price
                PricePolicyType.Populate();

                //NAS.DAL.Inventory.Lot.Lot
                NAS.DAL.Inventory.Lot.Lot.Populate();

                //NAS.DAL.Inventory.Command.InventoryCommandActorType
                NAS.DAL.Inventory.Command.InventoryCommandActorType.Populate();
                NAS.DAL.BI.Inventory.InventoryCommandDim.Populate();

                #region Other populate
                using (Session session = XpoHelper.GetNewSession())
                {
                    //Insert undefined supplier
                    if (!Util.isExistXpoObject <SupplierOrg>("OrganizationId",
                                                             Guid.Parse("3DEF2B62-2162-46CD-8418-DEE6F8E59E21")))
                    {
                        SupplierOrg undefinedSupplierOrg = new SupplierOrg(session)
                        {
                            OrganizationId       = Guid.Parse("3DEF2B62-2162-46CD-8418-DEE6F8E59E21"),
                            Name                 = "Mặc định",
                            Description          = "Mặc định",
                            Code                 = "MACDINH",
                            RowCreationTimeStamp = DateTime.Now,
                            RowStatus            = Constant.ROWSTATUS_ACTIVE,
                            OrganizationTypeId   =
                                NAS.DAL.Util.getDefaultXpoObject <OrganizationType>(session)
                        };
                        undefinedSupplierOrg.Save();
                    }
                }
                #endregion
            }
            catch (Exception)
            {
                throw new Exception("Populate failed");
            }
            finally
            {
            }
        }
Example #4
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);
        }