⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginfrm.cs

📁 .net 2005 c# 完整的门禁考勤系统
💻 CS
字号:
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;
using System.Data.OleDb;
using System.Data.Odbc ;
namespace AttendManager
{
    public partial class LoginFrm : Form
    {
        OdbcConnection m_connection;
        string m_sConn;
        int m_iCount = 0;
        private Form_Main m_FormMain;
        public LoginFrm(Form_Main mFrm, string strCancellation)
        {
            InitializeComponent();
            m_sConn = "Dsn=" + Properties.Settings.Default.DNS;
            m_FormMain = new Form_Main();
            m_FormMain = mFrm;
            if (strCancellation == "1")
            {
                this.Text = "登录窗口";
                this.btn_Cancle.Text = "退出";
            }
            else
            {
                this.btn_Cancle.Text = "取消";
                this.Text = "切换用户";
            }
            m_sConn = "Dsn=" + Properties.Settings.Default.DNS;

        }

        private void btn_Login_Click(object sender, EventArgs e)
        {
            bool bpass = CheckUser(this.comboBox_user.Text, this.txtPwd.Text);
            m_iCount = m_iCount + 1;

            if (bpass == true)
            {
                //MessageBox.Show("ok");
                this.Close();
                // MessageBox.Show("用户名或密码错误!");
            }
            else
            {
                MessageBox.Show("密码错误!", Properties.Settings.Default.APPTitle);
                this.txtPwd.Focus();
                if( m_iCount ==3 )
                {
                    Application.Exit();
                }
            }
        }
        

        private void btn_Cancle_Click(object sender, EventArgs e)
        {
            this.Close();
            Application.Exit();
        }

        private void txtUserName_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)(13))
            {
                this.txtPwd.Focus();
            }
        }

        private void txtPwd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)(13))
            {
                this.btn_Login_Click(null, null);
            }
        }
        private void FrmLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            //if (this.btn_Cancle.Text == "退出")
            //{
            //    if (m_blogin == true)
            //    {
            //        Application.Exit();
            //    }
            //}
            //else
            //{
            //    e.Cancel = false;
            //}
        }

        private void LoginFrm_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.用户”中。您可以根据需要移动或移除它。
            //this.用户TableAdapter.Fill(this.dataSet1.用户);

            m_connection = new OdbcConnection(m_sConn);
            m_connection.Open();
            GetUsers();
        }



        private  bool CheckUser(string sUser, string sPW)
        {
            bool bpass =false;

            if (sPW.Equals("") == false && sUser.Equals("") == false)
            {
                // Execute the DataReader and access the data.
                string queryString = "Select * From 用户 where (用户名 = '" + sUser + "' and 口令 = '" + sPW + "')";
                OdbcCommand command = new OdbcCommand(queryString, m_connection);
                OdbcDataReader reader = command.ExecuteReader();
                bpass = reader.HasRows;
                //设置用户信息
                if (bpass ==true)
                {
                    m_FormMain.m_sUser = sUser;
                    m_FormMain.m_sPW = sPW;
                    m_FormMain.m_iUserTpye =(int) reader.GetValue(3);
                    m_FormMain.m_connection = m_connection;
                    //string ss = reader.GetValue(1).ToString() + "--" + reader.GetValue(2).ToString() + "--" + reader.GetValue(3).ToString();
                    //MessageBox.Show(ss  );
                }
                
                reader.Close();
            }
            return bpass;

        }
        private void GetUsers()
        {

            // Execute the DataReader and access the data.
            string queryString = "Select * From 用户";
            OdbcCommand command = new OdbcCommand(queryString, m_connection);
            OdbcDataReader reader = command.ExecuteReader();

            BindingSource bs = new BindingSource();
            bs.DataSource = reader;
            this.comboBox_user.DataSource = bs;
            this.comboBox_user.ValueMember = "用户名";
            this.comboBox_user.DisplayMember = "用户名";
            reader.Close();

        }
        private void comboBox_user_SelectedIndexChanged(object sender, EventArgs e)
        {

            m_FormMain.m_sUser = comboBox_user.Text;
            this.txtPwd.Focus();
        }

        private void comboBox_user_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {
                this.txtPwd.Focus();
            }
        }


    }
}

⌨️ 快捷键说明

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