NewFile.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:7k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Drawing;
- using System.Web;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- namespace OA
- {
- /// <summary>
- /// NewFile 的摘要说明。
- /// </summary>
- public class NewFile : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.TextBox Accepter;
- protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
- protected System.Web.UI.WebControls.DropDownList DropDownList1;
- protected System.Web.UI.WebControls.DropDownList DropDownList2;
- protected System.Web.UI.HtmlControls.HtmlInputFile UpFile;
- protected System.Web.UI.HtmlControls.HtmlInputButton Send;
- protected System.Web.UI.WebControls.TextBox Title;
- protected System.Web.UI.HtmlControls.HtmlInputFile UP_FILE;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
- protected System.Data.DataSet ds;
- protected System.Web.UI.HtmlControls.HtmlInputHidden AccepterID;
- public string PID;
- private void Page_Load(object sender, System.EventArgs e)
- {
- CheckUser CHU = new CheckUser();
- CHU.UserName = User.Identity.Name;
- PID = CHU.UserID.ToString();
- if(CHU.Is_FileManager() == false)
- Response.Write("<script>alert('对不起,你没有查看此页面的权限!');history.back(2)</" + "script>");
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if(!IsPostBack)
- {
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- ds= new DataSet();
- SqlDataAdapter MyCommand = new SqlDataAdapter("SystemSelect",MyConnection);
- MyCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Fill(ds,"System");
- DropDownList1.DataSource=ds.Tables["System"].DefaultView;
- DropDownList1.DataTextField="SystemName";
- DropDownList1.DataValueField="SystemID";
- DropDownList1.DataBind();
- SqlDataAdapter MyCommand1 = new SqlDataAdapter("SelectOrganization",MyConnection);
- MyCommand1.SelectCommand.CommandType = CommandType.StoredProcedure;
- MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@SystemID", SqlDbType.NVarChar, 50));
- MyCommand1.SelectCommand.Parameters["@SystemID"].Value = "%1%";
- MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@TypeID", SqlDbType.Int, 4));
- MyCommand1.SelectCommand.Parameters["@TypeID"].Value = 2;
- MyCommand1.Fill(ds,"Organization0");
- DropDownList2.DataSource=ds.Tables["Organization0"].DefaultView;
- DropDownList2.DataTextField="OrganizationName";
- DropDownList2.DataValueField="OrganizationID";
- DropDownList2.DataBind();
- }
- // 在此处放置用户代码以初始化页面
- MyConnection.Close();
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
- this.Send.ServerClick += new System.EventHandler(this.Send_ServerClick);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- SqlDataAdapter MyCommand1 = new SqlDataAdapter("SelectOrganization",MyConnection);
- MyCommand1.SelectCommand.CommandType = CommandType.StoredProcedure;
- MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@SystemID", SqlDbType.NVarChar, 50));
- MyCommand1.SelectCommand.Parameters["@SystemID"].Value = "%"+DropDownList1.SelectedValue.ToString()+"%";
- MyCommand1.SelectCommand.Parameters.Add(new SqlParameter("@TypeID", SqlDbType.Int, 4));
- MyCommand1.SelectCommand.Parameters["@TypeID"].Value = 2;
- DataSet ds1 = new DataSet();
- MyCommand1.Fill(ds1,"Organization");
- DropDownList2.DataSource=ds1.Tables["Organization"].DefaultView;
- DropDownList2.DataTextField="OrganizationName";
- DropDownList2.DataValueField="OrganizationID";
- DropDownList2.DataBind();
- }
- private void Send_ServerClick(object sender, System.EventArgs e)
- {
- System.Web.HttpPostedFile UpFile = UP_FILE.PostedFile;
- int FileLength = UpFile.ContentLength;
- if (FileLength == 0)
- {
- RegisterStartupScript("alert","<script>alert('你未选择上传文件!')</script>");
- }
- else
- {
- if(AccepterID.Value.Trim()!="")
- {
- System.Byte[] FileByteArray = new System.Byte[FileLength];
- System.IO.Stream StreamObject = UpFile.InputStream;
- StreamObject.Read(FileByteArray,0,FileLength);
- SqlCommand MyCommand=new SqlCommand("InsertFile",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 500));
- MyCommand.Parameters["@Title"].Value = Title.Text;
- MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Binary, FileLength));
- MyCommand.Parameters["@Contents"].Value = FileByteArray;
- MyCommand.Parameters.Add("@ContentType", SqlDbType.NVarChar,50).Value = UpFile.ContentType;
- MyCommand.Parameters.Add("@ByteSize", SqlDbType.NVarChar,50).Value = UpFile.ContentLength;
- MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
- MyCommand.Parameters["@PersonID"].Value = PID;
- MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 500));
- MyCommand.Parameters["@AccepterID"].Value = AccepterID.Value.Trim();
- MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Int, 4));
- MyCommand.Parameters["@State"].Value = "0";
- MyCommand.Parameters.Add(new SqlParameter("@SystemID",SqlDbType.Int, 4));
- MyCommand.Parameters["@SystemID"].Value = DropDownList1.SelectedValue;
- MyCommand.Parameters.Add(new SqlParameter("@OrganizationID",SqlDbType.Int, 4));
- MyCommand.Parameters["@OrganizationID"].Value = DropDownList2.SelectedValue;
- MyCommand.Parameters.Add("@FileKind", SqlDbType.NVarChar,50).Value = RadioButtonList1.SelectedItem.Text;
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- RegisterStartupScript("alert","<script>alert('文件发送成功!')</script>");
- }
- catch
- {
- }
- MyConnection.Close();
- Accepter.Text="";
- Title.Text="";
- AccepterID.Value = "";
- }
- }
- }
- public static string[] RemoveDup(string[] myData)
- {
- if (myData.Length > 0)
- {
- Array.Sort(myData);
- int size = 1;
- for (int i=1; i<myData.Length; i++)
- if (myData[i] != myData[i-1])
- size++;
- string[] myTempData = new string[size];
- int j=0;
- myTempData[j++] = myData[0];
- for (int i=1; i<myData.Length; i++)
- if (myData[i] != myData[i-1])
- myTempData[j++] = myData[i];
- return myTempData;
- }
- return myData;
- }
- }
- }