/// <summary> /// 图片命名 /// </summary> /// <param name="supplierName"></param> /// <param name="productType"></param> /// <param name="ntsCode"></param> public void Excute(string filePath,string savePath) { BizProduct bizProduct = new BizProduct(); System.Collections.IList allPictures; string errMsg; IList<Product> products = bizProduct.ReadListFromExcelWithAllPictures( new System.IO.FileStream(filePath, System.IO.FileMode.Open) , out errMsg ,out allPictures ); // IList<Product> products = importer.Read(new System.IO.FileStream(filePath, System.IO.FileMode.Open), out allPictures); if (products.Count != allPictures.Count) { throw new Exception(string.Format( "提取失败:产品和图片的数量不相等.产品:{0},图片:{1}",products.Count,allPictures.Count)); } for (int i = 0; i < products.Count; i++) { HSSFPictureData pic = (HSSFPictureData)allPictures[i]; var modelNumber =NLibrary.StringHelper.ReplaceInvalidChaInFileName(products[i].ModelNumber,"$")+".jpg"; string fileName=savePath+modelNumber; NLibrary.IOHelper.EnsureFileDirectory(fileName); File.WriteAllBytes(fileName, pic.Data); } }
public Product Populate(string strProperties,BizProduct bizProduct) { string[] pros =strProperties.Split(new string[]{ "---"}, StringSplitOptions.None); if (pros.Length != 2) { throw new Exception("格式有误:" + strProperties); } Product p = bizProduct.GetOneBy_SupplierCode_ModelNumber(pros[0].Trim(), pros[1].Trim()); return p; }
protected void btnCreateProductCode_Click(object sender, EventArgs e) { NBiz.BizProduct bizProduct = new BizProduct(); IList<Product> product_all = bizProduct.GetAll<Product>().Where(x=>string.IsNullOrEmpty(x.ProductCode)).OrderBy(x=>x.NTSCode).ToList(); foreach (Product p in product_all) { string proCate = p.CategoryCode.Replace(".",string.Empty); // string topCateForProductCode = BizHelper.GetFirstCateCode(proCate); p.ProductCode = bizProduct.SerialNoUnit.GetFormatedSerialNo(proCate); bizProduct.SaveOrUpdate(p); bizProduct.SerialNoUnit.Save(); } Notification.Show(this, "", "done",this.Request.RawUrl); }
public void ImportWithDBCheck(BizProduct bizProduct, BizSupplier bizSupplier) { }
/// <summary> /// 导入总方法 /// </summary> public void Import(BizProduct bizProduct, BizSupplier bizSupplier) { //1 读取Excel列表 IList<Product> ProductsInExcel = ReadProductsFromExcel(CheckExcelFile()); //2 检查图片是否存在 CheckProductImages(ProductsInExcel); //检查数据库 if (NeedCheckWithDB) { //1 检查 供应商是否存在 IList<string> supplierNameList = GetSupplierNameList(ProductsInExcel); IList<string> supplierNameList_NotExists; IList<Supplier> supplierList = bizSupplier.GetListByNameList(supplierNameList, out supplierNameList_NotExists); if (supplierNameList_NotExists.Count > 0) { foreach (string supplierName in supplierNameList_NotExists) { sbImportMsg.AppendLine("不存在该供应商:" + supplierName); } return; } //2 检查数据是否已经导入 IList<Product> productsExisted; ProductsPassedDBCheck = bizProduct.CheckDB(ProductsHasImage, out productsExisted); ProductsExistedInDB = productsExisted; foreach (Product productExist in ProductsExistedInDB) { sbImportMsg.AppendLine("已存在该产品.供应商/型号:"+productExist.SupplierName+"/"+productExist.ModelNumber); } } //数据保存到数据库 // bizProduct.SaveList( }
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); }
/// <summary> /// 导入总方法 /// </summary> public void Import(BizProduct bizProduct, BizSupplier bizSupplier,IFormatSerialNoPersistent formatSerialnoPersisitent) { //1 读取Excel列表 IList<Product> ProductsInExcel = ReadProductsFromExcel(CheckExcelFile()); //2 检查图片是否存在 CheckProductImages(ProductsInExcel); //检查数据库 if (NeedCheckWithDB) { //1 检查 供应商是否存在 IList<string> supplierCodeList = GetSupplierCodeList(ProductsInExcel,bizSupplier); IList<string> supplierCodeList_NotExists; IList<Supplier> supplierList = bizSupplier.GetListByCodeList(supplierCodeList, out supplierCodeList_NotExists); if (supplierCodeList_NotExists.Count > 0) { foreach (string supplierCode in supplierCodeList_NotExists) { sbImportMsg.AppendLine("不存在该供应商:" + supplierCode); } return; } //2 检查数据是否已经导入 && 更新产品的供应商信息 IList<Product> productsExisted; ProductsPassedDBCheck = bizProduct.CheckSupplierExisted(ProductsHasImage, out productsExisted); ProductsExistedInDB = productsExisted; foreach (Product productExist in ProductsExistedInDB) { sbImportMsg.AppendLine("已存在该产品.供应商/型号:"+bizSupplier.GetByCode(productExist. SupplierCode).Name+"/"+productExist.ModelNumber); } } //数据保存到数据库-- 分配NTS编码 FormatSerialNoUnit serialNoMgr=new FormatSerialNoUnit(formatSerialnoPersisitent); foreach(Product p in ProductsPassedDBCheck) { p.NTSCode=serialNoMgr.GetFormatedSerialNo(p.CategoryCode+"."+p.SupplierCode ); } bizProduct.SaveList(ProductsPassedDBCheck); serialNoMgr.Save(); //图片复制至web的虚拟路径, 不合格数据拷贝 }