public void CreateProd_NoCode()
        {
            var entity = new ProductEntity();

            Assert.Throws(typeof(ApplicationException), () => {
                entity.Create();
            }, "Product code is necessary");
        }
        public async Task <IActionResult> CreateProduct(CreateProductModel model)
        {
            var entity = ProductEntity.Create(model.Name, model.Price, model.Quantity);
            await storageTableService.Create(entity);

            ViewBag.Message = "Product was created correctly";
            return(RedirectToAction(nameof(ProductIndex)));
        }
        public void CreateProd_NoPrice()
        {
            var code   = "P001";
            var title  = "Imoji / ToyWorld";
            var entity = new ProductEntity(code, title);

            Assert.Throws(typeof(ApplicationException), () => {
                entity.Create();
            }, "Price should greater than zero");
        }
        public void CreateProd_NoTitle()
        {
            var code   = "P001";
            var title  = string.Empty;
            var entity = new ProductEntity(code, title);

            Assert.Throws(typeof(ApplicationException), () => {
                entity.Create();
            }, "Product title is required");
        }
Beispiel #5
0
 public void SubmitForm(ProductEntity userEntity, string keyValue)
 {
     if (!string.IsNullOrEmpty(keyValue))
     {
         userEntity.Modify(keyValue);
     }
     else
     {
         userEntity.Create();
     }
     service.SubmitForm(userEntity, keyValue);
 }
Beispiel #6
0
 public void SubmitForm(ProductEntity productEntity, string keyValue)
 {
     if (string.IsNullOrEmpty(keyValue))
     {
         productEntity.Create();
         _service.Insert(productEntity);
     }
     else
     {
         productEntity.Modify(keyValue);
         _service.Update(productEntity);
     }
 }
        public void CreateProd_LongDescription()
        {
            var     code   = "P001";
            var     title  = "Imoji / ToyWorld";
            decimal price  = 2.99m;
            var     entity = new ProductEntity(code, title);

            entity.unitPrice   = price;
            entity.description = "This a very veeeeery long description, to validate that only 250 characters are allowed on description. And we are going to start writing now: 'Ein gutes Gewissen ist ein sanftes Ruhekissen', 'Einem geschenkten Gaul schaut man nicht ins Maul', 'Auch ein blindes Huhn findet mal ein Korn'";

            Assert.Throws(typeof(ApplicationException), () => {
                entity.Create();
            }, "Price should greater than zero");
        }
Beispiel #8
0
        //主子表保存
        public void SubmitForm(ProductEntity productEntity, string keyValue, List <ProductSubEntity> listProductSub)
        {
            if (!string.IsNullOrEmpty(keyValue))
            {
                productEntity.Modify(keyValue);
            }
            else
            {
                productEntity.Create();
            }
            List <ProductSubEntity> listProductSubUpdate = new List <ProductSubEntity>();
            List <FileEntity>       listFile             = new List <FileEntity>();

            foreach (var itemId in listProductSub)
            {
                ProductSubEntity productSubEntity = new ProductSubEntity();
                productSubEntity.F_ParentId      = productEntity.F_Id;
                productSubEntity.Attribute       = itemId.Attribute;
                productSubEntity.PictureGuId     = itemId.PictureGuId;
                productSubEntity.SKU             = itemId.SKU;
                productSubEntity.Supplier        = itemId.Supplier;
                productSubEntity.PurchaseAddress = itemId.PurchaseAddress;
                productSubEntity.HWeight         = itemId.HWeight;
                productSubEntity.GWeight         = itemId.GWeight;
                productSubEntity.SWeight         = itemId.SWeight;
                productSubEntity.Long            = itemId.Long;
                productSubEntity.Wide            = itemId.Wide;
                productSubEntity.High            = itemId.High;
                productSubEntity.PurchaseCost    = itemId.PurchaseCost;
                productSubEntity.TransportCost   = itemId.TransportCost;
                productSubEntity.OtherCost       = itemId.OtherCost;
                productSubEntity.F_Description   = itemId.F_Description;
                productSubEntity.Create();
                var      guid  = productSubEntity.F_Id;
                string[] files = itemId.PictureGuId.Split(',');
                foreach (string f in files)
                {
                    FileEntity file = new FileEntity();
                    file.F_ParentId = guid;
                    file.F_File     = f;
                    file.Create();
                    listFile.Add(file);
                }
                listProductSubUpdate.Add(productSubEntity);
            }
            service.SubmitForm(productEntity, listProductSubUpdate, keyValue);
        }
Beispiel #9
0
        public int Create(string code, string name, string description,
                          decimal unitPrice, int unitsInStock, decimal discount,
                          int unitsOrdered, string user)
        {
            var model = new ProductEntity(code, name)
            {
                description  = description,
                unitPrice    = unitPrice,
                unitsInStock = unitsInStock,
                unitsOrdered = unitsOrdered,
                discount     = discount,
                createdBy    = user
            };

            model.Create();
            return(this._productRepository.Create(model));
        }
        public async Task <IActionResult> Insert()
        {
            var categories = Enumerable.Range(0, 10).Select(x =>
            {
                var model  = CategoryMother.Create();
                var entity = CategoryEntity.Create(model.Name);
                return(entity);
            });
            await storageTableService.Create(categories);

            var products = Enumerable.Range(0, 10).Select(x =>
            {
                var model  = ProductMother.Create();
                var entity = ProductEntity.Create(model.Name, model.Price, model.Quantity);
                return(entity);
            });

            await storageTableService.Create(products);

            return(RedirectToAction(nameof(Index)));
        }
Beispiel #11
0
        public string SubmitForm(ProductEntity productEntity, string keyValue)
        {
            string f_Id;

            if (!string.IsNullOrEmpty(keyValue))
            {
                productEntity.Modify(keyValue);
                service.Update(productEntity);

                f_Id = keyValue;

                new LogApp().WriteDbLog("修改产品分类:" + productEntity.ProductName, DbLogType.Update);
            }
            else
            {
                f_Id = productEntity.Create();
                service.Insert(productEntity);
                new LogApp().WriteDbLog("新增产品分类:" + productEntity.ProductName, DbLogType.Create);
            }

            return(f_Id);
        }
Beispiel #12
0
        public string SubmitForm(ProductEntity productEntity, string id)
        {
            string _id;

            if (!string.IsNullOrEmpty(id))
            {
                productEntity.Modify(id);
                service.Update(productEntity);

                _id = id;

                new LogApp().WriteDbLog("修改产品分类:" + productEntity.ProductName, DbLogType.Update);
            }
            else
            {
                _id = productEntity.Create();
                service.Insert(productEntity);
                new LogApp().WriteDbLog("新增产品分类:" + productEntity.ProductName, DbLogType.Create);
            }

            return(_id);
        }
Beispiel #13
0
        private void Save()
        {
            if (Helpers.CheckEmpty(errorProvider1, txtProductName, txtPrice, dtpMadeDate, dtpExpireDate, txtBarcode))

            {
                return;
            }
            else
            {
                SaveCompleted = true;
                errorProvider1.Clear();
                ProductEntity productEntity = new ProductEntity();
                productEntity.ProductName = txtProductName.Text;
                productEntity.Price       = decimal.Parse(txtPrice.Text, NumberStyles.Currency);
                productEntity.Quantity    = int.Parse(txtQty.Text);
                productEntity.Barcode     = txtBarcode.Text;
                productEntity.MadeDate    = DateTime.Parse(dtpMadeDate.Text);
                productEntity.ExpireDate  = DateTime.Parse(dtpExpireDate.Text);
                productEntity.Active      = chkActive.Checked;
                productEntity.Photo       = myPicture1.GetByteArrayFromBrowse();
                productEntity.CategoryId  = (Guid)cboCategory.SelectedValue;

                if (productID != Guid.Empty)
                {
                    productEntity.Id = productID;
                    productEntity.Update(USER.UserName);
                    ProductDao.Update(productEntity);
                }
                else
                {
                    productEntity.Id = Guid.NewGuid();
                    productEntity.Create(USER.UserName);
                    ProductDao.Insert(productEntity);
                }
            }
        }
        /// <summary>
        /// 商品导入
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="dataResult"></param>
        /// <param name="errMessage"></param>
        /// <param name="importFile"></param>
        /// <returns></returns>
        public bool ImportProduct(ProductImportFileEntity importFile, DataTable dt, out DataTable dataResult, out string errMessage)
        {
            string userId = ManageProvider.Provider.Current().UserId;

            //构造导入返回结果表
            DataTable resultTable = new DataTable("Result");

            resultTable.Columns.Add("rowid", typeof(System.String));  //行号
            resultTable.Columns.Add("locate", typeof(System.String)); //位置
            resultTable.Columns.Add("reason", typeof(System.String)); //原因
            errMessage = string.Empty;
            bool isSuccess = false;

            if (dt != null && dt.Rows.Count > 0)
            {
                IDatabase database = DataFactory.Database();
                try
                {
                    List <ProductImportItemEntity> lstEntities = new List <ProductImportItemEntity>();
                    foreach (DataRow item in dt.Rows)
                    {
                        var importEntity = new ProductImportItemEntity();
                        importEntity.Create();
                        importEntity.FileId        = importFile.FileId;
                        importEntity.ProductCode   = item["商品编码"].ToString();
                        importEntity.ProductName   = item["商品名称"].ToString();
                        importEntity.BriefName     = item["商品简称"].ToString();
                        importEntity.Specification = item["规格"].ToString();
                        importEntity.BaseUnit      = item["基本单位"].ToString();
                        importEntity.BarCode       = item["商品条码"].ToString();
                        importEntity.Brand         = item["品牌"].ToString();

                        string  strWeight = item["重量"].ToString();
                        decimal weight    = 0;
                        if (decimal.TryParse(strWeight, out weight))
                        {
                            importEntity.Weight = weight;
                        }

                        string  strVolume = item["体积"].ToString();
                        decimal volume    = 0;
                        if (decimal.TryParse(strVolume, out volume))
                        {
                            importEntity.Volume = volume;
                        }

                        string  strLong     = item["长"].ToString();
                        decimal productLong = 0;
                        if (decimal.TryParse(strLong, out productLong))
                        {
                            importEntity.Long = productLong;
                        }

                        string  strWidth = item["宽"].ToString();
                        decimal width    = 0;
                        if (decimal.TryParse(strWidth, out width))
                        {
                            importEntity.Width = width;
                        }

                        string  strHeight = item["高"].ToString();
                        decimal height    = 0;
                        if (decimal.TryParse(strHeight, out height))
                        {
                            importEntity.Height = height;
                        }

                        string isLotControl = item["批号管控"].ToString();
                        importEntity.IsLotControl = isLotControl == "是" ? 1 : 0;

                        string isForceScan = item["是否强制扫描"].ToString();
                        importEntity.IsForcedScan = isForceScan == "是" ? 1 : 0;

                        importEntity.Remark = item["说明"].ToString();

                        if (string.IsNullOrWhiteSpace(importEntity.ProductCode))
                        {
                            throw new Exception("商品编码不能为空");
                        }
                        if (string.IsNullOrWhiteSpace(importEntity.ProductName))
                        {
                            throw new Exception("商品名称不能为空");
                        }

                        bool flag = _productBLL.IsExistProductCode(importEntity.ProductCode);
                        if (flag)
                        {
                            throw new Exception(string.Format("商品编码{0}已存在,不能重复导入", importEntity.ProductCode));
                        }

                        lstEntities.Add(importEntity);
                    }

                    DbTransaction isOpenTrans = database.BeginTrans();

                    List <ProductEntity> productEntities = new List <ProductEntity>();
                    foreach (ProductImportItemEntity importEntity in lstEntities)
                    {
                        ProductEntity productEntity = new ProductEntity();
                        productEntity.Create();
                        productEntity.ProductId     = importEntity.ProductId;
                        productEntity.Code          = importEntity.ProductCode;
                        productEntity.ProductName   = importEntity.ProductName;
                        productEntity.BriefName     = importEntity.BriefName;
                        productEntity.Width         = importEntity.Width;
                        productEntity.Volume        = importEntity.Volume;
                        productEntity.Specification = importEntity.Specification;
                        productEntity.Brand         = importEntity.Brand;
                        productEntity.BarCode       = importEntity.BarCode;
                        productEntity.BaseUnit      = importEntity.BaseUnit;
                        productEntity.Width         = importEntity.Width;
                        productEntity.Height        = importEntity.Height;
                        productEntity.Long          = importEntity.Long;
                        productEntity.IsLotControl  = importEntity.IsLotControl;
                        productEntity.IsForcedScan  = importEntity.IsForcedScan;
                        productEntity.Remark        = importEntity.Remark;
                        productEntities.Add(productEntity);
                    }

                    database.Insert(importFile);
                    foreach (ProductImportItemEntity orderImportEntity in lstEntities)
                    {
                        database.Insert(orderImportEntity, isOpenTrans);
                    }

                    foreach (ProductEntity orderImportEntity in productEntities)
                    {
                        database.Insert(orderImportEntity, isOpenTrans);
                    }

                    database.Commit();
                    isSuccess = true;
                }
                catch (Exception ex)
                {
                    database.Rollback();
                    BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message);
                    isSuccess  = false;
                    errMessage = ex.Message;
                }
            }
            dataResult = resultTable;
            return(isSuccess);
        }