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

OA系统

开发平台:

C#

  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.SqlClient;
  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. namespace OA
  14. {
  15. /// <summary>
  16. /// NewInfo 的摘要说明。
  17. /// </summary>
  18. public class NewInfo : System.Web.UI.Page
  19. {
  20. protected System.Data.SqlClient.SqlConnection MyConnection;
  21. protected System.Web.UI.WebControls.DropDownList DropDownList1;
  22. protected System.Web.UI.WebControls.TextBox Title;
  23. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  24. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
  25. protected System.Web.UI.HtmlControls.HtmlInputButton Send;
  26. protected System.Web.UI.WebControls.TextBox Writer;
  27. protected FreeTextBoxControls.FreeTextBox FreeTextBox1;
  28. protected System.Data.DataSet ds;
  29. public string PID;
  30. private void Page_Load(object sender, System.EventArgs e)
  31. {
  32. CheckUser CHU = new CheckUser();
  33. CHU.UserName = User.Identity.Name;
  34. PID = CHU.UserID.ToString();
  35. if(CHU.Is_FileManager() == false)
  36. Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
  37. MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
  38. if(!IsPostBack)
  39. {
  40. if(MyConnection.State.ToString()=="Closed")
  41. MyConnection.Open();  
  42. ds= new DataSet();
  43. SqlDataAdapter MyCommand = new SqlDataAdapter("SelectInfoCategories",MyConnection);
  44. MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
  45. MyCommand.Fill(ds,"InfoCategories");
  46. DropDownList1.DataSource=ds.Tables["InfoCategories"].DefaultView;
  47. DropDownList1.DataTextField="InfoCategoryName";
  48. DropDownList1.DataValueField="InfoCategoryID";
  49. DropDownList1.DataBind();
  50. MyConnection.Close();  
  51. // 在此处放置用户代码以初始化页面
  52. }
  53. }
  54. #region Web 窗体设计器生成的代码
  55. override protected void OnInit(EventArgs e)
  56. {
  57. //
  58. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  59. //
  60. InitializeComponent();
  61. base.OnInit(e);
  62. }
  63. /// <summary>
  64. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  65. /// 此方法的内容。
  66. /// </summary>
  67. private void InitializeComponent()
  68. {    
  69. this.Send.ServerClick += new System.EventHandler(this.Send_ServerClick);
  70. this.Load += new System.EventHandler(this.Page_Load);
  71. }
  72. #endregion
  73. private void Send_ServerClick(object sender, System.EventArgs e)
  74. {
  75. SqlCommand MyCommand=new SqlCommand("InsertInfo",MyConnection);
  76. MyCommand.CommandType = CommandType.StoredProcedure;
  77. MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 120));
  78. MyCommand.Parameters["@Title"].Value = Title.Text;
  79. int FileLength = ConvertToByte(FreeTextBox1.Text).Length;
  80. MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image, FileLength));
  81. MyCommand.Parameters["@Contents"].Value = ConvertToByte(FreeTextBox1.Text);
  82. MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
  83. MyCommand.Parameters["@PersonID"].Value = PID; 
  84. MyCommand.Parameters.Add(new SqlParameter("@Writer", SqlDbType.NVarChar, 50));
  85. MyCommand.Parameters["@Writer"].Value = Writer.Text;   
  86. MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID",SqlDbType.Int, 4));
  87. MyCommand.Parameters["@InfoCategoryID"].Value = DropDownList1.SelectedValue; 
  88. if(MyConnection.State.ToString()=="Closed")
  89. MyConnection.Open();  
  90. MyCommand.ExecuteNonQuery();
  91. MyConnection.Close(); 
  92. RegisterStartupScript("alert","<script>alert('信息编制成功!')</script>");
  93. Writer.Text="";
  94. Title.Text="";
  95.             FreeTextBox1.Text="";
  96. }
  97. public static byte[] ConvertToByte(string theString) 
  98. byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);
  99. return byteStream; 
  100. }
  101. }