NewUser.aspx.cs
资源名称:OA_at.rar [点击查看]
上传用户:tree100901
上传日期:2007-06-03
资源大小:2295k
文件大小:4k
源码类别:
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.Web.SessionState;
- using System.Web.UI;
- using System.Web.Security;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Text.RegularExpressions;
- namespace OA
- {
- /// <summary>
- /// NewUser 的摘要说明。
- /// </summary>
- public class NewUser : System.Web.UI.Page
- {
- protected System.Data.SqlClient.SqlConnection MyConnection;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
- protected System.Web.UI.WebControls.TextBox Organization;
- protected System.Web.UI.WebControls.TextBox Job;
- protected System.Web.UI.WebControls.TextBox Name;
- protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
- protected System.Web.UI.HtmlControls.HtmlInputButton Send;
- protected System.Data.SqlClient.SqlCommand MyCommand;
- private void Page_Load(object sender, System.EventArgs e)
- {
- // 在此处放置用户代码以初始化页面
- }
- #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 OID = CleanInput1(Organization.Text.Trim());
- string JID = CleanInput1(Job.Text.Trim());
- string [] OI = RemoveDup(OID.Replace("(","").Replace(")","").Split(new char[] {','}));
- string [] JI = RemoveDup(JID.Replace("(","").Replace(")","").Split(new char[] {','}));
- string O = "",J = "";
- for(int i=0; i<OI.Length; i++)
- {
- if(OI[i]!="")
- O +=","+OI[i];
- }
- for(int j=0; j<JI.Length; j++)
- {
- if(JI[j]!="")
- J +=","+JI[j];
- }
- MyConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
- MyCommand=new SqlCommand("InsertPerson",MyConnection);
- MyCommand.CommandType = CommandType.StoredProcedure;
- MyCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@Name"].Value = Name.Text.Trim();
- MyCommand.Parameters.Add(new SqlParameter("@OrganizationID",SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@OrganizationID"].Value = O.Substring(1);
- MyCommand.Parameters.Add(new SqlParameter("@JobID", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@JobID"].Value = J.Substring(1);
- MyCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.NVarChar, 50));
- MyCommand.Parameters["@Password"].Value = FormsAuthentication.HashPasswordForStoringInConfigFile("ANTAI","MD5");
- if(MyConnection.State.ToString()=="Closed")
- MyConnection.Open();
- MyCommand.ExecuteNonQuery();
- MyConnection.Close();
- Response.Write("<script>opener.location.href=opener.location.href;opener=null;window.close();</"+"script>");
- }
- public String CleanInput1(string strIn)
- {
- return Regex.Replace(strIn, @"[^ -9,]", "");
- }
- 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;
- }
- }
- }