Beispiel #1
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public BCW.MobileSlider.Model.MobileSlider DataRowToModel(DataRow row)
 {
     BCW.MobileSlider.Model.MobileSlider model = new BCW.MobileSlider.Model.MobileSlider();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["url"] != null)
         {
             model.url = row["url"].ToString();
         }
         if (row["contentType"] != null)
         {
             model.contentType = row["contentType"].ToString();
         }
         if (row["param"] != null)
         {
             model.param = row["param"].ToString();
         }
         if (row["sortid"] != null && row["sortid"].ToString() != "")
         {
             model.sortid = int.Parse(row["sortid"].ToString());
         }
         if (row["ptype"] != null && row["ptype"].ToString() != "")
         {
             model.ptype = int.Parse(row["ptype"].ToString());
         }
     }
     return(model);
 }
Beispiel #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(BCW.MobileSlider.Model.MobileSlider model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tb_MobileSlider(");
            strSql.Append("url,contentType,param,sortid,ptype)");
            strSql.Append(" values (");
            strSql.Append("@url,@contentType,@param,@sortid,@ptype)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@url",         SqlDbType.NVarChar, 100),
                new SqlParameter("@contentType", SqlDbType.NVarChar, 100),
                new SqlParameter("@param",       SqlDbType.NVarChar, 300),
                new SqlParameter("@sortid",      SqlDbType.Int,        4),
                new SqlParameter("@ptype",       SqlDbType.Int, 4)
            };
            parameters[0].Value = model.url;
            parameters[1].Value = model.contentType;
            parameters[2].Value = model.param;
            parameters[3].Value = model.sortid;
            parameters[4].Value = model.ptype;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(BCW.MobileSlider.Model.MobileSlider model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tb_MobileSlider set ");
            strSql.Append("url=@url,");
            strSql.Append("contentType=@contentType,");
            strSql.Append("param=@param,");
            strSql.Append("sortid=@sortid,");
            strSql.Append("ptype=@ptype");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@url",         SqlDbType.NVarChar, 100),
                new SqlParameter("@contentType", SqlDbType.NVarChar, 100),
                new SqlParameter("@param",       SqlDbType.NVarChar, 300),
                new SqlParameter("@sortid",      SqlDbType.Int,        4),
                new SqlParameter("@ptype",       SqlDbType.Int,        4),
                new SqlParameter("@id",          SqlDbType.Int, 4)
            };
            parameters[0].Value = model.url;
            parameters[1].Value = model.contentType;
            parameters[2].Value = model.param;
            parameters[3].Value = model.sortid;
            parameters[4].Value = model.ptype;
            parameters[5].Value = model.id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public BCW.MobileSlider.Model.MobileSlider GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,url,contentType,param,sortid,ptype from tb_MobileSlider ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            BCW.MobileSlider.Model.MobileSlider model = new BCW.MobileSlider.Model.MobileSlider();
            DataSet ds = SqlHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }