示例#1
0
        /// <summary>
        /// Insert a Product.
        /// </summary>
        public void Insert(Model.Product product)
        {
            this.Validate(product);
            //if (this.Exists(product.Id))
            //{
            //throw new Helper.InvalidValueException(Model.Product.PRO_Id);
            TiGuiExists(product);
            //  }

            if (this.ExistsNameInsert(product.ProductName))
            {
                throw new Helper.InvalidValueException(Model.Product.PRO_ProductName);
            }

            //设置KEY值
            string sequencekey = product.ProductCategory.Id;

            SequenceManager.Increment(sequencekey);

            StringBuilder strBU = new StringBuilder();

            string PrId = Guid.NewGuid().ToString();

            product.ProductId = PrId;
            if (product.BasedUnitGroup != null)
            {
                product.BasedUnitGroupId = product.BasedUnitGroup.UnitGroupId;
            }
            if (product.BuyEmployee != null)
            {
                product.BuyEmployeeId = product.BuyEmployee.EmployeeId;
            }
            if (product.BuyUnit != null)
            {
                product.BuyUnitId = product.BuyUnit.ProductUnitId;
            }
            if (product.CustomInspectionRule != null)
            {
                product.CustomInspectionRuleId = product.CustomInspectionRule.CustomInspectionRuleId;
            }
            if (product.Depot != null)
            {
                product.DepotId = product.Depot.DepotId;
            }
            if (product.DepotPosition != null)
            {
                product.DepotPositionId = product.DepotPosition.DepotPositionId;
            }
            if (product.DepotUnit != null)
            {
                product.DepotUnitId = product.DepotUnit.ProductUnitId;
            }
            //if (product.InsteadOfProductId != null) product.InsteadOfProductId = product.InsteadOfProduct.ProductId;
            if (product.MainUnit != null)
            {
                product.MainUnitId = product.MainUnit.ProductUnitId;
            }
            // if (product.PackageType != null) product.PackageTypeId = product.PackageType.PackageTypeId;
            if (product.ProduceUnit != null)
            {
                product.ProduceUnitId = product.ProduceUnit.ProductUnitId;
            }
            if (product.ProductCategory != null)
            {
                product.ProductCategoryId = product.ProductCategory.ProductCategoryId;
            }
            if (product.QualityTestPlan != null)
            {
                product.QualityTestPlanId = product.QualityTestPlan.QualityTestPlanId;
            }
            if (product.QualityTestUnit != null)
            {
                product.QualityTestUnitId = product.QualityTestUnit.ProductUnitId;
            }
            if (product.SellUnit != null)
            {
                product.SellUnitId = product.SellUnit.ProductUnitId;
            }
            // if (product.Supplier != null) product.SupplierId = product.Supplier.SupplierId;
            product.SupplierId = product.Supplier == null ? null : product.Supplier.SupplierId;
            if (product.VolumeUnit != null)
            {
                product.VolumeUnitId = product.VolumeUnit.ProductUnitId;
            }
            if (product.VolumeUnitGroup != null)
            {
                product.VolumeUnitGroupId = product.VolumeUnitGroup.UnitGroupId;
            }
            if (product.WeightUnit != null)
            {
                product.WeightUnitId = product.WeightUnit.ProductUnitId;
            }
            if (product.WeightUnitGroup != null)
            {
                product.WeightUnitGroupId = product.WeightUnitGroup.UnitGroupId;
            }
            //if (product.ProductImage == null)
            //    product.ProductImage = pic;
            //if (product.ProductImage1 == null)
            //    product.ProductImage1 = pic;
            //if (product.ProductImage2 == null)
            //    product.ProductImage2 = pic;
            //if (product.ProductImage3 == null)
            //    product.ProductImage3 = pic;

            product.ProductCategoryId = product.ProductCategory.ProductCategoryId;

            product.InsertTime = DateTime.Now;
            //product.UpdateTime = DateTime.Now;

            accessor.Insert(product);
            //ProductProcessAccessor.Delete(product);
            foreach (Model.ProductMouldDetail Pro in product.ProductMouldDetail)
            {
                if (string.IsNullOrEmpty(Pro.ProductMouldDetailId))
                {
                    continue;
                }
                Pro.ProductId = product.ProductId;
                ProductMouldDetailAccessor.Insert(Pro);
            }

            //自动生成对应的BOM单
            //string bomsql = " ProductId= '" + product.ProductId + "'";
            //if (!bomParentPartInfoAccessor.Exists_Field(bomsql))
            //{
            //Model.BomParentPartInfo bom = new Book.Model.BomParentPartInfo();
            //bom.BomId = Guid.NewGuid().ToString();
            //bom.Product = product;
            //bom.ProductId = product.ProductId;
            //bom.Id = new BL.BomParentPartInfoManager().GetId();
            //bom.LossRate = 0;
            //bom.EffectiveDate = DateTime.Now;
            //bom.DefaultQuantity = 1;
            //bom.Status = 0;
            //bom.IsEdit = "*";
            //new BL.BomParentPartInfoManager().Insert(bom);
            //}

            //foreach (Model.ProductProcess Pro in product.ProductProcess)
            //{
            //    if (string.IsNullOrEmpty(Pro.ProcessCategoryId)) continue;
            //    //strBU.Append(Pro.ProcessCategory.ProcessCategoryName);
            //    Pro.ProductProcessId = Guid.NewGuid().ToString();
            //    Pro.ProductId = product.ProductId;
            //    Pro.ProcessId = Pro.Process == null ? null : Pro.Process.ProcessId;

            //    Pro.ProcessCategoryId = Pro.ProcessCategory == null ? null : Pro.ProcessCategory.ProcessCategoryId;
            //    ProductProcessAccessor.Insert(Pro);
            //}



            //加工后名称添加
            ////if (product.ProductProcess!=null)
            ////{
            ////    if (product.ProductProcess.Count > 0)
            ////    {
            ////        product.ProductId = Guid.NewGuid().ToString();
            ////        ////product.ProductName = product.ProProcessName;0827
            ////        ProductProcessAccessor.Delete(product);
            ////        product.ProceebeforeProductId = PrId;
            ////        product.IsProcee = true;
            ////        accessor.Insert(product);
            ////        foreach (Model.ProductProcess Pro in product.ProductProcess)
            ////        {
            ////            if (Pro.ProcessCategory == null) continue;
            ////            Pro.ProductProcessId = Guid.NewGuid().ToString();
            ////            Pro.ProductId = product.ProductId;
            ////            Pro.ProcessId = Pro.Process == null ? null : Pro.Process.ProcessId;
            ////            Pro.ProcessCategoryId = Pro.ProcessCategory == null ? null : Pro.ProcessCategory.ProcessCategoryId;
            ////            ProductProcessAccessor.Insert(Pro);
            ////        }
            ////    }
            ////}
            //}
            //自动产生对应的厂商商品
            if (!string.IsNullOrEmpty(product.SupplierId))
            {
                Model.SupplierProduct supplierProduct = new Book.Model.SupplierProduct();
                supplierProduct.SupplierProductId         = Guid.NewGuid().ToString();
                supplierProduct.SupplierId                = product.SupplierId;
                supplierProduct.ProductId                 = product.ProductId;
                supplierProduct.InsertTime                = DateTime.Now;
                supplierProduct.UpdateTime                = DateTime.Now;
                supplierProduct.SupplierProductPriceRange = "1/999999999999/0/0";
                supplierProductAccessor.Insert(supplierProduct);
            }
        }
示例#2
0
        /// <summary>
        /// Insert a Product.
        /// </summary>
        public void Insert(Model.Product product, Model.ProductMark productMark)
        {
            this.Validate(product);
            //if (this.Exists(product.Id))
            //{
            //throw new Helper.InvalidValueException(Model.Product.PRO_Id);
            TiGuiExists(product);
            //  }

            if (this.ExistsNameInsert(product.ProductName))
            {
                throw new Helper.InvalidValueException(Model.Product.PRO_ProductName);
            }

            //设置KEY值
            string sequencekey = product.ProductCategory.Id;

            SequenceManager.Increment(sequencekey);

            StringBuilder strBU = new StringBuilder();

            string PrId = Guid.NewGuid().ToString();

            product.ProductId = PrId;
            if (product.BasedUnitGroup != null)
            {
                product.BasedUnitGroupId = product.BasedUnitGroup.UnitGroupId;
            }
            if (product.BuyEmployee != null)
            {
                product.BuyEmployeeId = product.BuyEmployee.EmployeeId;
            }
            if (product.BuyUnit != null)
            {
                product.BuyUnitId = product.BuyUnit.ProductUnitId;
            }
            if (product.CustomInspectionRule != null)
            {
                product.CustomInspectionRuleId = product.CustomInspectionRule.CustomInspectionRuleId;
            }
            if (product.Depot != null)
            {
                product.DepotId = product.Depot.DepotId;
            }
            if (product.DepotPosition != null)
            {
                product.DepotPositionId = product.DepotPosition.DepotPositionId;
            }
            if (product.DepotUnit != null)
            {
                product.DepotUnitId = product.DepotUnit.ProductUnitId;
            }
            //if (product.InsteadOfProductId != null) product.InsteadOfProductId = product.InsteadOfProduct.ProductId;
            if (product.MainUnit != null)
            {
                product.MainUnitId = product.MainUnit.ProductUnitId;
            }
            // if (product.PackageType != null) product.PackageTypeId = product.PackageType.PackageTypeId;
            if (product.ProduceUnit != null)
            {
                product.ProduceUnitId = product.ProduceUnit.ProductUnitId;
            }
            if (product.ProductCategory != null)
            {
                product.ProductCategoryId = product.ProductCategory.ProductCategoryId;
            }
            if (product.QualityTestPlan != null)
            {
                product.QualityTestPlanId = product.QualityTestPlan.QualityTestPlanId;
            }
            if (product.QualityTestUnit != null)
            {
                product.QualityTestUnitId = product.QualityTestUnit.ProductUnitId;
            }
            if (product.SellUnit != null)
            {
                product.SellUnitId = product.SellUnit.ProductUnitId;
            }
            // if (product.Supplier != null) product.SupplierId = product.Supplier.SupplierId;
            product.SupplierId = product.Supplier == null ? null : product.Supplier.SupplierId;
            if (product.VolumeUnit != null)
            {
                product.VolumeUnitId = product.VolumeUnit.ProductUnitId;
            }
            if (product.VolumeUnitGroup != null)
            {
                product.VolumeUnitGroupId = product.VolumeUnitGroup.UnitGroupId;
            }
            if (product.WeightUnit != null)
            {
                product.WeightUnitId = product.WeightUnit.ProductUnitId;
            }
            if (product.WeightUnitGroup != null)
            {
                product.WeightUnitGroupId = product.WeightUnitGroup.UnitGroupId;
            }
            //if (product.ProductImage == null)
            //    product.ProductImage = pic;
            //if (product.ProductImage1 == null)
            //    product.ProductImage1 = pic;
            //if (product.ProductImage2 == null)
            //    product.ProductImage2 = pic;
            //if (product.ProductImage3 == null)
            //    product.ProductImage3 = pic;

            product.ProductCategoryId = product.ProductCategory.ProductCategoryId;

            product.InsertTime = DateTime.Now;
            //product.UpdateTime = DateTime.Now;

            accessor.Insert(product);
            //ProductProcessAccessor.Delete(product);
            foreach (Model.ProductMouldDetail Pro in product.ProductMouldDetail)
            {
                if (string.IsNullOrEmpty(Pro.ProductMouldDetailId))
                {
                    continue;
                }
                Pro.ProductId = product.ProductId;
                ProductMouldDetailAccessor.Insert(Pro);
            }


            //雪芬-貼標籤  和  安適康 两家厂商自动带入 厂商商品对照表
            if (product.SupplierId == "e94591ac-aab4-47f0-b5bb-110e72cf155e" || product.SupplierId == "a7622c31-7d70-45de-a407-595dae617d36")
            {
                Model.SupplierProduct supplierProduct = new Book.Model.SupplierProduct();
                supplierProduct.SupplierProductId = Guid.NewGuid().ToString();
                supplierProduct.SupplierId        = product.SupplierId;
                supplierProduct.ProductId         = product.ProductId;
                supplierProduct.InsertTime        = DateTime.Now;
                supplierProduct.UpdateTime        = DateTime.Now;

                if (product.SupplierId == "e94591ac-aab4-47f0-b5bb-110e72cf155e")
                {
                    supplierProduct.SupplierProductPriceRange = "1/999999999999/0.092";
                }
                else
                {
                    supplierProduct.SupplierProductPriceRange = "1/999999999999/0";
                }

                supplierProduct.BuildEmployeeId = BL.V.ActiveOperator.EmployeeId;

                new SupplierProductManager().Insert(supplierProduct);
            }

            //商品唛头  2021年7月18日19:40:18
            if (!string.IsNullOrEmpty(productMark.MainMark) || !string.IsNullOrEmpty(productMark.SideMark))
            {
                productMark.Id        = Guid.NewGuid().ToString();
                productMark.ProductId = product.ProductId;

                productMarkAccessor.Insert(productMark);
            }


            //foreach (Model.ProductProcess Pro in product.ProductProcess)
            //{
            //    if (string.IsNullOrEmpty(Pro.ProcessCategoryId)) continue;
            //    //strBU.Append(Pro.ProcessCategory.ProcessCategoryName);
            //    Pro.ProductProcessId = Guid.NewGuid().ToString();
            //    Pro.ProductId = product.ProductId;
            //    Pro.ProcessId = Pro.Process == null ? null : Pro.Process.ProcessId;

            //    Pro.ProcessCategoryId = Pro.ProcessCategory == null ? null : Pro.ProcessCategory.ProcessCategoryId;
            //    ProductProcessAccessor.Insert(Pro);
            //}



            //加工后名称添加
            ////if (product.ProductProcess!=null)
            ////{
            ////    if (product.ProductProcess.Count > 0)
            ////    {
            ////        product.ProductId = Guid.NewGuid().ToString();
            ////        ////product.ProductName = product.ProProcessName;0827
            ////        ProductProcessAccessor.Delete(product);
            ////        product.ProceebeforeProductId = PrId;
            ////        product.IsProcee = true;
            ////        accessor.Insert(product);
            ////        foreach (Model.ProductProcess Pro in product.ProductProcess)
            ////        {
            ////            if (Pro.ProcessCategory == null) continue;
            ////            Pro.ProductProcessId = Guid.NewGuid().ToString();
            ////            Pro.ProductId = product.ProductId;
            ////            Pro.ProcessId = Pro.Process == null ? null : Pro.Process.ProcessId;
            ////            Pro.ProcessCategoryId = Pro.ProcessCategory == null ? null : Pro.ProcessCategory.ProcessCategoryId;
            ////            ProductProcessAccessor.Insert(Pro);
            ////        }
            ////    }
            ////}
            //}
        }