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

📄 source.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.SqlServerDal.Accessories
{
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using PowerEasy.IDal.Accessories;
    using PowerEasy.Model.Accessories;
    using PowerEasy.SqlServerDal;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;

    public class Source : ISource
    {
        private int m_TotalOfSource;

        public bool Add(SourceInfo sourceInfo)
        {
            Parameters cmdParams = GetParameters(sourceInfo);
            return DBHelper.ExecuteProc("PR_Accessories_Source_Insert", cmdParams);
        }

        public bool Delete(string strId)
        {
            return DBHelper.ExecuteSql("DELETE FROM PE_Source WHERE ID in(" + strId + ")");
        }

        public bool Exists(string sname)
        {
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@Name", DbType.String, sname);
            return DBHelper.ExistsSql("SELECT COUNT(ID) FROM PE_Source WHERE Name=@Name", cmdParams);
        }

        public bool ExistsPassedSource(string sourceName)
        {
            Parameters cmdParams = new Parameters();
            cmdParams.AddInParameter("@Name", DbType.String, sourceName);
            return DBHelper.ExistsSql("SELECT COUNT(ID) FROM PE_Source WHERE Name=@Name AND Passed=1", cmdParams);
        }

        private static Parameters GetParameters(SourceInfo sourceInfo)
        {
            Parameters parameters = new Parameters();
            parameters.AddInParameter("@Type", DbType.String, sourceInfo.Type);
            parameters.AddInParameter("@Name", DbType.String, sourceInfo.Name);
            parameters.AddInParameter("@Passed", DbType.Boolean, sourceInfo.Passed);
            parameters.AddInParameter("@onTop", DbType.Boolean, sourceInfo.OnTop);
            parameters.AddInParameter("@IsElite", DbType.Boolean, sourceInfo.Elite);
            parameters.AddInParameter("@Hits", DbType.Int32, sourceInfo.Hits);
            parameters.AddInParameter("@LastUseTime", DbType.DateTime, sourceInfo.LastUseTime);
            parameters.AddInParameter("@Photo", DbType.String, sourceInfo.Photo);
            parameters.AddInParameter("@Intro", DbType.String, sourceInfo.Intro);
            parameters.AddInParameter("@Address", DbType.String, sourceInfo.Address);
            parameters.AddInParameter("@Tel", DbType.String, sourceInfo.Tel);
            parameters.AddInParameter("@Fax", DbType.String, sourceInfo.Fax);
            parameters.AddInParameter("@Mail", DbType.String, sourceInfo.Mail);
            parameters.AddInParameter("@Email", DbType.String, sourceInfo.Email);
            parameters.AddInParameter("@ZipCode", DbType.Int32, sourceInfo.ZipCode);
            parameters.AddInParameter("@HomePage", DbType.String, sourceInfo.HomePage);
            parameters.AddInParameter("@Im", DbType.String, sourceInfo.Imeeting);
            parameters.AddInParameter("@ContacterName", DbType.String, sourceInfo.ContacterName);
            return parameters;
        }

        public SourceInfo GetSourceInfoById(int id)
        {
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Accessories_Source_GetSourceInfoByID");
            database.AddInParameter(storedProcCommand, "@ID", DbType.Int32, id);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand)))
            {
                if (reader.Read())
                {
                    return SourceFromrdr(reader);
                }
                return new SourceInfo(true);
            }
        }

        public IList<SourceInfo> GetSourceList(int startRowIndexId, int maxNumberRows, int searchType, string keyword, string sourceType, bool isShowDisable)
        {
            string str;
            switch (searchType)
            {
                case 0:
                    str = "Name like '%" + keyword + "%'";
                    break;

                case 1:
                    str = "Address like '%" + keyword + "%'";
                    break;

                case 2:
                    str = "Tel like '%" + keyword + "%'";
                    break;

                case 3:
                    str = "Intro like '%" + keyword + "%'";
                    break;

                case 4:
                    str = "Contacter like '%" + keyword + "%'";
                    break;

                case 5:
                    str = "Type='" + sourceType + "'";
                    break;

                default:
                    str = string.Empty;
                    break;
            }
            if (isShowDisable)
            {
                str = str + " AND Passed=1";
            }
            IList<SourceInfo> list = new List<SourceInfo>();
            Database database = DatabaseFactory.CreateDatabase();
            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, "ID");
            database.AddInParameter(storedProcCommand, "@StrColumn", DbType.String, "*");
            database.AddInParameter(storedProcCommand, "@Sorts", DbType.String, "DESC");
            database.AddInParameter(storedProcCommand, "@TableName", DbType.String, "PE_Source");
            database.AddInParameter(storedProcCommand, "@Filter", DbType.String, str);
            database.AddOutParameter(storedProcCommand, "@Total", DbType.Int32, maxNumberRows);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand)))
            {
                while (reader.Read())
                {
                    list.Add(SourceFromrdr(reader));
                }
            }
            this.m_TotalOfSource = (int) database.GetParameterValue(storedProcCommand, "@Total");
            return list;
        }

        public IList<SourceInfo> GetSourceListByType(string type)
        {
            IList<SourceInfo> list = new List<SourceInfo>();
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Accessories_Source_GetSourceInfoByType");
            database.AddInParameter(storedProcCommand, "@Type", DbType.String, type);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand)))
            {
                while (reader.Read())
                {
                    list.Add(SourceFromrdr(reader));
                }
            }
            return list;
        }

        public IList<SourceInfo> GetSourceTypeList()
        {
            string query = "SELECT Type FROM PE_Source GROUP BY Type";
            IList<SourceInfo> list = new List<SourceInfo>();
            Database database = DatabaseFactory.CreateDatabase();
            DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
            using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(sqlStringCommand)))
            {
                while (reader.Read())
                {
                    if (!string.IsNullOrEmpty(reader.GetString(0)))
                    {
                        SourceInfo item = new SourceInfo(reader.GetString(0));
                        list.Add(item);
                    }
                }
            }
            return list;
        }

        public int GetTotalOfSource()
        {
            return this.m_TotalOfSource;
        }

        private static SourceInfo SourceFromrdr(NullableDataReader rdr)
        {
            SourceInfo info = new SourceInfo();
            info.Id = rdr.GetInt32("ID");
            info.Type = rdr.GetString("Type");
            info.Name = rdr.GetString("Name");
            info.Passed = rdr.GetBoolean("Passed");
            info.OnTop = rdr.GetBoolean("onTop");
            info.Elite = rdr.GetBoolean("IsElite");
            info.Hits = rdr.GetInt32("Hits");
            info.LastUseTime = rdr.GetDateTime("LastUseTime");
            info.Photo = rdr.GetString("Photo");
            info.Intro = rdr.GetString("Intro");
            info.Address = rdr.GetString("Address");
            info.Tel = rdr.GetString("Tel");
            info.Fax = rdr.GetString("Fax");
            info.Mail = rdr.GetString("Mail");
            info.Email = rdr.GetString("Email");
            info.ZipCode = rdr.GetInt32("ZipCode");
            info.HomePage = rdr.GetString("HomePage");
            info.Imeeting = rdr.GetString("Im");
            info.ContacterName = rdr.GetString("Contacter");
            return info;
        }

        public bool Update(SourceInfo sourceInfo)
        {
            Parameters cmdParams = GetParameters(sourceInfo);
            cmdParams.AddInParameter("@ID", DbType.Int32, sourceInfo.Id);
            return DBHelper.ExecuteProc("PR_Accessories_Source_Update", cmdParams);
        }
    }
}

⌨️ 快捷键说明

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