C#实现登录功能

简介:
C#实现登录功能
   
   
FrmLogin.ca文件

  
  
   
    

    
    

/* 注释Manual
* 文件功能描述只需简述,具体详情在类的注释中描述。
* 创建标识和修改标识由创建或修改人员的拼音或英文名加日期组成。如:
        
* 一天内有多个修改的只需做一个在注释说明中做一个修改标识就够了。
* 在所有的代码修改处加上修改标识的注释。
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using XEP.Business;
using XEP.Util;

namespace XEP.UI
{
         public partial class FrmLogin : Form
        {
                 private FrmNewMain frmNewMain;
                 public FrmLogin()
                {
                        InitializeComponent();
                         this.CenterToScreen();
                }

                 //tfq-7-4---------------------------
                 public FrmLogin(FrmNewMain frmNewMain)
                {
                         this.frmNewMain = frmNewMain;
                        InitializeComponent();
                         this.CenterToScreen();
                }
                 //tfq----------------------------------

                 protected void InitUI()
                {
                         this.FormBorderStyle = FormBorderStyle.None;
                         //this.BackgroundImage = new Image();

                }

                 private void btnLogin_Click( object sender, EventArgs e)
                {
                         string id = txtEMPID.Text.Trim();
                         if (id.Contains( "'")||id.Contains( "=")||id.Contains( "is")||id.Contains( "true")||id.Contains( "@"))
                        {
                                MessageBox.Show( "输入工号违法");
                                 return;
                        }
                        
                         //判断全角半角
                         if (id.Length != System.Text.Encoding.Default.GetByteCount(id))
                        {
                                MessageBox.Show( "不允许全角输入", "输入错误");
                                 return;
                        }

                         if (id =="")
                        {
                                MessageBox.Show( "输入工号");
                                 return;
                        }
                         else if(txtPWD.Text =="")
                        {
                                 if (MessageBox.Show( "密码为空,继续登录吗?") == DialogResult.No)
                                {
                                         return;
                                }
                                
                        }
                         if (EmployeeBLL.CheckEmployeePassword(id, txtPWD.Text.Trim()))
                        {
                                 //new FrmMain(id).Show();
                                 //tfq-7-03
                                GlobalProperties.ScheEmpID = id;
                                 new FrmProscenium(id,frmNewMain).Show();
                                 this.Hide();
                                 //this.Close();
                                frmNewMain.resetStateStrip();
                        }
                         else
                        {
                                MessageBox.Show( "工号密码不匹配,注意是否打开大小写锁定键了?");
                                 return; ;
                        }
                }
                
                 private void btnReset_Click( object sender, EventArgs e)
                {
                         this.txtEMPID.Text = "";
                        txtPWD.Text = "";
                }

                 private void btnExit_Click( object sender, EventArgs e)
                {
                         this.Close();
                }

                 private void txtPWD_KeyPress( object sender, KeyPressEventArgs e)
                {
                        
                }

                 private void txtPWD_Enter( object sender, EventArgs e)
                {

                }

                 private void FrmLogin_FormClosing( object sender, FormClosingEventArgs e)
                {
                        frmNewMain.Show();
                }

                 private void txtPWD_TextChanged( object sender, EventArgs e)
                {

                }

                 private void groupBox1_Enter( object sender, EventArgs e)
                {

                }
        }
}

  
  
   
    EmplyeeDAL.cs
  
  

  
  

   
   
/*----------------------------------------------------------------/
Copyright (C)    
文件名:
文件功能描述:

    
创建标识:

修改标识:
修改描述:

/----------------------------------------------------------------*/


using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Data;
using XEP.Model;

namespace XEP.DataAccess
{
         public class EmployeeDAL
        {
                 /// <summary>
                 /// 验证用户登陆信息
                 /// </summary>
                 /// <param name="empid">员工号</param>
                 /// <param name="pwd">密码(MD5加密后)</param>
                 /// <returns></returns>
                 public static bool CheckPassword( string empid, string pwd)
                {
                         string sql = string.Format( "select EmpID from employee where empid = '{0}' and password = '{1}'",empid,pwd);
                         if (DBAccess.getExecuteCount(sql) > 0)
                        {
                                 return true;
                        }
                         else
                        {
                                 return false;
                        }
                }
                 ///<summary>
                 ///通过工号获取员工姓名
                 ///</summary>
                 ///<param name="empID" >员工号</parm>
                 ///<returns>employeeName</returns>
                 public static     string FindEmployeeByID( int empID)
                {

                         string employeeName = null;
                        SqlDataReader reader = DBAccess.getDataReader( "SELECT EmpName    FROM employee WHERE empID='" +empID+ "' ");
                         if (reader.Read())
                        {
                             employeeName    =reader.GetString(0);
                        }
                        DBAccess.close();
                         return employeeName;
                }

                 public static bool IsHasRight( short empLevel, string empID)
                {
                         string selectSql = string.Format( "SELECT * FROM Discount,Employee WHERE EmpID='{0}' AND Employee.Emplevel >= {1}", empID, empLevel);
                         if (DBAccess.getExecuteCount(selectSql)> 0)
                        {
                                 return true;
                        }
                         else
                        {
                                 return false;
                        }
                }

                 public static short GetEmpLevel( string empID)
                {
                         string sql = string.Format( "select EmpLevel from employee where empid = '{0}' ", empID);
                         return Convert.ToInt16(DBAccess.selectFirstRecord(sql));
                }

                 public static double GetEmpDiscount( string empID)
                {
                         string sql = string.Format( "select EmpDiscount from employee where empid = '{0}' ", empID);
                         return Convert.ToDouble(DBAccess.selectFirstRecord(sql));
                }

                 public static string GetRightCode( string empID)
                {
                         string sql = string.Format( "select UserRightCode from employee where empid = '{0}' ", empID);
                         return Convert.ToString(DBAccess.selectFirstRecord(sql));
                }

                 //tfq-7-3
                 public static string GetEmpNameByEmpID( string empid)
                {
                         string select = "select EmpName from Employee where EmpID='" +
                                empid + "'";
                        DataTable dt = DBAccess.getDataTable(select);
                         if (dt.Rows.Count > 0)
                        {
                                 string result = dt.Rows[0][0].ToString();
                                 return result;
                        }
                         else
                        {
                                 return "";
                        }
                }

                 /// <summary>
                 /// 获得所有员工的基本信息(工号、姓名)
                 /// </summary>
                 /// <returns>所有员工的信息(工号、姓名)</returns>
                 public static List<Employee> GetEmployee()
                {
                        List<Employee> listEmployee = new List<Employee>();
                        Employee emp = null;
                         string selectSql = "SELECT EmpID,EmpName FROM Employee";
                        SqlDataReader reader = DBAccess.getDataReader(selectSql);
                         while (reader.Read())
                        {
                                emp = new Employee();
                                emp.EmpID = reader.GetString(0);
                                emp.EmpName = reader.GetString(1);
                                listEmployee.Add(emp);
                        }
                        reader.Close();
                        DBAccess.close();
                         return listEmployee;
                }
        }
}
注:
MessageBoxResult
指定用户单击了哪个消息框按钮。MessageBoxResult  Show 方法返回。
成员名称说明: 
 None 消息框未返回值。 
 OK 消息框的结果值为确定 
 Cancel 消息框的结果值为取消 
 Yes 消息框的结果值为 
 No 消息框的结果值为  
Show 返回一个 MessageBoxResult 值,该值指定用户单击了消息框上的哪个按钮。MessageBoxButton 指定消息框上显示哪些按钮。从消息框返回的结果值取决于消息框上有什么按钮,以及用户如何关闭消息框:在包含确定按钮的消息框上,如果用户单击确定按钮、单击标题栏中的关闭按钮或按 Esc 键,则会返回 OK。在包含确定按钮和取消按钮的消息框上,如果用户单击确定按钮,则会返回 OK。如果用户单击取消按钮或标题栏中的关闭按钮,则会返回 Cancel。在包含按钮和按钮的消息框上,标题栏中的关闭按钮处于禁用状态。因此,如果用户单击按钮,则会返回 Yes,如果用户单击按钮,则会返回 No。在包含按钮、按钮和取消按钮的消息框上,如果单击了按钮,则会返回 Yes,如果单击了按钮,则会返回 No。如果用户单击取消按钮或标题栏中的关闭按钮,则会返回 Cancel

  
  
   
    
  
  
System.Collections.Generic 命名空间包含定义泛型集合的接口和类,泛型集合允许用户创建强类型集合,它能提供比非泛型强类型集合更好的类型安全性和性能。
 
输入全半角检验方法:
id.Length != System.Text.Encoding.Default.GetByteCount(id) 
 
 





     本文转自 gaochaojs 51CTO博客,原文链接:http://blog.51cto.com/jncumter/222706,如需转载请自行联系原作者

相关文章
|
7月前
|
XML 测试技术 API
利用C#开发ONVIF客户端和集成RTSP播放功能
利用C#开发ONVIF客户端和集成RTSP播放功能
4259 123
|
开发框架 C# iOS开发
基于C#开源、功能强大、灵活的跨平台开发框架 - Uno Platform
基于C#开源、功能强大、灵活的跨平台开发框架 - Uno Platform
605 3
|
监控 前端开发 安全
C#一分钟浅谈:文件上传与下载功能实现
【10月更文挑战第2天】在Web应用开发中,文件的上传与下载是常见需求。本文从基础入手,详细讲解如何在C#环境下实现文件上传与下载。首先介绍前端表单设计及后端接收保存方法,使用`&lt;input type=&quot;file&quot;&gt;`与`IFormFile`接口;接着探讨错误处理与优化策略,如安全性验证和路径管理;最后讲解文件下载的基本步骤,包括确定文件位置、设置响应头及发送文件流。此外,还提供了进阶技巧,如并发处理、大文件分块上传及进度监控,帮助开发者构建更健壮的应用系统。
949 16
|
传感器 IDE 测试技术
C#一分钟浅谈:Visual Studio IDE 高级功能
【10月更文挑战第24天】本文从初学者角度介绍了 Visual Studio 的高级功能,包括安装与配置、创建项目、运行与调试、常见问题及解决方案(如代码格式化、重构、导航、单元测试、代码分析),以及智能感知、Live Unit Testing、代码生成和代码片段等高级功能,帮助开发者提高效率和代码质量。
380 1
|
开发框架 Cloud Native .NET
10 个 C# 关键字和功能
10 个 C# 关键字和功能
231 8
|
网络协议 Unix Linux
精选2款C#/.NET开源且功能强大的网络通信框架
精选2款C#/.NET开源且功能强大的网络通信框架
595 0
|
物联网 C#
【C#】简单的蓝牙通讯功能实现
【C#】简单的蓝牙通讯功能实现
988 0
|
C#
如何使用c# 实现断点续传功能
如何使用c# 实现断点续传功能
328 0
|
网络协议 C#
C#:简化版的实现断点续传功能
C#:简化版的实现断点续传功能
383 0
小功能⭐️C#控制小数点后位数的方法
小功能⭐️C#控制小数点后位数的方法