示例#1
0
        public static void DeleteLogical(Guid supplierOrgId)
        {
            Session session = null;

            try
            {
                session = XpoHelper.GetNewSession();
                //Finds ManufacturerOrg by Id
                SupplierOrg supplierOrg = session.GetObjectByKey <SupplierOrg>(supplierOrgId);
                //Check foreign key constraint with Item table
                var itemList = supplierOrg.ItemSuppliers.Where(r => r.ItemId.RowStatus > 0);
                if (itemList.Count() > 0)
                {
                    string param0 = supplierOrg.Name;
                    string param1 = itemList.First().ItemId.Name;
                    throw new Exception(String.Format("Nhà cung cấp '{0}' đang được cấu hình trong hàng hóa '{1}'", param0, param1));
                }
                supplierOrg.RowStatus = Utility.Constant.ROWSTATUS_DELETED;
                supplierOrg.Save();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
示例#2
0
        public void Populate(string dataFilePath)
        {
            string          filePath      = dataFilePath;
            string          connStr       = Utils.GetOleConnectionString(filePath, true);
            string          dataSheetName = "dmkhachhang-nhacungcap";
            OleDbConnection connection    = null;

            try
            {
                connection = new OleDbConnection(connStr);
                connection.Open();

                OleDbCommand command =
                    new OleDbCommand("select * from [" + dataSheetName + "$]", connection);


                List <OrganizationEntity> organizationEntityList = new List <OrganizationEntity>();

                using (OleDbDataReader dr = command.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        //Collect data
                        OrganizationEntity organizationEntity = new OrganizationEntity()
                        {
                            Code          = (string)Utils.ConvertToNullIfDbNull(dr["Code"]),
                            Name          = (string)Utils.ConvertToNullIfDbNull(dr["Name"]),
                            Address       = (string)Utils.ConvertToNullIfDbNull(dr["Address"]),
                            TaxNumber     = (string)Utils.ConvertToNullIfDbNull(dr["TaxNumber"]),
                            Description   = (string)Utils.ConvertToNullIfDbNull(dr["Description"]),
                            AccountNumber = (string)Utils.ConvertToNullIfDbNull(dr["AccountNumber"]),
                            BankName      = (string)Utils.ConvertToNullIfDbNull(dr["BankName"]),
                        };

                        organizationEntityList.Add(organizationEntity);
                    }
                }

                using (Session session = XpoHelper.GetNewSession())
                {
                    //Populate NAAN_DEFAULT data
                    Util.Populate();


                    foreach (var organizationEntity in organizationEntityList)
                    {
                        try
                        {
                            //Check required
                            if (organizationEntity.Code == null || organizationEntity.Code.Trim().Length == 0)
                            {
                                continue;
                            }

                            //Check dupplicate code
                            bool isExist =
                                NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Organization.SupplierOrg>
                                    ("Code", organizationEntity.Code,
                                    Constant.ROWSTATUS_ACTIVE,
                                    Constant.ROWSTATUS_DEFAULT,
                                    Constant.ROWSTATUS_INACTIVE);
                            if (isExist)
                            {
                                continue;
                            }

                            //Get default organization type
                            OrganizationType defaultOrganizationType =
                                Util.getXPCollection <OrganizationType>(session, "Code", "NAAN_DEFAULT").FirstOrDefault();

                            SupplierOrg supplierOrg = new SupplierOrg(session)
                            {
                                AccountNumber        = organizationEntity.AccountNumber,
                                Address              = organizationEntity.Address,
                                BankName             = organizationEntity.BankName,
                                Code                 = organizationEntity.Code,
                                Description          = organizationEntity.Description,
                                Name                 = organizationEntity.Name,
                                TaxNumber            = organizationEntity.TaxNumber,
                                OrganizationTypeId   = defaultOrganizationType,
                                RowStatus            = Constant.ROWSTATUS_ACTIVE,
                                RowCreationTimeStamp = DateTime.Now
                            };
                            supplierOrg.Save();
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
示例#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
            {
            }
        }