Exemplo n.º 1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tbBlank GetModelTran(int id, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select id, chapterid, ques, ans, diff, selectcount, rightcount, questype, blanklength  ");
            strSql.Append("  from tbBlank ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            Util.MyUtil.PrintSql(strSql.ToString());
            Model.tbBlank model = new Model.tbBlank();
            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]["chapterid"].ToString() != "")
                {
                    model.chapterid = int.Parse(ds.Tables[0].Rows[0]["chapterid"].ToString());
                }
                model.ques = ds.Tables[0].Rows[0]["ques"].ToString();
                model.ans  = ds.Tables[0].Rows[0]["ans"].ToString();
                if (ds.Tables[0].Rows[0]["diff"].ToString() != "")
                {
                    model.diff = int.Parse(ds.Tables[0].Rows[0]["diff"].ToString());
                }
                if (ds.Tables[0].Rows[0]["selectcount"].ToString() != "")
                {
                    model.selectcount = int.Parse(ds.Tables[0].Rows[0]["selectcount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["rightcount"].ToString() != "")
                {
                    model.rightcount = int.Parse(ds.Tables[0].Rows[0]["rightcount"].ToString());
                }
                if (ds.Tables[0].Rows[0]["questype"].ToString() != "")
                {
                    model.questype = int.Parse(ds.Tables[0].Rows[0]["questype"].ToString());
                }
                if (ds.Tables[0].Rows[0]["blanklength"].ToString() != "")
                {
                    model.blanklength = int.Parse(ds.Tables[0].Rows[0]["blanklength"].ToString());
                }

                return(model);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tbBlank model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbBlank set ");

            strSql.Append(" chapterid = @chapterid , ");
            strSql.Append(" ques = @ques , ");
            strSql.Append(" ans = @ans , ");
            strSql.Append(" diff = @diff , ");
            strSql.Append(" selectcount = @selectcount , ");
            strSql.Append(" rightcount = @rightcount , ");
            strSql.Append(" questype = @questype , ");
            strSql.Append(" blanklength = @blanklength  ");
            strSql.Append(" where id=@id ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@id",          SqlDbType.Int,        4),
                new SqlParameter("@chapterid",   SqlDbType.Int,        4),
                new SqlParameter("@ques",        SqlDbType.NVarChar, 200),
                new SqlParameter("@ans",         SqlDbType.NVarChar, 500),
                new SqlParameter("@diff",        SqlDbType.Int,        4),
                new SqlParameter("@selectcount", SqlDbType.Int,        4),
                new SqlParameter("@rightcount",  SqlDbType.Int,        4),
                new SqlParameter("@questype",    SqlDbType.Int,        4),
                new SqlParameter("@blanklength", SqlDbType.Int, 4)
            };

            parameters[0].Value = model.id;
            parameters[1].Value = model.chapterid;
            parameters[2].Value = model.ques;
            parameters[3].Value = model.ans;
            parameters[4].Value = model.diff;
            parameters[5].Value = model.selectcount;
            parameters[6].Value = model.rightcount;
            parameters[7].Value = model.questype;
            parameters[8].Value = model.blanklength;                       Util.MyUtil.PrintSql(strSql.ToString());
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddTran(Model.tbBlank model, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbBlank(");
            strSql.Append("chapterid,ques,ans,diff,selectcount,rightcount,questype,blanklength");
            strSql.Append(") values (");
            strSql.Append("@chapterid,@ques,@ans,@diff,@selectcount,@rightcount,@questype,@blanklength");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@chapterid",   SqlDbType.Int,        4),
                new SqlParameter("@ques",        SqlDbType.NVarChar, 200),
                new SqlParameter("@ans",         SqlDbType.NVarChar, 500),
                new SqlParameter("@diff",        SqlDbType.Int,        4),
                new SqlParameter("@selectcount", SqlDbType.Int,        4),
                new SqlParameter("@rightcount",  SqlDbType.Int,        4),
                new SqlParameter("@questype",    SqlDbType.Int,        4),
                new SqlParameter("@blanklength", SqlDbType.Int, 4)
            };

            parameters[0].Value = model.chapterid;
            parameters[1].Value = model.ques;
            parameters[2].Value = model.ans;
            parameters[3].Value = model.diff;
            parameters[4].Value = model.selectcount;
            parameters[5].Value = model.rightcount;
            parameters[6].Value = model.questype;
            parameters[7].Value = model.blanklength;

            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());
        }
Exemplo n.º 4
0
		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Model.tbBlank GetModelTran(int id ,SqlTransaction transaction)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id, chapterid, ques, ans, diff, selectcount, rightcount, questype, blanklength  ");			
			strSql.Append("  from tbBlank ");
			strSql.Append(" where id=@id");
						SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)
};
			parameters[0].Value = id;

			 Util.MyUtil.PrintSql(strSql.ToString());
			Model.tbBlank model=new Model.tbBlank();
			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]["chapterid"].ToString()!="")
				{
					model.chapterid=int.Parse(ds.Tables[0].Rows[0]["chapterid"].ToString());
				}
																																				model.ques= ds.Tables[0].Rows[0]["ques"].ToString();
																																model.ans= ds.Tables[0].Rows[0]["ans"].ToString();
																												if(ds.Tables[0].Rows[0]["diff"].ToString()!="")
				{
					model.diff=int.Parse(ds.Tables[0].Rows[0]["diff"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["selectcount"].ToString()!="")
				{
					model.selectcount=int.Parse(ds.Tables[0].Rows[0]["selectcount"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["rightcount"].ToString()!="")
				{
					model.rightcount=int.Parse(ds.Tables[0].Rows[0]["rightcount"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["questype"].ToString()!="")
				{
					model.questype=int.Parse(ds.Tables[0].Rows[0]["questype"].ToString());
				}
																																if(ds.Tables[0].Rows[0]["blanklength"].ToString()!="")
				{
					model.blanklength=int.Parse(ds.Tables[0].Rows[0]["blanklength"].ToString());
				}
																														
				return model;
			}
			else
			{
				return null;
			}
		}