Beispiel #1
0
        /// <summary>
        /// 从excel文件中读取产品信息
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public IList <Product> ReadListFromExcel(System.IO.Stream stream, out string errMsg)
        {
            IDataTableConverter <Product>       productReader = new ProductDataTableConverter();
            ImportToDatabaseFromExcel <Product> importor      = new ImportToDatabaseFromExcel <Product>(productReader, this);

            return(importor.ReadList(stream, out errMsg));
        }
Beispiel #2
0
        /// <summary>
        /// 从excel文件中读取产品信息和内嵌图片
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="errMsg"></param>
        /// <param name="allPictures"></param>
        /// <returns></returns>
        public IList <Product> ReadListFromExcelWithAllPictures(System.IO.Stream stream, out string errMsg, out System.Collections.IList allPictures)
        {
            IDataTableConverter <Product>       productReader = new ProductDataTableConverter();
            ImportToDatabaseFromExcel <Product> importor      = new ImportToDatabaseFromExcel <Product>(productReader, this);

            return(importor.ReadListWithAllPictures(stream, out errMsg, out allPictures));
        }
Beispiel #3
0
        /// <summary>
        /// 导入excel产品列表
        /// </summary>
        /// <param name="stream">excel流</param>
        /// <param name="errMsg"></param>
        public void ImportProductFromExcel(System.IO.Stream stream, out string errMsg)
        {
            IDataTableConverter <Product>       productReader = new ProductDataTableConverter();
            ImportToDatabaseFromExcel <Product> importor      = new ImportToDatabaseFromExcel <Product>(productReader, this);

            importor.ImportXslData(stream, out errMsg);
        }
Beispiel #4
0
        private IList <Product> ReadProductsFromExcel(Stream stream)
        {
            IDataTableConverter <Product> productReader = new ProductDataTableConverter();
            string          errMsg;
            DataTable       dt       = new NLibrary.ReadExcelToDataTable(stream).Read(out errMsg);
            IList <Product> products = productReader.Convert(dt);

            return(products);
        }
Beispiel #5
0
        /// <summary>
        /// 文件结构检查
        ///  正确结构: Folder-|
        ///                   -xls文件.xls
        ///                   -图片文件夹
        ///  excel读取为
        /// </summary>
        /// <param name="folderPath"></param>
        /// <param name="productsHasPicture"></param>
        /// <param name="productsNotHasPicture"></param>
        /// <param name="imagesHasProduct"></param>
        /// <param name="imagesHasNotProduct"></param>
        public void CheckSingleFolder(string folderPath
                                      , out IList <Product> productsHasPicture
                                      , out IList <Product> productsNotHasPicture
                                      , out IList <Product> productsExistedInDB
                                      , out IList <FileInfo> imagesHasProduct
                                      , out IList <FileInfo> imagesHasNotProduct)
        {
            DirectoryInfo dir = new DirectoryInfo(folderPath);

            FileInfo[] excelFiles = dir.GetFiles("*.xls", SearchOption.TopDirectoryOnly);
            if (excelFiles.Length != 1)
            {
                throw new Exception("错误,文件夹 " + folderPath + " 应该有且仅有一个excel文件");
            }
            FileInfo excelFile = excelFiles[0];
            Stream   stream    = new FileStream(excelFile.FullName, FileMode.Open);
            IDataTableConverter <Product> productReader = new ProductDataTableConverter();
            string          errMsg;
            DataTable       dt       = new NLibrary.ReadExcelToDataTable(stream).Read(out errMsg);
            IList <Product> products = productReader.Convert(dt);

            sbMsg.AppendLine(products.Count + ":待导入");
            sbMsgForLog.AppendLine("待导入产品数量:" + products.Count);
            //排除数据库内重复的数据
            IList <Product> validItems = products;

            productsExistedInDB = new List <Product>();
            if (CheckWithDatabase)
            {
                DateTime beginCheckDbExists = DateTime.Now;

                validItems = BizProduct.CheckDB(
                    products, out productsExistedInDB);
                Console.WriteLine("Time Cost CheckDB:" + (DateTime.Now - beginCheckDbExists).TotalSeconds);
                sbMsg.AppendLine(productsExistedInDB.Count + ":已存在");
                foreach (Product pi in productsExistedInDB)
                {
                    sbMsg.AppendLine("     名称:" + pi.Name + "型号:" + pi.ModelNumber + "供应商名称:" + pi.SupplierName);
                }
            }
            //
            DateTime beginCheckImage = DateTime.Now;

            CheckProductImages(validItems, folderPath, out productsHasPicture
                               , out productsNotHasPicture
                               , out imagesHasProduct
                               , out imagesHasNotProduct);
            Console.WriteLine("Time Cost CheckImage:" + (DateTime.Now - beginCheckImage).TotalSeconds);
            sbMsg.AppendLine(productsNotHasPicture.Count + ":无图片");
            foreach (Product pnopic in productsNotHasPicture)
            {
                sbMsg.AppendLine("     名称:" + pnopic.Name + "型号:" + pnopic.ModelNumber + "供应商名称:" + pnopic.SupplierName);
            }
        }