151 lines
5.1 KiB
C#
151 lines
5.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using CommonLib;
|
|
using System.Data.SqlClient;
|
|
using CommonLib.data;
|
|
using DevExpress.XtraEditors;
|
|
using Lskj.Main.main;
|
|
|
|
namespace Lskj.Main.App_Code
|
|
{
|
|
/// <summary>
|
|
/// 登录基类
|
|
/// </summary>
|
|
public partial class FrmLoginBase : FormBase
|
|
{
|
|
public bool pwdForceChange = false;
|
|
public FrmLoginBase()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void FrmLoginBase_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取软件打开模式
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
protected int GetSoftOpenMode()
|
|
{
|
|
object obj = SqlHelper.ExecuteScalar(CommandType.Text, "select SoftOpenMode from p_employeetab where EmployeeId=" + ERPInfo.Instance.EmployeeId);
|
|
if (obj != null)
|
|
{
|
|
int openMode = Convert.ToInt32(obj);
|
|
ERPInfo.Instance.SoftOpenMode = openMode;
|
|
return openMode;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 用户登录
|
|
/// </summary>
|
|
/// <param name="strEmployeeId"></param>
|
|
/// <param name="strPwd"></param>
|
|
/// <param name="strName"></param>
|
|
/// <returns></returns>
|
|
protected bool Login(string strEmployeeId, string strPwd, string strName, bool qzLogin)
|
|
{
|
|
if (strEmployeeId == string.Empty)
|
|
{
|
|
XtraMessageBox.Show("请输入用户名称!");
|
|
return false;
|
|
}
|
|
|
|
int EmployeeId = 0;
|
|
string sPwd = strPwd;
|
|
if (int.TryParse(strEmployeeId, out EmployeeId) == false)
|
|
{
|
|
XtraMessageBox.Show("操作人员数据错误请与管理员联系");
|
|
return false;
|
|
}
|
|
|
|
strPwd = PubUtil.EncryptPassword(strPwd);
|
|
|
|
try
|
|
{
|
|
|
|
if (EmployeeId == 0)
|
|
{
|
|
XtraMessageBox.Show("操作人员数据错误,请与管理员联系!");
|
|
return false;
|
|
}
|
|
|
|
//强制登陆
|
|
if (qzLogin)
|
|
{
|
|
string tmpsql = "delete from p_LoginHostInfotab where OperatorId=" + EmployeeId + "";
|
|
SqlHelper.ExecuteNonQuery(CommandType.Text, tmpsql);
|
|
}
|
|
SqlParameter[] cmdParams = new SqlParameter[]
|
|
{
|
|
new SqlParameter("@ReturnValue",SqlDbType.Int),
|
|
new SqlParameter("@operatorid",SqlDbType.Int),
|
|
new SqlParameter("@pwd",SqlDbType.VarChar,100)
|
|
};
|
|
cmdParams[0].Direction = ParameterDirection.ReturnValue;
|
|
cmdParams[1].Value = EmployeeId;
|
|
cmdParams[2].Value = strPwd;
|
|
|
|
SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "P_Login_pr", cmdParams);
|
|
int iRet = int.Parse(cmdParams[0].Value.ToString());
|
|
switch (iRet)
|
|
{
|
|
case -1:
|
|
{
|
|
XtraMessageBox.Show("登录失败!");
|
|
break;
|
|
}
|
|
case 0:
|
|
{
|
|
ERPInfo.Instance.EmployeeName = strName;
|
|
ERPInfo.Instance.OperatorName = strName;
|
|
ERPInfo.Instance.EmployeeId = EmployeeId;
|
|
//设置delphi公用库参数
|
|
ERPInfo.Instance.SetDephiDllParams();
|
|
//检测密码为空则强制设置密码
|
|
if ((sPwd == "")&&(pwdForceChange))
|
|
{
|
|
FrmChangePwd frmPwd = new FrmChangePwd();
|
|
frmPwd.loginUser = strName;
|
|
frmPwd.loginId = EmployeeId;
|
|
DialogResult dr = frmPwd.ShowDialog();
|
|
if (dr != System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
case 1:
|
|
{
|
|
XtraMessageBox.Show("密码不正确,请重新输入!");
|
|
break;
|
|
}
|
|
case 2:
|
|
{
|
|
XtraMessageBox.Show("已经有该用户登陆,请换用户登陆!");
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
PubUtil.WriteError("登录失败", ex.Message);
|
|
XtraMessageBox.Show("登陆失败!");
|
|
}
|
|
return false;
|
|
}
|
|
}
|
|
}
|