EditInfo.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:5k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Text;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- 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>
- /// EditInfo 的摘要说明。
- /// </summary>
- public class EditInfo : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.DropDownList DropDownList1;
- protected System.Web.UI.WebControls.TextBox Title;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
- protected System.Web.UI.WebControls.TextBox Writer;
- protected System.Web.UI.HtmlControls.HtmlInputButton Send;
- protected System.Data.DataSet ds;
- protected System.Web.UI.WebControls.Label Sender;
- public string PID;
- protected FreeTextBoxControls.FreeTextBox Contents;
- public int IID;
- 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(Request.Params["InfoID"]!=null)
- {
- IID = Int32.Parse(Request.Params["InfoID"]);
- SqlDataAdapter MyCommand0 = new SqlDataAdapter("SelectInfoCategories",MyConnection);
- MyCommand0.SelectCommand.CommandType = CommandType.StoredProcedure;
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- ds= new DataSet();
- MyCommand0.Fill(ds,"InfoCategories");
- DropDownList1.DataSource=ds.Tables["InfoCategories"].DefaultView;
- DropDownList1.DataTextField="InfoCategoryName";
- DropDownList1.DataValueField="InfoCategoryID";
- DropDownList1.DataBind();
- SqlCommand MyCommand = new SqlCommand("InfomationContents",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@InfoID", SqlDbType.Int, 4));
- MyCommand.Parameters["@InfoID"].Value = Int32.Parse(Request.Params["InfoID"]);
- SqlDataReader myReader = MyCommand.ExecuteReader();
- myReader.Read();
- Title.Text = myReader["Title"].ToString();
- Session["cont"] = myReader["Contents"];
- Contents.Text = "0";
- Writer.Text = myReader["Writer"].ToString();
- Sender.Text = myReader["Name"].ToString();
- DropDownList1.SelectedValue = myReader["InfoCategoryID"].ToString().Trim();
- myReader.Close();
- MyConnection.Close();
- }
- // 在此处放置用户代码以初始化页面
- }
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Send.ServerClick += new System.EventHandler(this.Send_ServerClick);
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- private void Send_ServerClick(object sender, System.EventArgs e)
- {
- SqlCommand MyCommand=new SqlCommand("UpdateInfomation",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@Title",SqlDbType.NVarChar, 120));
- MyCommand.Parameters["@Title"].Value = Title.Text;
- if(Contents.Text.Trim()=="0")
- {
- MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image,((byte[])Session["cont"]).Length));
- MyCommand.Parameters["@Contents"].Value = (byte[])Session["cont"];
- }
- else
- {
- int FileLength = ConvertToByte(Contents.Text).Length;
- MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.Image, FileLength));
- MyCommand.Parameters["@Contents"].Value = ConvertToByte(Contents.Text);
- }
- MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
- MyCommand.Parameters["@PersonID"].Value = PID;
- MyCommand.Parameters.Add(new SqlParameter("@Writer", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@Writer"].Value = Writer.Text;
- MyCommand.Parameters.Add(new SqlParameter("@InfoCategoryID",SqlDbType.Int, 4));
- MyCommand.Parameters["@InfoCategoryID"].Value = DropDownList1.SelectedValue;
- MyCommand.Parameters.Add(new SqlParameter("@InfoID", SqlDbType.Int, 4));
- MyCommand.Parameters["@InfoID"].Value = Int32.Parse(Request.Params["InfoID"]);
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- MyCommand.ExecuteNonQuery();
- MyConnection.Close();
- RegisterStartupScript("alert","<script>alert('信息编制成功!');opener.location.href=opener.location.href;opener=null;window.close();</script>");
- }
- public static byte[] ConvertToByte(string theString)
- {
- byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);
- return byteStream;
- }
- }
- }