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

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. /// NewDocument 的摘要说明。
  16. /// </summary>
  17. public class NewDocument : System.Web.UI.Page
  18. {
  19. protected System.Data.SqlClient.SqlConnection MyConnection;
  20. protected System.Web.UI.HtmlControls.HtmlForm Form1;
  21. protected System.Web.UI.WebControls.TextBox Accepter;
  22. protected System.Web.UI.WebControls.TextBox Contents;
  23. protected FreeTextBoxControls.FreeTextBox FreeTextBox1;
  24. protected System.Web.UI.WebControls.TextBox Title;
  25. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
  26. protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
  27. protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
  28. protected System.Web.UI.HtmlControls.HtmlInputButton Send;
  29. protected System.Web.UI.HtmlControls.HtmlInputHidden AccepterID;
  30. protected System.Data.SqlClient.SqlCommand MyCommand;
  31. private void Page_Load(object sender, System.EventArgs e)
  32. {
  33. // 在此处放置用户代码以初始化页面
  34. }
  35. #region Web 窗体设计器生成的代码
  36. override protected void OnInit(EventArgs e)
  37. {
  38. //
  39. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  40. //
  41. InitializeComponent();
  42. base.OnInit(e);
  43. }
  44. /// <summary>
  45. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  46. /// 此方法的内容。
  47. /// </summary>
  48. private void InitializeComponent()
  49. {    
  50. this.Send.ServerClick += new System.EventHandler(this.Send_ServerClick);
  51. this.Load += new System.EventHandler(this.Page_Load);
  52. }
  53. #endregion
  54. private void Send_ServerClick(object sender, System.EventArgs e)
  55. {
  56. if(FreeTextBox1.Text.Trim()=="")
  57. RegisterStartupScript("alert","<script>alert('内容不能为空')</script>");
  58. else
  59. {
  60. MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
  61. SqlCommand MyCommand0 = new SqlCommand("PersonID",MyConnection);
  62. MyCommand0.CommandType = CommandType.StoredProcedure;
  63. MyCommand0.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
  64. MyCommand0.Parameters["@Name"].Value = User.Identity.Name;
  65. MyConnection.Open();
  66. SqlDataReader myReader =  MyCommand0.ExecuteReader(CommandBehavior.CloseConnection);
  67. string PID="";
  68. try
  69. {
  70. while(myReader.Read()) 
  71. {
  72. PID = myReader.GetInt32(0).ToString();
  73. }
  74. myReader.Close();
  75. }
  76. finally 
  77. {
  78. }
  79. if(RadioButtonList1.SelectedValue=="0")
  80. {
  81. string [] str = AccepterID.Value.Replace("(","").Replace(")","").Split(new Char [] {','});
  82. for(int i = 0; i<str.Length; i++)
  83. {
  84. if(str[i].Trim()!="")
  85. {
  86. MyCommand=new SqlCommand("InsertDocument",MyConnection);
  87. MyCommand.CommandType = CommandType.StoredProcedure;
  88. MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 50));
  89. MyCommand.Parameters["@Title"].Value = Title.Text;
  90. int FileLength = ConvertToByte(FreeTextBox1.Text).Length;
  91. MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image, FileLength));
  92. MyCommand.Parameters["@Contents"].Value = ConvertToByte(FreeTextBox1.Text);
  93. MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
  94. MyCommand.Parameters["@PersonID"].Value = PID; 
  95. MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 500));
  96. MyCommand.Parameters["@AccepterID"].Value = str[i].Trim();   
  97. MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Char,10));
  98. MyCommand.Parameters["@State"].Value = "0";
  99. MyCommand.Parameters.Add(new SqlParameter("@Process", SqlDbType.NVarChar, 500));
  100. MyCommand.Parameters["@Process"].Value = "0";   
  101. MyCommand.Parameters.Add(new SqlParameter("@WriterID", SqlDbType.NVarChar, 50));
  102. MyCommand.Parameters["@WriterID"].Value = PID;
  103. if(MyConnection.State.ToString()=="Closed")
  104. MyConnection.Open();
  105. try
  106. {
  107. MyCommand.ExecuteNonQuery();
  108.     RegisterStartupScript("alert","<script>alert('文档发送成功!')</script>");
  109. }
  110. catch
  111. {
  112. }
  113. }
  114. }
  115. if(AccepterID.Value.Trim()!="")
  116. {
  117. MyCommand=new SqlCommand("InsertDocument",MyConnection);
  118. MyCommand.CommandType = CommandType.StoredProcedure;
  119. MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 50));
  120. MyCommand.Parameters["@Title"].Value = Title.Text;
  121. int FileLength = ConvertToByte(FreeTextBox1.Text).Length;
  122. MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image, FileLength));
  123. MyCommand.Parameters["@Contents"].Value = ConvertToByte(FreeTextBox1.Text);
  124. MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
  125. MyCommand.Parameters["@PersonID"].Value = PID; 
  126. MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 500));
  127. MyCommand.Parameters["@AccepterID"].Value = AccepterID.Value.Trim();   
  128. MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Char,10));
  129. MyCommand.Parameters["@State"].Value = "0";
  130. MyCommand.Parameters.Add(new SqlParameter("@Process", SqlDbType.NVarChar, 500));
  131. MyCommand.Parameters["@Process"].Value = "0";   
  132. MyCommand.Parameters.Add(new SqlParameter("@WriterID", SqlDbType.NVarChar, 50));
  133. MyCommand.Parameters["@WriterID"].Value = PID;   
  134. if(MyConnection.State.ToString()=="Closed")
  135. MyConnection.Open();
  136. MyCommand.ExecuteNonQuery();
  137. MyConnection.Close(); 
  138. Accepter.Text="";
  139. FreeTextBox1.Text="";
  140. Title.Text="";
  141.                         AccepterID.Value = "";
  142. }
  143. }
  144. else
  145. {
  146. string [] str = AccepterID.Value.Replace("(","").Replace(")","").Split(new Char [] {'→'});
  147. string first = "";
  148. if(str[0]!="")
  149. first =  str[0];
  150. MyCommand=new SqlCommand("InsertDocument",MyConnection);
  151. MyCommand.CommandType = CommandType.StoredProcedure;
  152. MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 50));
  153. MyCommand.Parameters["@Title"].Value = Title.Text;
  154. int FileLength = ConvertToByte(FreeTextBox1.Text).Length;
  155. MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image, FileLength));
  156. MyCommand.Parameters["@Contents"].Value = ConvertToByte(FreeTextBox1.Text);
  157. MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
  158. MyCommand.Parameters["@PersonID"].Value = PID; 
  159. MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 500));
  160. MyCommand.Parameters["@AccepterID"].Value = first;   
  161. MyCommand.Parameters.Add(new SqlParameter("@Process", SqlDbType.NVarChar, 500));
  162. MyCommand.Parameters["@Process"].Value = "("+PID+")→"+AccepterID.Value.Trim();    
  163. MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Char,10));
  164. MyCommand.Parameters["@State"].Value = "0";
  165. MyCommand.Parameters.Add(new SqlParameter("@WriterID", SqlDbType.NVarChar, 50));
  166. MyCommand.Parameters["@WriterID"].Value = PID;   
  167. if(MyConnection.State.ToString()=="Closed")
  168. MyConnection.Open();
  169. MyCommand.ExecuteNonQuery();
  170. MyConnection.Close(); 
  171. RegisterStartupScript("alert","<script>alert('文档发送成功!')</script>");
  172. Accepter.Text="";
  173. FreeTextBox1.Text="";
  174. Title.Text="";
  175.     AccepterID.Value = "";
  176. }
  177. }
  178. }
  179. public static byte[] ConvertToByte(string theString) 
  180. byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);
  181. return byteStream; 
  182. }
  183. }