예제 #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PZYM.Shop.Model.Books GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks from Books ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            PZYM.Shop.Model.Books model = new PZYM.Shop.Model.Books();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Title  = ds.Tables[0].Rows[0]["Title"].ToString();
                model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                if (ds.Tables[0].Rows[0]["PublisherId"].ToString() != "")
                {
                    model.PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["PublishDate"].ToString() != "")
                {
                    model.PublishDate = DateTime.Parse(ds.Tables[0].Rows[0]["PublishDate"].ToString());
                }
                model.ISBN = ds.Tables[0].Rows[0]["ISBN"].ToString();
                if (ds.Tables[0].Rows[0]["WordsCount"].ToString() != "")
                {
                    model.WordsCount = int.Parse(ds.Tables[0].Rows[0]["WordsCount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["UnitPrice"].ToString() != "")
                {
                    model.UnitPrice = decimal.Parse(ds.Tables[0].Rows[0]["UnitPrice"].ToString());
                }
                model.ContentDescription = ds.Tables[0].Rows[0]["ContentDescription"].ToString();
                model.AurhorDescription  = ds.Tables[0].Rows[0]["AurhorDescription"].ToString();
                model.EditorComment      = ds.Tables[0].Rows[0]["EditorComment"].ToString();
                model.TOC = ds.Tables[0].Rows[0]["TOC"].ToString();
                if (ds.Tables[0].Rows[0]["CategoryId"].ToString() != "")
                {
                    model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Clicks"].ToString() != "")
                {
                    model.Clicks = int.Parse(ds.Tables[0].Rows[0]["Clicks"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PZYM.Shop.Model.Books GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"select  top 1 [Id]
      ,[Description]
      ,[CreativeHTML]
      ,[ImageUrl]
      ,[FileName]
      ,[FilePath]
      ,[MenuId] from Advertising ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            PZYM.Shop.Model.Books model = new PZYM.Shop.Model.Books();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Id"].ToString() != "")
                {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Description = ds.Tables[0].Rows[0]["Description"].ToString();
                if (ds.Tables[0].Rows[0]["CreativeHTML"].ToString() != "")
                {
                    model.CreativeHTML = ds.Tables[0].Rows[0]["CreativeHTML"].ToString();
                }
                if (ds.Tables[0].Rows[0]["MenuId"].ToString() != "")
                {
                    model.MenuId = Convert.ToInt32(ds.Tables[0].Rows[0]["MenuId"]);
                }
                if (ds.Tables[0].Rows[0]["ImageUrl"].ToString() != "")
                {
                    model.ImageUrl = ds.Tables[0].Rows[0]["ImageUrl"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FileName"].ToString() != "")
                {
                    model.FileName = ds.Tables[0].Rows[0]["FileName"].ToString();
                }
                if (ds.Tables[0].Rows[0]["FilePath"].ToString() != "")
                {
                    model.FilePath = ds.Tables[0].Rows[0]["FilePath"].ToString();
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
예제 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(PZYM.Shop.Model.Books model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Books(");
            strSql.Append("Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks)");
            strSql.Append(" values (");
            strSql.Append("@Title,@Author,@PublisherId,@PublishDate,@ISBN,@WordsCount,@UnitPrice,@ContentDescription,@AurhorDescription,@EditorComment,@TOC,@CategoryId,@Clicks)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",              SqlDbType.NVarChar,  200),
                new SqlParameter("@Author",             SqlDbType.NVarChar,  200),
                new SqlParameter("@PublisherId",        SqlDbType.Int,         4),
                new SqlParameter("@PublishDate",        SqlDbType.DateTime),
                new SqlParameter("@ISBN",               SqlDbType.NVarChar,   50),
                new SqlParameter("@WordsCount",         SqlDbType.Int,         4),
                new SqlParameter("@UnitPrice",          SqlDbType.Money,       8),
                new SqlParameter("@ContentDescription", SqlDbType.NVarChar),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar),
                new SqlParameter("@TOC",                SqlDbType.NVarChar),
                new SqlParameter("@CategoryId",         SqlDbType.Int,         4),
                new SqlParameter("@Clicks",             SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Author;
            parameters[2].Value  = model.PublisherId;
            parameters[3].Value  = model.PublishDate;
            parameters[4].Value  = model.ISBN;
            parameters[5].Value  = model.WordsCount;
            parameters[6].Value  = model.UnitPrice;
            parameters[7].Value  = model.ContentDescription;
            parameters[8].Value  = model.AurhorDescription;
            parameters[9].Value  = model.EditorComment;
            parameters[10].Value = model.TOC;
            parameters[11].Value = model.CategoryId;
            parameters[12].Value = model.Clicks;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #4
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(PZYM.Shop.Model.Books model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Advertising(");
            strSql.Append(@"[Description]
           ,[CreativeHTML]
           ,[ImageUrl]
           ,[FileName]
           ,[FilePath]
           ,[MenuId]
            )");
            strSql.Append(" values (");
            strSql.Append(@"@Description
           ,@CreativeHTML
           ,@ImageUrl
           ,@FileName
           ,@FilePath
           ,@MenuId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Description",  SqlDbType.NVarChar,   200),
                new SqlParameter("@CreativeHTML", SqlDbType.NText,    99999),
                new SqlParameter("@ImageUrl",     SqlDbType.NVarChar,   500),
                new SqlParameter("@FilePath",     SqlDbType.NVarChar,   500),
                new SqlParameter("@FileName",     SqlDbType.NVarChar,   500),
                new SqlParameter("@MenuId",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Description;
            parameters[1].Value = model.CreativeHTML;
            parameters[2].Value = model.ImageUrl;
            parameters[3].Value = model.FilePath;
            parameters[4].Value = model.FileName;
            parameters[5].Value = model.MenuId;
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #5
0
        /// <summary>
        /// 从索引库中检索关键字
        /// </summary>
        private void SearchFromIndexData()
        {
            string        indexPath = Context.Server.MapPath("~/IndexData");
            FSDirectory   directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NoLockFactory());
            IndexReader   reader    = IndexReader.Open(directory, true);
            IndexSearcher searcher  = new IndexSearcher(reader);
            //搜索条件
            PhraseQuery query = new PhraseQuery();

            //把用户输入的关键字进行分词
            foreach (string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"]))
            {
                query.Add(new Term("content", word));
            }
            //query.Add(new Term("content", "C#"));//多个查询条件时 为且的关系
            query.SetSlop(100);  //指定关键词相隔最大距离

            //TopScoreDocCollector盛放查询结果的容器
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);

            searcher.Search(query, null, collector);//根据query查询条件进行查询,查询结果放入collector容器
            //TopDocs 指定0到GetTotalHits() 即所有查询结果中的文档 如果TopDocs(20,10)则意味着获取第20-30之间文档内容 达到分页的效果
            ScoreDoc[] docs = collector.TopDocs(0, collector.GetTotalHits()).scoreDocs;

            //展示数据实体对象集合
            List <PZYM.Shop.Model.Books> bookResult = new List <PZYM.Shop.Model.Books>();

            for (int i = 0; i < docs.Length; i++)
            {
                int      docId = docs[i].doc;         //得到查询结果文档的id(Lucene内部分配的id)
                Document doc   = searcher.Doc(docId); //根据文档id来获得文档对象Document


                PZYM.Shop.Model.Books book = new PZYM.Shop.Model.Books();
                book.Title = doc.Get("title");
                //book.ContentDescription = doc.Get("content");//未使用高亮
                //搜索关键字高亮显示 使用盘古提供高亮插件
                book.ContentDescription = Common.SplitContent.HightLight(Request.QueryString["SearchKey"], doc.Get("content"));
                book.Id = Convert.ToInt32(doc.Get("id"));
                bookResult.Add(book);
            }
            Repeater1.DataSource = bookResult;
            Repeater1.DataBind();
        }
예제 #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PZYM.Shop.Model.Books model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Advertising set ");
            strSql.Append("Description=@Description,");
            strSql.Append("CreativeHTML=@CreativeHTML,");
            strSql.Append("ImageUrl=@ImageUrl,");
            strSql.Append("FileName=@FileName,");
            strSql.Append("FilePath=@FilePath,");
            strSql.Append("MenuId=@MenuId");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Description",  SqlDbType.NVarChar,   200),
                new SqlParameter("@CreativeHTML", SqlDbType.NText,    99999),
                new SqlParameter("@ImageUrl",     SqlDbType.NVarChar,   500),
                new SqlParameter("@FileName",     SqlDbType.NVarChar,   500),
                new SqlParameter("@FilePath",     SqlDbType.NVarChar,   500),
                new SqlParameter("@MenuId",       SqlDbType.Int,          4),
                new SqlParameter("@Id",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Description;
            parameters[1].Value = model.CreativeHTML;
            parameters[2].Value = model.ImageUrl;
            parameters[3].Value = model.FileName;
            parameters[4].Value = model.FilePath;
            parameters[5].Value = model.MenuId;
            parameters[6].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
        /// <summary>
        /// 从索引库中检索关键字
        /// </summary>
        private void SearchFromIndexData() {
            string indexPath = Context.Server.MapPath("~/IndexData");
            FSDirectory directory = FSDirectory.Open(new DirectoryInfo(indexPath), new NoLockFactory());
            IndexReader reader = IndexReader.Open(directory, true);
            IndexSearcher searcher = new IndexSearcher(reader);
            //搜索条件
            PhraseQuery query = new PhraseQuery();
            //把用户输入的关键字进行分词
            foreach(string word in Common.SplitContent.SplitWords(Request.QueryString["SearchKey"])) {
                query.Add(new Term("content", word));
            }
            //query.Add(new Term("content", "C#"));//多个查询条件时 为且的关系
            query.SetSlop(100); //指定关键词相隔最大距离

            //TopScoreDocCollector盛放查询结果的容器
            TopScoreDocCollector collector = TopScoreDocCollector.create(1000, true);
            searcher.Search(query, null, collector);//根据query查询条件进行查询,查询结果放入collector容器
            //TopDocs 指定0到GetTotalHits() 即所有查询结果中的文档 如果TopDocs(20,10)则意味着获取第20-30之间文档内容 达到分页的效果
            ScoreDoc[] docs = collector.TopDocs(0, collector.GetTotalHits()).scoreDocs;

            //展示数据实体对象集合
            List<PZYM.Shop.Model.Books> bookResult = new List<PZYM.Shop.Model.Books>();
            for(int i = 0; i < docs.Length; i++) {
                int docId = docs[i].doc;//得到查询结果文档的id(Lucene内部分配的id)
                Document doc = searcher.Doc(docId);//根据文档id来获得文档对象Document


                PZYM.Shop.Model.Books book = new PZYM.Shop.Model.Books();
                book.Title = doc.Get("title");
                //book.ContentDescription = doc.Get("content");//未使用高亮
                //搜索关键字高亮显示 使用盘古提供高亮插件
                book.ContentDescription = Common.SplitContent.HightLight(Request.QueryString["SearchKey"], doc.Get("content"));
                book.Id = Convert.ToInt32(doc.Get("id"));
                bookResult.Add(book);
            }
            Repeater1.DataSource = bookResult;
            Repeater1.DataBind();
        }
예제 #8
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(PZYM.Shop.Model.Books model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Books set ");
            strSql.Append("Title=@Title,");
            strSql.Append("Author=@Author,");
            strSql.Append("PublisherId=@PublisherId,");
            strSql.Append("PublishDate=@PublishDate,");
            strSql.Append("ISBN=@ISBN,");
            strSql.Append("WordsCount=@WordsCount,");
            strSql.Append("UnitPrice=@UnitPrice,");
            strSql.Append("ContentDescription=@ContentDescription,");
            strSql.Append("AurhorDescription=@AurhorDescription,");
            strSql.Append("EditorComment=@EditorComment,");
            strSql.Append("TOC=@TOC,");
            strSql.Append("CategoryId=@CategoryId,");
            strSql.Append("Clicks=@Clicks");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Title",              SqlDbType.NVarChar,  200),
                new SqlParameter("@Author",             SqlDbType.NVarChar,  200),
                new SqlParameter("@PublisherId",        SqlDbType.Int,         4),
                new SqlParameter("@PublishDate",        SqlDbType.DateTime),
                new SqlParameter("@ISBN",               SqlDbType.NVarChar,   50),
                new SqlParameter("@WordsCount",         SqlDbType.Int,         4),
                new SqlParameter("@UnitPrice",          SqlDbType.Money,       8),
                new SqlParameter("@ContentDescription", SqlDbType.NVarChar),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar),
                new SqlParameter("@TOC",                SqlDbType.NVarChar),
                new SqlParameter("@CategoryId",         SqlDbType.Int,         4),
                new SqlParameter("@Clicks",             SqlDbType.Int,         4),
                new SqlParameter("@Id",                 SqlDbType.Int, 4)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Author;
            parameters[2].Value  = model.PublisherId;
            parameters[3].Value  = model.PublishDate;
            parameters[4].Value  = model.ISBN;
            parameters[5].Value  = model.WordsCount;
            parameters[6].Value  = model.UnitPrice;
            parameters[7].Value  = model.ContentDescription;
            parameters[8].Value  = model.AurhorDescription;
            parameters[9].Value  = model.EditorComment;
            parameters[10].Value = model.TOC;
            parameters[11].Value = model.CategoryId;
            parameters[12].Value = model.Clicks;
            parameters[13].Value = model.Id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #9
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public PZYM.Shop.Model.Books GetModel(int Id) {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,Title,Author,PublisherId,PublishDate,ISBN,WordsCount,UnitPrice,ContentDescription,AurhorDescription,EditorComment,TOC,CategoryId,Clicks from Books ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters = {
					new SqlParameter("@Id", SqlDbType.Int,4)
};
            parameters[0].Value = Id;

            PZYM.Shop.Model.Books model = new PZYM.Shop.Model.Books();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if(ds.Tables[0].Rows.Count > 0) {
                if(ds.Tables[0].Rows[0]["Id"].ToString() != "") {
                    model.Id = int.Parse(ds.Tables[0].Rows[0]["Id"].ToString());
                }
                model.Title = ds.Tables[0].Rows[0]["Title"].ToString();
                model.Author = ds.Tables[0].Rows[0]["Author"].ToString();
                if(ds.Tables[0].Rows[0]["PublisherId"].ToString() != "") {
                    model.PublisherId = int.Parse(ds.Tables[0].Rows[0]["PublisherId"].ToString());
                }
                if(ds.Tables[0].Rows[0]["PublishDate"].ToString() != "") {
                    model.PublishDate = DateTime.Parse(ds.Tables[0].Rows[0]["PublishDate"].ToString());
                }
                model.ISBN = ds.Tables[0].Rows[0]["ISBN"].ToString();
                if(ds.Tables[0].Rows[0]["WordsCount"].ToString() != "") {
                    model.WordsCount = int.Parse(ds.Tables[0].Rows[0]["WordsCount"].ToString());
                }
                if(ds.Tables[0].Rows[0]["UnitPrice"].ToString() != "") {
                    model.UnitPrice = decimal.Parse(ds.Tables[0].Rows[0]["UnitPrice"].ToString());
                }
                model.ContentDescription = ds.Tables[0].Rows[0]["ContentDescription"].ToString();
                model.AurhorDescription = ds.Tables[0].Rows[0]["AurhorDescription"].ToString();
                model.EditorComment = ds.Tables[0].Rows[0]["EditorComment"].ToString();
                model.TOC = ds.Tables[0].Rows[0]["TOC"].ToString();
                if(ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") {
                    model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Clicks"].ToString() != "") {
                    model.Clicks = int.Parse(ds.Tables[0].Rows[0]["Clicks"].ToString());
                }
                return model;
            } else {
                return null;
            }
        }