Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.tbSingle model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update tbSingle 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(" option_a = @option_a , ");
            strSql.Append(" option_b = @option_b , ");
            strSql.Append(" option_c = @option_c , ");
            strSql.Append(" option_d = @option_d  ");
            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("@option_a",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_b",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_c",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_d",    SqlDbType.NVarChar, 100)
            };

            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.option_a;
            parameters[9].Value  = model.option_b;
            parameters[10].Value = model.option_c;
            parameters[11].Value = model.option_d;                       Util.MyUtil.PrintSql(strSql.ToString());
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.tbSingle GetModelTran(int id, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

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

            Util.MyUtil.PrintSql(strSql.ToString());
            Model.tbSingle model = new Model.tbSingle();
            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());
                }
                model.option_a = ds.Tables[0].Rows[0]["option_a"].ToString();
                model.option_b = ds.Tables[0].Rows[0]["option_b"].ToString();
                model.option_c = ds.Tables[0].Rows[0]["option_c"].ToString();
                model.option_d = ds.Tables[0].Rows[0]["option_d"].ToString();

                return(model);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int AddTran(Model.tbSingle model, SqlTransaction transaction)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into tbSingle(");
            strSql.Append("chapterid,ques,ans,diff,selectcount,rightcount,questype,option_a,option_b,option_c,option_d");
            strSql.Append(") values (");
            strSql.Append("@chapterid,@ques,@ans,@diff,@selectcount,@rightcount,@questype,@option_a,@option_b,@option_c,@option_d");
            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("@option_a",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_b",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_c",    SqlDbType.NVarChar, 100),
                new SqlParameter("@option_d",    SqlDbType.NVarChar, 100)
            };

            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.option_a;
            parameters[8].Value  = model.option_b;
            parameters[9].Value  = model.option_c;
            parameters[10].Value = model.option_d;

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

			 Util.MyUtil.PrintSql(strSql.ToString());
			Model.tbSingle model=new Model.tbSingle();
			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());
				}
																																				model.option_a= ds.Tables[0].Rows[0]["option_a"].ToString();
																																model.option_b= ds.Tables[0].Rows[0]["option_b"].ToString();
																																model.option_c= ds.Tables[0].Rows[0]["option_c"].ToString();
																																model.option_d= ds.Tables[0].Rows[0]["option_d"].ToString();
																										
				return model;
			}
			else
			{
				return null;
			}
		}