This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
/
ReportView.aspx.cs.dblinq
266 lines (225 loc) · 11.1 KB
/
ReportView.aspx.cs.dblinq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MomaTool.Database.Linq;
using System.Data.Linq;
using System.Net.Mail;
using System.Text;
public partial class ReportView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Content only available to logged-in users
if (Page.User.Identity.IsAuthenticated)
{
if (!Page.IsPostBack)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
Report report = MoMADBSupport.GetReport(db, id);
MomADefinition def = MoMADBSupport.GetMomaDefinition(db, report.MomADefinitionID);
ReportMetadata report_meta = MoMADBSupport.GetMetadata(db, id);
// ... and we need to find it from inside the LoginView
Label report_id_label = (Label)LoginView1.FindControl("ReportIDLabel");
report_id_label.Text = "Report " + report.ID;
DropDownList importance_ddl = (DropDownList)LoginView1.FindControl("ImportanceDropDownList");
importance_ddl.SelectedValue = report_meta.Importance;
TextBox application_content_textbox = (TextBox)LoginView1.FindControl("ApplicationContent");
application_content_textbox.Text = report_meta.ApplicationName;
Label author_content_label = (Label)LoginView1.FindControl("AuthorContent");
author_content_label.Text = report.ReporterName;
Label email_content_label = (Label)LoginView1.FindControl("EmailContent");
email_content_label.Text = report.ReporterEmail;
Label website_content_label = (Label)LoginView1.FindControl("WebsiteContent");
website_content_label.Text = report.ReporterHomepage;
Label framework_version_content_label = (Label)LoginView1.FindControl("FrameworkVersionContent");
// I get NullReferenceException here if I try to use report.MomADefinition.DisplayName
// with dblinq
framework_version_content_label.Text = def.DisplayName;
TextBox application_type_content_textbox = (TextBox)LoginView1.FindControl("ApplicationTypeContent");
application_type_content_textbox.Text = report_meta.ApplicationType;
/* Make this filterable to just show issues that still exist in svn */
var issues_q = (from iss in db.Issue
from type in db.IssueType
where iss.ReportID == id && iss.IssueTypeID == type.ID
select new
{
Type = type.LookupName,
Namespace = iss.MethodNamesPace,
ClassName = iss.MethodClass,
Method = iss.MethodName
});
GridView grid1 = (GridView)LoginView1.FindControl("IssuesGridView");
grid1.DataSource = issues_q;
grid1.DataBind();
// Make the default text go away when the user clicks in the Comments box
// (but ensure that it won't blow away a half-entered comment!)
TextBox new_comment_textbox = (TextBox)LoginView1.FindControl("NewComment");
new_comment_textbox.Text = "Type your comment here...";
new_comment_textbox.Attributes.Add("onFocus", "if (this.value == 'Type your comment here...') this.value='';");
this.UpdateComments(db, id);
if (!report.ReporterEmail.Contains("@"))
{
CheckBox send_comment_checkbox = (CheckBox)LoginView1.FindControl("SendCommentCheckBox");
/* Hide the email checkbox, as we can't email the submitter anyway... */
send_comment_checkbox.Visible = false;
send_comment_checkbox.Checked = false;
}
}
}
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
Report report = MoMADBSupport.GetReport(db, id);
ReportMetadata report_meta = MoMADBSupport.GetMetadata(db, id);
DropDownList importance_ddl = (DropDownList)LoginView1.FindControl("ImportanceDropDownList");
report_meta.Importance = importance_ddl.SelectedValue;
TextBox application_content_textbox = (TextBox)LoginView1.FindControl("ApplicationContent");
report_meta.ApplicationName = application_content_textbox.Text;
TextBox application_type_content_textbox = (TextBox)LoginView1.FindControl("ApplicationTypeContent");
report_meta.ApplicationType = application_type_content_textbox.Text;
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
}
}
int GetID()
{
string id_qs = Request.QueryString["ReportID"];
int id;
if (id_qs != null)
{
id = int.Parse(id_qs);
}
else
{
id = 1;
}
return id;
}
void UpdateComments(MoMADB db, int report_id)
{
ReportComment[] comments = MoMADBSupport.GetComments(db, report_id);
TextBox comments_textbox = (TextBox)LoginView1.FindControl("Comments");
comments_textbox.Text = "";
foreach (ReportComment comm in comments)
{
comments_textbox.Text += comm.Comment;
comments_textbox.Text += "\n";
comments_textbox.Text += comm.CommentER;
comments_textbox.Text += " @ ";
comments_textbox.Text += comm.CommentDate;
comments_textbox.Text += "\n\n\n";
}
/* FIXME: figure out how to scroll to the end of the textbox */
}
protected void ApplicationContent_TextChanged(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
Report report = MoMADBSupport.GetReport(db, id);
ReportMetadata report_meta = MoMADBSupport.GetMetadata(db, id);
TextBox application_content_textbox = (TextBox)LoginView1.FindControl("ApplicationContent");
report_meta.ApplicationName = application_content_textbox.Text;
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
}
}
protected void ApplicationType_TextChanged(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
Report report = MoMADBSupport.GetReport(db, id);
ReportMetadata report_meta = MoMADBSupport.GetMetadata(db, id);
TextBox application_type_content_textbox = (TextBox)LoginView1.FindControl("ApplicationTypeContent");
report_meta.ApplicationType = application_type_content_textbox.Text;
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
}
}
protected void Importance_SelectedIndexChanged(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
Report report = MoMADBSupport.GetReport(db, id);
ReportMetadata report_meta = MoMADBSupport.GetMetadata(db, id);
DropDownList importance_ddl = (DropDownList)LoginView1.FindControl("ImportanceDropDownList");
report_meta.Importance = importance_ddl.SelectedValue;
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
}
}
protected void CommentButton_Click(object sender, EventArgs e)
{
if (Page.User.Identity.IsAuthenticated)
{
int id = this.GetID();
MoMADB db = MoMADBSupport.OpenDB();
ReportComment comment = new ReportComment();
CheckBox send_comment_checkbox = (CheckBox)LoginView1.FindControl("SendCommentCheckBox");
TextBox newcomment_textbox = (TextBox)LoginView1.FindControl("NewComment");
Label email_content_label = (Label)LoginView1.FindControl("EmailContent");
comment.Comment = newcomment_textbox.Text;
comment.ReportID = id;
comment.CommentER = Page.User.Identity.Name;
comment.CommentDate = DateTime.Now;
comment.EmailEd = send_comment_checkbox.Checked;
db.ReportComment.InsertOnSubmit(comment);
db.SubmitChanges(ConflictMode.FailOnFirstConflict);
if (send_comment_checkbox.Checked)
{
/* Email the comment (we know the address is available, as the checkbox can't be
* checked otherwise)
*/
StringBuilder email_text = new StringBuilder();
email_text.AppendFormat("{0} added a comment to your MoMA report:\n\n", Page.User.Identity.Name);
email_text.AppendFormat("{0}", newcomment_textbox.Text);
email_text.AppendFormat("\n\nSee {0} for this report.\n", Page.Request.Url.ToString());
string from_addr = Membership.GetUser().Email;
try
{
MailMessage mess = new MailMessage(from_addr, "dick@acm.org"/*email_content_label.Text*/);
mess.Subject = "New comment on MoMA report " + id.ToString();
mess.Body = email_text.ToString();
mess.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
try
{
smtp.Send(mess);
}
catch (SmtpException ex)
{
/* Not sure what we can do here, except inform the commenter that the email didn't
* get sent
*/
}
}
catch (Exception ex)
{
/* MailMessage.ctor() can throw if the email address are malformed - again, not
* sure what can be done here
*/
}
}
/* This reads the entire set of comments - someone else might have added a comment to
* this report simultaneously
*/
this.UpdateComments(db, id);
newcomment_textbox.Text = "";
}
}
}