示例#1
0
 public static DataDoc Instance(HttpServerUtility Server)
 {
     if (!_Instance.bInitialized)
     {
         lock (_Instance)
         {
             if (!_Instance.bInitialized)
             {
                 FileName = Server.MapPath("App_Data/data.xml");
                 try
                 {
                     _Instance = Load(FileName);
                 }
                 catch
                 {
                     _Instance.Problems = new List <Problem>();
                     _Instance.Answers  = new List <Answer>();
                     _Instance.Comments = new List <Comment>();
                 }
                 _Instance.bInitialized = true;
             }
         }
     }
     return(_Instance);
 }
示例#2
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();
        }
示例#3
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbUser.Text))
            {
                lbResult.Text = "作成者を入力して下さい";
                return;
            }
            if (string.IsNullOrEmpty(tbTitle.Text))
            {
                lbResult.Text = "タイトルを入力して下さい";
                return;
            }
            if (string.IsNullOrEmpty(tbAnswer.Text))
            {
                lbResult.Text = "内容を入力して下さい";
                return;
            }
            lbResult.Text = "";
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                dc.AddAnswer(tbTitle.Text, tbUser.Text, tbAnswer.Text);
                dc.Save(null);
                lbResult.Text = "追加しました";
            }
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            lbResult.Text = "";
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Comment cm = dc.GetComment((int?)Session["Comment"]);
                if (cm == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                lbUser.Text    = cm.User;
                lbTime.Text    = cm.Time;
                lbComment.Text = cm.Contents;
                HttpCookie hc = Request.Cookies["user"];
                if (hc != null && cm.User == MasterPage.UserName(hc))
                {
                    btnDel.Visible = true;
                }
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            string user = (string)Session["SelUser"];

            if (string.IsNullOrEmpty(user))
            {
                lbResult.Text = "対象がありません";
                return;
            }
            lbUser.Text   = user;
            lbResult.Text = "";
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                int i0 = 0, i1 = 0, i2 = 0, i3 = 0;
                lstAnswer.Items.Clear();
                foreach (Problem pb in dc.Problems)
                {
                    if (!pb.Title.StartsWith("!"))
                    {
                        ++i0;
                        if (pb.User == user)
                        {
                            ++i1;
                        }
                    }
                }
                foreach (Answer aw in dc.RAnswers)
                {
                    if (aw.User != user)
                    {
                        continue;
                    }
                    ++i2;
                    lstAnswer.Items.Add(aw.ToString());
                    if (!dic.ContainsKey(aw.Title))
                    {
                        dic.Add(aw.Title, null);
                    }
                }
                foreach (Comment cm in dc.Comments)
                {
                    if (cm.User == user)
                    {
                        ++i3;
                    }
                }
                lbNProblem.Text = string.Format("{0} 件 / {1} 件", i1, i0);
                lbNAnswer.Text  = string.Format("{0} 件 / {1} 件", i2, dc.Answers.Count);
                lbRate.Text     = string.Format("{0:F2} %", dic.Count * 100.0 / Math.Max(1, i0));
                lbNComment.Text = string.Format("{0} 件 / {1} 件", i3, dc.Comments.Count);
            }
        }
示例#6
0
        public static DataDoc Load(string fnam)
        {
            var     xs = new XmlSerializer(typeof(DataDoc));
            DataDoc dd = null;

            using (var sr = new StreamReader(fnam))
                dd = (DataDoc)xs.Deserialize(sr);
            return(dd);
        }
示例#7
0
        protected void btnShowAnswer_Click(object sender, EventArgs e)
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Comment cm = dc.GetComment((int?)Session["Comment"]);
                if (cm != null)
                {
                    Session["Answer"] = cm.AnswerID;
                    Response.Redirect("ShowAnswer.aspx");
                }
            }
        }
示例#8
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);
        }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            lbResult.Text = "";
            string ttl = (string)Session["Title"];

            if (string.IsNullOrEmpty(ttl))
            {
                lbResult.Text = "対象がありません";
                return;
            }
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Problem pb = dc.GetProblem(ttl);
                if (pb == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                lbTitle.Text   = pb.Title;
                lbCate.Text    = pb.Category;
                lbUser.Text    = pb.User;
                lbTime.Text    = pb.Time;
                lbProblem.Text = pb.Contents;
                HttpCookie hc = Request.Cookies["user"];
                if (hc != null && pb.User == MasterPage.UserName(hc))
                {
                    btnEdit.Visible = btnDel.Visible = true;
                }
                lstAnswer.Items.Clear();
                foreach (Answer aw in dc.RAnswers)
                {
                    if (ttl != null && aw.Title != ttl)
                    {
                        continue;
                    }
                    lstAnswer.Items.Add(aw.ToString());
                }
            }
        }
示例#10
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 = "更新しました";
            }
        }
示例#11
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Problem pb = dc.GetProblem(tbTitle.Text);
                if (pb == null)
                {
                    lbResult.Text = "対象がありません";
                    return;
                }
                pb.Contents = tbProblem.Text;
                pb.Time     = DateTime.Now.ToString();
                dc.Save(null);
                lbResult.Text = "更新しました";
            }
        }
示例#12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            string key = (string)Session["Search"];

            lbSearch.Text = key;
            Regex   re = new Regex(key ?? "", RegexOptions.Compiled);
            int     i1 = 0, i2 = 0, i3 = 0;
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                foreach (Problem pb in dc.Problems)
                {
                    if (re.IsMatch(pb.Contents))
                    {
                        lstProblem.Items.Add(pb.ToString());
                        ++i1;
                    }
                }
                foreach (Answer aw in dc.Answers)
                {
                    if (re.IsMatch(aw.Contents))
                    {
                        lstAnswer.Items.Add(aw.ToString());
                        ++i2;
                    }
                }
                foreach (Comment cm in dc.Comments)
                {
                    if (re.IsMatch(cm.Contents))
                    {
                        lstComment.Items.Add(cm.ToString());
                        ++i3;
                    }
                }
                lbRes1.Text = "全 " + i1 + " 件";
                lbRes2.Text = "全 " + i2 + " 件";
                lbRes3.Text = "全 " + i3 + " 件";
            }
        }
示例#13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     lbResult.Text = "";
     if (IsPostBack)
     {
         return;
     }
     if ((string)Session["Mode"] == "new")
     {
         HttpCookie hc = Request.Cookies["user"];
         if (hc != null)
         {
             tbUser.Text = MasterPage.UserName(hc);
         }
         string selCate = (string)Session["SelCate"];
         if (!string.IsNullOrEmpty(selCate))
         {
             tbCate.Text = selCate;
         }
     }
     else
     {
         string  ttl = (string)Session["Title"];
         DataDoc dc  = DataDoc.Instance(Server);
         lock (dc)
         {
             Problem pb = dc.GetProblem(ttl);
             if (pb == null)
             {
                 lbResult.Text = "対象がありません";
                 return;
             }
             tbTitle.Text   = pb.Title;
             tbCate.Text    = pb.Category;
             tbUser.Text    = pb.User;
             tbProblem.Text = pb.Contents;
         }
         lbMode.Text       = "編集";
         tbTitle.ReadOnly  = tbCate.ReadOnly = tbUser.ReadOnly = true;
         tbTitle.BackColor = tbCate.BackColor = tbUser.BackColor = SystemColors.Control;
         btnAdd.Visible    = false;
         btnUpdate.Visible = btnShowProblem.Visible = true;
     }
 }
示例#14
0
        public void SetCateUser()
        {
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                lstCate.Items.Clear();
                lstUser.Items.Clear();
                lstCate.Items.Add("[全て]");
                foreach (string cate in dc.Categories())
                {
                    lstCate.Items.Add(cate);
                }
                foreach (string usr in dc.Users())
                {
                    lstUser.Items.Add(usr);
                }
            }
        }
示例#15
0
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbUser.Text))
            {
                lbResult.Text = "作成者を入力して下さい";
                return;
            }
            if (string.IsNullOrEmpty(tbTitle.Text))
            {
                lbResult.Text = "タイトルを入力して下さい";
                return;
            }
            if (string.IsNullOrEmpty(tbCate.Text))
            {
                lbResult.Text = "カテゴリを入力して下さい";
                return;
            }
            if (string.IsNullOrEmpty(tbProblem.Text))
            {
                lbResult.Text = "内容を入力して下さい";
                return;
            }
            lbResult.Text = "";
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Problem pb = dc.GetProblem(tbTitle.Text);
                if (pb != null)
                {
                    lbResult.Text = "カテゴリ(" + pb.Category + ")に同じタイトルがあります";
                    return;
                }
                dc.AddProblem(tbTitle.Text, tbCate.Text, tbUser.Text, tbProblem.Text);
                dc.Save(null);
                lbResult.Text = "追加しました";
            }
            Encoding   enc = Encoding.UTF8;
            MasterPage mp  = (MasterPage)Master;

            mp.SetUser(Convert.ToBase64String(enc.GetBytes(tbUser.Text)));
            mp.SetCateUser();
        }
示例#16
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;
            }
        }
示例#17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            lstList.Items.Clear();
            string  selCate = (string)Session["SelCate"];
            DataDoc dc      = DataDoc.Instance(Server);

            lock (dc)
            {
                foreach (Problem pb in dc.RProblems)
                {
                    if (selCate != null && pb.Category != selCate)
                    {
                        continue;
                    }
                    lstList.Items.Add(pb.ToString());
                }
            }
        }
示例#18
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 = "";
        }
示例#19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }
            HttpCookie hc = Request.Cookies["user"];
            string     user;

            if (hc == null || string.IsNullOrEmpty(user = MasterPage.UserName(hc)))
            {
                lbResult.Text = "ログインして下さい";
                return;
            }
            lstList.Items.Clear();
            DataDoc dc = DataDoc.Instance(Server);

            lock (dc)
            {
                Dictionary <string, object> dic = new Dictionary <string, object>();
                foreach (Answer aw in dc.Answers)
                {
                    if (aw.User == user && !dic.ContainsKey(aw.Title))
                    {
                        dic.Add(aw.Title, null);
                    }
                }
                foreach (Problem pb in dc.RProblems)
                {
                    if (!pb.Title.StartsWith("!") && !dic.ContainsKey(pb.Title))
                    {
                        lstList.Items.Add(pb.ToString());
                    }
                }
            }
        }
示例#20
0
 public static DataDoc Instance(HttpServerUtility Server)
 {
     if (!_Instance.bInitialized)
     {
         lock (_Instance)
         {
             if (!_Instance.bInitialized)
             {
                 FileName = Server.MapPath("App_Data/data.xml");
                 try
                 {
                     _Instance = Load(FileName);
                 }
                 catch
                 {
                     _Instance.Problems = new List<Problem>();
                     _Instance.Answers = new List<Answer>();
                     _Instance.Comments = new List<Comment>();
                 }
                 _Instance.bInitialized = true;
             }
         }
     }
     return _Instance;
 }
示例#21
0
 protected void btnReset_Click(object sender, EventArgs e)
 {
     DataDoc.Reset();
 }