Esempio n. 1
0
 public virtual void UpdateProduct(Model.Product.Product product)
 {
     UpdateObject(product);
 }
Esempio n. 2
0
        public void ImportGroupCatalog(
            string folderPath,
            int categoryId, string categoryStr,
            int markId, string markStr,
            int colorId, string colorStr,
            int sizeId, string sizeStr)
        {
            if (String.IsNullOrEmpty(folderPath))
            {
                throw new ArgumentNullException("folderPath", Resources.MsgInvalidFolderPath);
            }

            var directoryInfo = new DirectoryInfo(folderPath);

            if (!directoryInfo.Exists)
            {
                return;
            }

            foreach (var subDirectoryInfo in directoryInfo.GetDirectories())
            {
                ImportGroupCatalog(
                    subDirectoryInfo.FullName,
                    categoryId,
                    categoryStr,
                    markId,
                    markStr,
                    colorId,
                    colorStr,
                    sizeId,
                    sizeStr);
            }

            foreach (var fileInfo in directoryInfo.GetFiles())
            {
                var fileExtension = fileInfo.Extension;
                if (string.IsNullOrEmpty(fileExtension))
                {
                    continue;
                }

                fileExtension = fileExtension.ToUpper();
                if ((fileExtension != ".BMP" && fileExtension != ".GIF") && fileExtension != ".JPG")
                {
                    continue;
                }

                var productList = _productDataAccess.GetProductByPhoto(
                    fileInfo.FullName);

                if (productList.Count != 0)
                {
                    continue;
                }

                var product =
                    new Model.Product.Product
                {
                    ProductName = (categoryStr + " \\ " + markStr + " \\ " + colorStr),
                    CategoryId  = categoryId,
                    CategoryStr = categoryStr,
                    MarkId      = markId,
                    MarkStr     = markStr,
                    ColorId     = colorId,
                    ColorStr    = colorStr,
                    SizeId      = sizeId,
                    SizeStr     = sizeStr,
                    PhotoPath   = fileInfo.FullName,
                    QtyInStock  = 1
                };

                ManageProduct(
                    product,
                    Resources.OperationRequestInsert);
            }
        }
Esempio n. 3
0
 public virtual void DeleteProduct(Model.Product.Product product)
 {
     DeleteObject(product);
 }
Esempio n. 4
0
 public virtual void InsertProduct(Model.Product.Product product)
 {
     InsertObject(product);
 }
Esempio n. 5
0
        public void ImportProductFromXml(string folderName, string fileName)
        {
            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentNullException("fileName", Resources.ConstFileName);

            if (string.IsNullOrEmpty(fileName))
                throw new ArgumentNullException("folderName", Resources.ConstFolderName);

            var fileInfo = new FileInfo(folderName + @"\" + fileName);
            if (!fileInfo.Exists)
                return;

            //Import data from xml file
            IList productList = new List<Model.Product.Product>();
            var dtProduct = new DataTable("Product");
            var propertyInfos = typeof (Model.Product.Product).GetProperties();
            foreach (var dataColumn in
                propertyInfos.Select(propertyInfo => new DataColumn(propertyInfo.Name, propertyInfo.PropertyType)))
            {
                dtProduct.Columns.Add(dataColumn);
            }

            var dsProduct = new DataSet("Products");
            dsProduct.Tables.Add(dtProduct);
            dsProduct.ReadXml(folderName + @"\" + fileName);

            foreach (DataRow dataRow in dtProduct.Rows)
            {
                if (dataRow == null)
                    continue;

                var product = new Model.Product.Product();
                foreach (var propertyInfo in
                    propertyInfos.Where(propertyInfo => !propertyInfo.Name.Equals("ProductId")).Where(propertyInfo => !propertyInfo.Name.Equals("SkinStr")))
                {
                    if (dataRow[propertyInfo.Name] is DBNull)
                        propertyInfo.SetValue(
                            product,
                            string.Empty,
                            null);
                    else
                        propertyInfo.SetValue(
                            product,
                            dataRow[propertyInfo.Name],
                            null);
                }

                product.PhotoPath = AppContext.Counter.ProductPhotoLocalPath + product.PhotoPath;
                ManageProduct(product, Resources.OperationRequestInsert);
                productList.Add(product);
            }

            //Import picture from source
            foreach (Model.Product.Product product in productList)
            {
                var sourcePath =
                    folderName +
                    StringHelper.Right(
                        product.PhotoPath,
                        product.PhotoPath.Length - AppContext.Counter.ProductPhotoLocalPath.Length);
                var sourceFileInfo = new FileInfo(sourcePath);
                if (!sourceFileInfo.Exists)
                    continue;

                var directoryInfo =
                    new DirectoryInfo(
                        StringHelper.Left(
                            product.PhotoPath,
                            product.PhotoPath.Length - sourceFileInfo.Name.Length));
                if (!directoryInfo.Exists)
                    directoryInfo.Create();

                fileInfo = new FileInfo(product.PhotoPath);
                if (!fileInfo.Exists)
                    sourceFileInfo.CopyTo(fileInfo.FullName);
            }
        }
Esempio n. 6
0
        public void ImportGroupCatalog(
            string[] fileNames,
            int categoryId, string categoryStr,
            int markId, string markStr,
            int colorId, string colorStr,
            int sizeId, string sizeStr)
        {
            if (fileNames.Length == 0)
                return;

            if (String.IsNullOrEmpty(fileNames[0]))
                return;

            foreach (var fileName in fileNames)
            {
                var directoryInfo = new DirectoryInfo(fileName);
                if (directoryInfo.Exists)
                {
                    ImportGroupCatalog(
                        fileName,
                        categoryId, categoryStr,
                        markId, markStr,
                        colorId, colorStr,
                        sizeId, sizeStr);
                    continue;
                }

                var fileInfo = new FileInfo(fileName);
                if (!fileInfo.Exists)
                    continue;

                var fileExtension = fileInfo.Extension;
                if(string.IsNullOrEmpty(fileExtension))
                    continue;

                fileExtension = fileExtension.ToUpper();
                if (fileExtension != ".BMP" &&
                    fileExtension != ".GIF" &&
                    fileExtension != ".JPG")
                    continue;

                var productList = _productDataAccess.GetProductByPhoto(
                    fileInfo.FullName);

                if (productList.Count != 0)
                    continue;

                var product =
                    new Model.Product.Product
                    {
                        ProductName = (categoryStr + " \\ " + markStr + " \\ " + colorStr),
                        CategoryId = categoryId,
                        CategoryStr = categoryStr,
                        MarkId = markId,
                        MarkStr = markStr,
                        ColorId = colorId,
                        ColorStr = colorStr,
                        SizeId = sizeId,
                        SizeStr = sizeStr,
                        PhotoPath = fileInfo.FullName,
                        QtyInStock = 1
                    };

                ManageProduct(
                    product,
                    Resources.OperationRequestInsert);
            }
        }
Esempio n. 7
0
        public void ImportGroupCatalog(
            string folderPath,
            int categoryId, string categoryStr,
            int markId, string markStr,
            int colorId, string colorStr,
            int sizeId, string sizeStr)
        {
            if (String.IsNullOrEmpty(folderPath))
                throw new ArgumentNullException("folderPath", Resources.MsgInvalidFolderPath);

            var directoryInfo = new DirectoryInfo(folderPath);
            if (!directoryInfo.Exists)
                return;

            foreach (var subDirectoryInfo in directoryInfo.GetDirectories())
                ImportGroupCatalog(
                    subDirectoryInfo.FullName,
                    categoryId,
                    categoryStr,
                    markId,
                    markStr,
                    colorId,
                    colorStr,
                    sizeId,
                    sizeStr);

            foreach (var fileInfo in directoryInfo.GetFiles())
            {
                var fileExtension = fileInfo.Extension;
                if (string.IsNullOrEmpty(fileExtension))
                    continue;

                fileExtension = fileExtension.ToUpper();
                if ((fileExtension != ".BMP" && fileExtension != ".GIF") && fileExtension != ".JPG")
                    continue;

                var productList = _productDataAccess.GetProductByPhoto(
                    fileInfo.FullName);

                if (productList.Count != 0)
                    continue;

                var product =
                    new Model.Product.Product
                    {
                        ProductName = (categoryStr + " \\ " + markStr + " \\ " + colorStr),
                        CategoryId = categoryId,
                        CategoryStr = categoryStr,
                        MarkId = markId,
                        MarkStr = markStr,
                        ColorId = colorId,
                        ColorStr = colorStr,
                        SizeId = sizeId,
                        SizeStr = sizeStr,
                        PhotoPath = fileInfo.FullName,
                        QtyInStock = 1
                    };

                ManageProduct(
                    product,
                    Resources.OperationRequestInsert);
            }
        }