NewMessage.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:8k
源码类别:
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;
- namespace OA
- {
- /// <summary>
- /// WebForm1 的摘要说明。
- /// </summary>
- public class WebForm1 : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.HtmlControls.HtmlForm Form1;
- protected System.Web.UI.WebControls.TextBox Accepter;
- protected System.Web.UI.WebControls.TextBox Contents;
- protected FreeTextBoxControls.FreeTextBox FreeTextBox1;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Web.UI.HtmlControls.HtmlInputButton Send;
- protected System.Web.UI.HtmlControls.HtmlInputFile Attachment;
- protected System.Data.SqlClient.SqlCommand MyCommand;
- protected System.Web.UI.HtmlControls.HtmlInputHidden AccepterID;
- public string PID;
- private void Page_Load(object PersonID, System.EventArgs e)
- {
- 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);
- try
- {
- while(myReader.Read())
- {
- PID = myReader.GetInt32(0).ToString();
- }
- myReader.Close();
- }
- finally
- {
- }
- /* string strScript = "<script>document.Form1.Accepter.value=window.dialogArguments;</script>" ;
- if(!Page.IsStartupScriptRegistered("clientScript"))
- Page.RegisterClientScriptBlock("clientScript", strScript);
- */
- // 在此处放置用户代码以初始化页面
- }
- #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)
- {
- if(FreeTextBox1.Text.Trim()=="")
- RegisterStartupScript("alert","<script>alert('内容不能为空')</script>");
- else
- {
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- string filename = "";
- string filenamen = "";
- if(AccepterID.Value.Trim()!="")
- {
- 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, 2000));
- MyCommand.Parameters["@Contents"].Value = FreeTextBox1.Text;
- 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";
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- try
- {
- MyCommand.ExecuteNonQuery();
- }
- catch
- {
- }
- }
- string [] str = AccepterID.Value.Trim().Replace("(","").Replace(")","").Split(new Char [] {','});
- for(int i = 0; i<str.Length; i++)
- {
- if(str[i]!="")
- {
- 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 = FreeTextBox1.Text;
- 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 = str[i].ToString().Trim();
- 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="";
- FreeTextBox1.Text="";
- AccepterID.Value="";
- MyConnection.Close();
- }
- }
- 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;
- }
- }
- }