ab56a9bcf7
SVN-Revision: r240
1145 lines
46 KiB
C#
1145 lines
46 KiB
C#
/******************************
|
|
* 说明:登录界面
|
|
* 创建人:龚宇超
|
|
* 创建日期: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.PubMrpAnalyze.Properties;
|
|
using Lskj.Model;
|
|
using Lskj.PubMrpAnalyze.Model;
|
|
using DevExpress.XtraEditors.Controls;
|
|
using Lskj.Business.Impl;
|
|
using DevExpress.LookAndFeel;
|
|
using Lskj.AutoUpdate;
|
|
using System.Net;
|
|
using System.Xml;
|
|
using System.IO;
|
|
using System.Text.RegularExpressions;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using static Lskj.PubMrpAnalyze.AboutDevCompanion;
|
|
using System.Threading;
|
|
|
|
namespace Lskj.PubMrpAnalyze
|
|
{
|
|
/// <summary>
|
|
/// 登录界面
|
|
/// </summary>
|
|
public partial class FrmLogin : Form
|
|
{
|
|
private string m_UpdateIP = "";
|
|
private byte[] g_KeyValue = { 212, 61, 139, 3, 54, 70, 213, 254 };
|
|
/// <summary>
|
|
/// 是否鼠标按下
|
|
/// </summary>
|
|
private bool _isMouseDown;
|
|
/// <summary>
|
|
/// 记录窗口位置
|
|
/// </summary>
|
|
private Point _mousePostion;
|
|
private DataTable _ledgerTable;
|
|
private DataTable _userTable;
|
|
Regex regex = new Regex(@"(?=.*[0-9]) #必须包含数字
|
|
(?=.*[a-zA-Z]) #必须包含小写或大写字母
|
|
(?=.*[^a-zA-Z0-9]) #必须包含符号
|
|
.{8,18} #至少6个字符,最多18个字符
|
|
", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
|
|
public FrmLogin()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region 方法相关
|
|
/// <summary>
|
|
/// <para>说明:登陆时验证信息</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-12-10 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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;
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:在这用线程检测路径是否正确,不能阻塞主程序流程</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2020-12-10 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void CheckDirectoryExist()
|
|
{
|
|
string strDir = "\\\\" + m_UpdateIP + "\\update";
|
|
if (Directory.Exists(strDir))
|
|
ERPInfo.Instance.UpdateIP = m_UpdateIP;
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置帐套信息</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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<DataRow>().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<DataRow>().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)
|
|
{
|
|
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置系统用户</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-09 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void SetUsers()
|
|
{
|
|
BaseImpl.HasExistsColumn("P_SystemTab", "LoginPopupFlag", "int");
|
|
lueUserName.Focus();
|
|
lueUserName.ValueField = lueUserName.ValueMember = "UserId";
|
|
lueUserName.TextMember = "UserName";
|
|
lueUserName.SourceSQL = "select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName from P_EmployeeTab WHERE sign=0 and UseFlag=1";
|
|
|
|
|
|
if (SystemInfo.Instance.DisplayUserCode)
|
|
{
|
|
lueUserName.SourceSQL = "select EmployeeId UserId,LoginAccount UserCode,EmployeeName UserName, LoginAccount remark from P_EmployeeTab WHERE sign=0 and UseFlag=1";
|
|
_userTable = MainImpl.GetEmployeeListNew();
|
|
}
|
|
else {
|
|
_userTable = MainImpl.GetEmployeeList();
|
|
}
|
|
|
|
lueUserName.DataSource = _userTable;
|
|
|
|
if (SystemInfo.Instance.DisplayUserCode)
|
|
{
|
|
//GridColumn workNumberColumn = new GridColumn();
|
|
//workNumberColumn.Name = workNumberColumn.FieldName = "UserCode";
|
|
//workNumberColumn.Caption = "工号";
|
|
//workNumberColumn.Visible = true;
|
|
//workNumberColumn.Width = 120;
|
|
//this.lueUserName._popup.GridViewObj.Columns.Add(workNumberColumn);
|
|
GridColumn gridColumn = this.lueUserName._popup.GridViewObj.Columns.First(x => x.FieldName.Equals("remark"));
|
|
if(gridColumn!=null) gridColumn.Caption = "工号";
|
|
}
|
|
|
|
|
|
lueUserName.AutoShowPopup = "1".Equals(BaseImpl.GetResult("SELECT LoginPopupFlag FROM P_SystemTab") + "");
|
|
|
|
|
|
DataRow[] rowItems = _userTable.Select(" UserName = '" + DBConfig.Instance.LoginName + "'");
|
|
if (rowItems != null && rowItems.Length > 0)
|
|
{
|
|
lueUserName.EditValue = rowItems[0][lueUserName.ValueField] + "";
|
|
StateFlushed();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置delphi参数</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:启动自动更新</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void StartAutoUpdate()
|
|
{
|
|
if (string.IsNullOrEmpty(SystemInfo.Instance.UpdateAddress))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UpdateAddressIsNull);
|
|
return;
|
|
}
|
|
|
|
bool isUpdateSucess = false;
|
|
IAutoUpdater updater = new AutoUpdater(SystemInfo.Instance.UpdateAddress, true);
|
|
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)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:启动小平台</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:开始登录</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void StartLogin()
|
|
{
|
|
string userId = lueUserName.EditValue + "";
|
|
string userName = lueUserName.Text.Trim();
|
|
string password = txtPassword.Text.Trim();
|
|
string LoginAccount = string.Empty;
|
|
// 设置登录用户信息
|
|
bool isConstraint = chkLogin.Checked;
|
|
if (string.IsNullOrWhiteSpace(userName))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.UserNameNotNull);
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
// 默认有可能有空
|
|
DataTable table = MainImpl.GetEmployeeList();//获取员工信息存到表中
|
|
DataRow[] drRows = table.Select("UserName='" + userName + "' or UserCode='" + userName + "'");//找到所有UserNAme或UserCode为xxx的用户
|
|
if ((drRows == null) || (drRows.Count() < 1))
|
|
{
|
|
MessageUtil.Show(ResourceKeys.NameOrPasswordError);
|
|
return;
|
|
}
|
|
//找到多个操作员
|
|
if (drRows.Count() > 1)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.DuplicatedNameError);
|
|
return;
|
|
}
|
|
DataRow drRow = drRows[0];
|
|
//DataRow drRow = table.Rows.Cast<DataRow>().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;
|
|
}
|
|
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;
|
|
}
|
|
if (result == -1)
|
|
{
|
|
MessageUtil.Show(ResourceKeys.LoginFault + ResourceKeys.UnKownMacAddressTable);
|
|
return;
|
|
}
|
|
}
|
|
WaitForm.ShowForm(ResourceKeys.Logining);//验证登录后的加载框上输出的信息
|
|
int loginResult = MainImpl.Login(userId, password, isConstraint);
|
|
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));
|
|
ERPInfo.Instance.UserId = userId;
|
|
ERPInfo.Instance.UserName = userName;
|
|
ERPInfo.Instance.Password = SHAHelper.EncryptPassword(password);
|
|
ERPInfo.Instance.SkinName = skinName;
|
|
ERPInfo.Instance.AccountBook = cbLedger.Text;
|
|
ERPInfo.Instance.LoginAccount = LoginAccount;
|
|
ERPInfo.Instance.InPassWord = password;
|
|
DBConfig.Instance.LoginName = 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;
|
|
}
|
|
|
|
this.SetDelphiDllParams(); // 设置调用delphi参数
|
|
|
|
bool isStartMain = true;
|
|
bool isVerfyPassword = SystemInfo.Instance.VerfyPasswordStrength ? !regex.IsMatch(password) : false;
|
|
if ((SystemInfo.Instance.ForceUpdatePassword && string.IsNullOrEmpty(password)) || isVerfyPassword)
|
|
{
|
|
// 弹出修改密码窗口
|
|
FrmPassword frmPassword = new FrmPassword();
|
|
frmPassword.UserId = userId;
|
|
frmPassword.UserName = userName;
|
|
DialogResult result = frmPassword.ShowDialog();
|
|
isStartMain = result == DialogResult.OK;
|
|
}
|
|
if (isStartMain)
|
|
{
|
|
// 检查自动升级
|
|
if (chkUpdate.Checked)
|
|
{
|
|
WaitForm.ShowForm(ResourceKeys.AutoUpdating);
|
|
this.StartAutoUpdate();
|
|
}
|
|
// 启动小平台
|
|
if (chkClient.Checked)
|
|
{
|
|
this.StartSmallClient();
|
|
}
|
|
// 启动消息通知平台
|
|
if (chkNotice.Checked)
|
|
{
|
|
this.StartNotice();
|
|
}
|
|
|
|
this.DialogResult = DialogResult.OK;
|
|
//记录登录日志
|
|
LogUtil.WriteDebug("", "登录软件", "进入操作", "系统登录");
|
|
this.Close();
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 初始化mrp缓存数据
|
|
/// </summary>
|
|
private void InitCacheData()
|
|
{
|
|
string modelCode = "MRP001";
|
|
ModuleModel MoudleMainObj = new ModuleModel(MainImpl.GetSystemdllTab(modelCode));//获取主模块构建类
|
|
if (!Manager.cacheDic.ContainsKey(MoudleMainObj.CondKey+ "_queryTable"))
|
|
{
|
|
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(MoudleMainObj.CondKey);//获取主模块构建的条件
|
|
Manager.cacheDic.Add(MoudleMainObj.CondKey+ "_queryTable", queryTable);
|
|
}
|
|
DataTable moduleDetailTable = BaseModuleImpl.GetBaseDetailPages(modelCode);//获取所有主表配置明细
|
|
foreach (DataRow item in moduleDetailTable.Rows)
|
|
{
|
|
GridDetailModel gridDetailModel = new GridDetailModel(item);
|
|
string moduleCode = gridDetailModel.UnionModule;
|
|
ModuleModel MoudleDetailObj = new ModuleModel(MainImpl.GetSystemdllTab(moduleCode));//获取模块构建类
|
|
if (!Manager.cacheDic.ContainsKey(MoudleDetailObj.CondKey+"_queryTable"))
|
|
{
|
|
DataTable queryTable = BaseModuleImpl.GetCustomQueryFields(MoudleDetailObj.CondKey);//获取模块构建的条件
|
|
Manager.cacheDic.Add(MoudleDetailObj.CondKey+ "_queryTable", queryTable);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:打开消息通知</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期: </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void StartNotice()
|
|
{
|
|
FormHelper.StartProcess("Ls_Notice", new string[] { ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, ERPInfo.Instance.Password });
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:帐套</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2019-11-11 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="typeName">Name of the type.</param>
|
|
private void StartLedger(string ledgerValue)
|
|
{
|
|
DataRow focusRow = _ledgerTable.Rows.Cast<DataRow>().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.SetUsers();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 事件相关
|
|
/// <summary>
|
|
/// <para>说明:登录界面加载时</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-08 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void OnLoginLoad(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Thread thread = new Thread(InitCacheData);
|
|
thread.Start();
|
|
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.AutomaticUpdates)
|
|
{
|
|
this.chkUpdate.Checked = true;
|
|
this.chkUpdate.Enabled = false;//启用自动更新禁止修改
|
|
}
|
|
if (SystemInfo.Instance.AutoCheckedNotice)
|
|
{
|
|
this.chkNotice.Checked = true;
|
|
}
|
|
this.BackgroundImage = BitMapHelper.getBitmap(BitMapEnum.loginbg);
|
|
this.lblCopyright.Text = string.IsNullOrEmpty(SystemInfo.Instance.CopyRight) ? this.lblCopyright.Text : SystemInfo.Instance.CopyRight;
|
|
this.SetLedgers();
|
|
this.SetUsers();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
//LogUtil.WriteError(ResourceKeys.LoginModuleName, ex);
|
|
MessageUtil.Show(ResourceKeys.CheckDataFault);
|
|
}
|
|
//finally
|
|
//{
|
|
// SplashForm.HideForm();
|
|
//}
|
|
}
|
|
/// <summary>
|
|
/// 缓存数据源(固定数据源)
|
|
/// </summary>
|
|
public void cacheDic()
|
|
{
|
|
|
|
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭程序</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-10 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void OnColseClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DialogResult result = MessageUtil.Show(ResourceKeys.IsExit, MessageBoxButtons.YesNo);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
Application.Exit();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:设置服务器地址</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-11 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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.SetLedgers();
|
|
this.SetUsers();
|
|
SystemInfo.RefreshSystemParam();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// LogUtil.WriteError(ResourceKeys.LoginModuleName, ex);
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:登录</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
private void OnLoginClick(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
this.StartLogin();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:切换帐套</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-15 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="DevExpress.XtraEditors.Controls.ClosedEventArgs"/> instance containing the event data.</param>
|
|
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();
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标离开时</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标移动时</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-12 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:清空选中</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-06 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:清空EditValue值</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-12-06 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:回车登录</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-03-05 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param>
|
|
private void OnPasswordKeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
this.StartLogin();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:打开日志</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-06-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The sender.</param>
|
|
/// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
|
|
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 窗口拖动行为
|
|
/// <summary>
|
|
/// <para>说明:鼠标按下</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void plTop_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.OnMouseDown(e);
|
|
_mousePostion = Cursor.Position;
|
|
_isMouseDown = true;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标放开</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:鼠标移动</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-14 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender">The source of the event.</param>
|
|
/// <param name="e">The <see cref="MouseEventArgs"/> instance containing the event data.</param>
|
|
private void plTop_MouseMove(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
base.OnMouseMove(e);
|
|
if (_isMouseDown)
|
|
{
|
|
Point tempPos = Cursor.Position;
|
|
this.Location = new Point(Location.X + (tempPos.X - _mousePostion.X), Location.Y + (tempPos.Y - _mousePostion.Y));
|
|
_mousePostion = Cursor.Position;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
/// <summary>
|
|
/// 用户值改变事件
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnEditValueChanged(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
StateFlushed();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 用户值改变方法
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
public void StateFlushed()
|
|
{
|
|
string UserName = lueUserName.Text.Trim();
|
|
DataTable table = MainImpl.GetEmployeeList();//获取员工信息存到表中
|
|
bool isClear = true;
|
|
|
|
if (!string.IsNullOrEmpty(UserName))
|
|
{
|
|
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];
|
|
isClear = false;
|
|
}
|
|
}
|
|
}
|
|
if (isClear)
|
|
{
|
|
chkRemPwd.Checked = false;
|
|
this.txtPassword.Text = string.Empty;
|
|
}
|
|
}
|
|
}
|
|
} |