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

📄 formlogin.cs

📁 人事管理系统
💻 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.IO;
using System.Configuration;
using System.Runtime.InteropServices;

namespace HumanResourceManagement
{
    public partial class FormLogin : Form
    {
        public FormLogin()
        {
            InitializeComponent();
        }

        private const int CP_NOCLOSE_BUTTON = 0x200;
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams myCp = base.CreateParams;
                myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON;
                return myCp;
            }
        } 

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("您真的要退出吗?", "tishi", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            if (DialogResult == DialogResult.OK)
            {
                Application.ExitThread();
            }
        }

        private void BtnO_Click(object sender, EventArgs e)
        {
            if (TxtUserName.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请先输入你的用户名!", "提示");
            }
            else
            {
                SqlConnection con = DB.connection();
                con.Open();
                SqlCommand cmd = new SqlCommand("select LoginName from tblEmployee ", con);
                int count = Convert.ToInt32(cmd.ExecuteScalar());
                if (count == 0)
                {
                    con.Close();
                    DialogResult = MessageBox.Show("该用户不存在!", "提示");
                    TxtUserName.Text = "";
                    TxtPassword.Text = "";
                    TxtUserName.Focus();
                }
                else
                {
                    //this.Hide();
                    DB.setA = TxtUserName.Text;
                    FormChangePassword FCP = new FormChangePassword();
                    FCP.Show();
                }
            }
        }

        private void BtnOK_Click(object sender, EventArgs e)
        {
           


            if (TxtUserName.Text.Trim() == "")
            {
                DialogResult = MessageBox.Show("请输入你的用户名!", "提示");
                TxtUserName.Focus();
            }
            else
            {
                if (TxtPassword.Text.Trim() == "")
                {
                    DialogResult = MessageBox.Show("请输入你的密码!", "提示");
                    TxtPassword.Focus();
                }
                else
                {
                    try
                    {
                        SqlConnection con = DB.connection();
                        con.Open();
                        SqlCommand cmd = new SqlCommand("select Password from tblEmployee where LoginName=@Password", con);
                        SqlParameter pa = cmd.Parameters.Add(new SqlParameter("@Password", SqlDbType.NVarChar, 20));
                        cmd.Parameters["@Password"].Value = TxtUserName.Text;
                        pa.Direction = ParameterDirection.Input;
                        int count = Convert.ToInt32(cmd.ExecuteScalar());
                        if (count ==0)
                        {
                            con.Close();
                            DialogResult = MessageBox.Show("对不起!\r\n该用户不存在或你不是人事部管理人员!", "郑重提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            TxtUserName.Text = "";
                            TxtPassword.Text = "";
                            TxtUserName.Focus();
                        }
                        else
                        {
                            SqlCommand cmd1 = new SqlCommand("select count(*) from tblEmployee where LoginName='" + TxtUserName.Text.ToString().Trim() + "'and Password='" + TxtPassword.Text.ToString().Trim() + "'", con);
                            int count1 = Convert.ToInt32(cmd1.ExecuteScalar());
                            if (count1 > 0)
                            {
                                con.Close();
                                DB.setA = TxtUserName.Text;
                                this.Hide();
                                Main M = new Main();
                                M.Show();
                            }
                            else
                            {
                                con.Close();
                                DialogResult = MessageBox.Show("密码不正确!", "提示");
                                //TxtUserName.Text = "";
                                TxtPassword.Text = "";
                                TxtPassword.Focus();

                            }
                        }
                    }
                    catch (Exception EV)
                    {
                        DialogResult = MessageBox.Show("未能连接到数据库,请先查看数据库是否正常!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                }
            }


        }
    }
}

⌨️ 快捷键说明

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