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

📄 loginfrm.cs

📁 用csharp和ms sql 简单实现学生管理系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 学生管理系统
{
    public partial class LoginFrm : Form
    {
        public static bool blCanLogin = false;  //记录能否检验是否通过
        public static string strUser = "";      //记录用户名
        public static string user;

        private DataSet ds = new DataSet();
        private DataTable myTable;
        private DataRow myRow;
        private string sendStrSQL = "SELECT * from 用户清单";

        private Label 用户号;
        private Label 密码;
        private TextBox textBox1;
        private Button 登陆;
        private Button 取消;
        private TextBox textBox2;

        private System.ComponentModel.Container components = null;

        public LoginFrm()
        {
            InitializeComponent();
            LinkDataBase link = new LinkDataBase();
            string sendTableName = "用户清单";
            this.ds = link.SelectDataBase(sendStrSQL, sendTableName);
            this.myTable = ds.Tables[0];
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.用户号 = new System.Windows.Forms.Label();
            this.密码 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.登陆 = new System.Windows.Forms.Button();
            this.取消 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // 用户号
            // 
            this.用户号.AutoSize = true;
            this.用户号.Location = new System.Drawing.Point(34, 44);
            this.用户号.Name = "用户号";
            this.用户号.Size = new System.Drawing.Size(41, 12);
            this.用户号.TabIndex = 0;
            this.用户号.Text = "用户号";
            // 
            // 密码
            // 
            this.密码.AutoSize = true;
            this.密码.Location = new System.Drawing.Point(36, 87);
            this.密码.Name = "密码";
            this.密码.Size = new System.Drawing.Size(29, 12);
            this.密码.TabIndex = 1;
            this.密码.Text = "密码";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(111, 44);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(142, 21);
            this.textBox1.TabIndex = 2;
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(111, 87);
            this.textBox2.Name = "textBox2";
            this.textBox2.PasswordChar = '*';
            this.textBox2.Size = new System.Drawing.Size(142, 21);
            this.textBox2.TabIndex = 3;
            // 
            // 登陆
            // 
            this.登陆.Location = new System.Drawing.Point(38, 156);
            this.登陆.Name = "登陆";
            this.登陆.Size = new System.Drawing.Size(75, 23);
            this.登陆.TabIndex = 4;
            this.登陆.Text = "登陆";
            this.登陆.UseVisualStyleBackColor = true;
            this.登陆.Click += new System.EventHandler(this.登陆_Click);
            // 
            // 取消
            // 
            this.取消.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.取消.Location = new System.Drawing.Point(167, 156);
            this.取消.Name = "取消";
            this.取消.Size = new System.Drawing.Size(75, 23);
            this.取消.TabIndex = 5;
            this.取消.Text = "取消";
            this.取消.UseVisualStyleBackColor = true;
            this.取消.Click += new System.EventHandler(this.取消_Click);
            // 
            // login
            // 
            this.ClientSize = new System.Drawing.Size(294, 216);
            this.Controls.Add(this.取消);
            this.Controls.Add(this.登陆);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.密码);
            this.Controls.Add(this.用户号);
            this.MaximizeBox = false;
            this.MinimizeBox = false;
            this.Name = "login";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "用户登录";
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void 登陆_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < myTable.Rows.Count; i++)
            {
                this.myRow = myTable.Rows[i];
                //只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
                if (myRow[0].ToString().Trim() == this.textBox1.Text.ToString().Trim() &&
                    myRow[1].ToString().Trim() == this.textBox2.Text.ToString().Trim())
                {
                    blCanLogin = true;
                    strUser = myRow[0].ToString().Trim();//保存用户名
                    user = myRow[2].ToString().Trim();
                    this.Close();//关闭窗体
                    return;
                }
            }
            MessageBox.Show("您输入的用户号或密码不正确!");
            return;
        }

        private void 取消_Click(object sender, EventArgs e)
        {
			blCanLogin = false;
            this.Close();
        }

    }
}

⌨️ 快捷键说明

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