[c#]代码库
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Common;
using System.Data.SqlClient;
namespace Pos
{
public partial class frmMLogin : Form
{
public frmMLogin()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtLoginId.Text == "")
{
MessageBox.Show("你必须输入用户ID!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtLoginId.Focus();
return;
}
if (txtLoginPwd.Text == "")
{
MessageBox.Show("你必须输入用户密码!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtLoginPwd.Focus();
return;
}
LoginMain();
}
private void LoginMain()
{
string loginId = txtLoginId.Text.Trim();
string loginPwd = txtLoginPwd.Text;
string sql = string.Format("select * from vw_right where User_code='{0}' and User_pwd='{1}' and mod_Name='{2}'", loginId, loginPwd, "前台收银");
DataTable dt1 = SQLHelper.ExecuteDataSet(sql).Tables[0];
if ( dt1.Rows.Count > 0 )
{
PUser.UserCode = loginId;
PUser.UserPass = loginPwd;
PUser.UserName = dt1.Rows[0]["User_name"].ToString();
PUser.RoleID = dt1.Rows[0]["role_id"].ToString();
PUser.RoleName = dt1.Rows[0]["role_name"].ToString();
string sql2 = string.Format("select * from front_duty where User_code='{0}' and Duty_endTime is null", loginId);
DataTable dt2 = SQLHelper.ExecuteDataSet(sql2).Tables[0];
if (dt2.Rows.Count > 0)
{
PUser.dutyID = dt2.Rows[0]["duty_id"].ToString();
}
frmMain frm = new frmMain();
frm.Show();
this.Hide();
}
else
{
MessageBox.Show("用户名或密码出错,或者无操作权限!", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtLoginId.Focus();
return;
}
}
private void txtName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
if (txtLoginId.Text.Trim().Length > 0)
{
txtLoginPwd.Focus();
}
else
{
MessageBox.Show("你必须输入用户ID!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtLoginId.Focus();
//return;
}
}
}
private void txtPassword_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
LoginMain();
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
[代码运行效果截图]
初级程序员
by: 云代码会员 发表于:2016-08-01 12:34:47 顶(0) | 踩(0) 回复
666
回复评论