欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C#之九 登录界面

程序员文章站 2022-05-06 13:21:19
...

本文利用window窗体简单的实现form1跳转到from2的效果

下面是登录按钮的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace 登录界面
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {


        }




        private void button1_Click(object sender, EventArgs e)
        {
            //一个窗体跳至另一个窗体,未使用数据库
            //string name = "123";
            //string pwd = "321";
            //if (name == textBox1.Text && pwd == textBox2.Text)
            //{
            //    huanying huanYing = new huanying();
            //    huanYing.Show();
            //    this.Close();
            //    System.Threading.Thread.Sleep(2000);
            //}

            SqlConnection con = new SqlConnection("data source=192.168.16.215;database=Stu;uid=test;pwd=daode");

            DataTable dt = new DataTable();

            //打开连接
            con.Open();

            //建立SqlDataAdapter对象
            SqlDataAdapter da = new SqlDataAdapter("select * from student where stuname='" + textBox1.Text + "' and stupwd='" + textBox2.Text + "'", con);

            //用fill方法返回的数据,填充DataSet
            da.Fill(dt);

            // dgv.DataSource = dt;

            //关闭连接
            con.Close();

            if (textBox1.Text == "" || textBox2.Text == "")
            {

                MessageBox.Show("提示:请输入用户名和密码!", "警告");
            }

            else if (dt.Rows.Count != 1)

            {

                MessageBox.Show("用户名或者密码错误!");
            }
            else
            {
                MessageBox.Show("登录成功!");
                huanying huanYing = new huanying();
                huanYing.Show();
                this.Close();
                System.Threading.Thread.Sleep(2000);

            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
        }


    }
}


C#之九 登录界面
C#之九 登录界面C#之九 登录界面