Beispiel #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();
                }
            }
        }
Beispiel #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();
                }
            }
        }
Beispiel #3
0
        public void InsertItems(List <ItemEntity> itemEntityList, string itemTradingTypeName, string objectTypeName)
        {
            using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork())
            {
                foreach (var itemEntity in itemEntityList)
                {
                    try
                    {
                        if (itemEntity.Code.Equals("EVE006"))
                        {
                            string debug = "Y";
                        }
                        //Check required
                        if (itemEntity.Code == null || itemEntity.Code.Trim().Length == 0)
                        {
                            continue;
                        }

                        //Check dupplicate code
                        bool isExist =
                            NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Item.Item>
                                ("Code", itemEntity.Code,
                                Constant.ROWSTATUS_ACTIVE,
                                Constant.ROWSTATUS_DEFAULT,
                                Constant.ROWSTATUS_INACTIVE);
                        if (isExist)
                        {
                            continue;
                        }
                        //Get item trading type
                        ItemTradingType itemTradingType =
                            Util.getXPCollection <ItemTradingType>(uow, "Name", itemTradingTypeName).FirstOrDefault();
                        //Get Manufacturer
                        ManufacturerOrg manufacturerOrg =
                            Util.getXPCollection <ManufacturerOrg>(uow, "Code", itemEntity.ManufacturerCode,
                                                                   Constant.ROWSTATUS_ACTIVE).FirstOrDefault();

                        if (manufacturerOrg == null)
                        {
                            manufacturerOrg = Util.getDefaultXpoObject <ManufacturerOrg>(uow);
                        }

                        //Insert into Item table
                        NAS.DAL.Nomenclature.Item.Item item = new NAS.DAL.Nomenclature.Item.Item(uow)
                        {
                            Code                 = itemEntity.Code,
                            Description          = itemEntity.Description,
                            ManufacturerOrgId    = manufacturerOrg,
                            ItemTradingTypeId    = itemTradingType,
                            Name                 = itemEntity.Name,
                            RowStatus            = Constant.ROWSTATUS_ACTIVE,
                            RowCreationTimeStamp = DateTime.Now
                        };
                        item.Save();

                        //Get Supplier
                        SupplierOrg supplierOrg = Util.getXPCollection <SupplierOrg>(uow, "Code", itemEntity.SupplierCode,
                                                                                     Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (supplierOrg != null)
                        {
                            //Insert into ItemSupplier table
                            ItemSupplier itemSupplier = new ItemSupplier(uow)
                            {
                                ItemId        = item,
                                SupplierOrgId = supplierOrg
                            };
                            itemSupplier.Save();
                        }

                        ObjectType objectType = Util.getXPCollection <ObjectType>(uow, "Name", objectTypeName,
                                                                                  Constant.ROWSTATUS_ACTIVE).FirstOrDefault();
                        if (objectType != null)
                        {
                            //Insert into ItemSupplier table
                            ItemCustomType itemCustomType = new ItemCustomType(uow)
                            {
                                ItemId       = item,
                                ObjectTypeId = objectType
                            };
                            itemCustomType.Save();
                        }

                        uow.CommitChanges();

                        //using (Session itemUnitSession = XpoHelper.GetNewSession())
                        //{
                        //    //Get UNIT relation type
                        //    ItemUnitRelationType unitRelationType =
                        //        NAS.DAL.Util.getXPCollection<ItemUnitRelationType>(itemUnitSession, "Name", "UNIT").FirstOrDefault();
                        //    itemEntity.ItemUnits = itemEntity.ItemUnits.OrderBy(r => r.Level).ToList();

                        //    ////Insert into ItemUnit
                        //    foreach (ItemUnitEntity itemUnitEntity in itemEntity.ItemUnits)
                        //    {

                        //        NAS.DAL.Nomenclature.Item.Item itemTemp =
                        //            NAS.DAL.Util.getXPCollection<NAS.DAL.Nomenclature.Item.Item>
                        //                (itemUnitSession, "Code", itemUnitEntity.ItemCode).FirstOrDefault();

                        //        Unit unit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.UnitCode).FirstOrDefault();

                        //        if (unit == null)
                        //            break;

                        //        Unit parentUnit =
                        //            NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.ParentUnitCode).FirstOrDefault();

                        //        ItemUnit parentItemUnit = itemTemp.ItemUnits.Where(r => r.UnitId == parentUnit).FirstOrDefault();

                        //        ItemUnit itemUnit = new ItemUnit(itemUnitSession)
                        //        {
                        //            ItemId = itemTemp,
                        //            ItemUnitRelationTypeId = unitRelationType,
                        //            NumRequired = itemUnitEntity.NumRequired,
                        //            RowStatus = Constant.ROWSTATUS_ACTIVE,
                        //            UnitId = unit,
                        //            ParentItemUnitId = parentItemUnit,
                        //            RowCreationTimeStamp = DateTime.Now
                        //        };
                        //        itemUnit.Save();
                        //    }
                        //}
                    }
                    catch (Exception ex)
                    {
                        string msg = ex.Message;
                    }
                }
            }
        }
Beispiel #4
0
        /// <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
            {
            }
        }