/// <summary> /// /// </summary> /// <typeparam name="T"></typeparam> /// <param name="fieldName"></param> /// <param name="value"></param> /// <param name="type"></param> /// <param name="rowStatuses">params of row status, default is all.</param> /// <returns></returns> public static bool isExistXpoObject <T>(string fieldName, object value, BinaryOperatorType type, params short[] rowStatuses) { Session session = null; try { CriteriaOperator rowStatusCriteria = null; if (rowStatuses.Length > 0) { rowStatusCriteria = new InOperator("RowStatus", rowStatuses.ToList()); } CriteriaOperator fieldCriteria = new BinaryOperator(fieldName, value, type); CriteriaOperator criteria = CriteriaOperator.And(fieldCriteria, rowStatusCriteria); session = XpoHelper.GetNewSession(); var result = session.GetObjects(session.GetClassInfo(typeof(T)), criteria, null, 0, false, true); if (result != null && result.Count > 0) { return(true); } else { return(false); } } catch (Exception) { throw; } finally { if (session != null) { session.Dispose(); } } }
/// <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 { } }