Exemple #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public void Update(LearnSite.Model.Typer model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Typer set ");
            strSql.Append("Ttype=@Ttype,");
            strSql.Append("Tuse=@Tuse,");
            strSql.Append("Ttitle=@Ttitle,");
            strSql.Append("Tcontent=@Tcontent");
            strSql.Append(" where Tid=@Tid ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Tid",      SqlDbType.Int,        4),
                new SqlParameter("@Ttype",    SqlDbType.SmallInt,   2),
                new SqlParameter("@Tuse",     SqlDbType.Int,        4),
                new SqlParameter("@Ttitle",   SqlDbType.NVarChar, 100),
                new SqlParameter("@Tcontent", SqlDbType.NText)
            };
            parameters[0].Value = model.Tid;
            parameters[1].Value = model.Ttype;
            parameters[2].Value = model.Tuse;
            parameters[3].Value = model.Ttitle;
            parameters[4].Value = model.Tcontent;

            DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(LearnSite.Model.Typer model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Typer(");
            strSql.Append("Ttype,Tuse,Ttitle,Tcontent)");
            strSql.Append(" values (");
            strSql.Append("@Ttype,@Tuse,@Ttitle,@Tcontent)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Ttype",    SqlDbType.SmallInt,   2),
                new SqlParameter("@Tuse",     SqlDbType.Int,        4),
                new SqlParameter("@Ttitle",   SqlDbType.NVarChar, 100),
                new SqlParameter("@Tcontent", SqlDbType.NText)
            };
            parameters[0].Value = model.Ttype;
            parameters[1].Value = model.Tuse;
            parameters[2].Value = model.Ttitle;
            parameters[3].Value = model.Tcontent;

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

            if (obj == null)
            {
                return(1);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #3
0
        /// <summary>
        /// 随机得到一个对象实体
        /// </summary>
        public LearnSite.Model.Typer GetModelRnd(string tids)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("SELECT  TOP 1 Tid,Ttype,Tuse,Ttitle,Tcontent FROM Typer ");
            string wherestr = " WHERE Tid in (" + tids + ")";

            if (tids != "")
            {
                strSql.Append(wherestr);//如果指定文章,则查询指定文章
            }
            strSql.Append(" ORDER  BY NewID() ");

            LearnSite.Model.Typer model = new LearnSite.Model.Typer();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Tid"].ToString() != "")
                {
                    model.Tid = int.Parse(ds.Tables[0].Rows[0]["Tid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Ttype"].ToString() != "")
                {
                    model.Ttype = int.Parse(ds.Tables[0].Rows[0]["Ttype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Tuse"].ToString() != "")
                {
                    model.Tuse = int.Parse(ds.Tables[0].Rows[0]["Tuse"].ToString());
                }
                model.Ttitle   = ds.Tables[0].Rows[0]["Ttitle"].ToString();
                model.Tcontent = ds.Tables[0].Rows[0]["Tcontent"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public LearnSite.Model.Typer GetModel(int Tid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Tid,Ttype,Tuse,Ttitle,Tcontent from Typer ");
            strSql.Append(" where Tid=@Tid ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Tid", SqlDbType.Int, 4)
            };
            parameters[0].Value = Tid;

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

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Tid"].ToString() != "")
                {
                    model.Tid = int.Parse(ds.Tables[0].Rows[0]["Tid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Ttype"].ToString() != "")
                {
                    model.Ttype = int.Parse(ds.Tables[0].Rows[0]["Ttype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Tuse"].ToString() != "")
                {
                    model.Tuse = int.Parse(ds.Tables[0].Rows[0]["Tuse"].ToString());
                }
                model.Ttitle   = ds.Tables[0].Rows[0]["Ttitle"].ToString();
                model.Tcontent = ds.Tables[0].Rows[0]["Tcontent"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        /// <summary>
        /// ����õ�һ������ʵ��
        /// </summary>
        public LearnSite.Model.Typer GetModelRnd()
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT  TOP 1 Tid,Ttype,Tuse,Ttitle,Tcontent FROM Typer ");
            strSql.Append(" ORDER  BY NewID() ");

            LearnSite.Model.Typer model = new LearnSite.Model.Typer();
            DataSet ds = DbHelperSQL.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["Tid"].ToString() != "")
                {
                    model.Tid = int.Parse(ds.Tables[0].Rows[0]["Tid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Ttype"].ToString() != "")
                {
                    model.Ttype = int.Parse(ds.Tables[0].Rows[0]["Ttype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["Tuse"].ToString() != "")
                {
                    model.Tuse = int.Parse(ds.Tables[0].Rows[0]["Tuse"].ToString());
                }
                model.Ttitle = ds.Tables[0].Rows[0]["Ttitle"].ToString();
                model.Tcontent = ds.Tables[0].Rows[0]["Tcontent"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
Exemple #6
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public LearnSite.Model.Typer GetModel(int Tid)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 Tid,Ttype,Tuse,Ttitle,Tcontent from Typer ");
            strSql.Append(" where Tid=@Tid ");
            SqlParameter[] parameters = {
                    new SqlParameter("@Tid", SqlDbType.Int,4)};
            parameters[0].Value = Tid;

            LearnSite.Model.Typer model=new LearnSite.Model.Typer();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["Tid"].ToString()!="")
                {
                    model.Tid=int.Parse(ds.Tables[0].Rows[0]["Tid"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Ttype"].ToString()!="")
                {
                    model.Ttype=int.Parse(ds.Tables[0].Rows[0]["Ttype"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Tuse"].ToString()!="")
                {
                    model.Tuse=int.Parse(ds.Tables[0].Rows[0]["Tuse"].ToString());
                }
                model.Ttitle=ds.Tables[0].Rows[0]["Ttitle"].ToString();
                model.Tcontent=ds.Tables[0].Rows[0]["Tcontent"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }