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

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.IO;
  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. /// NewFile 的摘要说明。
  17. /// </summary>
  18. public class NewFile : System.Web.UI.Page
  19. {
  20. protected System.Data.SqlClient.SqlConnection MyConnection;
  21. protected System.Web.UI.WebControls.TextBox Accepter;
  22. protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
  23. protected System.Web.UI.WebControls.DropDownList DropDownList1;
  24. protected System.Web.UI.WebControls.DropDownList DropDownList2;
  25. protected System.Web.UI.HtmlControls.HtmlInputFile UpFile;
  26. protected System.Web.UI.HtmlControls.HtmlInputButton Send;
  27. protected System.Web.UI.WebControls.TextBox Title;
  28. protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;
  29. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
  30. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  31. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
  32. protected System.Data.DataSet ds;
  33. protected System.Web.UI.HtmlControls.HtmlInputHidden AccepterID;
  34. public string PID;
  35. private void Page_Load(object sender, System.EventArgs e)
  36. {
  37. CheckUser CHU = new CheckUser();
  38. CHU.UserName = User.Identity.Name;
  39. PID = CHU.UserID.ToString();
  40. if(CHU.Is_FileManager() == false)
  41. Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
  42. MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
  43. if(!IsPostBack)
  44. {
  45. if(MyConnection.State.ToString()=="Closed")
  46. MyConnection.Open();  
  47. ds= new DataSet();
  48. SqlDataAdapter MyCommand = new SqlDataAdapter("SystemSelect",MyConnection);
  49. MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
  50. MyCommand.Fill(ds,"System");
  51. DropDownList1.DataSource=ds.Tables["System"].DefaultView;
  52. DropDownList1.DataTextField="SystemName";
  53. DropDownList1.DataValueField="SystemID";
  54. DropDownList1.DataBind();
  55. SqlDataAdapter MyCommand1 = new SqlDataAdapter("SelectOrganization",MyConnection);
  56. MyCommand1.SelectCommand.CommandType = CommandType.StoredProcedure;
  57. MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@SystemID", SqlDbType.NVarChar, 50));
  58. MyCommand1.SelectCommand.Parameters["@SystemID"].Value = "%1%";
  59. MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@TypeID", SqlDbType.Int, 4));
  60. MyCommand1.SelectCommand.Parameters["@TypeID"].Value = 2;
  61. MyCommand1.Fill(ds,"Organization0");
  62. DropDownList2.DataSource=ds.Tables["Organization0"].DefaultView;
  63. DropDownList2.DataTextField="OrganizationName";
  64. DropDownList2.DataValueField="OrganizationID";
  65. DropDownList2.DataBind();
  66. }
  67. // 在此处放置用户代码以初始化页面
  68. MyConnection.Close();  
  69. }
  70. #region Web 窗体设计器生成的代码
  71. override protected void OnInit(EventArgs e)
  72. {
  73. //
  74. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  75. //
  76. InitializeComponent();
  77. base.OnInit(e);
  78. }
  79. /// <summary>
  80. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  81. /// 此方法的内容。
  82. /// </summary>
  83. private void InitializeComponent()
  84. {    
  85. this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
  86. this.Send.ServerClick += new System.EventHandler(this.Send_ServerClick);
  87. this.Load += new System.EventHandler(this.Page_Load);
  88. }
  89. #endregion
  90. private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
  91. {
  92. SqlDataAdapter MyCommand1 = new SqlDataAdapter("SelectOrganization",MyConnection);
  93. MyCommand1.SelectCommand.CommandType = CommandType.StoredProcedure;
  94. MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@SystemID", SqlDbType.NVarChar, 50));
  95. MyCommand1.SelectCommand.Parameters["@SystemID"].Value = "%"+DropDownList1.SelectedValue.ToString()+"%";
  96. MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@TypeID", SqlDbType.Int, 4));
  97. MyCommand1.SelectCommand.Parameters["@TypeID"].Value = 2;
  98. DataSet ds1 = new DataSet();
  99. MyCommand1.Fill(ds1,"Organization");
  100. DropDownList2.DataSource=ds1.Tables["Organization"].DefaultView;
  101. DropDownList2.DataTextField="OrganizationName";
  102. DropDownList2.DataValueField="OrganizationID";
  103. DropDownList2.DataBind();
  104. }
  105. private void Send_ServerClick(object sender, System.EventArgs e)
  106. {
  107. System.Web.HttpPostedFile UpFile = UP_FILE.PostedFile;
  108. int FileLength = UpFile.ContentLength;
  109. if (FileLength == 0) 
  110. {
  111. RegisterStartupScript("alert","<script>alert('你未选择上传文件!')</script>");
  112. else 
  113. {
  114. if(AccepterID.Value.Trim()!="")
  115. {
  116. System.Byte[] FileByteArray = new System.Byte[FileLength];
  117. System.IO.Stream StreamObject = UpFile.InputStream;
  118. StreamObject.Read(FileByteArray,0,FileLength);
  119. SqlCommand MyCommand=new SqlCommand("InsertFile",MyConnection);
  120. MyCommand.CommandType = CommandType.StoredProcedure;
  121. MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 500));
  122. MyCommand.Parameters["@Title"].Value = Title.Text;
  123. MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Binary, FileLength));
  124. MyCommand.Parameters["@Contents"].Value = FileByteArray;
  125. MyCommand.Parameters.Add("@ContentType", SqlDbType.NVarChar,50).Value = UpFile.ContentType;
  126. MyCommand.Parameters.Add("@ByteSize", SqlDbType.NVarChar,50).Value = UpFile.ContentLength;
  127. MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
  128. MyCommand.Parameters["@PersonID"].Value = PID; 
  129. MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 500));
  130. MyCommand.Parameters["@AccepterID"].Value = AccepterID.Value.Trim();   
  131. MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Int, 4));
  132. MyCommand.Parameters["@State"].Value = "0";
  133. MyCommand.Parameters.Add(new SqlParameter("@SystemID",SqlDbType.Int, 4));
  134. MyCommand.Parameters["@SystemID"].Value = DropDownList1.SelectedValue; 
  135. MyCommand.Parameters.Add(new SqlParameter("@OrganizationID",SqlDbType.Int, 4));
  136. MyCommand.Parameters["@OrganizationID"].Value = DropDownList2.SelectedValue; 
  137. MyCommand.Parameters.Add("@FileKind", SqlDbType.NVarChar,50).Value = RadioButtonList1.SelectedItem.Text;
  138. if(MyConnection.State.ToString()=="Closed")
  139. MyConnection.Open();
  140. try
  141. {
  142. MyCommand.ExecuteNonQuery();
  143. RegisterStartupScript("alert","<script>alert('文件发送成功!')</script>");
  144. }
  145. catch
  146. {
  147. }
  148. MyConnection.Close(); 
  149. Accepter.Text="";
  150. Title.Text="";
  151.                         AccepterID.Value = "";
  152. }
  153. }
  154. }
  155. public static string[] RemoveDup(string[] myData)
  156. {
  157. if (myData.Length > 0)
  158. {
  159. Array.Sort(myData);
  160. int size = 1;
  161. for (int i=1; i<myData.Length; i++)
  162. if (myData[i] != myData[i-1])
  163. size++;
  164. string[] myTempData = new string[size];
  165. int j=0;
  166. myTempData[j++] = myData[0];
  167. for (int i=1; i<myData.Length; i++)
  168. if (myData[i] != myData[i-1])
  169. myTempData[j++] = myData[i];
  170. return myTempData;
  171. }
  172. return myData; 
  173. }
  174. }
  175. }