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

📄 loginin.cs

📁 学生管理(包括学生成绩 档案和课程) 学生可以录入数据
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StudentManager
{
    public partial class LoginIn : Form
    {
        private string selectstr = null;
        private SqlCommand command1 = null;
        private SqlDataReader DataReader = null;
        private SqlConnection conn1 = null;
        public LoginIn()
        {
            InitializeComponent();            
            conn1 = new SqlConnection(DataLevel.Connection.ConnString);
            command1 = new SqlCommand();
            textBoxID.Select();
            
        }

        private void LoginIn_Load(object sender, EventArgs e)
        {
           

        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            if (textBoxID.Text == "" | textBoxpassword.Text == "")
            {
                MessageBox.Show("学号或密码不能为空 !");
                return;
            }
            string ID = textBoxID.Text.Trim();
            string password = textBoxpassword.Text.Trim();
            this.command1.Connection = conn1;
            selectstr = "Select * from [User] where UserID = '"+ID+"' and Password = '"+password+"'";
            command1.CommandText = selectstr;
            if (conn1.State == ConnectionState.Closed)
                conn1.Open();
            DataReader = command1.ExecuteReader();
            if (DataReader.Read())
            {
                try
                {
                   this.Hide();
                    Form frm = new MainForm();
                    frm.Show();
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.ToString());
                }
            }
            else
            {
                MessageBox.Show("该用户不存在或密码不正确! 请重新输入 !");
            }
            DataReader.Close();
            conn1.Close();
        }

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

    }
}

⌨️ 快捷键说明

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