Пример #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tbGrant model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbGrant set ");

            strSql.Append(" userid = @userid , ");
            strSql.Append(" subjectid = @subjectid , ");
            strSql.Append(" classid = @classid  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",        SqlDbType.Int, 4),
                new SqlParameter("@userid",    SqlDbType.Int, 4),
                new SqlParameter("@subjectid", SqlDbType.Int, 4),
                new SqlParameter("@classid",   SqlDbType.Int, 4)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.userid;
            parameters[2].Value = model.subjectid;
            parameters[3].Value = model.classid;                       Util.MyUtil.PrintSql(strSql.ToString());
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddTran(Model.tbGrant model, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbGrant(");
            strSql.Append("userid,subjectid,classid");
            strSql.Append(") values (");
            strSql.Append("@userid,@subjectid,@classid");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userid",    SqlDbType.Int, 4),
                new SqlParameter("@subjectid", SqlDbType.Int, 4),
                new SqlParameter("@classid",   SqlDbType.Int, 4)
            };

            parameters[0].Value = model.userid;
            parameters[1].Value = model.subjectid;
            parameters[2].Value = model.classid;

            object obj = SQLHelper.ExecuteScalar(transaction, CommandType.Text, strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
            Util.MyUtil.PrintSql(strSql.ToString());
        }
Пример #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.tbGrant model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbGrant(");
            strSql.Append("userid,subjectid,classid");
            strSql.Append(") values (");
            strSql.Append("@userid,@subjectid,@classid");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@userid",    SqlDbType.Int, 4),
                new SqlParameter("@subjectid", SqlDbType.Int, 4),
                new SqlParameter("@classid",   SqlDbType.Int, 4)
            };

            parameters[0].Value = model.userid;
            parameters[1].Value = model.subjectid;
            parameters[2].Value = model.classid;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
            Util.MyUtil.PrintSql(strSql.ToString());
        }
Пример #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tbGrant GetModelTran(int id, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, userid, subjectid, classid  ");
            strSql.Append("  from tbGrant ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Util.MyUtil.PrintSql(strSql.ToString());
            Model.tbGrant model = new Model.tbGrant();
            DataSet       ds    = SQLHelper.ExecuteDataset(transaction, CommandType.Text, strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["id"].ToString() != "")
                {
                    model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
                }
                if (ds.Tables[0].Rows[0]["userid"].ToString() != "")
                {
                    model.userid = int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["subjectid"].ToString() != "")
                {
                    model.subjectid = int.Parse(ds.Tables[0].Rows[0]["subjectid"].ToString());
                }
                if (ds.Tables[0].Rows[0]["classid"].ToString() != "")
                {
                    model.classid = int.Parse(ds.Tables[0].Rows[0]["classid"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.tbGrant GetModelTran(int id ,SqlTransaction transaction)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id, userid, subjectid, classid  ");			
			strSql.Append("  from tbGrant ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			 Util.MyUtil.PrintSql(strSql.ToString());
			Model.tbGrant model=new Model.tbGrant();
			DataSet ds=SQLHelper.ExecuteDataset(transaction,CommandType.Text, strSql.ToString(), parameters);
			
			if(ds.Tables[0].Rows.Count>0)
			{
												if(ds.Tables[0].Rows[0]["id"].ToString()!="")
				{
					model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["userid"].ToString()!="")
				{
					model.userid=int.Parse(ds.Tables[0].Rows[0]["userid"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["subjectid"].ToString()!="")
				{
					model.subjectid=int.Parse(ds.Tables[0].Rows[0]["subjectid"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["classid"].ToString()!="")
				{
					model.classid=int.Parse(ds.Tables[0].Rows[0]["classid"].ToString());
				}
																														
				return model;
			}
			else
			{
				return null;
			}
		}