⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.cs

📁 分布试数据库系统的管理员程序
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using RemotingClass;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Runtime.Remoting.Services;

namespace Login
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Login : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox tbID;
		private System.Windows.Forms.TextBox tbPassword;
		private System.Windows.Forms.Button button1;
		private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter_User;
		private System.Data.SqlClient.SqlConnection sqlConnection_User;
		private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
		private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label3;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Login()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Login));
			this.tbID = new System.Windows.Forms.TextBox();
			this.tbPassword = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.sqlDataAdapter_User = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConnection_User = new System.Data.SqlClient.SqlConnection();
			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.button2 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// tbID
			// 
			this.tbID.Location = new System.Drawing.Point(272, 112);
			this.tbID.Name = "tbID";
			this.tbID.TabIndex = 0;
			this.tbID.Text = "";
			// 
			// tbPassword
			// 
			this.tbPassword.Location = new System.Drawing.Point(272, 160);
			this.tbPassword.Name = "tbPassword";
			this.tbPassword.PasswordChar = '*';
			this.tbPassword.TabIndex = 1;
			this.tbPassword.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(200, 232);
			this.button1.Name = "button1";
			this.button1.TabIndex = 2;
			this.button1.Text = "登录";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// sqlDataAdapter_User
			// 
			this.sqlDataAdapter_User.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter_User.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter_User.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter_User.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																										  new System.Data.Common.DataTableMapping("Table", "SystemUser", new System.Data.Common.DataColumnMapping[] {
																																																						new System.Data.Common.DataColumnMapping("userid", "userid"),
																																																						new System.Data.Common.DataColumnMapping("password", "password")})});
			this.sqlDataAdapter_User.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = "DELETE FROM SystemUser WHERE (userid = @Original_userid) AND (password = @Origina" +
				"l_password)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection_User;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_userid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "userid", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection_User
			// 
			this.sqlConnection_User.ConnectionString = "workstation id=7B1EE60547FB453;packet size=4096;user id=sa;integrated security=SS" +
				"PI;initial catalog=Center;persist security info=False";
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO SystemUser(userid, password) VALUES (@userid, @password); SELECT user" +
				"id, password FROM SystemUser WHERE (userid = @userid)";
			this.sqlInsertCommand1.Connection = this.sqlConnection_User;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@userid", System.Data.SqlDbType.VarChar, 10, "userid"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT userid, password FROM SystemUser";
			this.sqlSelectCommand1.Connection = this.sqlConnection_User;
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = "UPDATE SystemUser SET userid = @userid, password = @password WHERE (userid = @Ori" +
				"ginal_userid) AND (password = @Original_password); SELECT userid, password FROM " +
				"SystemUser WHERE (userid = @userid)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection_User;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@userid", System.Data.SqlDbType.VarChar, 10, "userid"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@password", System.Data.SqlDbType.VarChar, 10, "password"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_userid", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "userid", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_password", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "password", System.Data.DataRowVersion.Original, null));
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.Color.Transparent;
			this.label1.Location = new System.Drawing.Point(232, 120);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(32, 23);
			this.label1.TabIndex = 3;
			this.label1.Text = "ID:";
			this.label1.Click += new System.EventHandler(this.label1_Click);
			// 
			// label2
			// 
			this.label2.BackColor = System.Drawing.Color.Transparent;
			this.label2.Location = new System.Drawing.Point(224, 168);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 23);
			this.label2.TabIndex = 4;
			this.label2.Text = "密码:";
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(312, 232);
			this.button2.Name = "button2";
			this.button2.TabIndex = 5;
			this.button2.Text = "退出";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.Color.Transparent;
			this.label3.Font = new System.Drawing.Font("华文行楷", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.ForeColor = System.Drawing.Color.Magenta;
			this.label3.Location = new System.Drawing.Point(16, 8);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(40, 256);
			this.label3.TabIndex = 7;
			this.label3.Text = "女孩时尚用品总店";
			// 
			// Login
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(416, 301);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.tbPassword);
			this.Controls.Add(this.tbID);
			this.ForeColor = System.Drawing.Color.Magenta;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Login";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "女孩时尚用品_总部";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Login());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(tbID.Text.ToString().Length==0)
				MessageBox.Show("请输入用户ID!");
			else if(tbPassword.Text.ToString().Length==0)
				MessageBox.Show("请输入用户密码!");
			else
			{
				DataSet userSet=new DataSet();
				String ID=tbID.Text.ToString().Trim();
				String Password=tbPassword.Text.ToString().Trim();
				sqlDataAdapter_User.SelectCommand.CommandText=
					"select * from SystemUser where userid= '"+ID+"'";
				sqlDataAdapter_User.Fill(userSet);
				DataTable userTable=userSet.Tables[0];
				DataRow findRow=userTable.Rows[0];//Find(ID);
				if(findRow==null)
					MessageBox.Show("没有此用户!");
				else
				{
					if(findRow[1].ToString().Trim().Equals(Password))
					{
						Interface i=new Interface();
						i.Show();


						//远程服务创建
						try
						{
							//注册通道
							IDictionary properties = new Hashtable();
							properties["name"] = "center";
//							properties["name"] = "tcp1";
							properties["port"] = "8080";
							properties["priority"] = "20";
//							MessageBox.Show("tcp"+branch.Trim());

							BinaryServerFormatterSinkProvider provider = new BinaryServerFormatterSinkProvider();
								

							TcpServerChannel chan = new TcpServerChannel(properties,provider);        
							ChannelServices.RegisterChannel(chan);
//
//							TcpServerChannel chan = new TcpServerChannel(8000);        
//							ChannelServices.RegisterChannel(chan);

							//注册远程对象.
//							RemotingConfiguration.RegisterWellKnownServiceType(typeof(Sale), "remotingSale", WellKnownObjectMode.SingleCall);
							RemotingConfiguration.RegisterWellKnownServiceType(typeof(Change), "centerChange", WellKnownObjectMode.Singleton);

							//								//IpcChannel channel = new IpcChannel("library");
							//								TcpChannel tc = new TcpChannel(9999);
							//								//HttpChannel channel = new HttpChannel(8888);//声明信道
							//								ChannelServices.RegisterChannel(tc, false);//注册信道
							//								RemotingConfiguration.Configure("RemoteServer.exe.config", false);//配置信道
						}
						catch (Exception ex)//捕获异常
						{
							MessageBox.Show(ex.Message);//弹出异常
						}		
						
					}
					else
						MessageBox.Show("密码错误!");
				}

			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void label1_Click(object sender, System.EventArgs e)
		{
		
		}

	
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -