温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:BugNet0.7.881.0汉化免安装版源码
当前文件路径:BugNet/BugNET_WAP/Bugs/AddBug.aspx.cs

1using System; 2
using System.Collections; 3
using System.Configuration; 4
using System.ComponentModel; 5
using System.Data; 6
using System.Data.Common; 7
using System.Drawing; 8
using System.Web; 9
using System.Web.SessionState; 10
using System.Web.UI; 11
using System.Web.UI.WebControls; 12
using System.Web.UI.HtmlControls; 13
using System.IO; 14
using BugNET.BusinessLogicLayer; 15
using FredCK.FCKeditorV2; 16
using BugNET.UserControls; 17
18
namespace BugNET 19
...{ 20
/**//// <summary> 21
/// Add Issue 22
/// </summary> 23
public partial class AddBug : BugNET.UserInterfaceLayer.BasePage 24
...{ 25
Private Methods#region Private Methods 26
/**//// <summary> 27
/// Handles the Load event of the Page control. 28
/// </summary> 29
/// <param name="sender">The source of the event.</param> 30
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 31
protected void Page_Load(object sender, System.EventArgs e) 32
...{ 33
if (!Page.IsPostBack) 34
...{ 35
//get project id 36
if (Request.QueryString["pid"] != null) 37
ProjectId = Convert.ToInt32(Request.Params["pid"]); 38
39
BindData(); 40
} 41
// The ExpandIssuePaths method is called to handle 42
// the SiteMapResolve event. 43
SiteMap.SiteMapResolve += 44
new SiteMapResolveEventHandler(this.ExpandProjectPaths); 45
} 46
47
/**//// <summary> 48
/// Handles the Unload event of the Page control. 49
/// </summary> 50
/// <param name="sender">The source of the event.</param> 51
/// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> 52
protected void Page_Unload(object sender, System.EventArgs e) 53
...{ 54
//remove the event handler 55
SiteMap.SiteMapResolve -= 56
new SiteMapResolveEventHandler(this.ExpandProjectPaths); 57
} 58
59
/**//// <summary> 60
/// Expands the project paths. 61
/// </summary> 62
/// <param name="sender">The sender.</param> 63
/// <param name="e">The <see cref="System.Web.SiteMapResolveEventArgs"/> instance containing the event data.</param> 64
/// <returns></returns> 65
private SiteMapNode ExpandProjectPaths(Object sender, SiteMapResolveEventArgs e) 66
...{ 67
SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true); 68
SiteMapNode tempNode = currentNode; 69
70
// The current node, and its parents, can be modified to include 71
// dynamic querystring information relevant to the currently 72
// executing request. 73
if (ProjectId != 0) 74
...{ 75
tempNode.Url = tempNode.Url + "?pid=" + ProjectId.ToString(); 76
} 77
78
if ((null != (tempNode = tempNode.ParentNode)) && 79
(ProjectId != 0)) 80
...{ 81
tempNode.Url = tempNode.Url + "?pid=" + ProjectId.ToString(); 82
} 83
84
return currentNode; 85
} 86
87
/**//// <summary> 88
/// Binds the data. 89
/// </summary> 90
private void BindData() 91
...{ 92
//Get Recently Added Bugs 93
rptRecentlyAdded.DataSource = Bug.GetRecentlyAddedBugsByProjectId(ProjectId); 94
rptRecentlyAdded.DataBind(); 95
96
//Get Project selected 97
Project p = Project.GetProjectById(ProjectId); 98
litProject.Text = p.Name; 99
litProjectCode.Text = p.Code; 100
p = null; 101
102
//Get Components 103
ComponentTree objComps = new ComponentTree(); 104
Comps.DisplayDefault = true; 105
Comps.DataSource = objComps.GetComponentTreeByProjectId(ProjectId); 106
Comps.DataBind(); 107
108
//Get Version 109
Version.DataSource= BugNET.BusinessLogicLayer.Version.GetVersionByProjectId(ProjectId); 110
Version.DataBind(); 111
112
//Get Type 113
Type.DataSource = BugNET.BusinessLogicLayer.Type.GetAllTypes(); 114
Type.DataBind(); 115
116
//Get Priority 117
Priority.DataSource = BugNET.BusinessLogicLayer.Priority.GetAllPriorities(); 118
Priority.DataBind(); 119
120
//Get Users 121
AssignTo.DataSource = Project.GetProjectMembers(ProjectId); 122
AssignTo.DataBind(); 123
124
Milestone.DataSource = BugNET.BusinessLogicLayer.Version.GetVersionByProjectId(ProjectId); 125
Milestone.DataBind(); 126
} 127
128
/**//// <summary> 129
/// Submit button 130
/// </summary> 131
/// <param name="sender"></param> 132
/// <param name="e"></param> 133
protected void cmdSubmit_Click(object sender, System.EventArgs e) 134
...{ 135
if (Page.IsValid & FCKDescription.Value.Trim().Length > 0) 136
...{ 137
string AssignedTo = string.Empty; 138
if(AssignTo.SelectedValue.Length > 0) 139
AssignedTo = AssignTo.SelectedValue; 140
double estimation; 141
double.TryParse(txtEstimation.Text.Trim(), out estimation); 142
Bug newBug = new Bug(ProjectId, 143
txtSummary.Text.Trim(), FCKDescription.Value.Trim(), 144
Comps.SelectedValue, Version.SelectedValue, 145
Priority.SelectedValue, Globals.NewBugStatusID, 146
Type.SelectedValue,Milestone.SelectedValue, 147
AssignedTo, User.Identity.Name, 148
estimation 149
); 150
151
if(newBug.Save()) 152
...{ 153
//If there is an attached file present then add it to the database 154
//and copy it to the directory specified in the web.config file 155
if(chkAddAttachment.Checked && fuAttachment.HasFile) 156
...{ 157
string ProjectPath = Project.GetProjectById(ProjectId).UploadPath; 158
string UploadedFileName = String.Format("{0:0000}_", newBug.Id) + System.IO.Path.GetFileName(fuAttachment.FileName); 159
string UploadedFilePath = Server.MapPath("~\\Uploads\\" + ProjectPath) + "\\" + UploadedFileName; 160
161
Attachment att = new Attachment(newBug.Id,UploadedFileName, 162
txtAttachmentDesc.Text, Convert.ToInt32(fuAttachment.FileContent.Length), fuAttachment.PostedFile.ContentType, User.Identity.Name); 163
164
//If save successful upload file 165
if(att.Save()) 166
...{ 167
try 168
...{ 169
fuAttachment.PostedFile.SaveAs(UploadedFilePath); 170
} 171
catch(DirectoryNotFoundException) 172
...{ 173
throw (new ApplicationException(string.Format("没有找到类别:{0}",ProjectPath))); 174
} 175
catch(System.Security.SecurityException) 176
...{ 177
throw (new ApplicationException("你没有上传到该服务器的权限")); 178
} 179
} 180
181
} 182
Response.Redirect(string.Format("BugDetail.aspx?bid={0}", newBug.Id)); 183
184
} 185
186
187
} 188
} 189
190
/**//// <summary> 191
/// Handles the ItemDataBound event of the rptRecentlyAdded control. 192
/// </summary> 193
/// <param name="sender">The source of the event.</param> 194
/// <param name="e">The <see cref="T:System.Web.UI.WebControls.RepeaterItemEventArgs"/> instance containing the event data.</param> 195
private void rptRecentlyAdded_ItemDataBound(object sender, RepeaterItemEventArgs e) 196
...{ 197
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 198
...{ 199
Bug b = (Bug)e.Item.DataItem; 200
((HyperLink)e.Item.FindControl("lnkBug")).Text = (b.Summary.Length >= 30) ? b.Summary.Substring(0,30) + "..." : b.Summary ; 201
((HyperLink)e.Item.FindControl("lnkBug")).NavigateUrl = "BugDetail.aspx?pid=" + ProjectId.ToString() + "&bid=" + b.Id.ToString(); 202
203
} 204
} 205
206
/**//// <summary> 207
/// Perform any initialization of the page 208
/// </summary> 209
/// <param name="sender"></param> 210
/// <param name="e"></param> 211
private void AddBug_Init(object sender, EventArgs e) 212
...{ 213
//get project id 214
if (Request.QueryString["pid"] != null) 215
ProjectId = Convert.ToInt32(Request.Params["pid"]); 216
217
//security check: add issue 218
if(!UserIT.HasPermission(ProjectId,Globals.Permissions.ADD_ISSUE.ToString())) 219
Response.Redirect("~/AccessDenied.aspx"); 220
221
//security check: assign issue 222
if(!UserIT.HasPermission(ProjectId,Globals.Permissions.ASSIGN_ISSUE.ToString())) 223
AssignTo.Visible=false; 224
225
//security check: add attachment 226
if(!UserIT.HasPermission(ProjectId,Globals.Permissions.ADD_ATTACHMENT.ToString())) 227
AddAttachment.Visible=false; 228
} 229
230
/**//// <summary> 231
/// Handles the CheckedChanged event of the chkAddAttachment control. 232
/// </summary> 233
/// <param name="sender">The source of the event.</param> 234
/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> 235
protected void chkAddAttachment_CheckedChanged(object sender, EventArgs e) 236
...{ 237
Attachment.Visible = !Attachment.Visible; 238
} 239
#endregion 240
241
Web Form Designer generated code#region Web Form Designer generated code 242
/**//// <summary> 243
/// Overrides the default OnInit to provide a security check for pages 244
/// </summary> 245
/// <param name="e"></param> 246
override protected void OnInit(EventArgs e) 247
...{ 248
// 249
// CODEGEN: This call is required by the ASP.NET Web Form Designer. 250
// 251
InitializeComponent(); 252
base.OnInit(e); 253
} 254
255
/**//// <summary> 256
/// Required method for Designer support - do not modify 257
/// the contents of this method with the code editor. 258
/// </summary> 259
private void InitializeComponent() 260
...{ 261
this.rptRecentlyAdded.ItemDataBound +=new RepeaterItemEventHandler(rptRecentlyAdded_ItemDataBound); 262
this.Init+=new EventHandler(AddBug_Init); 263
264
} 265
#endregion 266
} 267
} 268





}