EditMessage.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:11k
源码类别:
OA系统
开发平台:
C#
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Web;
- using System.IO;
- using System.Web.SessionState;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Text.RegularExpressions;
- namespace OA
- {
- /// <summary>
- /// ViewMessageState 的摘要说明。
- /// </summary>
- public class ViewMessageState : System.Web.UI.Page
- {
- protected System.Web.UI.WebControls.RadioButtonList RadioButtonList1;
- protected System.Web.UI.WebControls.TextBox Accepter;
- protected System.Web.UI.HtmlControls.HtmlInputButton Send;
- protected System.Web.UI.WebControls.Label OldAttachment;
- protected System.Web.UI.HtmlControls.HtmlInputFile Attachment;
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected FreeTextBoxControls.FreeTextBox Contents;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Data.SqlClient.SqlCommand MyCommand;
- private void Page_Load(object sender, System.EventArgs e)
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- if(!IsPostBack)
- {
- if(Request.Params["MessageID"]!=null)
- {
- int MID = Int32.Parse(Request.Params["MessageID"]);
- string PID = "";
- string AID = "";
- SqlCommand MyCommand = new SqlCommand("MessageContents",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@MessageID", SqlDbType.Int, 4));
- MyCommand.Parameters["@MessageID"].Value = Int32.Parse(Request.Params["MessageID"]);
- MyConnection.Open();
- SqlDataReader myReader = MyCommand.ExecuteReader();
- while(myReader.Read())
- {
- Contents.Text = myReader["Contents"].ToString();
- PID = myReader["PersonID"].ToString();
- AID = myReader["AccepterID"].ToString().Trim().Replace("(","").Replace(")","");
- if(myReader["Attachment"].ToString().Trim()!="")
- {
- RadioButtonList1.Items.Add(new ListItem("使用原有附件"));
- RadioButtonList1.Items.Add(new ListItem("添加新附件"));
- OldAttachment.Text= myReader["Attachment"].ToString();
- RadioButtonList1.SelectedIndex=0;
- }
- else
- {
- RadioButtonList1.Items.Add(new ListItem("添加新附件"));
- OldAttachment.Visible=false;
- }
- }
- myReader.Close();
- string [] str = AID.Split(new char[] {','});
- string AccepterName="";
- for(int i=0; i<str.Length; i++)
- {
- SqlCommand MyCommand0 = new SqlCommand("PersonName",MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add(new SqlParameter("@PersonID", SqlDbType.Int, 4));
- MyCommand0.Parameters["@PersonID"].Value = str[i];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader0 = MyCommand0.ExecuteReader();
- while(myReader0.Read())
- AccepterName += ","+myReader0["Name"].ToString();
- myReader0.Close();
- MyConnection.Close();
- }
- Accepter.Text = AccepterName.Substring(1);
- }
- }
- // 在此处放置用户代码以初始化页面
- }
- #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)
- {
- string filename = "";
- string filenamen = "";
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- SqlCommand MyCommand0 = new SqlCommand("PersonID",MyConnection);
- MyCommand0.CommandType = CommandType.StoredProcedure;
- MyCommand0.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
- MyCommand0.Parameters["@Name"].Value = User.Identity.Name;
- MyConnection.Open();
- SqlDataReader myReader = MyCommand0.ExecuteReader(CommandBehavior.CloseConnection);
- string PID="";
- try
- {
- while(myReader.Read())
- {
- PID = myReader.GetInt32(0).ToString();
- }
- myReader.Close();
- }
- finally
- {
- }
- string[] myData = Accepter.Text.Trim().Replace(",,",",").Split(new Char [] {','});
- string AccepterSec = "";
- string Sumac ="";
- string [] str = RemoveDup(myData);
- for(int i = 0; i<str.Length; i++)
- {
- SqlCommand MyCommand1 = new SqlCommand("PersonID",MyConnection);
- MyCommand1.CommandType = CommandType.StoredProcedure;
- MyCommand1.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
- MyCommand1.Parameters["@Name"].Value = str[i];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader1 = MyCommand1.ExecuteReader();
- while(myReader1.Read())
- {
- AccepterSec = myReader1.GetInt32(0).ToString();
- }
- myReader1.Close();
- if(AccepterSec.Trim()!="")
- {
- Sumac += ","+AccepterSec;
- }
- }
- if(Contents.Text.Trim()=="")
- RegisterStartupScript("alert","<script>alert('内容不能为空')</script>");
- else
- {
- if(Sumac!="")
- {
- MyCommand=new SqlCommand("InsertMessage",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- if (Attachment.PostedFile != null)
- filename=Path.GetFileName(Attachment.PostedFile.FileName).Trim();
- int j = 0;
- filenamen=filename;
- if(File.Exists(Server.MapPath("MessageAttachment\"+filenamen)))
- {
- filenamen = filename.Replace(".","("+j.ToString()+").");
- if(File.Exists(Server.MapPath("MessageAttachment\"+filenamen)))
- {
- int lastLocation = filename.LastIndexOf( "." );
- string[] dirs = Directory.GetFiles(Server.MapPath("MessageAttachment\"), ""+filename.Substring(0,lastLocation)+"(*");
- for(int l = 0; l<dirs.Length+1; l++)
- {
- string strf = filenamen.Replace("("+j.ToString()+").","("+l.ToString()+").");
- if(!File.Exists(Server.MapPath("MessageAttachment\"+strf)))
- filenamen = strf;
- }
- }
- }
- if(filenamen.Trim()!="")
- Attachment.PostedFile.SaveAs(Server.MapPath("MessageAttachment\"+filenamen));
- MyCommand.Parameters.Add(new SqlParameter("@Attachment", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@Attachment"].Value = filenamen;
- MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.NVarChar, 1000));
- MyCommand.Parameters["@Contents"].Value = Contents.Text;
- MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
- MyCommand.Parameters["@PersonID"].Value = PID;
- MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 120));
- MyCommand.Parameters["@AccepterID"].Value = "("+Sumac.Substring(1).Replace(",", "),(")+")";
- MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Int, 4));
- MyCommand.Parameters["@State"].Value = "0";
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- }
- MyConnection.Close();
- }
- for(int i = 0; i<str.Length; i++)
- {
- SqlCommand MyCommand1 = new SqlCommand("PersonID",MyConnection);
- MyCommand1.CommandType = CommandType.StoredProcedure;
- MyCommand1.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
- MyCommand1.Parameters["@Name"].Value = str[i];
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- SqlDataReader myReader1 = MyCommand1.ExecuteReader();
- while(myReader1.Read())
- {
- AccepterSec = myReader1.GetInt32(0).ToString();
- }
- myReader1.Close();
- if(AccepterSec.Trim()!="")
- {
- MyCommand=new SqlCommand("InsertMessage",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- int j = 0;
- if(File.Exists(Server.MapPath("MessageAttachment\"+filenamen)))
- {
- filenamen = filename.Replace(".","("+j.ToString()+").");
- if(File.Exists(Server.MapPath("MessageAttachment\"+filenamen)))
- {
- int lastLocation = filename.LastIndexOf( "." );
- string[] dirs = Directory.GetFiles(Server.MapPath("MessageAttachment\"), ""+filename.Substring(0,lastLocation)+"(*");
- for(int l = 0; l<dirs.Length+1; l++)
- {
- string strf = filenamen.Replace("("+j.ToString()+").","("+l.ToString()+").");
- if(!File.Exists(Server.MapPath("MessageAttachment\"+strf)))
- filenamen = strf;
- }
- }
- }
- if(filenamen.Trim()!="")
- Attachment.PostedFile.SaveAs(Server.MapPath("MessageAttachment\"+filenamen));
- MyCommand.Parameters.Add(new SqlParameter("@Attachment", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@Attachment"].Value = filenamen;
- MyCommand.Parameters.Add(new SqlParameter("@Contents",SqlDbType.NVarChar, 2000));
- MyCommand.Parameters["@Contents"].Value = Contents.Text;
- MyCommand.Parameters.Add(new SqlParameter("@PersonID",SqlDbType.Int, 4));
- MyCommand.Parameters["@PersonID"].Value = PID;
- MyCommand.Parameters.Add(new SqlParameter("@AccepterID", SqlDbType.NVarChar, 120));
- MyCommand.Parameters["@AccepterID"].Value = AccepterSec;
- MyCommand.Parameters.Add(new SqlParameter("@State",SqlDbType.Int, 4));
- MyCommand.Parameters["@State"].Value = "0";
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- RegisterStartupScript("alert","<script>alert('短信息未能正确发送!')</script>");
- }
- }
- }
- Accepter.Text="";
- Contents.Text="";
- MyConnection.Close();
- Response.Write("<script>opener.location.href=opener.location.href;opener=null;window.close();</"+"script>");
- }
- }
- 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;
- }
- public String CleanInput(string strIn)
- {
- return Regex.Replace(strIn, @"[^w,]", "");
- }
- }
- }