login.cs

来自「系统简介: 本系统是一个用于管理学生毕业系统的简单系统。系统包含的信息包括学生」· CS 代码 · 共 72 行

CS
72
字号
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 graduationNET
{
    public partial class login : Form
    {

        public login()
        {
            InitializeComponent();
        }

        private void ok_btn_Click(object sender, EventArgs e)
        {
            SqlConnection myconnection;

            SqlCommand sqlcmd;

            string constr = "Data Source=localhost;Initial Catalog=.NET_51671;Integrated Security= true;";
            myconnection = new SqlConnection(constr);

            if (idtxt.Text.Length == 0)
            {
                MessageBox.Show("用户名不能为空", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                idtxt.Focus();
            }

            string sqlstatement = "select count(id) from login_51671 where id=@id and pw=@pw ";

            sqlcmd = new SqlCommand(sqlstatement, myconnection);
            sqlcmd.Parameters.AddWithValue("@id", idtxt.Text.Trim());
            sqlcmd.Parameters.AddWithValue("@pw", pwtxt.Text.Trim());
            try
            {
                myconnection.Open();
                int rowcount = int.Parse(sqlcmd.ExecuteScalar().ToString());
                if (rowcount > 0)
                {
                    MainFrm mf = new MainFrm();
                    mf.Show();
                    this.Hide();

                }
                else
                {
                    MessageBox.Show("用户密码不正确...", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    idtxt.Focus();
                }
            }
            catch (SqlException ex)
            {
                MessageBox.Show("用户身份验证出错:" + ex.Message, "出现错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                myconnection.Close();
            }
        }

        private void cannel_btn_Click(object sender, EventArgs e)
        {
            Application.Exit(); //通知所有消息泵必须终止,并且在处理了消息以后关闭所有应用程序窗口。
        }
    }
}

⌨️ 快捷键说明

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