示例#1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Maticsoft.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("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("ISBN=@ISBN");
            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("@WordsCount",         SqlDbType.Int,        4),
                new SqlParameter("@UnitPrice",          SqlDbType.Money,      8),
                new SqlParameter("@ContentDescription", SqlDbType.NVarChar,  -1),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar,  -1),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar,  -1),
                new SqlParameter("@TOC",                SqlDbType.NVarChar,  -1),
                new SqlParameter("@CategoryId",         SqlDbType.Int,        4),
                new SqlParameter("@Id",                 SqlDbType.Int,        4),
                new SqlParameter("@ISBN",               SqlDbType.NVarChar, 50)
            };
            parameters[0].Value  = model.Title;
            parameters[1].Value  = model.Author;
            parameters[2].Value  = model.PublisherId;
            parameters[3].Value  = model.WordsCount;
            parameters[4].Value  = model.UnitPrice;
            parameters[5].Value  = model.ContentDescription;
            parameters[6].Value  = model.AurhorDescription;
            parameters[7].Value  = model.EditorComment;
            parameters[8].Value  = model.TOC;
            parameters[9].Value  = model.CategoryId;
            parameters[10].Value = model.Id;
            parameters[11].Value = model.ISBN;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Maticsoft.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,   -1),
                new SqlParameter("@AurhorDescription",  SqlDbType.NVarChar,   -1),
                new SqlParameter("@EditorComment",      SqlDbType.NVarChar,   -1),
                new SqlParameter("@TOC",                SqlDbType.NVarChar,   -1),
                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));
            }
        }
示例#3
0
        /// <summary>
        /// 热卖图书
        /// </summary>
        /// <returns></returns>
        public Books GetHotModel()
        {
            string sql = "select top 1 * from Books order by Clicks desc";

            Maticsoft.Model.Books model = new Maticsoft.Model.Books();
            DataSet ds = DbHelperSQL.Query(sql);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
示例#4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.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;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
示例#5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Maticsoft.Model.Books model)
 {
     return(dal.Update(model));
 }
示例#6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Maticsoft.Model.Books model)
 {
     return(dal.Add(model));
 }
示例#7
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Maticsoft.Model.Books DataRowToModel(DataRow row)
 {
     Maticsoft.Model.Books model = new Maticsoft.Model.Books();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Title"] != null)
         {
             model.Title = row["Title"].ToString();
         }
         if (row["Author"] != null)
         {
             model.Author = row["Author"].ToString();
         }
         if (row["PublisherId"] != null && row["PublisherId"].ToString() != "")
         {
             model.PublisherId = int.Parse(row["PublisherId"].ToString());
         }
         if (row["PublishDate"] != null && row["PublishDate"].ToString() != "")
         {
             model.PublishDate = DateTime.Parse(row["PublishDate"].ToString());
         }
         if (row["ISBN"] != null)
         {
             model.ISBN = row["ISBN"].ToString();
         }
         if (row["WordsCount"] != null && row["WordsCount"].ToString() != "")
         {
             model.WordsCount = int.Parse(row["WordsCount"].ToString());
         }
         if (row["UnitPrice"] != null && row["UnitPrice"].ToString() != "")
         {
             model.UnitPrice = decimal.Parse(row["UnitPrice"].ToString());
         }
         if (row["ContentDescription"] != null)
         {
             model.ContentDescription = row["ContentDescription"].ToString();
         }
         if (row["AurhorDescription"] != null)
         {
             model.AurhorDescription = row["AurhorDescription"].ToString();
         }
         if (row["EditorComment"] != null)
         {
             model.EditorComment = row["EditorComment"].ToString();
         }
         if (row["TOC"] != null)
         {
             model.TOC = row["TOC"].ToString();
         }
         if (row["CategoryId"] != null && row["CategoryId"].ToString() != "")
         {
             model.CategoryId = int.Parse(row["CategoryId"].ToString());
         }
         if (row["Clicks"] != null && row["Clicks"].ToString() != "")
         {
             model.Clicks = int.Parse(row["Clicks"].ToString());
         }
     }
     return(model);
 }