⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 edit_bug.aspx

📁 Bug管理系统
💻 ASPX
📖 第 1 页 / 共 4 页
字号:
<%@ Page language="C#" validateRequest="false"%>
 
<!--
Copyright 2002-2005 Corey Trager
Distributed under the terms of the GNU General Public License
-->
<!-- #include file = "inc.aspx" -->
<!-- #include file = "inc_insert_bug.aspx" -->
<!-- #include file = "inc_print_bug.aspx" -->

<script language="C#" runat="server">

int id;
String sql;
bool project_changed;
bool assigned_to_changed;


DataSet ds_custom_cols;
DataRow dr;

DbUtil dbutil;
Security security;
System.Collections.Hashtable hash_custom_cols;
System.Collections.Hashtable hash_prev_custom_cols;

int permission_level;

const int PERMISSION_NONE = 0;
const int PERMISSION_READONLY = 1;
const int PERMISSION_REPORTER = 3;
const int PERMISSION_ALL = 2;


///////////////////////////////////////////////////////////////////////
void Page_Load(Object sender, EventArgs e)
{

	Util.do_not_cache(Response);
	dbutil = new DbUtil();
	security = new Security();
	security.check_security(dbutil, Request, Response, Security.ANY_USER_OK);

	hash_custom_cols = new System.Collections.Hashtable();
	hash_prev_custom_cols = new System.Collections.Hashtable();

	msg.InnerText = "";
	custom_field_msg.InnerHtml = "";
	project_changed = false;
	assigned_to_changed = false;
	status_changed = false;

	string var = Request.QueryString["id"];
	if (var == null)
	{
		id = 0;
	}
	else
	{
		if (Util.is_int(var))
		{
			id = Convert.ToInt32(var);
		}
		else
		{
			Response.Write ("<link rel=StyleSheet href=btnet.css type=text/css>");
			security.write_menu(Response, Util.get_setting("PluralBugLabel","bugs"));
			Response.Write("<p>&nbsp;</p><div class=align>");
			Response.Write("<div class=err>Error: ");
			Response.Write(Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug")));
			Response.Write(" ID must be an integer.</div>");
			Response.Write("<p><a href=bugs.aspx>View ");
			Response.Write(Util.get_setting("PluralBugLabel","bugs"));
			Response.Write("</a>");
			Response.End();
		}
	}


	// determine custom fields
	ds_custom_cols = Util.get_custom_columns(dbutil);


	if (!IsPostBack)
	{

		// add or edit?
		if (id == 0)
		{
			sub.Value = "Create";
			comment.Rows = 12;
		}
		else
		{
			sub.Value = "Update";
		}


		load_drop_downs();
		

		if (id == 0)
		{

			if (security.this_adds_not_allowed)
			{
				display_bug_not_found(id);
			}

			string initial_project = (string) Session["project"];

			sql = @"select isnull(us_forced_project,0) from users where us_id = $us";
			sql = sql.Replace("$us", Convert.ToString(security.this_usid));
			int current_forced_project = (int) dbutil.execute_scalar(sql);

			if (current_forced_project != 0)
			{
				initial_project = Convert.ToString(current_forced_project);
				set_controls_to_readonly();
			}

			string default_value;
			
			if (initial_project != null && initial_project != "0")
			{
				foreach (ListItem li in project.Items)
				{
					if (li.Value == initial_project)
					{
						li.Selected = true;
						current_project.InnerText = li.Text;
						break;
					}
				}
			}
			else
			{
				default_value = Util.get_setting("DefaultProject", "[no project]");
				foreach (ListItem li in project.Items)
				{
					if (li.Text == default_value)
					{
						li.Selected = true;
					}
					else
					{
						li.Selected = false;
					}
				}
			}

			default_value = Util.get_setting("DefaultCategory", "[no category]");
			foreach (ListItem li in category.Items)
			{
				if (li.Text == default_value)
				{
					li.Selected = true;
				}
				else
				{
					li.Selected = false;
				}
			}

			default_value = Util.get_setting("DefaultPriority", "[no priority]");
			foreach (ListItem li in priority.Items)
			{
				if (li.Text == default_value)
				{
					li.Selected = true;
				}
				else
				{
					li.Selected = false;
				}
			}

			foreach (ListItem li in assigned_to.Items)
			{
				if (li.Text == "[not assigned]")
				{
					li.Selected = true;
				}
				else
				{
					li.Selected = false;
				}
			}

			default_value = Util.get_setting("DefaultStatus", "new");
			foreach (ListItem li in status.Items)
			{
				if (li.Text == default_value)
				{
					li.Selected = true;
				}
				else
				{
					li.Selected = false;
				}
			}

			default_value = Util.get_setting("DefaultUserDefinedBugAttribute", "[none]");
			foreach (ListItem li in udf.Items)
			{
				if (li.Text == default_value)
				{
					li.Selected = true;
				}
				else
				{
					li.Selected = false;
				}
			}


			foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
			{
				hash_custom_cols.Add((string)drcc["name"], "");
				hash_prev_custom_cols.Add((string)drcc["name"], "");
			}


			if (current_forced_project != 0)
			{
				set_controls_to_readonly();
			}

		}
		else
		{

			// Get this entry's data from the db and fill in the form


			dr = Util.get_bug_datarow(id, ds_custom_cols, security, dbutil);

			if (dr == null)
			{
				display_bug_not_found(id);
			}

			foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
			{
				hash_custom_cols.Add((string)drcc["name"], dr[(string)drcc["name"]]);
				hash_prev_custom_cols.Add((string)drcc["name"], dr[(string)drcc["name"]]);
			}


			bugid.InnerText = Convert.ToString((int) dr["id"]);

			// Fill in this form
			short_desc.Value = (string) dr["short_desc"];
			title.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug"))
				+" ID " + Convert.ToString(dr["id"]) + " " + (string) dr["short_desc"];

			current_project.InnerText = (string) dr["current_project"];

			assigned_to_username.InnerText = Util.format_username(
				(string) dr["assigned_to_username"], 
				(string) dr["assigned_to_fullname"]);

			// reported by
			string s;
			s = "Reported by <span class=static>" + Util.format_username(
				(string) dr["reporter"], 
				(string) dr["reporter_fullname"]);
					
			s += "</span> on <span class=static>";
			s += Util.format_db_date (dr["reported_date"]);
			s += "</span>";
			
			reported_by.InnerHtml = s;

			foreach (ListItem li in project.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["project"])
				{
					li.Selected = true;
					break;
				}
			}

			foreach (ListItem li in category.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["category"])
				{
					li.Selected = true;
					break;
				}
			}

			foreach (ListItem li in priority.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["priority"])
				{
					li.Selected = true;
					break;
				}
			}

			foreach (ListItem li in assigned_to.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["assigned_to_user"])
				{
					li.Selected = true;
					break;
				}
			}

			foreach (ListItem li in status.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["status"])
				{
					li.Selected = true;
					break;
				}
			}

			foreach (ListItem li in udf.Items)
			{
				if (Convert.ToInt32(li.Value) == (int) dr["udf"])
				{
					li.Selected = true;
					break;
				}
			}


			// save for next bug
			Session["project"] = project.SelectedItem.Value;

			prev_short_desc.Value = (string) dr["short_desc"];
			prev_project.Value = Convert.ToString((int)dr["project"]);
			prev_category.Value = Convert.ToString((int)dr["category"]);
			prev_priority.Value = Convert.ToString((int)dr["priority"]);
			prev_assigned_to.Value = Convert.ToString((int)dr["assigned_to_user"]);
			prev_status.Value = Convert.ToString((int)dr["status"]);
			prev_udf.Value = Convert.ToString((int)dr["udf"]);
			prev_pcd1.Value = (string) dr["bg_project_custom_dropdown_value1"];
			prev_pcd2.Value = (string) dr["bg_project_custom_dropdown_value2"];
			prev_pcd3.Value = (string) dr["bg_project_custom_dropdown_value3"];

			string attachment_link = "<a href='javascript:add_attachment("
				+ Convert.ToString(id)
				+ ")'>add attachment</a>&nbsp;&nbsp;&nbsp;&nbsp;<span class=smallnote>(save changes first)</span>";
			attachment.InnerHtml = attachment_link;

			string send_email_link = "<a href='javascript:send_email("
				+ Convert.ToString(id)
				+ ")'>send email</a>&nbsp;&nbsp;&nbsp;&nbsp;<span class=smallnote>(save changes first)</span>";
			send_email.InnerHtml = send_email_link;

			string history_link = "<a target=_blank href=view_bug_history.aspx?id="
				+ Convert.ToString(id)
				+ ">view change history</a>";
			history.InnerHtml = history_link;

			string subscribers_link = "<a target=_blank href=view_subscribers.aspx?id="
				+ Convert.ToString(id)
				+ ">view subscribers</a>";
			subscribers.InnerHtml = subscribers_link;

			if (dr["last_updated_user"] != "")
			{
				last_changed.InnerHtml = "Last changed by <b>"
					+ Util.format_username(
						(string) dr["last_updated_user"],
						(string) dr["last_updated_fullname"])
					+ "</b> on <b>"
					+ Util.format_db_date(dr["last_updated_date"])
					+ "</b>";
			}

			format_subcribe_cancel_link();


			print.InnerHtml = "<a target=_blank href=print_bug.aspx?id="
				+ Convert.ToString(id)
				+ ">print</a>";


			// edit bug
			if (security.this_is_admin
			|| Util.get_setting("AllowBugMergingForNonAdmins","0") == "1")
			{
				string merge_bug_link = "<a href=merge_bug.aspx?id="
					+ Convert.ToString(id)
					+ ">merge</a>";

				merge_bug.InnerHtml = merge_bug_link;
			}

			// delete bug
			if (security.this_is_admin
			|| Util.get_setting("AllowBugDeletionForNonAdmins","0") == "1")
			{
				string delete_bug_link = "<a href=delete_bug.aspx?id="
					+ Convert.ToString(id)
					+ ">delete</a>";

				delete_bug.InnerHtml = delete_bug_link;
			}


			// custom bug link
			if (Util.get_setting("CustomBugLinkLabel","") != "")
			{
				string custom_bug_link = "<a href=" 
					+ Util.get_setting("CustomBugLinkUrl","")
					+ "?bugid="
					+ Convert.ToString(id)
					+ ">" 
					+ Util.get_setting("CustomBugLinkLabel","") 
					+ "</a>";

				custom.InnerHtml = custom_bug_link;
			}

			format_prev_next_bug();

			// look at permission level and react accordingly
			permission_level = (int)dr["pu_permission_level"];
			
			// reduce permissions for guest
			if (security.this_is_guest && permission_level == PERMISSION_ALL)
			{
				permission_level = PERMISSION_REPORTER;
			}

			if (permission_level == PERMISSION_NONE)
			{
				Response.Write ("<link rel=StyleSheet href=btnet.css type=text/css>");
				security.write_menu(Response, Util.get_setting("PluralBugLabel","bugs"));
				Response.Write("<p>&nbsp;</p><div class=align>");
				Response.Write("<div class=err>You are not allowed to view this bug</div>");
				Response.Write("<p><a href=bugs.aspx>View Bugs</a>");
				Response.End();
			}
			else if (permission_level == PERMISSION_READONLY
			|| permission_level == PERMISSION_REPORTER)
			{

				set_controls_to_readonly();

			}


		}

	}
	else // is PostBack
	{

		if (id != 0)
		{

			title.InnerText = Util.capitalize_first_letter(Util.get_setting("SingularBugLabel","bug"))
				+ " ID " + Convert.ToString(id) + " " + short_desc.Value;

			permission_level = fetch_permission_level();


			if (permission_level == PERMISSION_READONLY
			|| permission_level == PERMISSION_REPORTER)
			{
				set_controls_to_readonly();
			}

		}

		// Fetch the values of the custom columns from the Request
		// and stash them in a hash table.

		foreach (DataRow drcc in ds_custom_cols.Tables[0].Rows)
		{
			if (permission_level == PERMISSION_ALL || id == 0)
			{
				hash_custom_cols.Add(drcc["name"].ToString(), Request[(string)drcc["name"]]);
			}
			else
			{
				hash_custom_cols.Add(drcc["name"].ToString(), Request["prev_" + (string)drcc["name"]]);
			}
			hash_prev_custom_cols.Add(drcc["name"].ToString(), Request["prev_" + (string)drcc["name"]]);
		}
	}


	string current_assigned_to_selection;
	if (assigned_to.SelectedItem != null)
	{
		current_assigned_to_selection = assigned_to.SelectedItem.Value;
	}
	else
	{
		if (id != 0 && !IsPostBack)
		{
			current_assigned_to_selection =  Convert.ToString((int) dr["assigned_to_user"]);
		}
		else
		{
			current_assigned_to_selection = "0";
		}
	}

	// fill re-assign dropdown
	if (project.SelectedItem == null)
	{

		sql = @"select us_id, case when $fullnames then us_lastname + ', ' + us_firstname else us_username end us_username 
			from users
			where us_active = 1
			order by us_username";

	}
	else
	{
		// Only users explicitly allowed will be listed
		if (Util.get_setting("DefaultPermissionLevel","2") == "0")
		{
			sql = @"select us_id, case when $fullnames then us_lastname + ', ' + us_firstname else us_username end us_username 
				from users
				where us_active = 1
				and us_id in
					(select pu_user from project_user_xref
					where pu_project = $pr
					and pu_permission_level <> 0)
				order by us_username";
		}
		// Only users explictly DISallowed will be omitted
		else
		{
			sql = @"select us_id, case when $fullnames then us_lastname + ', ' + us_firstname else us_username end us_username 
				from users
				where us_active = 1
				and us_id not in
					(select pu_user from project_user_xref
					where pu_project = $pr
					and pu_permission_level = 0)
				order by us_username";
		}
	}

	if (Util.get_setting("UseFullNames","0") == "0")
	{
		// false condition
		sql = sql.Replace("$fullnames","0 = 1");
	}
	else
	{
		// true condition
		sql = sql.Replace("$fullnames","1 = 1");
	}

	sql = sql.Replace("$pr", project.SelectedItem.Value);

	assigned_to.DataSource =
		dbutil.get_dataview(sql);
	assigned_to.DataTextField = "us_username";
	assigned_to.DataValueField = "us_id";
	assigned_to.DataBind();
	assigned_to.Items.Insert(0, new ListItem("[not assigned]", "0"));


	foreach (ListItem li in assigned_to.Items)
	{
		if (li.Value == current_assigned_to_selection)
		{
			li.Selected = true;
			break;
		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -