⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 product.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 3 页
字号:
namespace PowerEasy.Shop
{
    using PowerEasy.Common;
    using PowerEasy.CommonModel;
    using PowerEasy.Components;
    using PowerEasy.Contents;
    using PowerEasy.Enumerations;
    using PowerEasy.IDal.Contents;
    using PowerEasy.IDal.Shop;
    using PowerEasy.Model.CommonModel;
    using PowerEasy.Model.Contents;
    using PowerEasy.Model.Shop;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;
    using System.Text;

    public class Product
    {
        private static readonly IProduct dal = DataAccess.CreateProduct();
        private static readonly IContentManage dalContentManage = DataAccess.CreateContentManage();
        private PowerEasy.Model.Contents.CommonModelInfo m_CommonModelInfo;
        private static string m_ErrMsg;
        private static string m_MessgeOfBatchImport;
        private ProductInfo m_ProductInfoData;

        public Product()
        {
        }

        public Product(int generalId)
        {
            this.GetProductAllDataById(generalId);
        }

        private static bool Add(int modelId, string tableName, ProductInfo info)
        {
            DoHtmlEncode(info);
            return ((dalContentManage.AddCommonModel(modelId, tableName, info.Fields, info.ProductId) && ProductCommon.Add(info, tableName)) && dal.Add(tableName, info));
        }

        public static bool Add(int modelId, ProductInfo productInfo, IList<ProductDataInfo> productDataInfoList, IList<ProductPriceInfo> priceInfoList)
        {
            ModelInfo modelInfoById = ModelManager.GetModelInfoById(modelId);
            if (modelInfoById.IsNull)
            {
                return false;
            }
            string tableName = modelInfoById.TableName;
            int newProductId = GetNewProductId();
            productInfo.ProductId = newProductId;
            bool flag = true;
            int num2 = 0;
            int alarmNum = 0;
            foreach (ProductDataInfo info2 in productDataInfoList)
            {
                num2 += info2.Stocks;
                alarmNum = info2.AlarmNum;
            }
            productInfo.Stocks = num2;
            productInfo.AlarmNum = alarmNum;
            flag = Add(modelId, tableName, productInfo);
            StockInfo stockInfo = new StockInfo();
            stockInfo.StockId = StockManage.GetMaxId() + 1;
            stockInfo.StockNum = StockItem.GetInStockNum();
            DataRow[] rowArray = productInfo.Fields.Select("FieldName='Inputer'");
            if (rowArray.Length > 0)
            {
                stockInfo.Inputer = rowArray[0]["FieldValue"].ToString();
            }
            stockInfo.InputTime = DateTime.Now;
            stockInfo.StockType = StockType.InStock;
            stockInfo.Remark = "商品库存初始";
            StockManage.Add(stockInfo);
            if (flag)
            {
                IList<StockItemInfo> infoList = new List<StockItemInfo>();
                if (!string.IsNullOrEmpty(productInfo.Properties))
                {
                    flag = ProductData.Add(newProductId, tableName, productDataInfoList);
                    foreach (ProductDataInfo info4 in productDataInfoList)
                    {
                        StockItemInfo item = new StockItemInfo();
                        item.ItemId = StockItem.GetMaxId() + 1;
                        item.Amount = info4.Stocks;
                        item.Price = info4.PriceInfo.Price;
                        item.ProductId = newProductId;
                        item.TableName = tableName;
                        item.Property = info4.PropertyValue;
                        item.StockId = stockInfo.StockId;
                        item.ProductNum = productInfo.ProductNum;
                        item.Unit = productInfo.Unit;
                        item.ProductName = productInfo.ProductName;
                        infoList.Add(item);
                    }
                }
                else
                {
                    StockItemInfo info6 = new StockItemInfo();
                    info6.Amount = productInfo.Stocks;
                    info6.Price = productInfo.PriceInfo.Price;
                    info6.ProductId = newProductId;
                    info6.TableName = tableName;
                    info6.Property = string.Empty;
                    info6.ProductNum = productInfo.ProductNum;
                    info6.Unit = productInfo.Unit;
                    info6.ProductName = productInfo.ProductName;
                    infoList.Add(info6);
                }
                StockItem.Add(infoList, stockInfo.StockId);
                if (((productInfo.PriceInfo.PriceMember == -1M) || (productInfo.PriceInfo.PriceAgent == -1M)) && (priceInfoList != null))
                {
                    flag = ProductPrice.Add(newProductId, tableName, priceInfoList);
                }
            }
            return flag;
        }

        public static bool AddBuyTimes(int productId, string tableName)
        {
            return ProductCommon.AddBuyTimes(productId, tableName);
        }

        private static void AddNewRows(DataTable dataTable, string fieldName, string fieldValue, FieldType fieldType, int fieldLevel)
        {
            DataRow row = dataTable.NewRow();
            row["FieldName"] = fieldName;
            row["FieldValue"] = fieldValue;
            row["FieldType"] = fieldType;
            row["FieldLevel"] = fieldLevel;
            dataTable.Rows.Add(row);
        }

        public static bool AddOrderNum(int id, int quantity)
        {
            return ProductCommon.AddOrderNum(id, quantity);
        }

        public static bool AddOrderNum(int productId, string tableName, int quantity)
        {
            return ProductCommon.AddOrderNum(productId, tableName, quantity);
        }

        public static bool AddOrderNum(int productId, string tableName, string property, int quantity)
        {
            return (ProductCommon.AddOrderNum(productId, tableName, quantity) && ProductData.AddOrderNum(productId, tableName, property, quantity));
        }

        public static bool AddStocks(int productId, int quantity)
        {
            return AddStocks(productId, quantity, null);
        }

        public static bool AddStocks(int productId, int quantity, string propertyValue)
        {
            if (string.IsNullOrEmpty(propertyValue))
            {
                return ProductCommon.AddStocks(productId, quantity);
            }
            return (ProductData.AddStocks(productId, quantity, propertyValue) && ProductCommon.AddStocks(productId, quantity));
        }

        public static int BatchImport(DataTable dtField, string filePath, int specialId, int nodeId, int modelId)
        {
            ModelInfo modelInfoById = ModelManager.GetModelInfoById(modelId);
            if (modelInfoById.IsNull)
            {
                return 0;
            }
            string tableName = modelInfoById.TableName;
            ProductInfo info = new ProductInfo();
            info.EnableWholesale = false;
            info.EnableSingleSell = true;
            info.SalePromotionType = 0;
            DataTable dataTable = GetDataTableFromModel(modelId, specialId, nodeId);
            info.Fields = ContentManage.GetNewContentData(dataTable);
            OleDbConnection selectConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"");
            string selectCommandText = "select * from [sheet1$]";
            OleDbDataAdapter adapter = new OleDbDataAdapter(selectCommandText, selectConnection);
            DataSet dataSet = new DataSet();
            adapter.Fill(dataSet, "ss");
            StringBuilder builder = new StringBuilder();
            int num2 = 0;
            for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
            {
                int newProductId = GetNewProductId();
                info.ProductId = newProductId;
                DataRow rows = dataSet.Tables[0].Rows[i];
                info.ProductName = GetExcelFieldValue(rows, dtField, "ProductName", string.Empty);
                info.ProductNum = GetExcelFieldValue(rows, dtField, "ProductNum", string.Empty);
                if (string.IsNullOrEmpty(info.ProductNum))
                {
                    Random random = new Random();
                    info.ProductNum = DateTime.Now.ToString("yyyyMMddHHmmss") + random.Next().ToString();
                }
                else if (IsExistSameProductNum(info.ProductNum))
                {
                    builder.Append("<li>商品:" + info.ProductName + "的编号已存在,未导入!</li>");
                    continue;
                }
                info.Unit = GetExcelFieldValue(rows, dtField, "Unit", "个");
                info.PriceInfo.Price = DataConverter.CDecimal(GetExcelFieldValue(rows, dtField, "Price", string.Empty));
                info.PriceMarket = DataConverter.CDecimal(GetExcelFieldValue(rows, dtField, "Price_Market", string.Empty));
                info.Weight = DataConverter.CDouble(GetExcelFieldValue(rows, dtField, "Weight", string.Empty));
                info.Stocks = DataConverter.CLng(GetExcelFieldValue(rows, dtField, "Stocks", string.Empty));
                info.AlarmNum = DataConverter.CLng(GetExcelFieldValue(rows, dtField, "AlarmNum", string.Empty));
                info.ProducerName = GetExcelFieldValue(rows, dtField, "ProducerName", string.Empty);
                info.TrademarkName = GetExcelFieldValue(rows, dtField, "TrademarkName", string.Empty);
                info.BarCode = GetExcelFieldValue(rows, dtField, "BarCode", string.Empty);
                info.ProductIntro = GetExcelFieldValue(rows, dtField, "ProductIntro", string.Empty);
                info.ProductExplain = GetExcelFieldValue(rows, dtField, "ProductExplain", string.Empty);
                info.Stars = DataConverter.CLng(GetExcelFieldValue(rows, dtField, "Stars", "3"));
                info.PriceInfo.PriceMember = info.PriceInfo.Price;
                info.PriceInfo.PriceAgent = info.PriceInfo.Price;
                DataRow[] rowArray = info.Fields.Select("FieldName='Title'");
                if (rowArray.Length == 0)
                {
                    AddNewRows(dataTable, "Title", info.ProductName, FieldType.TitleType, 0);
                }
                else
                {
                    rowArray[0][1] = info.ProductName;
                }
                bool flag = Add(modelId, tableName, info);
                StockInfo stockInfo = new StockInfo();
                stockInfo.StockId = StockManage.GetMaxId() + 1;
                stockInfo.StockNum = StockItem.GetInStockNum();
                DataRow[] rowArray2 = info.Fields.Select("FieldName='Inputer'");
                if (rowArray2.Length > 0)
                {
                    stockInfo.Inputer = rowArray2[0]["FieldValue"].ToString();
                }
                stockInfo.InputTime = DateTime.Now;
                stockInfo.StockType = StockType.InStock;
                stockInfo.Remark = "商品库存初始";
                StockManage.Add(stockInfo);
                if (flag)
                {
                    IList<StockItemInfo> infoList = new List<StockItemInfo>();
                    StockItemInfo item = new StockItemInfo();
                    item.Amount = info.Stocks;
                    item.Price = info.PriceInfo.Price;
                    item.ProductId = newProductId;
                    item.TableName = tableName;
                    item.Property = string.Empty;
                    item.ProductNum = info.ProductNum;
                    item.Unit = info.Unit;
                    item.ProductName = info.ProductName;
                    infoList.Add(item);
                    StockItem.Add(infoList, stockInfo.StockId);
                }
                else
                {
                    builder.Append("<li>商品:" + info.ProductName + "导入失败!</li>");
                    continue;
                }
                num2++;
            }
            m_MessgeOfBatchImport = builder.ToString();
            return num2;
        }

        public static bool CharacterIsExists(ProductCharacter target, ProductCharacter source)
        {
            return ((target & source) == source);
        }

        private static string CheckEnableSingleSell(string cartId, ProductInfo info)
        {
            string str = "";
            if (!info.EnableSingleSell)
            {
                str = CheckEnableSingleSell(ShoppingCart.GetProductIdAndTableNameInCart(cartId, false), info);
            }
            return str;
        }

        private static string CheckEnableSingleSell(StringBuilder productIdInCart, ProductInfo info)
        {
            string str = "";
            if (!info.EnableSingleSell)
            {
                bool flag = true;
                string[] strArray = info.DependentProducts.Split(new char[] { ',' });
                ProductInfo productById = new ProductInfo();
                foreach (string str2 in strArray)
                {
                    productById = GetProductById(DataConverter.CLng(str2));
                    if (!productById.IsNull && !StringHelper.FoundCharInArr(productIdInCart.ToString(), productById.ProductId.ToString() + "|" + productById.TableName))
                    {
                        flag = false;
                        break;
                    }
                }
                if (!flag)
                {
                    str = "<li>" + info.ProductName + "不能直接购买!请先购买此商品的从属商品" + productById.ProductName + "后再购买。</li>";
                }
            }
            return str;
        }

        public static string CheckStocks(ProductInfo productInfo, string propertyValue, int amount, StringBuilder productIdInCart)
        {
            int stocks = amount;
            string str = string.Empty;
            str = CheckEnableSingleSell(productIdInCart, productInfo);
            if (string.IsNullOrEmpty(str))
            {
                if (!productInfo.EnableBuyWhenOutofstock)
                {
                    if (productInfo.StocksProject == StocksProject.ActualStock)
                    {
                        if (string.IsNullOrEmpty(propertyValue))
                        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -