00001 using System;
00002 using System.Collections.Generic;
00003 using System.ComponentModel;
00004 using System.Drawing;
00005 using System.Data;
00006 using System.Text;
00007 using System.Windows.Forms;
00008 using Shared;
00009
00010 namespace CommentControls
00011 {
00018 public partial class WorkingCommentControl : UserControl
00019 {
00020 IAccessHandler accessHandler;
00021 bool replyToComment = false, creating = false;
00022 int literature, project;
00023 Dictionary<int, TreeNode> commentsTable = new Dictionary<int, TreeNode>();
00024
00028 public WorkingCommentControl()
00029 {
00030 InitializeComponent();
00031 UpdateComments();
00032 }
00033
00040 public WorkingCommentControl(IAccessHandler accessHandler, int literature, int project)
00041 {
00042 InitializeComponent();
00043 this.accessHandler = accessHandler;
00044 this.literature = literature;
00045 this.project = project;
00046 UpdateComments();
00047 }
00048
00052 public IAccessHandler AccessHandler
00053 {
00054 get { return accessHandler; }
00055 set { accessHandler = value; }
00056 }
00057
00061 public int Project
00062 {
00063 get { return project; }
00064 set { project = value; }
00065 }
00066
00070 public int Literature
00071 {
00072 get { return literature; }
00073 set { literature = value; }
00074 }
00075
00076
00077 #region CommentControl Buttons
00078
00079 private void commentCreateButton_Click(object sender, EventArgs e)
00080 {
00081 commentContentTextBox.ReadOnly = false;
00082 commentDetailsTextbox.ReadOnly = false;
00083 commentDetailsTextbox.Focus();
00084 commentSubmitButton.Visible = true;
00085 commentCancelButton.Visible = true;
00086 commentCreateButton.Visible = false;
00087 commentEditButton.Visible = false;
00088 commentReplyButton.Visible = false;
00089 commentContentTextBox.Text = "";
00090 commentDetailsTextbox.Text = "";
00091 commentsTreeview.Enabled = false;
00092 creating = true;
00093 }
00094
00095 private void commentCancelButton_Click(object sender, EventArgs e)
00096 {
00097 commentReplyButton.Enabled = false;
00098 commentEditButton.Enabled = false;
00099 commentSubmitButton.Visible = false;
00100 commentCancelButton.Visible = false;
00101 commentContentTextBox.ReadOnly = true;
00102 commentContentTextBox.Text = "";
00103 commentDetailsTextbox.ReadOnly = true;
00104 commentDetailsTextbox.Text = "";
00105 commentCreateButton.Visible = true;
00106 commentEditButton.Visible = true;
00107 commentReplyButton.Visible = true;
00108
00109 PopulateCommentsTree();
00110 replyToComment = false;
00111 creating = false;
00112 commentsTreeview.Enabled = true;
00113 }
00114
00115 private void commentEditButton_Click(object sender, EventArgs e)
00116 {
00117
00118 }
00119
00120 private void commentSubmitButton_Click(object sender, EventArgs e)
00121 {
00122 commentSubmitButton.Visible = false;
00123 commentCancelButton.Visible = false;
00124 commentCreateButton.Visible = true;
00125 commentEditButton.Visible = true;
00126 commentReplyButton.Visible = true;
00127 commentContentTextBox.ReadOnly = true;
00128 commentDetailsTextbox.ReadOnly = true;
00129
00130 int id;
00131
00132 if (replyToComment == false)
00133 accessHandler.CreateComment(new CommentInfo(-1, literature, project, accessHandler.WhoAmI, commentDetailsTextbox.Text,
00134 commentContentTextBox.Text, DateTime.Now, project < 0 ? CommentType.Literature : CommentType.Reference), out id);
00135
00136 else
00137 {
00138 CommentInfo ci = (CommentInfo)commentsTreeview.SelectedNode.Tag;
00139 accessHandler.CreateComment(new CommentInfo(-1, ci.id, ci.project, accessHandler.WhoAmI, commentDetailsTextbox.Text, commentContentTextBox.Text, DateTime.Now, CommentType.Comment), out id);
00140
00141 }
00142
00143 commentContentTextBox.Text = "";
00144 commentDetailsTextbox.Text = "";
00145
00146 PopulateCommentsTree();
00147
00148 TreeNode[] temp = commentsTreeview.Nodes.Find(id.ToString(), true);
00149
00150 if (temp.Length > 0) commentsTreeview.SelectedNode = temp[0];
00151
00152 replyToComment = false;
00153 commentsTreeview.Enabled = true;
00154 creating = false;
00155 }
00156
00157 private void commentReplyButton_Click(object sender, EventArgs e)
00158 {
00159 commentContentTextBox.ReadOnly = false;
00160 commentDetailsTextbox.ReadOnly = false;
00161 commentDetailsTextbox.Focus();
00162 commentSubmitButton.Visible = true;
00163 commentCancelButton.Visible = true;
00164 commentCreateButton.Visible = false;
00165 commentEditButton.Visible = false;
00166 commentReplyButton.Visible = false;
00167 commentContentTextBox.Text = "";
00168 commentDetailsTextbox.Text = "";
00169 commentsTreeview.Enabled = false;
00170
00171 replyToComment = true;
00172 }
00173
00174 #endregion
00175
00176 #region Comment Methods & Events
00177
00181 public void UpdateComments()
00182 {
00183 commentCancelButton_Click(null, null);
00184 }
00185
00189 private void PopulateCommentsTree()
00190 {
00191 if (accessHandler == null)
00192 return;
00193 commentsTreeview.Nodes.Clear();
00194
00195 CommentInfo[] comments = project < 0 ? accessHandler.GetComments(literature) : accessHandler.GetComments(literature, project) ;
00196
00197 commentsTable = new Dictionary<int, TreeNode>();
00198
00199 foreach (CommentInfo c in comments)
00200 {
00201 TreeNode temp = new TreeNode("''" + c.title + "''" + " by " + c.poster + ", " + c.Date.Year);
00202 temp.Name = c.id.ToString();
00203 temp.Tag = c;
00204
00205 commentsTable.Add(c.id, temp);
00206
00207 if (literature == c.parent) commentsTreeview.Nodes.Add(temp);
00208
00209 else commentsTable[c.parent].Nodes.Add(temp);
00210
00211 }
00212
00213 commentsTreeview.ExpandAll();
00214
00215 }
00216
00217 private void commentsTreeview_AfterSelect(object sender, TreeViewEventArgs e)
00218 {
00219 if (commentsTreeview.SelectedNode == null)
00220 return;
00221
00222 commentDetailsTextbox.Text = "";
00223 commentDetailsTextbox.Text = ((CommentInfo)commentsTreeview.SelectedNode.Tag).title;
00224
00225 commentContentTextBox.Text = "";
00226 commentContentTextBox.Text = ((CommentInfo)commentsTreeview.SelectedNode.Tag).text;
00227
00228 commentReplyButton.Enabled = true;
00229 }
00230
00231
00232
00233 #endregion
00234
00235
00236
00237 }
00238 }