예제 #1
0
        protected void btnAddComment_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbComment.Text))
            {
                lbResult.Text = "コメントを入力して下さい";
                return;
            }
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                HttpCookie hc = Request.Cookies["user"];
                string     user;
                if (hc == null || string.IsNullOrEmpty(user = MasterPage.UserName(hc)))
                {
                    lbResult.Text = "ログインして下さい";
                    return;
                }
                Answer aw = dc.GetAnswer((int?)Session["Answer"]);
                if (aw == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                dc.AddComment(aw.ID, user, tbComment.Text);
                dc.Save(null);
            }
            SetData();
        }
예제 #2
0
        protected void btnYes_Click(object sender, EventArgs e)
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                bool   bNotFound = true;
                string tgt       = (string)Session["DeleteTarget"];
                if (tgt == "Problem")
                {
                    Problem pb = dc.GetProblem((string)Session["Title"]);
                    if (pb != null)
                    {
                        bNotFound = false;
                        dc.Problems.Remove(pb);
                    }
                }
                else if (tgt == "Answer")
                {
                    Answer aw = dc.GetAnswer((int?)Session["Answer"]);
                    if (aw != null)
                    {
                        bNotFound = false;
                        dc.Answers.Remove(aw);
                    }
                }
                else if (tgt == "Comment")
                {
                    Comment cm = dc.GetComment((int?)Session["Comment"]);
                    if (cm != null)
                    {
                        bNotFound = false;
                        dc.Comments.Remove(cm);
                    }
                }
                if (bNotFound)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                dc.Save(null);
            }
            lbResult.Text = "";
            btnNo_Click(null, null);
        }
예제 #3
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Answer aw = dc.GetAnswer((int?)Session["Answer"]);
                if (aw == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                aw.Contents = tbAnswer.Text;
                aw.Time     = DateTime.Now.ToString();
                dc.Save(null);
                lbResult.Text = "更新しました";
            }
        }
예제 #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            lbResult.Text = "";
            if (IsPostBack)
            {
                return;
            }
            string ttl = (string)Session["Title"];

            if (!string.IsNullOrEmpty(ttl))
            {
                tbTitle.Text = ttl;
            }
            if ((string)Session["Mode"] == "new")
            {
                HttpCookie hc = Request.Cookies["user"];
                if (hc != null)
                {
                    tbUser.Text = MasterPage.UserName(hc);
                }
            }
            else
            {
                DataDoc dc = DataDoc.Instance(Server);
                lock (dc)
                {
                    Answer aw = dc.GetAnswer((int?)Session["Answer"]);
                    if (aw == null)
                    {
                        lbResult.Text = "対象がありません";
                        return;
                    }
                    tbUser.Text   = aw.User;
                    tbAnswer.Text = aw.Contents;
                }
                lbMode.Text       = "編集";
                tbTitle.ReadOnly  = tbUser.ReadOnly = true;
                tbTitle.BackColor = tbUser.BackColor = SystemColors.Control;
                btnAdd.Visible    = false;
                btnUpdate.Visible = btnShowAnswer.Visible = true;
            }
        }
예제 #5
0
        private void SetData()
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Answer aw = dc.GetAnswer((int?)Session["Answer"]);
                if (aw == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                lbTitle.Text     = aw.Title;
                Session["Title"] = aw.Title;
                lbUser.Text      = aw.User;
                lbTime.Text      = aw.Time;
                tbAnswer.Text    = aw.Contents;
                HttpCookie hc = Request.Cookies["user"];
                if (hc != null)
                {
                    string user = MasterPage.UserName(hc);
                    if (user == aw.User)
                    {
                        btnEdit.Visible = btnDel.Visible = true;
                    }
                    pnlCommentAdd.Visible = !string.IsNullOrEmpty(user);
                }
                lstComment.Items.Clear();
                foreach (Comment cm in dc.RComments)
                {
                    if (cm.AnswerID != aw.ID)
                    {
                        continue;
                    }
                    lstComment.Items.Add(cm.ToString());
                }
            }
            lbResult.Text = "";
        }