Exemplo n.º 1
0
 public FormatSerialNoUnit(IFormatSerialNoPersistent persistent)
 {
     this.persistent = persistent;
     //SerialList = persistent.GetAll();
 }
Exemplo n.º 2
0
        /// <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的虚拟路径,  不合格数据拷贝
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 public FormatSerialNoUnit(IFormatSerialNoPersistent persistent)
 {
     this.persistent = persistent;
     SerialList      = persistent.GetAll();
 }