예제 #1
0
파일: subject.cs 프로젝트: lythen/YueFeiSys
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Lythen.Model.subject model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into subject(");
            strSql.Append("Subject_title,Subject_info,Subject_parent)");
            strSql.Append(" values (");
            strSql.Append("@Subject_title,@Subject_info,@Subject_parent)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Subject_title",  SqlDbType.VarChar,  20),
                new SqlParameter("@Subject_info",   SqlDbType.VarChar, 500),
                new SqlParameter("@Subject_parent", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Subject_title;
            parameters[1].Value = model.Subject_info;
            parameters[2].Value = model.Subject_parent;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #2
0
파일: subject.cs 프로젝트: lythen/YueFeiSys
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Lythen.Model.subject model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update subject set ");
            strSql.Append("Subject_title=@Subject_title,");
            strSql.Append("Subject_info=@Subject_info,");
            strSql.Append("Subject_parent=@Subject_parent");
            strSql.Append(" where Subject_id=@Subject_id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Subject_title",  SqlDbType.VarChar,  20),
                new SqlParameter("@Subject_info",   SqlDbType.VarChar, 500),
                new SqlParameter("@Subject_parent", SqlDbType.Int,       4),
                new SqlParameter("@Subject_id",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Subject_title;
            parameters[1].Value = model.Subject_info;
            parameters[2].Value = model.Subject_parent;
            parameters[3].Value = model.Subject_id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
파일: subject.cs 프로젝트: lythen/YueFeiSys
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Lythen.Model.subject DataRowToModel(DataRow row)
 {
     Lythen.Model.subject model = new Lythen.Model.subject();
     if (row != null)
     {
         if (row["Subject_id"] != null && row["Subject_id"].ToString() != "")
         {
             model.Subject_id = int.Parse(row["Subject_id"].ToString());
         }
         if (row["Subject_title"] != null)
         {
             model.Subject_title = row["Subject_title"].ToString();
         }
         if (row["Subject_info"] != null)
         {
             model.Subject_info = row["Subject_info"].ToString();
         }
         if (row["Subject_parent"] != null && row["Subject_parent"].ToString() != "")
         {
             model.Subject_parent = int.Parse(row["Subject_parent"].ToString());
         }
     }
     return(model);
 }
예제 #4
0
파일: subject.cs 프로젝트: lythen/YueFeiSys
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Lythen.Model.subject GetModel(int Subject_id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Subject_id,Subject_title,Subject_info,Subject_parent from subject ");
            strSql.Append(" where Subject_id=@Subject_id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Subject_id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Subject_id;

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

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