Beispiel #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (CurrentQA == null)
     {
         List <TMS.QAInfo> qaList = new TMS.QA().SelectList(1, "1=1", "ID asc", null);
         if (qaList.Count == 1)
         {
             CurrentQA = qaList[0];
             Response.Redirect("QA.aspx?cat=" + Server.UrlEncode(CurrentQA.CatName) + "&ID=" + CurrentQA.ID);
         }
         else
         {
             //没有任何内容,跳转到首页
             Response.Redirect("Default.aspx");
         }
     }
 }
Beispiel #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string title   = tbName.Text.Trim();
        string catName = ddlCat.SelectedValue;
        string content = tbContent.Text;
        var    bll     = new TMS.QA();

        if (title.IsNullOrEmpty())
        {
            MessageBox.Show("标题必须填写!");
            return;
        }

        if (content.IsNullOrEmpty())
        {
            MessageBox.Show("内容必须填写!");
            return;
        }

        if (QAID == 0)
        {
            //添加
            QAInfo model = new QAInfo();
            model.QATitle   = title;
            model.CatName   = catName;
            model.QAContent = content;
            bll.Add(model);
            MessageBox.Show("添加成功!", CurrentUrl);
        }
        else
        {
            QAInfo model = bll.Select(QAID);
            if (model == null)
            {
                MessageBox.Show("该问答不存在!", true);
                return;
            }
            model.QATitle   = title;
            model.CatName   = catName;
            model.QAContent = content;
            bll.Update(model);
            MessageBox.Show("修改成功!");
        }
    }