protected void btnImport_Click(object sender, EventArgs e)
    {
        DateTime finishTime=Convert.ToDateTime(tbxFinishTime.Text.Trim());
        ImportOperationLog il = new ImportOperationLog();
        string fileNames=string.Empty;
        foreach(DirectoryInfo dir in GetImportedDir())
        {
         fileNames+=dir.Name+"|";
        }
        fileNames = fileNames.TrimEnd('|');

        try
        {

            ProductImportor importor = new ProductImportor(true);
            //importor.CheckWithDatabase = true;
            importor.WebProductImagesPath = Server.MapPath("/ProductImages/original/");
            importor.Import(GetImportedDir(), ProductsData_Imported);
            tbxMsg.CssClass = "success";
            tbxMsg.Text = importor.ImportMsg;

            //保存日志
            bizImportlog.Import(fileNames, importor.Result_ProductsSuccessImported, finishTime, tbxFrom.Text
                , "数据部",importor.ImportMsgForLog);
        }
        catch (Exception ex)
        {
            tbxMsg.CssClass = "error";
            tbxMsg.Text = ex.Message;
            if (ex.InnerException != null)
            {
                tbxMsg.Text += Environment.NewLine + ex.InnerException.Message;
            }
        }
    }
Пример #2
0
        /// <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);
        }