Reports.aspx.cs
上传用户:autodoor
上传日期:2022-08-04
资源大小:9973k
文件大小:5k
源码类别:

.net编程

开发平台:

Others

  1. using System;
  2. using System.Data;
  3. using System.Web;
  4. using System.Text;
  5. using System.Web.UI.WebControls;
  6. using qminoa.BLL.PM;
  7. using qminoa.DA;
  8. namespace qminoa.Webs.PM
  9. {
  10. public class Reports : qminoa.Webs.PageBase
  11. {
  12. protected System.Web.UI.WebControls.ListBox ProjectList;
  13. protected System.Web.UI.WebControls.ListBox UserList;
  14. protected System.Web.UI.WebControls.Button GenProjectRpt;
  15. protected System.Web.UI.WebControls.Button GenResourceRpt;
  16. protected System.Web.UI.WebControls.TextBox StartDate;
  17. protected System.Web.UI.WebControls.TextBox EndDate;
  18. protected System.Web.UI.WebControls.RequiredFieldValidator ProjectListRequiredFieldValidator;
  19. protected System.Web.UI.WebControls.RequiredFieldValidator UserListRequiredFieldValidator;
  20. protected System.Web.UI.WebControls.DropDownList BranchDropList;
  21. protected System.Web.UI.WebControls.DropDownList DepartmentDropList;
  22. public const string UserRoleAdministrator = "1";
  23. public const string UserRoleProjectManager = "2";
  24. private PMUser  _user;
  25. private void Page_Load(object sender, System.EventArgs e)
  26. {
  27. this.PageBegin("项目统计报告",true);
  28. _user = new PMUser(Convert.ToInt16(this.Empid));
  29. if(_user.Role != UserRoleAdministrator && _user.Role != UserRoleProjectManager)
  30. {
  31. Response.Redirect(Application["vRoot"]+"/login.aspx");  
  32. }
  33. DateTime startingDate = DateTime.Today;
  34. DateTime endingDate = DateTime.Today;
  35. if (!this.IsPostBack)
  36. {   
  37. ProjectList.DataSource = Project.GetProjects(_user.UserID, _user.Role);
  38. ProjectList.DataTextField = "Name";
  39. ProjectList.DataValueField = "ProjectID";
  40. ProjectList.DataBind();
  41. AdminDB admin = new AdminDB();
  42. BranchDropList.DataSource=admin.GetAllBranch();
  43. BranchDropList.DataBind();
  44. BranchDropList.Items[0].Selected=true;
  45. DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
  46. DepartmentDropList.DataBind();
  47. DepartmentDropList.Items[0].Selected=true;
  48. UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
  49. UserList.DataTextField = "UserName";
  50. UserList.DataValueField = "UserID";
  51. UserList.DataBind();
  52. BLL.PM.TimeEntry.FillCorrectStartEndDates(DateTime.Today, ref startingDate, ref endingDate);
  53. StartDate.Text = startingDate.ToShortDateString();
  54. EndDate.Text = endingDate.ToShortDateString();
  55. }
  56. }
  57. private string BuildValueList(ListItemCollection items)
  58. {
  59. StringBuilder idList = new StringBuilder();
  60. foreach (ListItem item in items)
  61. {
  62. if (item.Selected)
  63. {
  64. if (idList.ToString() != string.Empty)
  65. idList.Append(",");
  66. idList.Append(item.Value.ToString());
  67. }
  68. }
  69. return idList.ToString();
  70. }
  71. #region Web Form Designer generated code
  72. override protected void OnInit(EventArgs e)
  73. {
  74. //
  75. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  76. //
  77. InitializeComponent();
  78. base.OnInit(e);
  79. }
  80. /// <summary>
  81. /// Required method for Designer support - do not modify
  82. /// the contents of this method with the code editor.
  83. /// </summary>
  84. private void InitializeComponent()
  85. {    
  86. this.GenProjectRpt.Click += new System.EventHandler(this.GenProjectRpt_Click);
  87. this.BranchDropList.SelectedIndexChanged += new System.EventHandler(this.BranchDropList_SelectedIndexChanged);
  88. this.DepartmentDropList.SelectedIndexChanged += new System.EventHandler(this.DepartmentDropList_SelectedIndexChanged);
  89. this.GenResourceRpt.Click += new System.EventHandler(this.GenResourceRpt_Click);
  90. this.Load += new System.EventHandler(this.Page_Load);
  91. }
  92. #endregion
  93. private void GenProjectRpt_Click(object sender, System.EventArgs e)
  94. {
  95. ProjectListRequiredFieldValidator.Validate();
  96. if (ProjectListRequiredFieldValidator.IsValid)
  97. Server.Transfer("ProjectReport.aspx?IDs=" + BuildValueList(ProjectList.Items));
  98. }
  99. private void GenResourceRpt_Click(object sender, System.EventArgs e)
  100. {
  101. UserListRequiredFieldValidator.Validate();
  102. if (UserListRequiredFieldValidator.IsValid)
  103. Response.Redirect("ResourceReport.aspx?IDs=" + BuildValueList(UserList.Items) + 
  104. "&Start=" + StartDate.Text + "&End=" + EndDate.Text, false);
  105. }
  106. private void BranchDropList_SelectedIndexChanged(object sender, System.EventArgs e)
  107. {
  108. AdminDB admin = new AdminDB();
  109. DepartmentDropList.DataSource=admin.GetDepByBranch(Int32.Parse(BranchDropList.SelectedItem.Value));
  110. DepartmentDropList.DataBind();
  111. if(DepartmentDropList.Items.Count !=0)
  112. {
  113. UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
  114. UserList.DataTextField = "UserName";
  115. UserList.DataValueField = "UserID";
  116. UserList.DataBind();
  117. }
  118. else
  119. {
  120. UserList.Items.Clear();
  121. }
  122. }
  123. private void DepartmentDropList_SelectedIndexChanged(object sender, System.EventArgs e)
  124. {
  125. UserList.DataSource = PMUser.GetUsers(_user.UserID, _user.Role,Int32.Parse(DepartmentDropList.SelectedItem.Value));
  126. UserList.DataTextField = "UserName";
  127. UserList.DataValueField = "UserID";
  128. UserList.DataBind();
  129. }
  130. }
  131. }