ManageInfoCategory.aspx.cs
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:6k
源码类别:

OA系统

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. namespace OA
  13. {
  14. /// <summary>
  15. /// ManageInfoSection 的摘要说明。
  16. /// </summary>
  17. public class ManageInfoSection : System.Web.UI.Page
  18. {
  19. protected System.Data.SqlClient.SqlConnection MyConnection;
  20. protected System.Web.UI.WebControls.DataGrid MyDataGrid;
  21. protected System.Web.UI.WebControls.TextBox InfoCategoryName;
  22. protected System.Web.UI.HtmlControls.HtmlInputButton AddInfoCategory;
  23. protected System.Web.UI.WebControls.DropDownList DropDownList1;
  24. public string PID;
  25. private void Page_Load(object sender, System.EventArgs e)
  26. {
  27. CheckUser CHU = new CheckUser();
  28. CHU.UserName = User.Identity.Name;
  29. PID = CHU.UserID.ToString();
  30. if(CHU.Is_FileManager() == false)
  31. Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
  32. MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
  33. if(!IsPostBack)
  34. {
  35. BindGrid();
  36. Page.DataBind();
  37. }
  38. // 在此处放置用户代码以初始化页面
  39. }
  40. #region Web 窗体设计器生成的代码
  41. override protected void OnInit(EventArgs e)
  42. {
  43. //
  44. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  45. //
  46. InitializeComponent();
  47. base.OnInit(e);
  48. }
  49. /// <summary>
  50. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  51. /// 此方法的内容。
  52. /// </summary>
  53. private void InitializeComponent()
  54. {    
  55. this.AddInfoCategory.ServerClick += new System.EventHandler(this.AddInfoCategory_ServerClick);
  56. this.Load += new System.EventHandler(this.Page_Load);
  57. }
  58. #endregion
  59. public void MyDataGrid_Edit(Object sender, DataGridCommandEventArgs E)
  60. {
  61. MyDataGrid.EditItemIndex = (int)E.Item.ItemIndex;
  62. BindGrid();
  63. }
  64. public void MyDataGrid_Cancel(Object sender, DataGridCommandEventArgs E)
  65. {
  66. MyDataGrid.EditItemIndex = -1;
  67. BindGrid();
  68. }
  69. public void MyDataGrid_Update(Object sender, DataGridCommandEventArgs E)
  70. {
  71. if(((System.Web.UI.WebControls.TextBox)E.Item.Cells[2].Controls[0]).Text.Trim()!="")
  72. {
  73. SqlCommand MyCommand = new SqlCommand("UpdateInfoCategory", MyConnection);
  74. MyCommand.CommandType = CommandType.StoredProcedure;
  75. MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID", SqlDbType.Int, 4));
  76. MyCommand.Parameters["@InfoCategoryID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
  77. MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryName", SqlDbType.NVarChar, 50));
  78. MyCommand.Parameters["@InfoCategoryName"].Value = ((System.Web.UI.WebControls.TextBox)E.Item.Cells[2].Controls[0]).Text;
  79. MyCommand.Parameters.Add(new SqlParameter("@OrganizationID", SqlDbType.Int, 4));
  80. MyCommand.Parameters["@OrganizationID"].Value = ((DropDownList)E.Item.FindControl("edit_OR")).SelectedValue.ToString();
  81. MyCommand.Connection.Open();
  82. try 
  83. {
  84. MyCommand.ExecuteNonQuery();
  85. MyDataGrid.EditItemIndex = -1;
  86. }
  87. catch
  88. {
  89. }
  90. MyCommand.Connection.Close();
  91. BindGrid();
  92. }
  93. }
  94. public void BindGrid() 
  95. {
  96. SqlDataAdapter MyCommand2 = new SqlDataAdapter("InfoCategorySelect",MyConnection);
  97. MyCommand2.SelectCommand.CommandType = CommandType.StoredProcedure;
  98. DataSet ds = new DataSet();
  99. MyCommand2.Fill(ds, "InfoCategory");
  100. MyDataGrid.DataSource=ds.Tables["InfoCategory"].DefaultView;
  101. MyDataGrid.DataBind();
  102. }
  103. public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs E) 
  104. {
  105. SqlCommand MyCommand = new SqlCommand("DeleteInfoCategory",MyConnection);
  106. MyCommand.CommandType = CommandType.StoredProcedure;
  107. MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID", SqlDbType.Int, 4));
  108. MyCommand.Parameters["@InfoCategoryID"].Value = MyDataGrid.DataKeys[(int)E.Item.ItemIndex];
  109. if(MyConnection.State.ToString()=="Closed")
  110. MyConnection.Open(); 
  111. try
  112. {
  113. MyCommand.ExecuteNonQuery();
  114. }
  115. catch
  116. {
  117. RegisterStartupScript("alert","<script>alert('出现错误:未能删除记录!')</" + "script>");
  118. }
  119. MyConnection.Close();
  120. BindGrid();
  121. }
  122. public void MyDataGrid_ItemDataBound(Object sender, DataGridItemEventArgs e) 
  123. {
  124. if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
  125. {
  126. LinkButton myDeleteButton;
  127. myDeleteButton = (LinkButton) e.Item.Cells[1].Controls[0];
  128. myDeleteButton.Attributes.Add("onclick", @"return confirm('你确认要删除此信息吗?');");
  129. }
  130. if(e.Item.ItemType == ListItemType.EditItem)
  131. {
  132. DropDownList DropList;
  133. DropList= (DropDownList)e.Item.FindControl("Edit_OR");
  134. String myRole = DataBinder.Eval(e.Item.DataItem, "Expr1").ToString();
  135. DropList.Items.FindByText(myRole).Selected = true;
  136. }
  137. }
  138. private void AddInfoCategory_ServerClick(object sender, System.EventArgs e)
  139. {
  140. Page.Validate();
  141. if ( !Page.IsValid )
  142. {
  143. return;
  144. }
  145. if(InfoCategoryName.Text.Trim()!="")
  146. {
  147. SqlCommand MyCommand = new SqlCommand("InsertInfoCategory", MyConnection);
  148. MyCommand.CommandType = CommandType.StoredProcedure;
  149. MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryName", SqlDbType.NVarChar, 50));
  150. MyCommand.Parameters["@InfoCategoryName"].Value = InfoCategoryName.Text;
  151. MyCommand.Parameters.Add(new SqlParameter("@OrganizationID", SqlDbType.Int, 4));
  152. MyCommand.Parameters["@OrganizationID"].Value = DropDownList1.SelectedValue.ToString();
  153. MyCommand.Connection.Open();
  154. try 
  155. {
  156. MyCommand.ExecuteNonQuery();
  157. }
  158. catch 
  159. {
  160. }
  161. MyCommand.Connection.Close();
  162. InfoCategoryName.Text = "";
  163. BindGrid();
  164. }
  165. else
  166. RegisterStartupScript("alert","<script>alert('公司名称不能为空!')</" + "script>");
  167. }
  168. }
  169. }