dl.cs

来自「实习时候做的一个c#的财务管理系统」· CS 代码 · 共 76 行

CS
76
字号
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 cwgl
{
    public partial class dl : Form
    {
        public dl()
        {
            InitializeComponent();
        }

        SqlConnection con = new SqlConnection(global::cwgl.Properties.Settings.Default.cwglCon);

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

        private void button1_Click(object sender, EventArgs e)
        {
            string t1 = textBox1.Text.ToString().Trim();
            string t2 = textBox2.Text.ToString().Trim();
            
            try
            {
                con.Open();
                string sql = "SELECT  * FROM admin";
                SqlCommand com = new SqlCommand(sql, con);
                SqlDataReader sdr = com.ExecuteReader();
                sdr.Read();
                    if (Convert.ToString(sdr["users"]) == t1 && Convert.ToString(sdr["password"]) == t2)
                    {
                        main m = new main();
                        m.Show();
                       
                        sdr.Close();
                        con.Close();
                        this.Close();
                    }
                    else if (Convert.ToString(sdr["users"]) != t1)
                    {
                        MessageBox.Show("用户名错误,请重新输入!", "系统提示");
                        this.textBox1.Text = "";
                        this.textBox2.Text = "";
                        return;
                    }
                    else
                    {
                        MessageBox.Show("密码错误,请重新输入!","系统提示");
                        this.textBox2.Text = "";
                        return;

                    }
                }

            
            catch (SqlException e1)
            {
            }
            finally
            {
                con.Close();
            }



        }
    }
}

⌨️ 快捷键说明

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