/// <summary> /// 编辑商品 /// </summary> /// <param name="Rid"></param> /// <returns></returns> public ActionResult Edit(int Rid) { var model = new Product(); if (Rid > 0) { model = new DALProduct().GetSingleProduct(Rid); } return(View(model)); }
/// <summary> /// Converte dal entity to entity on bal /// </summary> /// <param name="entity">entity to be converted</param> /// <returns>bal entity</returns> public static ProductEntity ToBalProduct(this DALProduct entity) { return(new ProductEntity() { ProductsName = entity.ProductsName, Description = entity.Desription, Amount = entity.Amount, Price = entity.Price, Category = entity.Category, Buyer = entity.Buyer }); }
public ActionResult AddProduct(tbl_Product pd) { DALProduct dal = new DALProduct(); dal.AddProduct(pd); var catId = dal.GetAllCategoryId().ToList(); ViewData.Add("categoryId", catId); ViewData.Add("Message", "product record Added"); //RedirectToAction("ViewCategoryName"); return(View()); }
public static int CreatePV(ProductVariationInfo productVariation, ref List <string> errors) { if (productVariation == null) { errors.Add("Product Variation cannot be null"); return(-1); } System.Diagnostics.Debug.WriteLine("THIS IS THE PID:" + productVariation.product_id); if (productVariation.product_id <= 0 || productVariation.product_id > DALProduct.ReadProductList(ref errors).Count) { errors.Add("Invalid product_id"); } if (productVariation.product_brand_id <= 0 || productVariation.product_brand_id > DALBrand.ReadBrandList(ref errors).Count) { errors.Add("Invalid product_brand_id"); } if (productVariation.product_cutting_id <= 0 || productVariation.product_cutting_id > DALProductCutting.ReadProductCuttingList(ref errors).Count) { errors.Add("Invalid product_cutting_id"); } if (productVariation.product_color_id <= 0 || productVariation.product_color_id > DALProductColor.ReadProductColorList(ref errors).Count) { errors.Add("Invalid product_color_id"); } if (productVariation.sex != 'F' && productVariation.sex != 'M' && productVariation.sex != 'U') { errors.Add("Invalid sex"); } if (productVariation.size != "XS" && productVariation.size != "S" && productVariation.size != "M" && productVariation.size != "L" && productVariation.size != "XL" && productVariation.size != "XXL") { errors.Add("Invalid size"); } if (productVariation.stock < 0) { errors.Add("Invalid stock"); } if (productVariation.price < 0) { errors.Add("Invalid price"); } if (productVariation.condition != 'a' && productVariation.condition != 's' && productVariation.condition != 'd') { errors.Add("Invalid condition"); } if (errors.Count > 0) { return(-1); } return(DALProductVariationInfo.CreatePV(productVariation, ref errors)); }
/// <summary> /// 分页查询 /// </summary> /// <param name="model"></param> /// <param name="currentPage"></param> /// <param name="pageSize"></param> /// <returns></returns> public ActionResult PageList(Product model, int currentPage = 1, int pageSize = 20) { int recordCount = 0; List <Product> Product = new DALProduct().QueryPagination(currentPage, pageSize, out recordCount, model).ToList(); ViewBag.RecordCount = recordCount; ViewBag.CurrentPage = currentPage; ViewBag.PageSize = pageSize; ViewBag.PageCount = Math.Ceiling((double)recordCount / (double)pageSize); ViewBag.Model = model; return(View(Product)); }
public IHttpActionResult GetAll(int page) { IProducManager mprod = new IProducManager(); DALProduct dalProduct = new DALProduct(); var responseProducs = new ResponseProduct(); responseProducs.totalPaginas = mprod.Pagination(); responseProducs.products = dalProduct.GetProducts(page); return(Ok(responseProducs)); }
public static int UpdateProduct(int productId, string productName, ref List <string> errors) { if (productId <= 0 || productId > DALProduct.ReadProductList(ref errors).Count) { errors.Add("Invalid product id"); } if (errors.Count > 0) { return(-1); } return(DALProduct.UpdateProduct(productId, productName, ref errors)); }
public static ProductInfo ReadProduct(int productId, ref List <string> errors) { if (productId <= 0 || productId > DALProduct.ReadProductList(ref errors).Count) { errors.Add("Invalid product id"); } if (errors.Count > 0) { return(null); } return(DALProduct.ReadProductDetail(productId, ref errors)); }
public void ReadAllProductTest() { List <string> errors = new List <string>(); // TODO: Initialize to an appropriate value List <string> errorsExpected = new List <string>(); // TODO: Initialize to an appropriate value List <ProductInfo> ProductList1 = DALProduct.ReadProductList(ref errors); List <ProductInfo> ProductList2 = DALProduct.ReadProductList(ref errors); Assert.AreEqual(ProductList1.Count, ProductList2.Count); Assert.AreEqual(errors.Count, 0); for (int i = 0; i < ProductList1.Count; i++) { Assert.AreEqual(ProductList1[i].product_id, ProductList2[i].product_id); Assert.AreEqual(ProductList1[i].product_name, ProductList2[i].product_name); } }
public void CreateProductTest() { Random rand = new Random(); string product_name = "Hello Kitty" + rand.Next(10000); // TODO: Initialize to an appropriate value List <string> errors = new List <string>(); // TODO: Initialize to an appropriate value List <string> errorsExpected = new List <string>(); // TODO: Initialize to an appropriate value int actual; actual = DALProduct.CreateProduct(product_name, ref errors); ProductInfo pi = DALProduct.ReadProductDetail(actual, ref errors); Assert.AreEqual(pi.product_name, product_name); Assert.AreEqual(pi.product_id, actual); }
protected void btnDelete_Click(object sender, EventArgs e) { foreach (RepeaterItem item in rptProducts.Items) { CheckBox chbSelect = (CheckBox)item.FindControl("chbSelect"); if (chbSelect.Checked) { Label lblProductCode = (Label)item.FindControl("lblProductCode"); DALProduct obj = new DALProduct(); obj.Product_Delete(Convert.ToInt32(lblProductCode.Text)); } } BindProducts(); }
public int BusinessManufacturer(EntityAddProduct entity) { int Result = 0; SqlParameter objDataParams = new SqlParameter(); objDataParams = new SqlParameter("@Name", SqlDbType.VarChar, 50) { Value = entity.Manufacturer }; DALProduct obj = new DALProduct(); Result = obj.DataManufacturer(objDataParams); return(Result); }
protected void btnUpdate_Click(object sender, EventArgs e) { Products p = new Products(); p.ProductCode = Convert.ToInt32(Request.QueryString["p_c_z"]); p.CategoryCode = Convert.ToInt32(ddlCategory.SelectedValue); p.ProductName = txtProductName.Text; p.PurchaseRate = Convert.ToDecimal(txtPurchaseRate.Text); p.SaleRate = Convert.ToDecimal(txtSaleRate.Text); p.ExpiryDate = Convert.ToDateTime(txtExpiryDate.Text); DALProduct obj = new DALProduct(); obj.Product_Update(p); Response.Redirect("ProductList.aspx"); }
/// <summary> /// 添加/修改保存 /// </summary> /// <param name="model"></param> /// <returns></returns> public ActionResult Save(Product model) { ResultMsg msg = new ResultMsg(); //修改 if (model.Rid > 0) { msg = new DALProduct().Update(model); } //添加 else if (model.Rid == 0) { msg = new DALProduct().Insert(model); } return(Json(new { Success = msg.Success, Result = msg.ReturnInt, ErrMsg = msg.ErrMsg })); }
protected void Page_Load(object sender, EventArgs e) { if (Session["IsValid"] == null) { Response.Redirect("../Login.aspx"); } if (this.IsPostBack == false) { DALProduct obj = new DALProduct(); DataSet ds = obj.Product_Add_Load(); ddlCategory.DataTextField = "CategoryName"; ddlCategory.DataValueField = "CategoryCode"; ddlCategory.DataSource = ds.Tables[0]; ddlCategory.DataBind(); } }
public void UpdateProductTest() { int myId = 1; Random rand = new Random(); ProductInfo pi = new ProductInfo(myId, "turtle neck " + rand.Next(10000)); List <string> errors = new List <string>(); int result = DALProduct.UpdateProduct(pi.product_id, pi.product_name, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreNotEqual(-1, result); ProductInfo verify = DALProduct.ReadProductDetail(myId, ref errors); Assert.AreEqual(0, errors.Count); Assert.AreEqual(pi.product_id, verify.product_id); Assert.AreEqual(pi.product_name, verify.product_name); }
protected void Page_Load(object sender, EventArgs e) { if (Session["IsValid"] == null) { Response.Redirect("../Login.aspx"); } if (this.IsPostBack == false) { DALProduct obj = new DALProduct(); DataSet ds = obj.Product_Add_Load(); ddlCategory.DataTextField = "CategoryName"; ddlCategory.DataValueField = "CategoryCode"; ddlCategory.DataSource = ds.Tables[0]; ddlCategory.DataBind(); int productCode = Convert.ToInt32(Request.QueryString["p_c_z"]); BindProductDetail(productCode); } }
protected void btnSave_Click(object sender, EventArgs e) { try { Products p = new Products(); p.CategoryCode = Convert.ToInt32(ddlCategory.SelectedValue); p.ProductName = txtProductName.Text; p.PurchaseRate = Convert.ToDecimal(txtPurchaseRate.Text); p.SaleRate = Convert.ToDecimal(txtSaleRate.Text); p.ExpiryDate = Convert.ToDateTime(txtExpiryDate.Text); p.ImageURL = UploadImage(); DALProduct obj = new DALProduct(); obj.Product_Add(p); } catch (Exception ex) { DALUser obj = new DALUser(); obj.ErrorLog_Add("Add Product | " + ex.Message); lblMessage.Text = "Some invalid Data, check again"; } }
public static int UpdatePV(ProductVariationInfo productVariation, ref List <string> errors) { if (productVariation == null) { errors.Add("Product Variation cannot be null"); } else if (productVariation.product_variation_id <= 0 || productVariation.product_variation_id > DALProductVariationInfo.ReadPVList(ref errors).Count) { errors.Add("Invalid product variation id"); } else if (productVariation.product_id <= 0 || productVariation.product_id > DALProduct.ReadProductList(ref errors).Count) { errors.Add("Invalid product_id"); } else if (productVariation.product_brand_id <= 0 || productVariation.product_brand_id > DALBrand.ReadBrandList(ref errors).Count) { errors.Add("Invalid product_brand_d"); } else if (productVariation.product_cutting_id <= 0 || productVariation.product_cutting_id > DALProductCutting.ReadProductCuttingList(ref errors).Count) { errors.Add("Invalid product_cutting_id"); } else if (productVariation.product_color_id <= 0 || productVariation.product_color_id > DALProductColor.ReadProductColorList(ref errors).Count) { errors.Add("Invalid product_color_id"); } else if (productVariation.sex != 'F' && productVariation.sex != 'M' && productVariation.sex != 'U') { errors.Add("Invalid sex"); } else if (productVariation.size != "XS" && productVariation.size != "S" && productVariation.size != "M" && productVariation.size != "L" && productVariation.size != "XL" && productVariation.size != "XXL") { errors.Add("Invalid size"); } else if (productVariation.stock < 0) { errors.Add("Invalid stock"); } else if (productVariation.price < 0) { errors.Add("Invalid price"); } else if (productVariation.condition != 'a' && productVariation.condition != 's' && productVariation.condition != 'd') { errors.Add("Invalid condition"); } if (errors.Count > 0) { return(-1); } return(DALProductVariationInfo.UpdateProductVariationInfo(productVariation, ref errors)); }
/// <summary> /// /// </summary> /// <param name="folderName">包含excel和对应产品图片的文件夹</param> /// <param name="amountProductsHasPicture_NotExitsted">可供导入的产品(没有导入过,有图片)</param> /// <param name="amountProductNotHasPicture_OrHasExisted">不合格产品(已导入,或 没图片</param> /// <param name="amountProductExistsInDb_HasExisted">不合格产品(已导入)</param> /// <param name="amountImagesHasNotProduct_OrHasExisted">没有产品信息的图片</param> /// <param name="needCheckDataBase">是否从数据库查询产品是否存在</param> /// <param name="dalProduct">供mock,判断是否存在的方法</param> /// <param name="dalSupplier">供mock,获取供应商的方法.</param> private void CheckSingleFolderTest( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier) { IList <Product> productsHasPicture, productsNotHasPicture, productsExistedInDB; IList <FileInfo> imagesHasProduct, imagesHasNotProduct; string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; ProductImportor checker = new ProductImportor(); checker.BizProduct.DalBase = dalProduct; checker.BizProduct.DalSupplier = dalSupplier; checker.CheckWithDatabase = needCheckDataBase; checker.CheckSingleFolder(folderFullPath , out productsHasPicture , out productsNotHasPicture , out productsExistedInDB , out imagesHasProduct , out imagesHasNotProduct); // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, productsHasPicture.Count); Assert.AreEqual(amountProductNotHasPicture, productsNotHasPicture.Count); Assert.AreEqual(amountProductExistsInDb, productsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, imagesHasNotProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) { saveFolderOfSupplier = productsHasPicture[0].SupplierName; } else if (productsNotHasPicture.Count > 0) { saveFolderOfSupplier = productsNotHasPicture[0].SupplierName; } else { throw new Exception(); } DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier + "\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) { supplierName = productsExistedInDB[0].SupplierName; } else if (productsHasPicture.Count > 0) { supplierName = productsHasPicture[0].SupplierName; } else if (productsNotHasPicture.Count > 0) { supplierName = productsNotHasPicture[0].SupplierName; } else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, productsHasPicture , productsNotHasPicture , productsExistedInDB , imagesHasProduct , imagesHasNotProduct , saveFolder); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }
private void CheckSingleFolder2Test( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier , IFormatSerialNoPersistent ifsp , DalBase<Product> dalBaseProduct) { string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; SingleFolderImport checker = new SingleFolderImport(folderFullPath); BizProduct bizP = new BizProduct(); bizP.DalProduct = dalProduct; bizP.DalBase = dalBaseProduct; BizSupplier bizS = new BizSupplier(); bizS.DalSupplier = dalSupplier; bizP.DalSupplier = dalSupplier; checker.NeedCheckWithDB = needCheckDataBase; checker.Import(bizP, bizS, ifsp); IList<Product> productsHasPicture = checker.ProductsPassedDBCheck , productsNotHasPicture = checker.ProductsNotHasImage , productsExistedInDB = checker.ProductsExistedInDB; IList<FileInfo> imagesHasProduct = checker.ImagesHasProduct , imagesHasNotProduct = checker.ImagesNotHasProduct; // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, checker.ProductsPassedDBCheck.Count); Assert.AreEqual(amountProductNotHasPicture, checker.ProductsNotHasImage.Count); Assert.AreEqual(amountProductExistsInDb, checker.ProductsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, checker.ImagesNotHasProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) saveFolderOfSupplier = bizS.GetByCode(productsHasPicture[0].SupplierCode).Name; else if (productsNotHasPicture.Count > 0) saveFolderOfSupplier = bizS.GetByCode(productsNotHasPicture[0].SupplierCode).Name; else throw new Exception(); DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier + "\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) supplierName = bizS.GetByCode(productsExistedInDB[0].SupplierCode).Name; else if (productsHasPicture.Count > 0) supplierName = bizS.GetByCode(productsHasPicture[0].SupplierCode).Name; else if (productsNotHasPicture.Count > 0) supplierName = bizS.GetByCode(productsNotHasPicture[0].SupplierCode).Name; else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, saveFolder, WebProductImagesPath ); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }
public string[] GetProductsByName(string prefixText, int count) { DAL.DALProduct dALProduct = new DALProduct(); return(dALProduct.GetLstProductsByName(prefixText, count)); }
/// <summary> /// /// </summary> /// <param name="folderName">包含excel和对应产品图片的文件夹</param> /// <param name="amountProductsHasPicture_NotExitsted">可供导入的产品(没有导入过,有图片)</param> /// <param name="amountProductNotHasPicture_OrHasExisted">不合格产品(已导入,或 没图片</param> /// <param name="amountProductExistsInDb_HasExisted">不合格产品(已导入)</param> /// <param name="amountImagesHasNotProduct_OrHasExisted">没有产品信息的图片</param> /// <param name="needCheckDataBase">是否从数据库查询产品是否存在</param> /// <param name="dalProduct">供mock,判断是否存在的方法</param> /// <param name="dalSupplier">供mock,获取供应商的方法.</param> private void CheckSingleFolderTest( string folderName , int amountProductsHasPicture , int amountProductNotHasPicture , int amountProductExistsInDb , int amountImagesHasNotProduct , bool needCheckDataBase , DALProduct dalProduct , DALSupplier dalSupplier) { IList<Product> productsHasPicture, productsNotHasPicture, productsExistedInDB; IList<FileInfo> imagesHasProduct, imagesHasNotProduct; string folderFullPath = Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\" + folderName + "\\"; ProductImportor checker = new ProductImportor(); checker.BizProduct.DalBase = dalProduct; checker.BizProduct.DalSupplier = dalSupplier; checker.CheckWithDatabase = needCheckDataBase; checker.CheckSingleFolder(folderFullPath , out productsHasPicture , out productsNotHasPicture , out productsExistedInDB , out imagesHasProduct , out imagesHasNotProduct); // Assert.AreEqual("Success", FormatChecker.Check(folderContainsExcelAndImages)); Assert.AreEqual(amountProductsHasPicture, productsHasPicture.Count); Assert.AreEqual(amountProductNotHasPicture, productsNotHasPicture.Count); Assert.AreEqual(amountProductExistsInDb, productsExistedInDB.Count); Assert.AreEqual(amountImagesHasNotProduct, imagesHasNotProduct.Count); DateTime beginSaveResult = DateTime.Now; string saveFolder=Environment.CurrentDirectory + "\\TestFiles\\FormatCheck\\检测结果\\"; string saveFolderOfSupplier; if (productsHasPicture.Count > 0) saveFolderOfSupplier = productsHasPicture[0].SupplierName; else if (productsNotHasPicture.Count > 0) saveFolderOfSupplier = productsNotHasPicture[0].SupplierName; else throw new Exception(); DirectoryInfo dirOfSavedSupplier = new DirectoryInfo(saveFolder + "合格数据\\" + saveFolderOfSupplier+"\\"); if (dirOfSavedSupplier.Exists) { dirOfSavedSupplier.Delete(true); } string supplierName = string.Empty; if (productsExistedInDB.Count > 0) supplierName = productsExistedInDB[0].SupplierName; else if (productsHasPicture.Count > 0) supplierName = productsHasPicture[0].SupplierName; else if (productsNotHasPicture.Count > 0) supplierName = productsNotHasPicture[0].SupplierName; else { return; } supplierName = StringHelper.ReplaceInvalidChaInFileName(supplierName, string.Empty); checker.HandlerCheckResult( supplierName, productsHasPicture , productsNotHasPicture , productsExistedInDB , imagesHasProduct , imagesHasNotProduct , saveFolder); Assert.AreEqual(productsHasPicture.Count, dirOfSavedSupplier.GetImageFiles().ToArray().Length); Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginSaveResult).TotalSeconds); }
public static List <ProductInfo> ReadAllProduct(ref List <string> errors) { return(DALProduct.ReadProductList(ref errors)); }