login.cs

来自「本系统可以对某个班级的成绩进行管理」· CS 代码 · 共 73 行

CS
73
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsApplication1
{
    public partial class login : Form
    {
        private info owner;
        public login(info owner)
        {
            InitializeComponent();
            this.owner = owner;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            try
            {
                SqlConnection myconnection = new SqlConnection();
                myconnection.ConnectionString = "server=hxl;database=studentpoints;integrated security=true ";
                myconnection.Open();


                SqlCommand mycommand = new SqlCommand();
                mycommand.CommandText = "select * from 用户表 where 用户名='" + textBox1.Text.Trim() +
                    "'and " + "密码='" + textBox2.Text.Trim() + "'";

                mycommand.Connection = myconnection;

                SqlDataReader dr = mycommand.ExecuteReader();//查找密码跟用户名
                while (dr.Read())
                {

                    owner.USERID = dr.GetString(2);
                }



                if (owner.USERID != null)//表的权限标志1,2,3
                {


                    this.Close();
                    owner.Opacity = 1;//透明度



                }
                else
                {
                    MessageBox.Show("密码和用户输入有错误!");
                }
            }

            catch (SqlException se)
            {
                MessageBox.Show("连接数据库出现错误!" + se.Message);

            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}

⌨️ 快捷键说明

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