📄 edit_bug.aspx
字号:
{
short_desc_err.InnerText = "";
}
if (comment.Value.Length > 7000)
{
good = false;
comment_err.InnerText = "Comment cannot be longer than 7000 characters.";
}
else
{
comment_err.InnerText = "";
}
if (!did_something_change())
{
return false;
}
foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
{
string name = drcc["name"].ToString();
string val = Request[name];
if (val == null) continue;
// if a date was entered, convert to db format
if (val.Length > 0)
{
string datatype = drcc["datatype"].ToString();
if (datatype == "datetime")
{
try
{
DateTime.Parse(val, Util.get_culture_info());
}
catch (FormatException)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" not in a valid date format.<br>";
return false;
}
}
else if (datatype == "int")
{
if (!Util.is_int(val))
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" must be an integer.<br>";
return false;
}
}
else if (datatype == "decimal")
{
try
{
Decimal.Parse(val, Util.get_culture_info());
// check if there are too many digits overall
int xprec = Convert.ToInt32(drcc["xprec"]);
if (val.Replace(".","").Length > xprec)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" has too many digits.<br>";
return false;
}
// check if there are too many digits to left or right of decimal
int xscale = Convert.ToInt32(drcc["xscale"]);
int pos = val.IndexOf(".");
if (pos > -1)
{
if (pos > xprec - xscale)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" has too many digits to the left of the decimal point.<br>";
return false;
}
if (val.Length-(pos+1) > xscale)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" has too many digits to the right of the decimal point.<br>";
return false;
}
}
}
catch (FormatException)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" not in a valid decimal format.<br>";
return false;
}
}
}
else
{
int nullable = (int) drcc["isnullable"];
if (nullable == 0)
{
custom_field_msg.InnerHtml = "<br>\"" + name + "\" is required.<br>";
return false;
}
}
}
return good;
}
///////////////////////////////////////////////////////////////////////
void format_last_update_text()
{
DateTime last_update_date = (DateTime) dbutil.execute_scalar(sql);
last_changed.InnerHtml = "last changed by <b>"
+ Util.format_username(security.this_username, security.this_fullname)
+ "</b> on <b>"
+ Util.format_db_date(last_update_date)
+ "</b>";
}
///////////////////////////////////////////////////////////////////////
void on_update (Object sender, EventArgs e)
{
bool good = validate();
// save for next bug
Session["project"] = project.SelectedItem.Value;
if (good)
{
if (id == 0) // insert new
{
string pcd1 = Request["pcd1"];
string pcd2 = Request["pcd2"];
string pcd3 = Request["pcd3"];
if (pcd1 == null)
{
pcd1 = "";
}
if (pcd2 == null)
{
pcd2 = "";
}
if (pcd3 == null)
{
pcd3 = "";
}
pcd1 = pcd1.Replace("'","''");
pcd2 = pcd2.Replace("'","''");
pcd3 = pcd3.Replace("'","''");
int int_new_id = insert_bug(
short_desc.Value,
security.this_usid,
Convert.ToInt32(project.SelectedItem.Value),
Convert.ToInt32(category.SelectedItem.Value),
Convert.ToInt32(priority.SelectedItem.Value),
Convert.ToInt32(assigned_to.SelectedItem.Value),
Convert.ToInt32(status.SelectedItem.Value),
Convert.ToInt32(udf.SelectedItem.Value),
Request["pcd1"],
Request["pcd2"],
Request["pcd3"],
HttpUtility.HtmlDecode(comment.Value),
null,
hash_custom_cols);
new_id.Value = Convert.ToString(int_new_id);
msg.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")) + " was created.";
sub.Value = "Update";
Response.Redirect("edit_bug.aspx?id=" + Convert.ToString(id));
status_changed = true;
}
else // edit existing
{
if (permission_level == PERMISSION_REPORTER)
{
sql = @"declare @now datetime
set @now = getdate()
update bugs set
bg_last_updated_user = $lu,
bg_last_updated_date = @now
where bg_id = $id
select @now";
sql = sql.Replace("$lu", Convert.ToString(security.this_usid));
sql = sql.Replace("$id", Convert.ToString(id));
format_last_update_text();
}
else
{
string new_project;
if (project_changed)
{
new_project = project.SelectedItem.Value;
}
else
{
new_project = prev_project.Value;
}
string new_assigned_to;
if (assigned_to_changed)
{
new_assigned_to = assigned_to.SelectedItem.Value;
}
else
{
new_assigned_to = prev_assigned_to.Value;
}
if (new_assigned_to == "0")
{
// assign to default user
int default_user = get_default_user(Convert.ToInt32(new_project));
new_assigned_to = Convert.ToString(default_user);
assigned_to_changed = true;
foreach (ListItem li in assigned_to.Items)
{
if (Convert.ToInt32(li.Value) == default_user)
{
li.Selected = true;
break;
}
else
{
li.Selected = false;
}
}
}
sql = @"declare @now datetime
set @now = getdate()
update bugs set
bg_short_desc = N'$sd',
bg_project = $pj,
bg_category = $ct,
bg_priority = $pr,
bg_assigned_to_user = $au,
bg_status = $st,
bg_last_updated_user = $lu,
bg_last_updated_date = @now,
bg_user_defined_attribute = $udf,
bg_project_custom_dropdown_value1 = N'$pcd1',
bg_project_custom_dropdown_value2 = N'$pcd2',
bg_project_custom_dropdown_value3 = N'$pcd3'
$custom_cols_placeholder
where bg_id = $id
select @now";
sql = sql.Replace("$sd", short_desc.Value.Replace("'","''"));
sql = sql.Replace("$lu", Convert.ToString(security.this_usid));
sql = sql.Replace("$id", Convert.ToString(id));
sql = sql.Replace("$pj", new_project);
sql = sql.Replace("$ct", category.SelectedItem.Value);
sql = sql.Replace("$pr", priority.SelectedItem.Value);
sql = sql.Replace("$au", new_assigned_to);
sql = sql.Replace("$st", status.SelectedItem.Value);
sql = sql.Replace("$udf", udf.SelectedItem.Value);
string pcd1 = Request["pcd1"];
string pcd2 = Request["pcd2"];
string pcd3 = Request["pcd3"];
if (pcd1 == null)
{
pcd1 = "";
}
if (pcd2 == null)
{
pcd2 = "";
}
if (pcd3 == null)
{
pcd3 = "";
}
sql = sql.Replace("$pcd1", pcd1.Replace("'","''"));
sql = sql.Replace("$pcd2", pcd2.Replace("'","''"));
sql = sql.Replace("$pcd3", pcd3.Replace("'","''"));
if (ds_custom_cols.Tables[0].Rows.Count == 0)
{
sql = sql.Replace("$custom_cols_placeholder","");
}
else
{
string custom_cols_sql = "";
foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
{
custom_cols_sql += ",[" + drcc["name"].ToString() + "]";
custom_cols_sql += " = ";
string val = Request[drcc["name"].ToString()].Replace("'","''");
// if a date was entered, convert to db format
if (val.Length > 0
&& drcc["datatype"].ToString() == "datetime")
{
val = Util.format_local_date_into_db_format(val);
}
if (val.Length == 0)
{
custom_cols_sql += "null";
}
else
{
custom_cols_sql += "N'" + val + "'";
}
}
sql = sql.Replace("$custom_cols_placeholder", custom_cols_sql);
}
format_last_update_text();
auto_subscribe(id, Convert.ToInt32(new_project));
format_subcribe_cancel_link();
record_changes();
} // permission_level = 3 or not
insert_comment(id, security.this_usid, HttpUtility.HtmlDecode(comment.Value), null);
string result = send_notifications(UPDATE,
id,
security.this_usid);
if (result == "")
{
msg.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")) + " was updated.";
}
else
{
msg.InnerHtml = result + "<br><br>" + Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")) + " was updated.";
}
comment.Value = "";
} // edit existing or not
}
else
{
if (id == 0) // insert new
{
msg.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")) + " was not created.";
}
else // edit existing
{
msg.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")) + " was not updated.";
}
}
}
///////////////////////////////////////////////////////////////////////
void write_comment(DataRow dr, int comment_id)
{
Response.Write ("<tr><td class=cmt><table width=100% ><tr><td align=left>");
if ((string)dr["bc_type"] == "update") // update
{
// posted by
Response.Write ("<span class=pst>changed by ");
Response.Write (Util.format_email_username(
id,
(string) dr["us_email"],
(string) dr["us_username"],
(string) dr["us_fullname"]));
Response.Write (" on ");
Response.Write (Util.format_db_date(dr["bc_date"]));
Response.Write ("</span></td>");
}
else
{
// Email sent to somebody
if ((string)dr["bc_type"] == "sent" ) // sent email
{
Response.Write ("<span class=pst>email sent to ");
Response.Write (Util.format_email_to(
id,
HttpUtility.HtmlEncode((string)dr["bc_email_to"])));
Response.Write (" by ");
Response.Write (Util.format_email_username(
id,
(string) dr["us_email"],
(string) dr["us_username"],
(string) dr["us_fullname"]));
}
// Email received from somebody
else if ((string)dr["bc_type"] == "received" ) // received email
{
Response.Write ("<span class=pst>email received from ");
Response.Write (Util.format_email_from(
id,
(string)dr["bc_email_from"]));
}
// Regular comment posted
else
{
Response.Write ("<span class=pst>comment posted by ");
Response.Write (Util.format_email_username(
id,
(string) dr["us_email"],
(string) dr["us_username"],
(string) dr["us_fullname"]));
}
Response.Write (" on ");
Response.Write (Util.format_db_date(dr["bc_date"]));
Response.Write ("</span></td>");
Response.Write ("<td align=right> ");
if ((string)dr["bc_type"] == "received" )
{
Response.Write (" <a style='font-size: 8pt;'");
Response.Write ("href=send_email.aspx?quote=1&bc_id=" + Convert.ToString(comment_id));
Response.Write (">reply</a>");
Response.Write (" <a style='font-size: 8pt;'");
Response.Write ("href=send_email.aspx?quote=1&bc_id=" + Convert.ToString(comment_id) + "&reply=all");
Response.Write (">reply all</a>");
}
// delete link
if (security.this_is_admin
|| Util.get_setting("AllowCommentDeletionForNonAdmins","1") == "1")
{
Response.Write (" <a style='font-size: 8pt;'");
Response.Write (" href=edit_comment.aspx?id="
+ Convert.ToString(comment_id) + "&bug_id=" + Convert.ToString(id));
Response.Write (">edit</a>");
Response.Write (" <a style='font-size: 8pt;'");
Response.Write (" href=delete_comment.aspx?id="
+ Convert.ToString(comment_id) + "&bug_id=" + Convert.ToString(id));
Response.Write (">delete</a>");
}
Response.Write ("</td>");
}
// the text itself
Response.Write ("</td></tr></table><table border=0><tr><td>");
string s = (string) dr["bc_comment"];
s = Util.format_comment(s);
Response.Write (s);
}
///////////////////////////////////////////////////////////////////////
void write_comment_attachment(DataRow dr)
{
Response.Write ("<p><span class=pst>attachment: </span>");
Response.Write (dr["ba_file"]);
Response.Write (" ");
Response.Write ("<a target=_blank href=view_attachment.aspx?download=0&id=");
Response.Write (Convert.ToString(dr["ba_id"]));
Response.Write ("&bug_id=");
Response.Write (Convert.ToString(id));
Response.Write (">view</a> ");
Response.Write ("<a target=_blank href=view_attachment.aspx?download=1&id=");
Response.Write (Convert.ToString(dr["ba_id"]));
Response.Write ("&bug_id=");
Response.Write (Convert.ToString(id));
Response.Write (">save</a>");
}
///////////////////////////////////////////////////////////////////////
void write_comments()
{
DataSet ds_comments = Util.get_bug_comments(id, dbutil);
int bc_id;
int prev_bc_id = -1;
foreach (DataRow dr in ds_comments.Tables[0].Rows)
{
bc_id = (int) dr["bc_id"];
if (bc_id == prev_bc_id)
{
// show another attachment
write_comment_attachment(dr);
}
else
{
// show the comment and maybe an attachment
if (prev_bc_id != -1) {
Response.Write ("</table>");
}
write_comment(dr, bc_id);
if (Convert.ToString(dr["ba_file"]) != "")
{
write_comment_attachment(dr);
}
prev_bc_id = bc_id;
}
}
Response.Write ("</table>");
}
///////////////////////////////////////////////////////////////////////
void write_attachments()
{
sql = @"select
ba_file [file],
ba_desc [desc],
us_username [user],
ba_uploaded_date [date],
ba_size [size],
'<a target=_blank href=view_attachment.aspx?download=0&id=' + convert(varchar,ba_id)
+ '&bug_id=' + convert(varchar,ba_bug) + '>view</a>' [view],
'<a target=_blank href=view_attachment.aspx?download=1&id=' + convert(varchar,ba_id)
+ '&bug_id=' + convert(varchar,ba_bug) + '>save</a>' [save],
'<a href=edit_attachment.aspx?id=' + convert(varchar,ba_id)
+ '&bug_id=' + convert(varchar,ba_bug) + '>edit</a>' [edit]";
// delete link
if (security.this_is_admin
|| Util.get_setting("AllowAttachmentDeletionForNonAdmins","1") == "1")
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -