示例#1
0
        public CodeRuleNumberData Insert(
            Session session,
            Guid codeRuleDefinitionId,
            Guid codeRuleDataFormatId,
            int beginNumber,
            int step,
            int endNumber,
            Guid ruleRepeaterTypeId)
        {
            CodeRuleNumberData codeRuleNumberData = null;

            try
            {
                //Get CodeRuleDefinition
                CodeRuleDefinition codeRuleDefinition = session.GetObjectByKey <CodeRuleDefinition>(codeRuleDefinitionId);
                //Get CodeRuleDataFormat
                CodeRuleDataFormat codeRuleDataFormat = session.GetObjectByKey <CodeRuleDataFormat>(codeRuleDataFormatId);
                //Get RuleRepeaterType
                RuleRepeaterType ruleRepeaterType = session.GetObjectByKey <RuleRepeaterType>(ruleRepeaterTypeId);
                //Create new CodeRuleStringData
                codeRuleNumberData = new CodeRuleNumberData(session)
                {
                    CodeRuleDataFormatId = codeRuleDataFormat,
                    CodeRuleDataId       = Guid.NewGuid(),
                    CodeRuleDefinitionId = codeRuleDefinition,
                    CreateDate           = DateTime.Now,
                    RowStatus            = Utility.Constant.ROWSTATUS_ACTIVE,
                    BeginNumberValue     = beginNumber,
                    EndNumberValue       = endNumber,
                    LastNumber           = beginNumber - step,
                    RuleRepeaterTypeId   = ruleRepeaterType,
                    Step = step
                };
                codeRuleNumberData.Save();
                return(codeRuleNumberData);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
示例#2
0
        public CodeRuleNumberData Update(Session session,
                                         Guid codeRuleDefinitionId,
                                         Guid codeRuleDataFormatId,
                                         int beginNumber,
                                         int step,
                                         int endNumber,
                                         Guid ruleRepeaterTypeId)
        {
            CodeRuleNumberData codeRuleNumberData = null;

            try
            {
                CodeRuleDataBO codeRuleDataBO = new CodeRuleDataBO();
                //Check updating CodeRuleDataType already exist
                //Get CodeRuleDataFormat
                CodeRuleDataFormat codeRuleDataFormat =
                    session.GetObjectByKey <CodeRuleDataFormat>(codeRuleDataFormatId);

                //Get CodeRuleDefinition
                CodeRuleDefinition codeRuleDefinition =
                    session.GetObjectByKey <CodeRuleDefinition>(codeRuleDefinitionId);

                codeRuleNumberData = (CodeRuleNumberData)codeRuleDataBO.GetCodeRuleData(session,
                                                                                        codeRuleDefinition.CodeRuleDefinitionId,
                                                                                        codeRuleDataFormat.CodeRuleDataTypeId.CodeRuleDataTypeId);

                foreach (var item in codeRuleDefinition.CodeRuleData)
                {
                    item.RowStatus = Utility.Constant.ROWSTATUS_INACTIVE;
                    item.Save();
                }

                if (codeRuleNumberData == null)
                {
                    codeRuleNumberData =
                        Insert(session,
                               codeRuleDefinition.CodeRuleDefinitionId,
                               codeRuleDataFormatId,
                               beginNumber,
                               step,
                               endNumber,
                               ruleRepeaterTypeId);
                }
                else
                {
                    int  lastestNum         = 0;
                    bool isUpdateLastestNum = false;

                    RuleRepeaterType ruleRepeaterType = session.GetObjectByKey <RuleRepeaterType>(ruleRepeaterTypeId);

                    codeRuleNumberData.BeginNumberValue     = beginNumber;
                    codeRuleNumberData.Step                 = step;
                    codeRuleNumberData.EndNumberValue       = endNumber;
                    codeRuleNumberData.RuleRepeaterTypeId   = ruleRepeaterType;
                    codeRuleNumberData.CodeRuleDataFormatId = codeRuleDataFormat;
                    codeRuleNumberData.RowStatus            = Utility.Constant.ROWSTATUS_ACTIVE;
                    //If lastest number is out of updating range
                    //then update lastest number
                    lastestNum = codeRuleNumberData.LastNumber;
                    if (step > 0)
                    {
                        if (((lastestNum + step) > endNumber) || (lastestNum + step) < beginNumber)
                        {
                            isUpdateLastestNum = true;
                        }
                    }
                    else if (step < 0)
                    {
                        if (((lastestNum + step) < endNumber) || (lastestNum + step) > beginNumber)
                        {
                            isUpdateLastestNum = true;
                        }
                    }
                    if (isUpdateLastestNum)
                    {
                        //update lastest number
                        codeRuleNumberData.LastNumber = beginNumber - step;
                    }
                    codeRuleNumberData.Save();
                }

                return(codeRuleNumberData);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#3
0
文件: Util.cs 项目: 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
            {
            }
        }