frm-log.cs

来自「这是我个人写的一个实例用于登记公司的电脑信息」· CS 代码 · 共 86 行

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

namespace 计算机及IP管理
{
    public partial class form1 : Form
    {
        UserCls cls = new UserCls(); 
        DataSet myds;

        public form1()
        {
            InitializeComponent();
        }

        private void btnLog_Click(object sender, EventArgs e)
        {
            //此窗体的DialogResult值赋值,将在Main函数中判断此值
            if (txtName.Text.Trim() == "")
            {
                MessageBox.Show("用户名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtName.Focus();
                return;
            }
            if (txtpsw.Text.Trim() == "")
            {
                MessageBox.Show("密码不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtpsw.Focus();
                return;
            }
            string strsql = "select  * from t_user where name='" + txtName.Text.Trim() + "'and psw='" + txtpsw.Text.Trim() + "'";        
            myds = cls.GetDataSet(strsql, "t_user");        
                if (myds.Tables[0].Rows.Count>0)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("用户名或密码有误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }          
        }

        private void form1_Load(object sender, EventArgs e)
        {
            //启动应用程序可显示的样式
            Application.EnableVisualStyles();
        }

        //文本框的输入,如果输入回车键,则进行用户判断
        private void txtpsw_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                //此窗体的DialogResult值赋值,将在Main函数中判断此值
                if (txtName.Text.Trim() == "")
                {
                    MessageBox.Show("用户名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtName.Focus();
                    return;
                }
                if (txtpsw.Text.Trim() == "")
                {
                    MessageBox.Show("密码不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtpsw.Focus();
                    return;
                }
                string strsql = "select  * from t_user where name='" + txtName.Text.Trim() + "'and psw='" + txtpsw.Text.Trim() + "'";
                myds = cls.GetDataSet(strsql, "t_user");
                if (myds.Tables[0].Rows.Count > 0)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    MessageBox.Show("用户名或密码有误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }  
            }
        }
    }
}

⌨️ 快捷键说明

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