Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据 Mtitle,Mcontent,Mdate,Mpublish,Mid
        /// </summary>
        public bool Update(LearnSite.Model.TxtForm model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update TxtForm set ");
            strSql.Append("Mtitle=@Mtitle,");
            strSql.Append("Mcontent=@Mcontent,");
            strSql.Append("Mdate=@Mdate,");
            strSql.Append("Mpublish=@Mpublish ");
            strSql.Append(" where Mid=@Mid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Mtitle",   SqlDbType.NVarChar,  50),
                new SqlParameter("@Mcontent", SqlDbType.NText),
                new SqlParameter("@Mdate",    SqlDbType.DateTime),
                new SqlParameter("@Mpublish", SqlDbType.Bit,        1),
                new SqlParameter("@Mid",      SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Mtitle;
            parameters[1].Value = model.Mcontent;
            parameters[2].Value = model.Mdate;
            parameters[3].Value = model.Mpublish;
            parameters[4].Value = model.Mid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public LearnSite.Model.TxtForm DataRowToModel(DataRow row)
 {
     LearnSite.Model.TxtForm model = new LearnSite.Model.TxtForm();
     if (row != null)
     {
         if (row["Mid"] != null && row["Mid"].ToString() != "")
         {
             model.Mid = int.Parse(row["Mid"].ToString());
         }
         if (row["Mtitle"] != null)
         {
             model.Mtitle = row["Mtitle"].ToString();
         }
         if (row["Mcid"] != null && row["Mcid"].ToString() != "")
         {
             model.Mcid = int.Parse(row["Mcid"].ToString());
         }
         if (row["Mcontent"] != null)
         {
             model.Mcontent = row["Mcontent"].ToString();
         }
         if (row["Mdate"] != null && row["Mdate"].ToString() != "")
         {
             model.Mdate = DateTime.Parse(row["Mdate"].ToString());
         }
         if (row["Mhit"] != null && row["Mhit"].ToString() != "")
         {
             model.Mhit = int.Parse(row["Mhit"].ToString());
         }
         if (row["Mpublish"] != null && row["Mpublish"].ToString() != "")
         {
             if ((row["Mpublish"].ToString() == "1") || (row["Mpublish"].ToString().ToLower() == "true"))
             {
                 model.Mpublish = true;
             }
             else
             {
                 model.Mpublish = false;
             }
         }
         if (row["Mdelete"] != null && row["Mdelete"].ToString() != "")
         {
             if ((row["Mdelete"].ToString() == "1") || (row["Mdelete"].ToString().ToLower() == "true"))
             {
                 model.Mdelete = true;
             }
             else
             {
                 model.Mdelete = false;
             }
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LearnSite.Model.TxtForm model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TxtForm(");
            strSql.Append("Mtitle,Mcid,Mcontent,Mdate,Mhit,Mpublish,Mdelete)");
            strSql.Append(" values (");
            strSql.Append("@Mtitle,@Mcid,@Mcontent,@Mdate,@Mhit,@Mpublish,@Mdelete)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Mtitle",   SqlDbType.NVarChar,  50),
                new SqlParameter("@Mcid",     SqlDbType.Int,        4),
                new SqlParameter("@Mcontent", SqlDbType.NText),
                new SqlParameter("@Mdate",    SqlDbType.DateTime),
                new SqlParameter("@Mhit",     SqlDbType.Int,        4),
                new SqlParameter("@Mpublish", SqlDbType.Bit,        1),
                new SqlParameter("@Mdelete",  SqlDbType.Bit, 1)
            };
            parameters[0].Value = model.Mtitle;
            parameters[1].Value = model.Mcid;
            parameters[2].Value = model.Mcontent;
            parameters[3].Value = model.Mdate;
            parameters[4].Value = model.Mhit;
            parameters[5].Value = model.Mpublish;
            parameters[6].Value = model.Mdelete;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LearnSite.Model.TxtForm GetModel(int Mid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Mid,Mtitle,Mcid,Mcontent,Mdate,Mhit,Mpublish,Mdelete from TxtForm ");
            strSql.Append(" where Mid=@Mid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Mid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Mid;

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

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