コード例 #1
0
ファイル: QuestionService.cs プロジェクト: 303699796/UFB
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(UFB.Model.Question model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Question set ");
            //strSql.Append("category=@category,");
            strSql.Append("question=@question,");
            strSql.Append("solution=@solution,");
            strSql.Append("time=@time");
            strSql.Append(" where questionID=@questionID");
            SqlParameter[] parameters =
            {
                //new SqlParameter("@category", SqlDbType.VarChar,64),
                new SqlParameter("@question",   SqlDbType.VarChar,        128),
                new SqlParameter("@solution",   SqlDbType.VarChar,        128),
                new SqlParameter("@time",       SqlDbType.SmallDateTime),
                new SqlParameter("@questionID", SqlDbType.Int, 4)
            };
            //parameters[0].Value = model.category;
            parameters[0].Value = model.question;
            parameters[1].Value = model.solution;
            parameters[2].Value = model.time;
            parameters[3].Value = model.questionID;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
ファイル: QuestionService.cs プロジェクト: 303699796/UFB
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(UFB.Model.Question model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Question(");
            strSql.Append("category,question,solution,time)");
            strSql.Append(" values (");
            strSql.Append("@category,@question,@solution,@time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@category", SqlDbType.VarChar,  64),
                new SqlParameter("@question", SqlDbType.VarChar, 128),
                new SqlParameter("@solution", SqlDbType.VarChar, 128),
                new SqlParameter("@time",     SqlDbType.SmallDateTime)
            };
            parameters[0].Value = model.category;
            parameters[1].Value = model.question;
            parameters[2].Value = model.solution;
            parameters[3].Value = model.time;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #3
0
ファイル: QuestionService.cs プロジェクト: 303699796/UFB
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public UFB.Model.Question DataRowToModel(DataRow row)
 {
     UFB.Model.Question model = new UFB.Model.Question();
     if (row != null)
     {
         if (row["questionID"] != null && row["questionID"].ToString() != "")
         {
             model.questionID = int.Parse(row["questionID"].ToString());
         }
         if (row["category"] != null)
         {
             model.category = row["category"].ToString();
         }
         if (row["question"] != null)
         {
             model.question = row["question"].ToString();
         }
         if (row["solution"] != null)
         {
             model.solution = row["solution"].ToString();
         }
         if (row["time"] != null && row["time"].ToString() != "")
         {
             model.time = DateTime.Parse(row["time"].ToString());
         }
     }
     return(model);
 }
コード例 #4
0
ファイル: Modify.aspx.cs プロジェクト: 303699796/UFB
 private void ShowInfo(int questionID)
 {
     UFB.BLL.QuestionManager bll   = new UFB.BLL.QuestionManager();
     UFB.Model.Question      model = bll.GetModel(questionID);
     this.lblquestionID.Text = model.questionID.ToString();
     this.txtcategory.Text   = model.category;
     this.txtquestion.Text   = model.question;
     this.txtsolution.Text   = model.solution;
     this.txttime.Text       = model.time.ToString();
 }
コード例 #5
0
ファイル: Modify.aspx.cs プロジェクト: 303699796/UFB
        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";

            if (this.txtcategory.Text.Trim().Length == 0)
            {
                strErr += "category不能为空!\\n";
            }
            if (this.txtquestion.Text.Trim().Length == 0)
            {
                strErr += "question不能为空!\\n";
            }
            if (this.txtsolution.Text.Trim().Length == 0)
            {
                strErr += "solution不能为空!\\n";
            }
            if (!PageValidate.IsDateTime(txttime.Text))
            {
                strErr += "time格式错误!\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int      questionID = int.Parse(this.lblquestionID.Text);
            string   category   = this.txtcategory.Text;
            string   question   = this.txtquestion.Text;
            string   solution   = this.txtsolution.Text;
            DateTime time       = DateTime.Parse(this.txttime.Text);


            UFB.Model.Question model = new UFB.Model.Question();
            model.questionID = questionID;
            model.category   = category;
            model.question   = question;
            model.solution   = solution;
            model.time       = time;

            UFB.BLL.QuestionManager bll = new UFB.BLL.QuestionManager();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功!", "list.aspx");
        }
コード例 #6
0
ファイル: QuestionService.cs プロジェクト: 303699796/UFB
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public UFB.Model.Question GetModel(int questionID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 questionID,category,question,solution,time from Question ");
            strSql.Append(" where questionID=@questionID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@questionID", SqlDbType.Int, 4)
            };
            parameters[0].Value = questionID;

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

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