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

📄 product.cs

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

    public class Product : IProduct
    {
        private int m_TotalOfAllProducts;
        private int m_TotalOfProducts;

        public bool Add(string tableName, ProductInfo info)
        {
            DataRow[] dataRows = Query.GetDataRows(info.Fields, "FieldLevel=1");
            string filedSting = Query.GetFiledSting(dataRows);
            filedSting = filedSting + (string.IsNullOrEmpty(filedSting) ? "ID" : ",ID");
            string parametersString = Query.GetParametersString(dataRows);
            parametersString = parametersString + (string.IsNullOrEmpty(parametersString) ? "@ID" : ",@ID");
            string strSql = Query.GetInsertTableSql(tableName, filedSting, parametersString);
            Parameters cmdParams = GetParameters(info);
            cmdParams.AddInParameter("@ID", DbType.Int32, info.ProductId);
            return DBHelper.ExecuteSql(strSql, cmdParams);
        }

        public bool Delete(string generalIdList)
        {
            string[] strArray = generalIdList.Split(new char[] { ',' });
            ContentManage manage = new ContentManage();
            ProductCommon common = new ProductCommon();
            ProductData data = new ProductData();
            ProductPrice price = new ProductPrice();
            for (int i = 0; i < strArray.Length; i++)
            {
                CommonModelInfo commonModelInfoById = manage.GetCommonModelInfoById(DataConverter.CLng(strArray[i]));
                if (!commonModelInfoById.IsNull && (DataConverter.CLng(commonModelInfoById.LinkType) == 0))
                {
                    manage.DeleteVirtualContent(DataConverter.CLng(strArray[i]));
                    DBHelper.ExecuteSql("DELETE FROM " + commonModelInfoById.TableName + " WHERE ID=" + commonModelInfoById.ItemId.ToString());
                    common.DeleteById(commonModelInfoById.ItemId, commonModelInfoById.TableName);
                    data.DeleteByProduct(commonModelInfoById.ItemId, commonModelInfoById.TableName);
                    price.Delete(commonModelInfoById.ItemId, commonModelInfoById.TableName);
                }
            }
            return DBHelper.ExecuteSql("DELETE FROM PE_CommonModel WHERE GeneralId IN(" + generalIdList + ")");
        }

        public int GetGeneralId(string tableName, int productId)
        {
            string strSql = "select top 1 generalid from pe_commonModel where tableName=@TableName and itemid=@ProductId and linktype = 0";
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@TableName", DbType.String, tableName);
            cmdParams.AddInParameter("@ProductId", DbType.Int32, productId);
            return DataConverter.CLng(DBHelper.ExecuteScalarSql(strSql, cmdParams));
        }

        public int GetNewProductId()
        {
            return (DBHelper.GetMaxId("PE_CommonModel", "GeneralId") + 1);
        }

        private static Parameters GetParameters(ProductInfo productInfo)
        {
            Parameters parameters = new Parameters();
            foreach (Parameter parameter in Query.GetParameters(productInfo.Fields, "FieldLevel=1").Entries)
            {
                parameters.AddInParameter(parameter.Name, parameter.DBType, parameter.Value);
            }
            return parameters;
        }

        public ProductInfo GetProductById(int id)
        {
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@ID", DbType.Int32, id);
            using (NullableDataReader reader = DBHelper.ExecuteReaderSql("Select * From PE_CommonProduct Where ProductID=@ID", cmdParams))
            {
                if (reader.Read())
                {
                    ProductInfo productInfo = new ProductInfo();
                    ProductFromrdr<ProductInfo>(reader, productInfo);
                    return productInfo;
                }
                return new ProductInfo(true);
            }
        }

        public ProductInfo GetProductById(int productId, string tableName)
        {
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@TableName", DbType.String, tableName);
            cmdParams.AddInParameter("@ProductId", DbType.Int32, productId);
            using (NullableDataReader reader = DBHelper.ExecuteReaderSql("Select * From PE_CommonProduct Where TableName=@TableName and ProductId=@ProductId", cmdParams))
            {
                if (reader.Read())
                {
                    ProductInfo productInfo = new ProductInfo();
                    ProductFromrdr<ProductInfo>(reader, productInfo);
                    return productInfo;
                }
                return new ProductInfo(true);
            }
        }

        public ProductInfo GetProductById(int generalId, int productId, string tableName)
        {
            ProductInfo productById = this.GetProductById(productId, tableName);
            if (!productById.IsNull)
            {
                DataTable table = DBHelper.ExecuteDataSetSql("SELECT C.*,T.*,C.ItemId AS InfoId,C.ItemId AS SpecialId FROM PE_CommonModel C INNER JOIN " + tableName + " T ON C.ItemID=T.ID WHERE GeneralId=@GeneralId", new Parameters("@GeneralId", 11, generalId)).Tables[0];
                productById.Fields = table;
            }
            return productById;
        }

        public IList<ProductInfo> GetProductInfoList(int startRowIndexId, int maxNumberRows, string tableName, string searchProductName, string productType)
        {
            IList<ProductInfo> list = new List<ProductInfo>();
            Database database = DatabaseFactory.CreateDatabase();
            StringBuilder builder = new StringBuilder(" 1=1 ");
            if (!string.IsNullOrEmpty(tableName))
            {
                builder.Append(" and P.TableName='" + tableName + "' ");
            }
            builder.Append(" and P.EnableSale =1 and P.ProductType in (" + productType + ") ");
            if (!string.IsNullOrEmpty(searchProductName))
            {
                builder.Append(" and P.ProductName like '%" + searchProductName + "%'");
            }
            DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Common_GetList");
            database.AddInParameter(storedProcCommand, "@StartRows", DbType.Int32, startRowIndexId);
            database.AddInParameter(storedProcCommand, "@PageSize", DbType.Int32, maxNumberRows);
            database.AddInParameter(storedProcCommand, "@SortColumn", DbType.String, "P.ProductID");
            database.AddInParameter(storedProcCommand, "@StrColumn", DbType.String, "P.*");
            database.AddInParameter(storedProcCommand, "@Sorts", DbType.String, "DESC");
            database.AddInParameter(storedProcCommand, "@TableName", DbType.String, "PE_CommonProduct P inner join PE_CommonModel M on P.TableName=M.TableName and P.ProductID=M.ItemID and M.LinkType=0 and Status=99");
            database.AddInParameter(storedProcCommand, "@Filter", DbType.String, builder.ToString());
            database.AddOutParameter(storedProcCommand, "@Total", DbType.Int32, maxNumberRows);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand)))
            {
                while (reader.Read())
                {
                    ProductInfo productInfo = new ProductInfo();
                    ProductFromrdr<ProductInfo>(reader, productInfo);
                    list.Add(productInfo);
                }
            }
            this.m_TotalOfProducts = (int) database.GetParameterValue(storedProcCommand, "@Total");
            return list;
        }

        public IDictionary<int, string> GetProductList(int modelId, string productIdList)
        {
            string strSql = string.Format("select itemId , Title from PE_commonModel where ModelId = {0} and LinkType = 0 and Status<>-3 and itemId in ( {1} )", modelId.ToString(), productIdList);
            IDictionary<int, string> dictionary = new Dictionary<int, string>();
            using (NullableDataReader reader = DBHelper.ExecuteReaderSql(strSql))
            {
                while (reader.Read())
                {
                    dictionary.Add(reader.GetInt32("itemId"), reader.GetString("Title"));
                }
            }
            return dictionary;
        }

        public IDictionary<int, string> GetProductList(int modelId, int searchType, string keyword, string keyword2)
        {
            StringBuilder builder = new StringBuilder("select P.ProductName,M.GeneralId from PE_CommonProduct P inner join PE_CommonModel M on M.ItemID=P.ProductID where M.LinkType=0 and M.Status<>-3 and  M.ModelId = @ModelId");
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@ModelId", DbType.Int32, modelId);
            if (!string.IsNullOrEmpty(keyword))
            {
                switch (searchType)
                {
                    case 1:
                        builder.Append(" and P.ProductName like '%" + keyword + "%'");
                        break;

                    case 2:
                        builder.Append(" and P.Price >= @Keyword");
                        cmdParams.AddInParameter("@Keyword", DbType.Decimal, DataConverter.CDecimal(keyword));
                        if (!string.IsNullOrEmpty(keyword2))
                        {
                            builder.Append(" and P.Price<= @Keyword2");
                            cmdParams.AddInParameter("@Keyword2", DbType.Decimal, DataConverter.CDecimal(keyword2));
                        }
                        break;

                    case 3:
                        builder.Append(" and P.ProductID>=@Keyword");
                        cmdParams.AddInParameter("@Keyword", DbType.Decimal, DataConverter.CDecimal(keyword));
                        if (!string.IsNullOrEmpty(keyword2))
                        {
                            builder.Append(" and P.ProductID<=@Keyword2");
                            cmdParams.AddInParameter("@Keyword2", DbType.Decimal, DataConverter.CDecimal(keyword2));
                        }
                        break;

                    case 4:
                        builder.Append(" and P.ProdutType = @Keyword");
                        cmdParams.AddInParameter("@Keyword", DbType.Int32, DataConverter.CLng(keyword));
                        break;
                }
            }
            IDictionary<int, string> dictionary = new Dictionary<int, string>();
            using (NullableDataReader reader = DBHelper.ExecuteReaderSql(builder.ToString(), cmdParams))
            {
                while (reader.Read())
                {
                    dictionary.Add(reader.GetInt32("GeneralId"), reader.GetString("ProductName"));
                }
            }
            return dictionary;
        }

        public string GetProductName(int productId, string tableName)
        {
            string str = "";
            string strSql = "select Title from PE_commonModel where TableName = @TableName and LinkType = 0 and itemId = @ProductId";
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@ProductId", DbType.String, productId);
            cmdParams.AddInParameter("@TableName", DbType.String, tableName);
            using (NullableDataReader reader = DBHelper.ExecuteReaderSql(strSql, cmdParams))
            {
                if (reader.Read())
                {
                    str = reader.GetString("Title");
                }
            }
            return str;
        }

        public IList<ProductDetailInfo> GetProductsList(int startRowIndexId, int maxNumberRows, int searchType, string field, string keyword, int modelId)
        {
            string str;
            if (searchType > 0)
            {
                str = "SpeedSearch";
                keyword = searchType.ToString();
            }
            else
            {
                str = field;
            }
            return this.GetProductsList(startRowIndexId, maxNumberRows, str, keyword, string.Empty, 0, 0x63, modelId, true);
        }

        public IList<ProductDetailInfo> GetProductsList(int startRowIndexId, int maxNumberRows, string searchType, string keyword, string nodeIds, int listType, int status)
        {
            return this.GetProductsList(startRowIndexId, maxNumberRows, searchType, keyword, nodeIds, listType, status, 0, false);
        }

        private IList<ProductDetailInfo> GetProductsList(int startRowIndexId, int maxNumberRows, string searchType, string keyword, string nodeIds, int listType, int status, int modelId, bool wholesale)
        {
            string str;
            string str2;
            Database database = DatabaseFactory.CreateDatabase();
            GetSortParameter(listType, out str, out str2);
            string str3 = "";
            string temp = " and ";
            if (!string.IsNullOrEmpty(nodeIds))
            {
                str3 = " M.NodeId IN (" + nodeIds.ToString() + ") ";
            }
            else
            {
                str3 = " M.TableName is not null ";
            }
            if ((status < 100) && (status > -4))
            {
                str3 = string.Concat(new object[] { str3, temp, "M.Status=", status, " " });
            }
            if (status == 100)
            {
                str3 = str3 + temp + "M.Status <= 99 AND M.Status >=0 ";
            }
            if (status == 0x65)
            {
                str3 = str3 + temp + "M.Status < 99 AND M.Status >0 ";
            }
            if (modelId > 0)
            {
                str3 = string.Concat(new object[] { str3, temp, "M.ModelID =", modelId });
            }
            if (wholesale)
            {
                str3 = str3 + temp + "P.EnableWholesale =1";
            }
            DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Common_GetList");
            database.AddInParameter(storedProcCommand, "@StartRows", DbType.Int32, startRowIndexId);
            database.AddInParameter(storedProcCommand, "@PageSize", DbType.Int32, maxNumberRows);
            database.AddInParameter(storedProcCommand, "@SortColumn", DbType.String, str);
            database.AddInParameter(storedProcCommand, "@StrColumn", DbType.String, "N.NodeName,M.EliteLevel,M.CreateTime,M.UpdateTime,M.NodeId,M.GeneralId,M.ModelId,M.LinkType,P.*");
            database.AddInParameter(storedProcCommand, "@Sorts", DbType.String, str2);
            database.AddInParameter(storedProcCommand, "@TableName", DbType.String, "PE_CommonProduct P inner join (PE_CommonModel M right join PE_Nodes N on M.NodeID= N.NodeID) on P.ProductID = M.ItemID and P.TableName = M.TableName and M.Status<>-3");
            if (string.IsNullOrEmpty(searchType))
            {
                database.AddInParameter(storedProcCommand, "@Filter", DbType.String, str3);
            }
            else if (searchType == "SpeedSearch")
            {
                str3 = GetSpeedSearchFilter(keyword, str3, temp);
                database.AddInParameter(storedProcCommand, "@Filter", DbType.String, str3);
            }
            else
            {

⌨️ 快捷键说明

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