/******************************
* 说明:登录界面
* 创建人:龚宇超
* 创建日期:2017-08-08
* 修改人:
* 修改日期:
* 修改备注:
* 版本:1.0.0.0
******************************/
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 Lskj.Control.Model;
using Lskj.Business;
using Lskj.Control;
using Lskj.Data;
using Lskj.Util;
using Lskj.Core;
using Lskj.Main.Properties;
using Lskj.Model;
using DevExpress.XtraEditors.Controls;
using Lskj.Business.Impl;
using DevExpress.LookAndFeel;
using Lskj.AutoUpdate;
using System.Net;
using System.Xml;
using Lskj.Main.Model;
using System.IO;
using System.Text.RegularExpressions;
using DevExpress.XtraGrid.Columns;
using Xilium.CefGlue;
using Lskj.Control.ZKFinger;
using libzkfpcsharp;
using System.Reflection;
using System.Diagnostics;
using static Lskj.Control.Model.StaticControl;
using System.Runtime.InteropServices;
namespace Lskj.Main
{
///
/// 登录界面
///
public partial class FrmLogin : Form
{
private bool isLoginByAd = false;
private string m_UpdateIP = "";
private byte[] g_KeyValue = { 212, 61, 139, 3, 54, 70, 213, 254 };
///
/// 是否鼠标按下
///
private bool _isMouseDown;
public bool isLoginFinger = false;
System.Threading.Thread captureThread;
///
/// 记录窗口位置
///
private Point _mousePostion;
private DataTable _ledgerTable;
private DataTable _userTable;
Regex regex = new Regex(@"(?=.*[0-9]) #必须包含数字
(?=.*[a-zA-Z]) #必须包含小写或大写字母
(?=.*[^a-zA-Z0-9]) #必须包含符号
.{8,18} #至少8个字符,最多18个字符
", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
private bool isPlaintextPwd;
private string DisplayName = "UserName";
public FrmLogin()
{
InitializeComponent();
//启动时自动更新
if (SystemInfo.Instance.UpdateAtStartup && !string.IsNullOrWhiteSpace(SystemInfo.Instance.UpdateAddress))
{
WaitForm.ShowForm(ResourceKeys.AutoUpdating);
this.StartAutoUpdate();
}
}
#region 方法相关
///
/// 说明:登陆时验证信息
/// 创建人:王一帆
/// 创建日期:2020-12-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private int XlValid()
{
int Rtn = 0;
try
{
DataRow dr = BaseImpl.GetVeriSystemTab();
if (dr != null)
{
ERPInfo.Instance.ClientName = dr["ClientName"].ToString() + " (注:软件维护截止时间:2020-9-21)";
ERPInfo.Instance.bSmartClientIsOK = dr["hasCommunicationClient"].ToString() == "1";
m_UpdateIP = dr["UpdateIP"].ToString().Trim();
ERPInfo.Instance.SkinName = dr["SkinPath"].ToString();
//在这用线程检测路径是否正确,不能阻塞主程序流程
if (m_UpdateIP != string.Empty)
{
ThreadFun dd = new ThreadFun(CheckDirectoryExist);
ThreadHelper.AddProcedure(dd);
}
if (dr["coid"].ToString() == "9090")
{
if (DateTime.Now < DateTime.Parse("2014-12-01"))
return Rtn;
}
string ValidateCodeE = "", ValidateCodeT = "";
int CodeELen = 0, CodeTLen = 0;
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
if (DelphiHelper.GetValidateCode(ref sb1, ref CodeELen, ref sb2, ref CodeTLen) == false)
throw new Exception("");
ValidateCodeE = sb1.ToString().Substring(0, CodeELen);//jY3vY7lfEs8=
sb1.Clear();
sb1.Append(ValidateCodeE);
ValidateCodeT = sb2.ToString().Substring(0, CodeTLen);//k3b5LNPzWeIK4gqggtYZ1A==
sb2.Clear();
sb2.Append(ValidateCodeT);
string GclientName = dr["clientname"].ToString();
int Gtagid = int.Parse(dr["UserTagid"].ToString());
if (Gtagid == 1)
{
string Guserid = Publentry.XGetDate(new StringBuilder().Append(Publentry.Decrypt_Des(sb1, g_KeyValue)));
//FindPassWord(Guserid, "", "");
}
else
{
string endstr = Publentry.XGetDate(new StringBuilder(Publentry.Decrypt_Des(sb1, g_KeyValue)));
ERPInfo.Instance.ClientName = dr["ClientName"].ToString() + " (注:软件维护截止时间:" + endstr + ")";
if (DateTime.Parse(Publentry.XGetDate(new StringBuilder(Publentry.Decrypt_Des(sb1, g_KeyValue)))) < DateTime.Now)
{
Rtn = 1;
MessageUtil.Show("软件已经达到的最后期限请与朗速软件联系!");
return 1;
//Publentry.XGetDate(new StringBuilder(Publentry.Decrypt_Des(sb1, g_KeyValue))) "2099-12-31" string
}
string GEndDate = Publentry.Decrypt_Des(sb2, g_KeyValue);
if (DateTime.Parse(GEndDate) < DateTime.Now)
{
Rtn = 1;
MessageUtil.Show("软件已过期请与朗速软件公司联系");
return 1;
}
if (DateTime.Parse(GEndDate) < DateTime.Now.AddDays(7))
{
TimeSpan ts = DateTime.Parse(GEndDate) - DateTime.Now;
MessageUtil.Show("你软件维护周期时间还剩 " + ts.ToString() + " 天,请速与管理员联系");
return 1;
}
}
}
else
{
Rtn = 5;
MessageBox.Show("软件数据被人为破坏导致软件不能正常运行请与朗速软件公司联系");
}
}
catch (Exception ex)
{
Rtn = 1;
MessageBox.Show("软件数据破坏,请与朗速软件公司联系" + ex.Message);
}
return Rtn;
}
///
/// 说明:在这用线程检测路径是否正确,不能阻塞主程序流程
/// 创建人:王一帆
/// 创建日期:2020-12-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void CheckDirectoryExist()
{
string strDir = "\\\\" + m_UpdateIP + "\\update";
if (Directory.Exists(strDir))
ERPInfo.Instance.UpdateIP = m_UpdateIP;
}
///
/// 说明:设置帐套信息
/// 创建人:龚宇超
/// 创建日期:2017-08-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetLedgers()
{
// 获取帐套信息
try
{
_ledgerTable = MainImpl.GetLedgerList();
cbLedger.Properties.Items.Clear();
if (_ledgerTable.Rows.Count > 0)
{
foreach (DataRow item in _ledgerTable.Rows)
{
cbLedger.Properties.Items.Add(item["ShowName"]);
}
if (!string.IsNullOrEmpty(DBConfig.Instance.DataBase))
{
DataRow ledRow = _ledgerTable.Rows.Cast().FirstOrDefault(x => DBConfig.Instance.DataBase.Equals(x["DBname"] + ""));
cbLedger.Text = ledRow != null ? ledRow["ShowName"] + "" : _ledgerTable.Rows[0]["ShowName"] + "";
}
else
if (!string.IsNullOrEmpty(DBConfig.Instance.DataBook))//数据库连接参数配置类的帐套
{
DataRow ledRow = _ledgerTable.Rows.Cast().FirstOrDefault(x => DBConfig.Instance.DataBook.Equals(x["ShowName"] + ""));
cbLedger.Text = ledRow != null ? ledRow["ShowName"] + "" : _ledgerTable.Rows[0]["ShowName"] + "";
}
else
{
cbLedger.Text = _ledgerTable.Rows[0]["ShowName"] + "";
}
//this.StartLedger(cbLedger.EditValue + "");
}
else
{
cbLedger.Enabled = false;
}
}
catch (Exception)
{
}
}
///
/// 说明:设置系统用户
/// 创建人:龚宇超
/// 创建日期:2017-08-09
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetUsers()
{
string arg = string.Empty;
if (this.language.Visible)
{
BaseImpl.HasExistsColumn("P_EmployeeTab", "useLanguage", "nvarchar(50)");
arg = " ,useLanguage";
}
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.LoginUsername)&& BaseImpl.HasExistsColumn("P_EmployeeTab", SystemInfo.Instance.LoginUsername))
{
this.DisplayName= SystemInfo.Instance.LoginUsername;
arg+= " ,"+ this.DisplayName;
}
//if (BaseImpl.HasExistsColumn("P_EmployeeTab", "DefaultLedger"))
// arg += ",DefaultLedger";
BaseImpl.HasExistsColumn("P_SystemTab", "LoginPopupFlag", "int");
lueUserName.Focus();
lueUserName.ValueField = lueUserName.ValueMember = "UserId";
lueUserName.TextMember = this.DisplayName;
lueUserName.SourceSQL = string.Format("select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName {0} from P_EmployeeTab WHERE sign=0 and UseFlag=1", arg);
if (SystemInfo.Instance.DisplayUserCode)
{
lueUserName.SourceSQL = string.Format("select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName, LoginAccount 工号 {0} from P_EmployeeTab WHERE sign=0 and UseFlag=1", arg);
_userTable = MainImpl.GetEmployeeListNew();
}
else
{
_userTable = MainImpl.GetEmployeeList();
}
lueUserName.DataSource = _userTable;
lueUserName.AutoShowPopup = "1".Equals(BaseImpl.GetResult("SELECT LoginPopupFlag FROM P_SystemTab") + "");
DataRow[] rowItems = _userTable.Select(" "+ DisplayName + " = '" + DBConfig.Instance.LoginName + "'");
DataRow[] rowItemsUserCode = _userTable.Select(" UserCode = '" + DBConfig.Instance.LoginName + "'");
if (rowItems != null && rowItems.Length > 0)
{
lueUserName.EditValue = rowItems[0][lueUserName.ValueField] + "";
StateFlushed();
}
else if (rowItemsUserCode != null && rowItemsUserCode.Length > 0)
{
lueUserName.Text = DBConfig.Instance.LoginName;
StateFlushed();
}
else if (_userTable.Columns.Contains("AD_Id") && !string.IsNullOrEmpty(DBConfig.Instance.LoginName))
{
rowItems = _userTable.Select(" AD_Id = '" + DBConfig.Instance.LoginName + "'");
if (rowItems != null && rowItems.Length > 0)
{
lueUserName.Text = rowItems[0]["AD_Id"] + "";
StateFlushed();
}
}
}
///
/// 说明:设置delphi参数
/// 创建人:龚宇超
/// 创建日期:2018-03-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void SetDelphiDllParams()
{
try
{
StringBuilder sb1 = new StringBuilder();
sb1.Append(ERPInfo.Instance.UserName);
StringBuilder sb2 = new StringBuilder();
sb2.Append(ERPInfo.Instance.WindowName);
StringBuilder sb3 = new StringBuilder();
sb3.Append(ERPInfo.Instance.SkinName);
//给delphi库设置参数(用户id、子系统id、操作员名称、计算机名称)
DelphiHelper.Delphi_SetParams(Convert.ToInt32(ERPInfo.Instance.UserId), Convert.ToInt32(ERPInfo.Instance.SubSysId), sb1, sb2, sb3);
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
LogHelper.Instance.WriteError(ex);
//LogUtil.WriteError("设置delphi参数错误", ex);
}
}
///
/// 说明:启动自动更新
/// 创建人:龚宇超
/// 创建日期:2018-02-23
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void StartAutoUpdate()
{
if (string.IsNullOrEmpty(SystemInfo.Instance.UpdateAddress))
{
MessageUtil.Show(ResourceKeys.UpdateAddressIsNull);
return;
}
string verDesp = string.Empty;
if (BaseImpl.HasExistsTable("p_ErpProUpdateInfo"))
{
string sqlValue = "select top 1 verDesp from p_ErpProUpdateInfo order by updateDate desc";
verDesp = SqlHelper.ExecuteString("verDesp", sqlValue);
}
bool isUpdateSucess = false;
IAutoUpdater updater = new AutoUpdater(SystemInfo.Instance.UpdateAddress, true,false, verDesp);
try
{
updater.Update();
isUpdateSucess = true;
}
catch (WebException ex)
{
MessageUtil.Show(ResourceKeys.ServerConnectionFault + "\r\n" + ex);
}
catch (XmlException ex)
{
MessageUtil.Show(ResourceKeys.DownLoadUpdateXmlFault + "\r\n" + ex);
}
catch (NotSupportedException ex)
{
MessageUtil.Show(ResourceKeys.UpdateXmlSettingFault + "\r\n" + ex);
}
catch (ArgumentException ex)
{
MessageUtil.Show(ResourceKeys.DownLoadUpdateFileFault + "\r\n" + ex);
}
catch (Exception ex)
{
MessageUtil.Show(ResourceKeys.UpdateError + "\r\n" + ex);
LogHelper.Instance.WriteError(ex);
LogUtil.WriteError("更新失败!", ex);
}
finally
{
if (!isUpdateSucess)
{
try
{
updater.RollBack();
}
catch (Exception)
{
}
}
}
}
///
/// 说明:启动小平台
/// 创建人:龚宇超
/// 创建日期:2018-02-23
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void StartSmallClient()
{
try
{
if (File.Exists(PubUtil.AbsolutelySmallClientPath))
{
//WinHelper.WinExec(PubUtil.AbsolutelySmallClientPath + " " + ERPInfo.Instance.UserId + " " + ERPInfo.Instance.Password);
string[] args = new string[2];
args[0] = ERPInfo.Instance.UserId;
args[1] = ERPInfo.Instance.Password;
WinHelper.StartProcess(PubUtil.AbsolutelySmallClientPath, args);
}
else
{
MessageUtil.Show(this.chkClient.Text + ResourceKeys.FileNotFound);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:开始登录
/// 创建人:龚宇超
/// 创建日期:2018-03-05
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private bool StartLogin()
{
bool isLoginSucess = false;
string userId = lueUserName.EditValue + "";
string userName = lueUserName.Text.Trim();
string password = txtPassword.Text.Trim();
string LoginAccount = string.Empty;
string ErrorLogText = string.Empty;//日志记录信息
// 设置登录用户信息
bool isConstraint = chkLogin.Checked;
if (string.IsNullOrWhiteSpace(userName))
{
MessageUtil.Show(ResourceKeys.UserNameNotNull);
return isLoginSucess;
}
try
{
// 默认有可能有空
DataTable table = MainImpl.GetEmployeeList();//获取员工信息存到表中
WaitForm.ShowForm(ResourceKeys.Logining);//验证登录后的加载框上输出的信息
#region Ad域判断打开
BaseResponse responseinfo = new BaseResponse();
int loginResult = 0;
bool isAd = false;
if (LoginByAD(lueUserName.Text, password, ref responseinfo))
{
DataTable dataTable = SqlHelper.ExecuteDataTable(string.Format("EXEC[P_Login_pr] '','','{0}','',5", lueUserName.Text));
if (dataTable.Rows.Count > 0)
{
userId = dataTable.Rows[0]["employeeid"] + "";
DataRow[] datas = table.Select("UserId=" + userId);//找到userId为当前的用户
if (datas.Count() > 0)
{
//ad域登录成功,就记录当前输入的账号密码,后面替换后的不记录
IniHelper.Write(DBConfig.Instance.ServerName + lueUserName.Text, AESUtil.Encrypt(chkRemPwd.Checked + "^" + password));
isAd = true;
DataRow data = datas[0];
userId = data["UserId"] + "";
userName = data["UserName"] + "";
LoginAccount = data["UserCode"] + "";
password = data["Password"] + "";
ERPInfo.Instance.LoginResult = true;
isLoginByAd = true;
}
}
else
{
MessageUtil.Show("无对应的ad域关联数据");
return isLoginSucess;
}
}
else
{
if (!string.IsNullOrEmpty(responseinfo.msg))
{
MessageUtil.Show(responseinfo.msg);
return isLoginSucess;
}
DataRow[] drRows = table.Select(""+DisplayName+"='" + userName + "' or UserCode='" + userName + "'");//找到所有UserNAme或UserCode为xxx的用户
if ((drRows == null) || (drRows.Count() < 1))
{
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
return isLoginSucess;
}
//找到多个操作员
if (drRows.Count() > 1)
{
MessageUtil.Show(ResourceKeys.DuplicatedNameError);
return isLoginSucess;
}
DataRow drRow = drRows[0];
//DataRow drRow = table.Rows.Cast().FirstOrDefault(x => userName.Equals(x["UserName"] + ""));
if (drRow != null)
{
userId = drRow["UserId"] + "";
userName = drRow["UserName"] + "";
LoginAccount = drRow["UserCode"] + "";
}
else
{
userId = "";
}
if (string.IsNullOrWhiteSpace(userId))
{
MessageUtil.Show(ResourceKeys.UserNotFound);
return isLoginSucess;
}
//检查软件有效性
//if (XlValid() != 0)
//{
// ERPInfo.Instance.LoginResult = false;
// MessageUtil.Show("检查软件有效性失败.");
// Application.Exit();
// return false;
//}
ERPInfo.Instance.LoginResult = true;
// 检查Mac地址
if (SystemInfo.Instance.MacEnabled)
{
int result = MainImpl.CheckMacAddress(ERPInfo.Instance.MacAddress, userId);
MainImpl.LoginAfterRegister(ERPInfo.Instance.MacAddress, userId);
if (result == 0)
{
MessageUtil.Show(ResourceKeys.LoginFault + ResourceKeys.UnKownMacAddress);
return isLoginSucess;
}
if (result == -1)
{
MessageUtil.Show(ResourceKeys.LoginFault + ResourceKeys.UnKownMacAddressTable);
return isLoginSucess;
}
}
if (SystemInfo.Instance.IsEncrypt)
{
int[] keyHandles = ERPInfo.Instance.keyHandles = new int[8];
int[] keyNumber = ERPInfo.Instance.keyNumber = new int[8];
string appId = DBConfig.Instance.ServerName;
int frtn = SmartX1Api.SmartX1Find(appId, keyHandles, keyNumber);
int keyHandle = ERPInfo.Instance.keyHandles[0];
int uPin1 = Convert.ToInt32("0x987F6BCD", 16);
int uPin2 = Convert.ToInt32("0xE193C5B2", 16);
int uPin3 = Convert.ToInt32("0xD507CC28", 16);
int uPin4 = Convert.ToInt32("0x4B125AF6", 16);
int rtn = SmartX1Api.SmartX1Open(keyHandle, uPin1, uPin2, uPin3, uPin4);
if (rtn == 0)
{
//string writeKey = string.Format("{0}_{1}", DBConfig.Instance.ServerName, DBConfig.Instance.DataBase);
//int length = 256;
//byte[] readBuffer = new byte[length];
//int readRtn = SmartX1Api.SmartX1ReadPage(keyHandle, 1, 0, ref length, readBuffer);
//if (readRtn == 0)
//{
// Dictionary readKeysValues = new Dictionary();
// string readVerifyStr = Encoding.Default.GetString(readBuffer);
// string[] readVerifyStrArray = readVerifyStr.Replace("\0", "").Split(';');//获取多个账套设置
// foreach (string readVerify in readVerifyStrArray)
// {
// string[] readKeyValue = readVerify.Split('^');//获取单个账套
// if (readKeyValue.Length == 2)
// {
// readKeysValues.Add(readKeyValue[0], readKeyValue[1]);
// }
// }
// if (readKeysValues.ContainsKey(writeKey))//如果存在当前账套
// {
// string[] verifyArray = readKeysValues[writeKey].Split('^');
// if (!verifyArray.Contains(userId))
// {
// MessageUtil.Show("当前人员未拥有登录权限");
// return false;
// }
// }
// else
// {
// MessageUtil.Show("当前人员未拥有登录权限");
// return false;
// }
//}
//else
//{
// MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
// return false;
//}
}
else
{
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
return false;
}
}
// 判断mac地址
if (!MainImpl.CheckingMacAddress(userId))
{
MessageUtil.Show(ResourceKeys.MacAddressError + ",当前地址:" + ERPInfo.Instance.MacAddress);
System.Windows.Forms.Clipboard.SetText(ERPInfo.Instance.MacAddress);
return false;
}
loginResult = MainImpl.Login(userId, password, isConstraint);
}
#endregion
switch (loginResult)
{
case 0://登录成功
//记录登录人员macAdress
if (!MainImpl.HasExistsColumn("p_employeetab", "MacAdress"))
{
BaseImpl.ExecSqlValue("alter table p_employeetab add MacAdress varchar(100)");
}
BaseImpl.ExecSqlValue(string.Format("update p_employeetab set MacAdress = '{0}' where employeeid='{1}'", ERPInfo.Instance.MacAddress, userId));
if (!MainImpl.HasExistsColumn("p_employeetab", "ClientIp"))
{
BaseImpl.ExecSqlValue("alter table p_employeetab add ClientIp varchar(100)");
}
BaseImpl.ExecSqlValue(string.Format("update p_employeetab set ClientIp = '{0}' where employeeid='{1}'", ERPInfo.Instance.LoginIPV4, userId));
//更改系统日期格式
if (SystemInfo.Instance.AutoSystemDataFormat)
{
FormatSystemDatetime formatSystemDatetime = new FormatSystemDatetime();
formatSystemDatetime.SetDateTimeFormat();
}
// 设置皮肤
string skinName = MainImpl.GetUserSkin(userId);
skinName = string.IsNullOrEmpty(skinName) ? ERPInfo.Instance.SkinName : skinName;
UserLookAndFeel.Default.SetSkinStyle(skinName);
if (!isAd)
{
//2025-02-20 改成存输入的名字(工号),避免重名的问题
IniHelper.Write(DBConfig.Instance.ServerName + lueUserName.Text, AESUtil.Encrypt(chkRemPwd.Checked + "^" + password));
}
//设置登录人电话
string phone = MainImpl.GetUserPhone(userId);
ERPInfo.Instance.SeriesId = SystemInfo.Instance.seriesid;
ERPInfo.Instance.UserLinkPhone = phone;
ERPInfo.Instance.UserId = userId;
ERPInfo.Instance.UserName = userName;
ERPInfo.Instance.Password = isLoginByAd ? password : SHAHelper.EncryptPassword(password);
ERPInfo.Instance.SkinName = skinName;
ERPInfo.Instance.AccountBook = cbLedger.Text;
ERPInfo.Instance.LoginAccount = LoginAccount;
ERPInfo.Instance.InPassWord = password;
ERPInfo.Instance.PrimitiveBrowser = SystemInfo.Instance.PrimitiveBrowser;
if (BaseImpl.HasExistsColumn("p_formmenuconfigtab", "SingleOpenMode")) ERPInfo.Instance.SingleOpenMode = true;
DBConfig.Instance.LoginName = isLoginByAd ? lueUserName.Text.Trim() : lueUserName.Text;
DBConfig.Instance.NoticeUserID = userId;
DBConfig.Instance.NoticeUserName = userName;
DBConfig.Instance.NoticeClient = chkNotice.Checked;
DBConfig.Instance.UpdateSet = chkUpdate.Checked;
DBConfig.Instance.SmallClient = chkClient.Checked;
DBConfig.Instance.DataBook = cbLedger.Text;
DBConfig.Instance.WriteConfig();
if (userName.Equals("管理员") && !string.IsNullOrWhiteSpace(ERPInfo.Instance.LoginAccount) && !isAd)
{
ERPInfo.Instance.Password = SqlHelper.ExecuteString("Password", "select Password from P_EmployeeTab where LoginAccount='" + ERPInfo.Instance.LoginAccount + "'");
//ERPInfo.Instance.Password = password;
}
ERPInfo.Instance.LanguageName = this.language.Text;
LanguageTranslation.GetLanguageComparisonTable();//获取翻译表数据
if (!string.IsNullOrWhiteSpace(ERPInfo.Instance.LanguageName) && !ERPInfo.Instance.LanguageName.Equals("中文"))
{
Localizer.Active = new XtraLocalizer();
DevExpress.XtraGrid.Localization.GridLocalizer.Active = new XtraGridLocalizer();
}
this.SetDelphiDllParams(); // 设置调用delphi参数
bool isStartMain = true;
bool isVerfyPassword = SystemInfo.Instance.VerfyPasswordStrength ? !regex.IsMatch(password) : false;
if ((SystemInfo.Instance.ForceUpdatePassword && (string.IsNullOrEmpty(password) || password.Equals("123456"))) || isVerfyPassword)
{
// 弹出修改密码窗口
FrmPassword frmPassword = new FrmPassword();
frmPassword.UserId = userId;
frmPassword.UserName = userName;
DialogResult result = frmPassword.ShowDialog();
isStartMain = result == DialogResult.OK;
}
//清空临时文件
PubUtil.ClearFilesInDirectory(PubUtil.ImageDownloadPath);
if (isStartMain)
{
// 检查自动升级
if (chkUpdate.Checked && !SystemInfo.Instance.UpdateAtStartup)
{
WaitForm.ShowForm(ResourceKeys.AutoUpdating);
this.StartAutoUpdate();
}
// 启动小平台
if (chkClient.Checked)
{
this.StartSmallClient();
}
// 启动消息通知平台
if (chkNotice.Checked)
{
this.StartNotice();
}
//加载外部exe
if (!string.IsNullOrEmpty(SystemInfo.Instance.IsLoadExe))
{
//LoadExe();
//System.Threading.Thread thread = new System.Threading.Thread(LoadExe);
//thread.Start();
}
this.DialogResult = DialogResult.OK;
//记录登录日志
LogUtil.WriteDebug("", "登录软件", "进入操作", "系统登录");
this.Close();
isLoginSucess = true;
}
break;
case 1: // 密码不正确
ErrorLogText = string.Format("登录用户Id:{0}\r\n登录用户名称:{1}\r\n输入密码:{2}", userId, userName, password);
LogUtil.WriteDebug("", "登录失败", ErrorLogText, "");
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
break;
case 2: // 已有此用户登录
MessageUtil.Show(ResourceKeys.AlreadyLogin);
break;
case -2:
MessageUtil.Show(ResourceKeys.MultiFailedLogin);
break;
case -1: // 登录失败
default:
//ErrorLogText = string.Format("登录用户Id:{0}\r\n登录用户名称:{1}\r\n输入密码:{2}", userId, userName, password);
//LogUtil.WriteDebug("", "登录失败", ErrorLogText, "");
MessageUtil.Show(ResourceKeys.LoginFault);
break;
}
}
catch (Exception ex)
{
MessageUtil.Show(ResourceKeys.LoginFault + "\r\n" + ex.Message);
LogUtil.WriteError(ResourceKeys.UserLogin, ex);
}
finally
{
WaitForm.HideForm();
}
return isLoginSucess;
}
private bool StartLoginByFinger(string userId)
{
bool isLoginSucess = false;
string LoginAccount = string.Empty;
string userName = "";
string password = "";
// 设置登录用户信息
bool isConstraint = chkLogin.Checked;
try
{
// 默认有可能有空
DataTable table = MainImpl.GetEmployeeList();//获取员工信息存到表中
WaitForm.ShowForm(ResourceKeys.Logining);//验证登录后的加载框上输出的信息
BaseResponse responseinfo = new BaseResponse();
int loginResult = 0;
if (!string.IsNullOrEmpty(responseinfo.msg))
{
MessageUtil.Show(responseinfo.msg);
return isLoginSucess;
}
DataRow[] drRows = table.Select("UserId='" + userId + "'");
if ((drRows == null) || (drRows.Count() < 1))
{
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
return isLoginSucess;
}
//找到多个操作员
if (drRows.Count() > 1)
{
MessageUtil.Show(ResourceKeys.DuplicatedNameError);
return isLoginSucess;
}
DataRow drRow = drRows[0];
//DataRow drRow = table.Rows.Cast().FirstOrDefault(x => userName.Equals(x["UserName"] + ""));
if (drRow != null)
{
userId = drRow["UserId"] + "";
userName = drRow["UserName"] + "";
password = drRow["Password"] + "";
LoginAccount = drRow["UserCode"] + "";
}
else
{
userId = "";
}
if (string.IsNullOrWhiteSpace(userId))
{
MessageUtil.Show(ResourceKeys.UserNotFound);
return isLoginSucess;
}
//检查软件有效性
//if (XlValid() != 0)
//{
// ERPInfo.Instance.LoginResult = false;
// MessageUtil.Show("检查软件有效性失败.");
// Application.Exit();
// return false;
//}
ERPInfo.Instance.LoginResult = true;
// 检查Mac地址
if (SystemInfo.Instance.MacEnabled)
{
int result = MainImpl.CheckMacAddress(ERPInfo.Instance.MacAddress, userId);
MainImpl.LoginAfterRegister(ERPInfo.Instance.MacAddress, userId);
if (result == 0)
{
MessageUtil.Show(ResourceKeys.LoginFault + ResourceKeys.UnKownMacAddress);
return isLoginSucess;
}
if (result == -1)
{
MessageUtil.Show(ResourceKeys.LoginFault + ResourceKeys.UnKownMacAddressTable);
return isLoginSucess;
}
}
loginResult = 0;
switch (loginResult)
{
case 0: // 登录成功
//更改系统日期格式
if (SystemInfo.Instance.AutoSystemDataFormat)
{
FormatSystemDatetime formatSystemDatetime = new FormatSystemDatetime();
formatSystemDatetime.SetDateTimeFormat();
}
// 设置皮肤
string skinName = MainImpl.GetUserSkin(userId);
skinName = string.IsNullOrEmpty(skinName) ? ERPInfo.Instance.SkinName : skinName;
UserLookAndFeel.Default.SetSkinStyle(skinName);
//IniHelper.Write(DBConfig.Instance.ServerName + userName, AESUtil.Encrypt(chkRemPwd.Checked + "^" + password));
//设置登录人电话
string phone = MainImpl.GetUserPhone(userId);
ERPInfo.Instance.UserLinkPhone = phone;
ERPInfo.Instance.UserId = userId;
ERPInfo.Instance.UserName = userName;
ERPInfo.Instance.Password = password;
ERPInfo.Instance.SkinName = skinName;
ERPInfo.Instance.AccountBook = cbLedger.Text;
ERPInfo.Instance.LoginAccount = LoginAccount;
ERPInfo.Instance.InPassWord = AESUtil.Decrypt(password);
ERPInfo.Instance.PrimitiveBrowser = SystemInfo.Instance.PrimitiveBrowser;
DBConfig.Instance.LoginName = isLoginByAd ? "" : userName;
DBConfig.Instance.NoticeUserID = userId;
DBConfig.Instance.NoticeUserName = userName;
DBConfig.Instance.NoticeClient = chkNotice.Checked;
DBConfig.Instance.UpdateSet = chkUpdate.Checked;
DBConfig.Instance.SmallClient = chkClient.Checked;
DBConfig.Instance.DataBook = cbLedger.Text;
DBConfig.Instance.WriteConfig();
if (userName.Equals("管理员") && !string.IsNullOrWhiteSpace(ERPInfo.Instance.LoginAccount))
{
password = SqlHelper.ExecuteString("Password", "select Password from P_EmployeeTab where LoginAccount='" + ERPInfo.Instance.LoginAccount + "'");
ERPInfo.Instance.Password = password;
}
ERPInfo.Instance.LanguageName = this.language.Text;
LanguageTranslation.GetLanguageComparisonTable();//获取翻译表数据
this.SetDelphiDllParams(); // 设置调用delphi参数
bool isStartMain = true;
bool isVerfyPassword = SystemInfo.Instance.VerfyPasswordStrength ? !regex.IsMatch(password) : false;
if ((SystemInfo.Instance.ForceUpdatePassword && (string.IsNullOrEmpty(password) || password.Equals("123456"))) || isVerfyPassword)
{
// 弹出修改密码窗口
FrmPassword frmPassword = new FrmPassword();
frmPassword.UserId = userId;
frmPassword.UserName = userName;
DialogResult result = frmPassword.ShowDialog();
isStartMain = result == DialogResult.OK;
}
if (isStartMain)
{
// 检查自动升级
if (chkUpdate.Checked && !SystemInfo.Instance.UpdateAtStartup)
{
WaitForm.ShowForm(ResourceKeys.AutoUpdating);
this.StartAutoUpdate();
}
// 启动小平台
if (chkClient.Checked)
{
this.StartSmallClient();
}
// 启动消息通知平台
if (chkNotice.Checked)
{
this.StartNotice();
}
this.DialogResult = DialogResult.OK;
//记录登录日志
LogUtil.WriteDebug("", "登录软件", "进入操作", "系统登录");
this.Close();
isLoginSucess = true;
}
break;
case 1: // 密码不正确
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
break;
case 2: // 已有此用户登录
MessageUtil.Show(ResourceKeys.AlreadyLogin);
break;
case -1: // 登录失败
default:
MessageUtil.Show(ResourceKeys.LoginFault);
break;
}
}
catch (Exception ex)
{
MessageUtil.Show(ResourceKeys.LoginFault + "\r\n" + ex.Message);
LogUtil.WriteError(ResourceKeys.UserLogin, ex);
}
finally
{
WaitForm.HideForm();
}
return isLoginSucess;
}
///
/// 使用AD域登录
/// 创建日期:2023-3-30
/// 修改人:王一帆
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
///
private bool LoginByAD(string LoginAccount, string Pwd, ref BaseResponse responseinfo)
{
if (ADUtil.ADLogin == null)
{
ADUtil.ADLogin = SystemInfo.Instance.adlogin;
ADUtil.ADPath = SystemInfo.Instance.ADPath;
ADUtil.ADUser = SystemInfo.Instance.ADUser;
ADUtil.ADPwd = SystemInfo.Instance.ADPwd;
if (string.IsNullOrEmpty(ADUtil.ADPath))
{
//responseinfo.msg = "AD域配置不正确,请检查!";
return false;
}
}
if (ADUtil.ADLogin == true)
{
LoginResult result = ADUtil.LoginByAccount(LoginAccount, Pwd);
responseinfo.success = true;
if (result != LoginResult.LOGIN_USER_OK)
{
responseinfo.success = false;
switch (result)
{
case LoginResult.LOGIN_USER_ACCOUNT_INACTIVE: responseinfo.msg = "登录失败,用户账号被禁用!"; break;
case LoginResult.LOGIN_USER_PASSWORD_INCORRECT: responseinfo.msg = "登录失败,用户密码不正确!"; break;
case LoginResult.LOGIN_USER_DOESNT_EXIST: responseinfo.msg = "登录失败,用户不存在!"; break;
}
return false;
}
return true;
}
return false;
}
///
/// 说明:打开消息通知
/// 创建人:龚宇超
/// 创建日期:
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
private void StartNotice()
{
FormHelper.StartProcess("Ls_Notice", new string[] { ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, ERPInfo.Instance.Password });
}
///
/// 说明:帐套
/// 创建人:龚宇超
/// 创建日期:2019-11-11
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// Name of the type.
private void StartLedger(string ledgerValue)
{
DataRow focusRow = _ledgerTable.Rows.Cast().FirstOrDefault(x => ledgerValue.Equals(x["ShowName"] + ""));
if (focusRow != null)
{
string serverIP = focusRow["IP"] + "";
string dbName = focusRow["DBName"] + "";
string dataBook = focusRow["ShowName"] + "";
if (string.IsNullOrWhiteSpace(serverIP) || string.IsNullOrWhiteSpace(dbName))
{
MessageUtil.Show(ResourceKeys.UnSetServerAddress);
return;
}
else
{
DBConfig.Instance.DataBook = dataBook;
DBConfig.Instance.ServerName = serverIP;
DBConfig.Instance.DataBase = dbName;
if (!DBConfig.Instance.CreateConnection(DBConfig.Instance.Connection))
{
MessageUtil.Show(ResourceKeys.ServerAddressFault);
return;
}
else
{
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection(DBConfig.Instance.dephiConnection))) == 0)
{
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
return;
}
ERPInfo.Instance.AccountBook = ResourceKeys.CurrentAccountBook + ledgerValue;
SystemInfo.RefreshSystemParam();
this.SetLanguage();
this.SetUsers();
}
}
}
}
#endregion
#region 事件相关
///
/// 说明:登录界面加载时
/// 创建人:龚宇超
/// 创建日期:2017-08-08
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnLoginLoad(object sender, EventArgs e)
{
try
{
string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.ini");
if (File.Exists(file))
{
string configFlag = IniHelper.Read("SystemResources.ini", "FrmConfigFlag");
if (configFlag.Equals("1"))
this.btnSetConfig.Text = "服务器直连";
else
this.btnSetConfig.Text = "数据库连接";
}
else
{
this.btnSetConfig.Text = "数据库连接";
File.Create(file);
}
BaseImpl.HasExistsColumn("P_SystemTab", "BsAttachFlag", "int default(0)");
this.chkUpdate.Checked = DBConfig.Instance.UpdateSet;
this.chkClient.Checked = DBConfig.Instance.SmallClient;
this.chkNotice.Checked = DBConfig.Instance.NoticeClient;
if (SystemInfo.Instance.AllowForgetPwd)
{
this.forgetPwd.Visible = true;//允许修改密码
}
if (SystemInfo.Instance.ViewPwd)
{
this.checkPwd.Visible = true;//查看密码明文
}
if (SystemInfo.Instance.AutomaticUpdates)
{
this.chkUpdate.Checked = true;
this.chkUpdate.Enabled = false;//启用自动更新禁止修改
}
if (SystemInfo.Instance.AutoCheckedNotice)
{
this.chkNotice.Checked = true;
}
if (SystemInfo.Instance.StartMessageBox)
{
this.chkNotice.Checked = true;
this.chkNotice.Enabled = false;//消息通知禁止修改
}
if (SystemInfo.Instance.DisableRememberPassword)
{
this.chkRemPwd.Checked = false;//记住密码取消勾选
this.chkRemPwd.Enabled = false;//记住密码禁止修改
}
if (SystemInfo.Instance.HiddenIntelligentClient || SystemInfo.Instance.HiddenNotification || SystemInfo.Instance.HiddenServerSetting)
{
List controls = new List();
//隐藏 智能客户端
if (SystemInfo.Instance.HiddenIntelligentClient)
{
this.chkClient.Visible = false;
}
//隐藏 消息通知
if (SystemInfo.Instance.HiddenNotification)
{
this.chkNotice.Checked = false;
this.chkNotice.Visible = false;
}
//隐藏 设置服务器
if (SystemInfo.Instance.HiddenServerSetting)
{
this.pictureBox1.Visible = false;
this.btnSetConfig.Visible = false;
}
int X = this.chkUpdate.Location.X + this.chkUpdate.Width + 10;
//controls.Add(this.chkUpdate);
controls.Add(this.chkClient);
controls.Add(this.chkNotice);
controls.Add(this.pictureBox1);
foreach (System.Windows.Forms.Control item in controls)
{
if (item.Visible)
{
item.Location = new Point(X, item.Location.Y);
X = item.Location.X + item.Width + 10;
if (item is PictureBox) this.btnSetConfig.Location = new Point(item.Location.X + item.Width, this.btnSetConfig.Location.Y);
}
}
}
this.BackgroundImage = BitMapHelper.getBitmap(BitMapEnum.loginbg);
this.lblCopyright.Text = string.IsNullOrEmpty(SystemInfo.Instance.CopyRight) ? this.lblCopyright.Text : SystemInfo.Instance.CopyRight;
if (SystemInfo.Instance.IsShowVersion)
{
string version = string.Format(" Version:{0}", Assembly.GetExecutingAssembly().GetName().Version + "");
string updateTimeStr = IniHelper.Read("ApplicationUpdateTime");
string updateTime = string.Format("更新时间:{0}", updateTimeStr);
this.lblCopyright.Text += string.Format("{0}", version);
if (!string.IsNullOrEmpty(updateTimeStr))
{
this.upDateTimeLab.Visible = true;
this.upDateTimeLab.Text = string.Format("{0}", updateTime);
}
else
{
this.upDateTimeLab.Visible = false;
}
}
//设置语言
this.SetLanguage();
this.SetLedgers();
this.SetUsers();
//弹出提示框
if (SystemInfo.Instance.LoginAnnouncement)
{
if (BaseImpl.HasExistsTable("p_ErpProUpdateInfo")&& BaseImpl.HasExistsColumn("p_ErpProUpdateInfo", "AnnouncementDisplay"))
{
bool result = "1".Equals(BaseImpl.GetResult("select 1 from p_ErpProUpdateInfo where AnnouncementDisplay=1 order by updateDate desc") + "");
if (result)
{
FrmAnnouncement frmAnnouncement = new FrmAnnouncement();
frmAnnouncement.ShowDialog();
}
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
//LogUtil.WriteError(ResourceKeys.LoginModuleName, ex);
MessageUtil.Show(ResourceKeys.CheckDataFault);
}
finally
{
//SplashForm.HideForm();
this.TopMost = false;
if (SystemInfo.Instance.IsFingerLogin)
{
if (StaticControl.fingerHelper != null)
{
StaticControl.fingerHelper.Close();
StaticControl.fingerHelper = null;
}
FingerHelper.FreeSensor();
StaticControl.fingerHelper = new FingerHelper();
captureThread = new System.Threading.Thread(new System.Threading.ThreadStart(DoCapture));
captureThread.IsBackground = true;
captureThread.Start();
}
}
}
private void DoCapture()
{
while (!isLoginFinger)
{
try
{
int cbCapTmp = 2048;
int ret = zkfp2.AcquireFingerprint(StaticControl.fingerHelper.mDevHandle, StaticControl.fingerHelper.FPBuffer, StaticControl.fingerHelper.CapTmp, ref cbCapTmp);
if (ret == zkfp.ZKFP_ERR_OK)
{
string employeeid = StaticControl.fingerHelper.Compare();
if (!string.IsNullOrWhiteSpace(employeeid))
{
this.Invoke(new Action(() =>
{
bool isSucess = StartLoginByFinger(employeeid);
if (isSucess)
{
isLoginFinger = true;
captureThread.Abort();
if (StaticControl.fingerHelper != null)
{
StaticControl.fingerHelper.Close();
StaticControl.fingerHelper = null;
}
FingerHelper.FreeSensor();
}
}));
}
}
}
catch (Exception)
{
}
}
}
///
/// 说明:关闭程序
/// 创建人:龚宇超
/// 创建日期:2017-08-10
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnColseClick(object sender, EventArgs e)
{
try
{
DialogResult result = MessageUtil.Show(ResourceKeys.IsExit, MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Process[] p = Manager.GetApplicationProcesses();
foreach (Process item in p)
{
try
{
item.Kill();
}
catch (Exception)
{
}
}
Application.Exit();
//Process.GetCurrentProcess().Kill();
//Environment.Exit(0);
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:设置服务器地址
/// 创建人:龚宇超
/// 创建日期:2017-08-11
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnSetConfigClick(object sender, EventArgs e)
{
try
{
FrmConfigSet frmConfigSet = new FrmConfigSet();
//FrmConfig config = new FrmConfig();
//DialogResult result = config.ShowDialog();
DialogResult result = frmConfigSet.ShowDialog();
string nConfigFlag = IniHelper.Read("SystemResources.ini", "FrmConfigFlag");
if (nConfigFlag.Equals("1"))
this.btnSetConfig.Text = "服务器直连";
else
this.btnSetConfig.Text = "数据库连接";
if (result == DialogResult.OK)
{
this.SetLanguage();
this.SetLedgers();
this.SetUsers();
SystemInfo.RefreshSystemParam();
}
}
catch (Exception ex)
{
// LogUtil.WriteError(ResourceKeys.LoginModuleName, ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:登录
/// 创建人:龚宇超
/// 创建日期:2017-08-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnLoginClick(object sender, EventArgs e)
{
try
{
bool isSucess = this.StartLogin();
if (isSucess && SystemInfo.Instance.IsFingerLogin)
{
isLoginFinger = true;
captureThread.Abort();
if (StaticControl.fingerHelper != null)
{
StaticControl.fingerHelper.Close();
StaticControl.fingerHelper = null;
}
FingerHelper.FreeSensor();
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:切换帐套
/// 创建人:龚宇超
/// 创建日期:2017-08-15
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnLedgerClosed(object sender, ClosedEventArgs e)
{
try
{
WaitForm.ShowForm(ResourceKeys.ServerConnecting);
string ledgerValue = cbLedger.EditValue + "";
this.StartLedger(ledgerValue);
}
catch (Exception ex)
{
// LogUtil.WriteError(ResourceKeys.LoginModuleName, ex);
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
finally
{
WaitForm.HideForm();
}
}
///
/// 说明:鼠标离开时
/// 创建人:龚宇超
/// 创建日期:2017-08-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnLoginMouseLeave(object sender, EventArgs e)
{
try
{
btnLogin.BackgroundImage = Resources.login_btn;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:鼠标移动时
/// 创建人:龚宇超
/// 创建日期:2017-08-12
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnLoginMouseMove(object sender, MouseEventArgs e)
{
try
{
btnLogin.BackgroundImage = Resources.login_btn_select;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:清空选中
/// 创建人:龚宇超
/// 创建日期:2017-12-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnUserNameKeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Back)
{
this.lueUserName.EditValue = null;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:清空EditValue值
/// 创建人:龚宇超
/// 创建日期:2017-12-06
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnUserNameTextChanged(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(this.lueUserName.Text))
{
this.lueUserName.EditValue = null;
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:回车登录
/// 创建人:龚宇超
/// 创建日期:2018-03-05
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void OnPasswordKeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.Enter)
{
bool isSucess = this.StartLogin();
if (isSucess && SystemInfo.Instance.IsFingerLogin)
{
isLoginFinger = true;
captureThread.Abort();
if (StaticControl.fingerHelper != null)
{
StaticControl.fingerHelper.Close();
StaticControl.fingerHelper = null;
}
FingerHelper.FreeSensor();
}
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:打开日志
/// 创建人:龚宇超
/// 创建日期:2018-06-01
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The sender.
/// The instance containing the event data.
private void OnLogClick(object sender, EventArgs e)
{
try
{
if (File.Exists(PubUtil.SystemUpdateLogPath))
{
System.Diagnostics.Process.Start("notepad.exe", PubUtil.SystemUpdateLogPath);
}
}
catch (Exception)
{
}
}
#endregion
#region 窗口拖动行为
///
/// 说明:鼠标按下
/// 创建人:龚宇超
/// 创建日期:2017-08-14
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void plTop_MouseDown(object sender, MouseEventArgs e)
{
try
{
base.OnMouseDown(e);
System.Windows.Forms.Control control = (System.Windows.Forms.Control)sender;
Point mousePoint = control.PointToClient(System.Windows.Forms.Control.MousePosition);
_mousePostion = new Point(mousePoint.X, mousePoint.Y);
_isMouseDown = true;
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:鼠标放开
/// 创建人:龚宇超
/// 创建日期:2017-08-14
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void plTop_MouseUp(object sender, MouseEventArgs e)
{
try
{
base.OnMouseUp(e);
_isMouseDown = false;
//this.Focus();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 说明:鼠标移动
/// 创建人:龚宇超
/// 创建日期:2017-08-14
/// 修改人:
/// 修改日期:
/// 修改备注:
/// 版本:1.0
///
/// The source of the event.
/// The instance containing the event data.
private void plTop_MouseMove(object sender, MouseEventArgs e)
{
try
{
base.OnMouseMove(e);
if (_isMouseDown && e.Button == MouseButtons.Left)
{
this.Location = new Point(Location.X + (e.X - _mousePostion.X), Location.Y + (e.Y - _mousePostion.Y));
}
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
#endregion
///
/// 用户值改变事件
///
///
///
private void OnEditValueChanged(object sender, EventArgs e)
{
try
{
StateFlushed();
}
catch (Exception ex)
{
string Message = ErrorMessage.PromptErrorMessage(ex);
MessageUtil.Show(Message, ex.Message);
}
}
///
/// 用户值改变方法
///
///
///
public void StateFlushed()
{
string UserName = lueUserName.Text.Trim();
bool isClear = true;
//if (dataRow != null && dataTable.Columns.Contains("DefaultLedger"))
//{
// string DefaultLedger= dataRow["DefaultLedger"] + "";
//}
if (this.language.Visible)
{
DataTable dataTable = this.lueUserName.DataSource as DataTable;
DataRow[] array = dataTable.Select(""+DisplayName+"='" + UserName + "'");
DataRow dataRow = array.Length > 0 ? array[0] : null;
if (dataRow != null && !string.IsNullOrWhiteSpace(dataRow["useLanguage"] + ""))
{
this.language.Text = dataRow["useLanguage"] + "";
}
}
if (!string.IsNullOrEmpty(UserName) && !SystemInfo.Instance.DisableRememberPassword)
{
string[] PwdState = AESUtil.Decrypt(IniHelper.Read(DBConfig.Instance.ServerName + UserName)).Split('^');
if (PwdState.Count() >= 2)
{
chkRemPwd.Checked = Convert.ToBoolean(PwdState[0]);
if (chkRemPwd.Checked)
{
this.txtPassword.Text = PwdState[1];
if (PwdState.Count() > 2) this.txtPassword.Text = string.Join("^", PwdState.Skip(1));
isClear = false;
this.lueUserName.Text = UserName;
this.txtPassword.Focus();
}
}
}
if (SystemInfo.Instance.AccountSwitchingRestrictions > 0)
{
DataTable dataTable = this.lueUserName.DataSource as DataTable;
DataRow[] array = dataTable.Select("" + DisplayName + "='" + UserName + "'");
DataRow dataRow = array.Length > 0 ? array[0] : null;
if (dataRow != null)
{
int uid = int.Parse(dataRow["UserId"] + "");
if (uid <= SystemInfo.Instance.AccountSwitchingRestrictions)
{
this.cbLedger.Enabled = true;
}
else
{
this.cbLedger.Enabled = false;
}
}
}
if (isClear)
{
chkRemPwd.Checked = false;
this.txtPassword.Text = string.Empty;
}
}
///
/// 指纹识别监视
///
///
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);//调用父类方法,以确保其他功能正常
switch (m.WParam.ToInt32())
{
//指纹识别改变事件
case 7:
if (SystemInfo.Instance.IsFingerLogin)
{
if (StaticControl.fingerHelper != null)
{
StaticControl.fingerHelper.Close();
StaticControl.fingerHelper = null;
}
FingerHelper.FreeSensor();
StaticControl.fingerHelper = new FingerHelper();
}
break;
}
}
///
/// 登录界面显示时设置焦点
///
///
///
private void FrmLogin_Shown(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(this.txtPassword.Text))
{
this.txtPassword.Focus();
}
}
///
/// 设置语言
///
private void SetLanguage()
{
try
{
//return;
this.language.Visible = false;
this.language.Properties.Items.Clear();
DataTable allLanguage = LanguageTranslation.GetAllLanguage();
if (allLanguage != null && allLanguage.Rows.Count > 1)
{
this.language.Visible = true;
foreach (DataRow item in allLanguage.Rows)
{
if (!(item["COLUMN_NAME"] + "").Equals("id", StringComparison.InvariantCultureIgnoreCase)) this.language.Properties.Items.Add(item["COLUMN_NAME"]);
}
this.language.SelectedIndex = 0;
}
}
catch (Exception ex)
{
}
}
///
/// 语言框选中改变
///
///
///
private void Language_SelectedValueChanged(object sender, EventArgs e)
{
string nConfigFlag = IniHelper.Read("SystemResources.ini", "FrmConfigFlag");
string btnSetConfigText = "设置服务器";
if (nConfigFlag.Equals("1"))
btnSetConfigText = "服务器直连";
else
btnSetConfigText = "数据库连接";
if (this.language.Text.Equals("中文"))
{
this.chkLogin.Text = "强制登录";
this.chkRemPwd.Text = "记住密码";
this.chkUpdate.Text = "自动升级";
this.chkClient.Text = "智能客户端";
this.chkNotice.Text = "消息通知";
this.btnSetConfig.Text = btnSetConfigText;
string updateTimeStr = IniHelper.Read("ApplicationUpdateTime");
string updateTime = string.Format("更新时间:{0}", updateTimeStr);
this.upDateTimeLab.Text = string.Format("{0}", updateTime);
}
else
{
DataTable dataTable = LanguageTranslation.GetLoginLanguage(this.language.Text);//获取翻译表数据
if (dataTable != null && dataTable.Rows.Count > 0)
{
foreach (DataRow item in dataTable.Rows)
{
if ("强制登录".Equals(item["中文"] + "")) this.chkLogin.Text = item[this.language.Text] + "";
if ("记住密码".Equals(item["中文"] + "")) this.chkRemPwd.Text = item[this.language.Text] + "";
if ("自动升级".Equals(item["中文"] + "")) this.chkUpdate.Text = item[this.language.Text] + "";
if ("智能客户端".Equals(item["中文"] + "")) this.chkClient.Text = item[this.language.Text] + "";
if ("消息通知".Equals(item["中文"] + "")) this.chkNotice.Text = item[this.language.Text] + "";
if (btnSetConfigText.Equals(item["中文"] + "")) this.btnSetConfig.Text = item[this.language.Text] + "";
if ("更新时间".Equals(item["中文"] + ""))
{
string updateTimeStr = IniHelper.Read("ApplicationUpdateTime");
string updateTime = string.Format("{0}:{1}", item[this.language.Text] + "", updateTimeStr);
this.upDateTimeLab.Text = string.Format("{0}", updateTime);
}
}
}
}
}
///
/// 忘记密码点击时
///
///
///
private void OnForgetPwdClick(object sender, EventArgs e)
{
using (BaseForm baseForm = new BaseForm())
{
FrmWebBrowser frmWebBrowser = new FrmWebBrowser();
frmWebBrowser.Dock = DockStyle.Fill;
baseForm.Controls.Add(frmWebBrowser);
baseForm.Text = "忘记密码";
baseForm.Size = new Size(1000, 600);
string forgetPwdUrl = "";
if (SystemInfo.Instance.OAUrl.EndsWith("/"))
{
forgetPwdUrl = $"{SystemInfo.Instance.OAUrl}lserp_v8/index.html?verify=1";
}
else
{
forgetPwdUrl = $"{SystemInfo.Instance.OAUrl}/lserp_v8/index.html?verify=1";
}
frmWebBrowser.FrmLoad(forgetPwdUrl, 1, false);
baseForm.ShowDialog();
}
}
private void OnCheckPwdClick(object sender, EventArgs e)
{
if (isPlaintextPwd)
{
//加密
txtPassword.Properties.PasswordChar = '*';
checkPwd.Image = Properties.Resources.密码显示; // 睁眼图标
toolTip.SetToolTip(checkPwd, "显示密码");
}
else
{
//明文显示
txtPassword.Properties.PasswordChar = '\0';
checkPwd.Image = Properties.Resources.密码不显示; // 睁眼图标
toolTip.SetToolTip(checkPwd, "隐藏密码");
}
isPlaintextPwd = !isPlaintextPwd;
}
}
}