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

📄 form1.cs

📁 因本人正在学习中
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;
namespace 图书
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.RadioButton radbtn_gly;
		private System.Windows.Forms.RadioButton tadbtn_pu;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btnCancle;
		private System.Windows.Forms.Button btnSure;
		private System.Windows.Forms.TextBox txtID;
		private System.Windows.Forms.TextBox txtMI;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		public static string connstr;
		public  int usertype;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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()
		{
			this.radbtn_gly = new System.Windows.Forms.RadioButton();
			this.tadbtn_pu = new System.Windows.Forms.RadioButton();
			this.label3 = new System.Windows.Forms.Label();
			this.btnCancle = new System.Windows.Forms.Button();
			this.btnSure = new System.Windows.Forms.Button();
			this.txtID = new System.Windows.Forms.TextBox();
			this.txtMI = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// radbtn_gly
			// 
			this.radbtn_gly.Location = new System.Drawing.Point(184, 160);
			this.radbtn_gly.Name = "radbtn_gly";
			this.radbtn_gly.Size = new System.Drawing.Size(72, 24);
			this.radbtn_gly.TabIndex = 19;
			this.radbtn_gly.Text = "管理员";
			// 
			// tadbtn_pu
			// 
			this.tadbtn_pu.Location = new System.Drawing.Point(56, 160);
			this.tadbtn_pu.Name = "tadbtn_pu";
			this.tadbtn_pu.Size = new System.Drawing.Size(72, 24);
			this.tadbtn_pu.TabIndex = 18;
			this.tadbtn_pu.Text = "普通用户";
			// 
			// label3
			// 
			this.label3.Dock = System.Windows.Forms.DockStyle.Top;
			this.label3.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(0, 0);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(292, 32);
			this.label3.TabIndex = 17;
			this.label3.Text = "图书管理登录";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// btnCancle
			// 
			this.btnCancle.Location = new System.Drawing.Point(168, 208);
			this.btnCancle.Name = "btnCancle";
			this.btnCancle.TabIndex = 15;
			this.btnCancle.Text = "取消(&C)";
			this.btnCancle.Click += new System.EventHandler(this.btnCancle_Click);
			// 
			// btnSure
			// 
			this.btnSure.Location = new System.Drawing.Point(56, 208);
			this.btnSure.Name = "btnSure";
			this.btnSure.TabIndex = 14;
			this.btnSure.Text = "确定(&S)";
			this.btnSure.Click += new System.EventHandler(this.btnSure_Click);
			// 
			// txtID
			// 
			this.txtID.BackColor = System.Drawing.Color.LavenderBlush;
			this.txtID.ForeColor = System.Drawing.Color.DodgerBlue;
			this.txtID.Location = new System.Drawing.Point(104, 56);
			this.txtID.Name = "txtID";
			this.txtID.Size = new System.Drawing.Size(136, 21);
			this.txtID.TabIndex = 12;
			this.txtID.Text = "";
			// 
			// txtMI
			// 
			this.txtMI.BackColor = System.Drawing.Color.LavenderBlush;
			this.txtMI.ForeColor = System.Drawing.Color.DodgerBlue;
			this.txtMI.Location = new System.Drawing.Point(104, 120);
			this.txtMI.Name = "txtMI";
			this.txtMI.PasswordChar = '*';
			this.txtMI.Size = new System.Drawing.Size(136, 21);
			this.txtMI.TabIndex = 13;
			this.txtMI.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(40, 56);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(56, 23);
			this.label1.TabIndex = 10;
			this.label1.Text = "登录名:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(48, 120);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 23);
			this.label2.TabIndex = 11;
			this.label2.Text = "密码:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
			this.ClientSize = new System.Drawing.Size(292, 273);
			this.Controls.Add(this.radbtn_gly);
			this.Controls.Add(this.tadbtn_pu);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.btnCancle);
			this.Controls.Add(this.btnSure);
			this.Controls.Add(this.txtID);
			this.Controls.Add(this.txtMI);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.label2);
			this.ForeColor = System.Drawing.Color.Blue;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "登录界面";
			this.ResumeLayout(false);

		}
		#endregion

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

		private void btnSure_Click(object sender, System.EventArgs e)
		{
			
			
			
			
				if(this.txtID.Text =="" || this.txtMI.Text =="")
				{
					MessageBox.Show("请输入完整信息!");
				}
				else
				{
					if(this.radbtn_gly.Checked==true)
					{
						if(txtID.Text=="徐蓉" && txtMI.Text=="123")
						{	
			
							
							frmMain_gj newfrm=new frmMain_gj();
							newfrm.Show();	
							MessageBox.Show("你已经登陆成功");
							this.Hide();		
						}
						else
						{
							
							MessageBox.Show("你无权!");
						}
					}
					else
					{
						if(this.tadbtn_pu.Checked==true)
						{
							StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
							string sn=sr.ReadLine();
							SqlConnection conn=new SqlConnection(sn);
							SqlCommand comm = new SqlCommand("id_pwd",conn);
							comm.CommandType=CommandType.StoredProcedure;
							comm.Parameters.Add("@id",this.txtID.Text.Trim());
							comm.Parameters.Add("@pwd",this.txtMI.Text.Trim());
							SqlParameter pm = new SqlParameter("@s",SqlDbType.Int);
							pm.Direction=ParameterDirection.Output;
							comm.Parameters.Add(pm);
							try
							{
								conn.Open();                                    
								comm.ExecuteNonQuery();
								if(Convert.ToInt32(pm.Value)!=0)
								{
									frmMain_pt f = new frmMain_pt();
									f.Show();
									this.Hide();
								}
								else
								{
									MessageBox.Show("登陆失败!");
								}
							}
							catch(Exception ex)
							{
								MessageBox.Show(ex.Message);					
							}
						}
						else
						{
							MessageBox.Show("请选择用户!");
						}
					}
				}	
			txtID.Clear();
			txtMI.Clear();
		}
		
		private void databinding()
		{
			string connstr=Form1.connstr;
			SqlConnection conn=new SqlConnection(connstr);
			SqlCommand comm=new SqlCommand("",conn);
			
		
		}

		private void btnCancle_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
		private void Form1_Load(object sender, System.EventArgs e)
		{
			StreamReader sr=new StreamReader("ts.ini",System.Text.Encoding.Default);
			Form1.connstr=sr.ReadToEnd();
			sr.Close();
				databinding();
		}

}
	

		
		
			
		}	

	
	

⌨️ 快捷键说明

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