loginin.cs

来自「学生管理(包括学生成绩 档案和课程) 学生可以录入数据」· CS 代码 · 共 75 行

CS
75
字号
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 + =
减小字号Ctrl + -
显示快捷键?