基线 SVN r240
SVN-Revision: r240
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Lskj.Main.Model
|
||||
{
|
||||
class AutoSizeChange
|
||||
{
|
||||
private static double _FormHeight = (double)(Screen.PrimaryScreen.Bounds.Height) * 1.2 / (double)1080;
|
||||
private static double _FormWidth = (double)(Screen.PrimaryScreen.Bounds.Width) * 1.2 / (double)1920;
|
||||
public static void ControllInitializeSize(System.Windows.Forms.Control Control)
|
||||
{
|
||||
foreach (System.Windows.Forms.Control ctrol in Control.Controls)
|
||||
{
|
||||
if (ctrol.Controls.Count > 0)
|
||||
{
|
||||
if (ctrol is Panel || ctrol is DevExpress.XtraEditors.PanelControl || ctrol is UserControl)
|
||||
{
|
||||
ctrol.Width = Convert.ToInt32(ctrol.Width * _FormWidth);
|
||||
ctrol.Height = Convert.ToInt32(ctrol.Height * _FormHeight);
|
||||
ctrol.Location = new Point(Convert.ToInt32(ctrol.Location.X * _FormWidth), Convert.ToInt32(ctrol.Location.Y * _FormHeight));
|
||||
//ctrol.Font = new Font(ctrol.Font.OriginalFontName, Convert.ToSingle(ctrol.Font.Size * _FormHeight * _FormWidth * 1.3));
|
||||
}
|
||||
if (ctrol is Lskj.Control.AutoGridLookUp)
|
||||
{
|
||||
ctrol.Width = Convert.ToInt32(ctrol.Width * _FormWidth);
|
||||
ctrol.Height = Convert.ToInt32(ctrol.Height * _FormHeight);
|
||||
ctrol.Location = new Point(Convert.ToInt32(ctrol.Location.X * _FormWidth), Convert.ToInt32(ctrol.Location.Y * _FormHeight));
|
||||
ctrol.Font = new Font(ctrol.Font.OriginalFontName, Convert.ToSingle(ctrol.Font.SizeInPoints * _FormHeight * _FormWidth));
|
||||
}
|
||||
ControllInitializeSize(ctrol);
|
||||
}
|
||||
else
|
||||
{
|
||||
SizeChange(ctrol);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static void SizeChange(System.Windows.Forms.Control Control)
|
||||
{
|
||||
if (Control.BackgroundImage != null)
|
||||
{
|
||||
Image image = Control.BackgroundImage;
|
||||
Size size = new Size(Convert.ToInt32(Control.BackgroundImage.Width * _FormWidth), Convert.ToInt32(Control.BackgroundImage.Height * _FormHeight));
|
||||
Control.BackgroundImage = resizeImage(image, size);
|
||||
}
|
||||
|
||||
Control.Width = Convert.ToInt32(Control.Width * _FormWidth);
|
||||
Control.Height = Convert.ToInt32(Control.Height * _FormHeight);
|
||||
Control.Location = new Point(Convert.ToInt32(Control.Location.X * _FormWidth), Convert.ToInt32(Control.Location.Y * _FormHeight));
|
||||
Control.Font = new Font(Control.Font.OriginalFontName, Convert.ToSingle(Control.Font.SizeInPoints * _FormHeight * _FormWidth));
|
||||
}
|
||||
private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
|
||||
{
|
||||
//获取图片宽度
|
||||
int sourceWidth = imgToResize.Width;
|
||||
//获取图片高度
|
||||
int sourceHeight = imgToResize.Height;
|
||||
|
||||
float nPercent = 0;
|
||||
float nPercentW = 0;
|
||||
float nPercentH = 0;
|
||||
//计算宽度的缩放比例
|
||||
nPercentW = ((float)size.Width / (float)sourceWidth);
|
||||
//计算高度的缩放比例
|
||||
nPercentH = ((float)size.Height / (float)sourceHeight);
|
||||
|
||||
if (nPercentH < nPercentW)
|
||||
nPercent = nPercentH;
|
||||
else
|
||||
nPercent = nPercentW;
|
||||
//期望的宽度
|
||||
int destWidth = (int)(sourceWidth * nPercent);
|
||||
//期望的高度
|
||||
int destHeight = (int)(sourceHeight * nPercent);
|
||||
|
||||
Bitmap b = new Bitmap(destWidth, destHeight);
|
||||
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
//绘制图像
|
||||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
||||
g.Dispose();
|
||||
return (System.Drawing.Image)b;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,131 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using Lskj.Main.Properties;
|
||||
using Lskj.Util;
|
||||
|
||||
namespace Lskj.Main.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源图片管理类
|
||||
/// </summary>
|
||||
public static class BitMapHelper
|
||||
{
|
||||
#region 本地资源文件
|
||||
/// <summary>
|
||||
/// 获取本地资源文件
|
||||
/// </summary>
|
||||
/// <param name="mapEnum"></param>
|
||||
/// <returns></returns>
|
||||
public static Bitmap getBitmap(BitMapEnum mapEnum)
|
||||
{
|
||||
Bitmap bitmap = null;
|
||||
try
|
||||
{
|
||||
FileStream fs = File.OpenRead(getBitMapPath(mapEnum)); //OpenRead
|
||||
|
||||
int filelength = (int)fs.Length; //获得文件长度
|
||||
Byte[] image = new Byte[filelength]; //建立一个字节数组
|
||||
fs.Read(image, 0, filelength); //按字节流读取
|
||||
Image result = Image.FromStream(fs);
|
||||
fs.Close();
|
||||
|
||||
bitmap = new Bitmap(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
switch (mapEnum)
|
||||
{
|
||||
case BitMapEnum.loginbg:
|
||||
bitmap = Resources.newlogin;
|
||||
break;
|
||||
case BitMapEnum.submenubg:
|
||||
bitmap = Resources.sub_backgroud;
|
||||
break;
|
||||
case BitMapEnum.submenubg_tip:
|
||||
bitmap = Resources.sub_tip_backgound;
|
||||
break;
|
||||
case BitMapEnum.logobg:
|
||||
bitmap = Resources.logo;
|
||||
break;
|
||||
case BitMapEnum.logo2bg:
|
||||
bitmap = Resources.logo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取文件路径
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static string getBitMapPath(BitMapEnum mapEnum)
|
||||
{
|
||||
string bitmapPath = string.Empty;
|
||||
switch (mapEnum)
|
||||
{
|
||||
case BitMapEnum.loginbg:
|
||||
bitmapPath = BitMapType.Loginbg;
|
||||
break;
|
||||
case BitMapEnum.submenubg:
|
||||
bitmapPath = BitMapType.Submenubg;
|
||||
break;
|
||||
case BitMapEnum.submenubg_tip:
|
||||
bitmapPath = BitMapType.Submenubg_tip;
|
||||
break;
|
||||
case BitMapEnum.logobg:
|
||||
bitmapPath = BitMapType.Logobg;
|
||||
break;
|
||||
case BitMapEnum.logo2bg:
|
||||
bitmapPath = BitMapType.Logo2bg;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return PubUtil.BitMapPath + bitmapPath;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片存放地址
|
||||
/// </summary>
|
||||
public static class BitMapType
|
||||
{
|
||||
/// <summary>
|
||||
/// 登录背景图
|
||||
/// </summary>
|
||||
public static string Loginbg = @"Login\newlogin.png";
|
||||
/// <summary>
|
||||
/// 子系统背景图
|
||||
/// </summary>
|
||||
public static string Submenubg = @"Submenu\submenu.png";
|
||||
/// <summary>
|
||||
/// 子系统背景图提示
|
||||
/// </summary>
|
||||
public static string Submenubg_tip = @"Submenu\submenu_tip.png";
|
||||
/// <summary>
|
||||
/// logo背景图
|
||||
/// </summary>
|
||||
public static string Logobg = @"Main\logo.png";
|
||||
/// <summary>
|
||||
/// logo2背景图
|
||||
/// </summary>
|
||||
public static string Logo2bg = @"Main2\logo.png";
|
||||
}
|
||||
/// <summary>
|
||||
/// 图片类型
|
||||
/// </summary>
|
||||
public enum BitMapEnum
|
||||
{
|
||||
loginbg,
|
||||
submenubg,
|
||||
submenubg_tip,
|
||||
logobg,
|
||||
logo2bg
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,954 @@
|
||||
/******************************
|
||||
* 说明:主程序启动相关管理类
|
||||
* 创建人:龚宇超
|
||||
* 创建日期:2017-08-09
|
||||
* 修改人:
|
||||
* 修改日期:
|
||||
* 修改备注:
|
||||
* 版本:1.0.0.0
|
||||
******************************/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using Lskj.Control.Model;
|
||||
using Lskj.Core;
|
||||
using DevExpress.XtraEditors;
|
||||
using Lskj.Control;
|
||||
using Lskj.Data;
|
||||
using System.Threading;
|
||||
using Lskj.Business;
|
||||
using System.Data;
|
||||
using Lskj.Model;
|
||||
using DevExpress.XtraTab;
|
||||
using Lskj.Util;
|
||||
using DevExpress.Utils;
|
||||
using System.Diagnostics;
|
||||
using Lskj.Business.Impl;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Net;
|
||||
|
||||
namespace Lskj.Main.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 主程序启动相关管理类
|
||||
/// </summary>
|
||||
public sealed class Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 主程序
|
||||
/// </summary>
|
||||
private static FrmMain _frmMain = null;
|
||||
/// <summary>
|
||||
/// 主菜单程序
|
||||
/// </summary>
|
||||
private static FrmSubSystem _frmSubSystem = null;
|
||||
public static XtraTabControl TabMain = null;
|
||||
public static int MinusTheHeight = 0;
|
||||
public static int frmHeight = 0;
|
||||
public static string BsName;
|
||||
public static string BsUrl;
|
||||
public static int isAwaitTime = 10;
|
||||
/// <summary>
|
||||
/// 默认下载地址
|
||||
/// </summary>
|
||||
private static string filePath = string.Empty;
|
||||
/// <summary>
|
||||
/// 返回地址值
|
||||
/// </summary>
|
||||
private static string outText = string.Empty;
|
||||
/// <summary>
|
||||
/// 记录当前打开的窗口
|
||||
/// </summary>
|
||||
public static Dictionary<string, DllModule> ModuleForms = new Dictionary<string, DllModule>();
|
||||
/// <summary>
|
||||
/// 记录F4配置快速菜单模块
|
||||
/// </summary>
|
||||
public static Form QuickMenuForm = null;
|
||||
/// <summary>
|
||||
/// <para>说明:程序启动入口</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-09 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
public static void StartForm()
|
||||
{
|
||||
bool isStart = true;
|
||||
// 加载Splash动画界面
|
||||
SplashForm.ShowForm();
|
||||
//CheckLocalConfig();
|
||||
// C#数据库连接检查
|
||||
bool isLocalConnect = false;
|
||||
string file = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.ini");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
string configFlag = IniHelper.Read("SystemResources.ini", "FrmConfigFlag");
|
||||
if (configFlag.Equals("1"))
|
||||
isLocalConnect = true;
|
||||
}
|
||||
if (isLocalConnect)
|
||||
{
|
||||
string ip = IniHelper.Read("SystemResources.ini", "LocalLastIP");
|
||||
string port = IniHelper.Read("SystemResources.ini", "LocalLastPort");
|
||||
ConnectServer(ip, port);
|
||||
}
|
||||
if (!DBConfig.Instance.CreateConnection(DBConfig.Instance.Connection))
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnConnectServer);
|
||||
SplashForm.HideForm();
|
||||
DialogResult result = RunConfigForm();
|
||||
isStart = result == DialogResult.OK;
|
||||
}
|
||||
if (isStart)
|
||||
{
|
||||
// Delphi数据库连接检查
|
||||
if (DelphiHelper.Delphi_Init(new StringBuilder(DBConfig.Instance.GetDelphiConnection(DBConfig.Instance.dephiConnection))) == 0)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnConnectServer + "[By Delphi]");
|
||||
SplashForm.HideForm();
|
||||
RunConfigForm();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
SplashForm.HideForm();
|
||||
// 汉化dev控件
|
||||
BaseResources.Localization(LocalizationType.CHS);
|
||||
// 启动登录页面
|
||||
DialogResult result = RunLoginForm();
|
||||
//登陆正确方可继续下一步
|
||||
if (ERPInfo.Instance.LoginResult == false)
|
||||
return;
|
||||
if (result == DialogResult.OK)
|
||||
{
|
||||
DataTable table = MainImpl.EnableSubSystem();
|
||||
ERPInfo.Instance.SubMenuCount = table.Rows.Count;
|
||||
if (table.Rows.Count == 1)
|
||||
{
|
||||
ERPInfo.Instance.SubSysId = table.Rows[0]["SubSysId"] + "";
|
||||
ERPInfo.Instance.SubSysName = table.Rows[0]["SubSysName"] + "";
|
||||
}
|
||||
ReStartMain();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SplashForm.HideForm();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:重新启动</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="skipMenu">是否跳过子系统选择(适用于切换用户).</param>
|
||||
public static void ReStartMain(bool skipMenu = false)
|
||||
{
|
||||
WhenConstraintLogin();
|
||||
LockApplication();
|
||||
if (_frmMain != null)
|
||||
{
|
||||
if (ERPInfo.Instance.WatermarkForm != null)
|
||||
{
|
||||
ERPInfo.Instance.WatermarkForm.Close();
|
||||
ERPInfo.Instance.WatermarkForm.Dispose();
|
||||
}
|
||||
_frmMain.Close();
|
||||
_frmMain.Dispose();
|
||||
_frmMain = null;
|
||||
}
|
||||
|
||||
bool isStart = true;
|
||||
bool isOpenBs = false;
|
||||
DialogResult result;
|
||||
|
||||
if (ERPInfo.Instance.SubMenuCount > 1 && !skipMenu)
|
||||
{
|
||||
// 进入子系统界面
|
||||
result = RunSubSystemForm();
|
||||
isStart = result == DialogResult.OK;
|
||||
isOpenBs = result == DialogResult.Yes;
|
||||
}
|
||||
if (isStart)
|
||||
{
|
||||
// 直接进入主界面
|
||||
RunMainForm();
|
||||
if (ERPInfo.Instance.SubMenuCount > 1)
|
||||
{
|
||||
ReStartMain();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitSystem();
|
||||
}
|
||||
}
|
||||
else if (isOpenBs)
|
||||
{
|
||||
string ReBsUrl = BsUrl.Replace("{userCode}", ERPInfo.Instance.LoginAccount);
|
||||
ReBsUrl = ReBsUrl.Replace("{password}", ERPInfo.Instance.Password);
|
||||
string url = ReplaceHelper.ReplaceUserInfo(ReBsUrl);
|
||||
// 固定传入参数(窗口标题、操作员ID、操作员名称、权限、模版编号)
|
||||
string[] defaultArgs = string.Format(ModuleArgs.DefaultArgs, BsName, ERPInfo.Instance.UserId, ERPInfo.Instance.UserName, "", "").Split('~');
|
||||
string[] menuArgs = new string[] { "", "", url };
|
||||
string[] args = defaultArgs.Concat(menuArgs).ToArray();
|
||||
IForm form = null;
|
||||
|
||||
form = FormHelper.LoadDllForm("Lskj.PubBrower2.dll", args);
|
||||
|
||||
form.SubForm.WindowState = FormWindowState.Maximized;
|
||||
form.SubForm.ShowDialog();
|
||||
if (ERPInfo.Instance.SubMenuCount > 1)
|
||||
{
|
||||
ReStartMain();
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitSystem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ExitSystem();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开模块</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-18 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="menuId">The menu identifier.</param>
|
||||
/// <param name="menuName">Name of the menu.</param>
|
||||
/// <param name="modelFlag">The model flag.</param>
|
||||
/// <param name="
|
||||
/// Params">The URL parameters.</param>
|
||||
public static void OpenModule(string menuId, string menuName, string dllName, string modelFlag, string urlParams)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 验证参数
|
||||
if (string.IsNullOrWhiteSpace(menuId) || string.IsNullOrWhiteSpace(dllName))
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.NotFoundMenu);
|
||||
return;
|
||||
}
|
||||
// 验证权限
|
||||
int purview = MainImpl.GetUserPurviewsByMenuId(menuId);
|
||||
if (purview == 0)
|
||||
{
|
||||
MessageUtil.Show(ResourceKeys.UnPurview);
|
||||
return;
|
||||
}
|
||||
//验证是否设置不能打开多个相同模块
|
||||
bool SingleOpenMode = MainImpl.GetOpenRestrictions(menuId);
|
||||
|
||||
|
||||
LogUtil.WriteDebug(modelFlag.ToString(), "操作模块", menuName, menuName, menuId.ToString());
|
||||
DllModule module = new DllModule
|
||||
{
|
||||
DllName = ReplaceDllFileName(dllName),
|
||||
Id = menuId,
|
||||
Name = menuName,
|
||||
Code = modelFlag.ToString()
|
||||
};
|
||||
string[] args = new string[]{
|
||||
menuName,
|
||||
ERPInfo.Instance.UserId,
|
||||
ERPInfo.Instance.UserName,
|
||||
purview + "",
|
||||
urlParams,
|
||||
menuId
|
||||
};
|
||||
dllName = MainImpl.GetDefaultValue(dllName);
|
||||
if (SystemInfo.Instance.SoftOpenMode || SingleOpenMode)
|
||||
{
|
||||
foreach (XtraTabPage tablepage in TabMain.TabPages)
|
||||
{
|
||||
if (tablepage.Text == menuName)
|
||||
{
|
||||
MessageUtil.Show("已设置不能打开多个相同模块!");
|
||||
TabMain.SelectedTabPage = tablepage;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dllName.ToLower().Contains(".exe"))
|
||||
{
|
||||
//WinHelper.WinExec(File.Exists(dllName) ? dllName : PubUtil.AbsolutelyLibPath + dllName, 1);
|
||||
// WinHelper.WinExec(dllName);
|
||||
Process.Start(File.Exists(dllName) ? dllName : PubUtil.AbsolutelyLibPath + dllName, string.Join(",", args));
|
||||
}
|
||||
else if (dllName.ToLower().IndexOf("http:", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
dllName.ToLower().IndexOf("www.", StringComparison.OrdinalIgnoreCase) != -1 ||
|
||||
dllName.ToLower().IndexOf("ftp:", StringComparison.OrdinalIgnoreCase) != -1)
|
||||
{
|
||||
Process.Start(dllName);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dllName.ToLower().EndsWith(".lsp"))
|
||||
{
|
||||
//MessageBox.Show(PubUtil.AbsolutelyLibPath + dllName+" "+ menuName+" "+purview+" "+urlParams);
|
||||
// 打开delphi程序
|
||||
DelphiHelper.LoadDelphiDll(PubUtil.AbsolutelyLibPath + dllName, "", menuName, "", "", purview, urlParams);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 打开module程序
|
||||
AddModuleToTab(module, args);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(Message, ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:添加模块到tab中</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-16 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="tabMain">The tab main.</param>
|
||||
/// <param name="module">The module.</param>
|
||||
/// <param name="args">The arguments.</param>
|
||||
public static void AddModuleToTab(DllModule module, string[] args)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool isQuickLoad = (args[5] + "").Equals(SystemInfo.Instance.QuickMenuId);
|
||||
//if (isQuickLoad && QuickMenuForm != null)
|
||||
//{
|
||||
// QuickMenuForm.WindowState = FormWindowState.Normal;
|
||||
// //QuickMenuForm.BringToFront();
|
||||
// return;
|
||||
//}
|
||||
string guid = Guid.NewGuid().ToString();
|
||||
XtraTabPage tp = new XtraTabPage();
|
||||
if (SystemInfo.Instance.IsDogVerify)
|
||||
{
|
||||
if (!CheckPrivateTable())
|
||||
{
|
||||
MessageUtil.Show("私密模块权限验证失败,请联系管理员");
|
||||
return;
|
||||
}
|
||||
DataTable privateDllTab = SqlHelper.ExecuteDataTable("select * from P_PrivateDllTab where privateTag=1");
|
||||
if (privateDllTab.Select(string.Format("LMenuid='{0}'", args[5].Trim())).Count() > 0)
|
||||
{
|
||||
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)
|
||||
{
|
||||
//U盾密码验证
|
||||
if (ERPInfo.Instance.isDogVerifyPassword)
|
||||
{
|
||||
FrmVerify frmVerify = new FrmVerify();
|
||||
DialogResult dialogResult = frmVerify.ShowDialog();
|
||||
if (dialogResult != DialogResult.OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
byte[] buffer = new byte[4096];
|
||||
int nrtn = SmartX1Api.SmartX1ReadStorage(keyHandle, 0, 4096, buffer);
|
||||
if (nrtn == 0)
|
||||
{
|
||||
string writeKey = string.Format("{0}_{1}", DBConfig.Instance.ServerName, DBConfig.Instance.DataBase);
|
||||
Dictionary<string, string> readKeysValues = new Dictionary<string, string>();
|
||||
string verifyStr = Encoding.Default.GetString(buffer);
|
||||
string[] readVerifyStrArray = verifyStr.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(args[5].Trim()))
|
||||
{
|
||||
MessageUtil.Show("未拥有当前模块查看权限");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticControl.DogVerifyModuleForms.Add(tp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("未拥有当前模块查看权限");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("U盾数据获取失败,请重试或联系管理员");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageUtil.Show("U盾验证失败,请重试或联系管理员");
|
||||
return;
|
||||
}
|
||||
SmartX1Api.SmartX1Close(keyHandle);
|
||||
}
|
||||
}
|
||||
|
||||
if (isQuickLoad)
|
||||
{
|
||||
List<string> list = args.ToList();
|
||||
list.Add(module.DllName);
|
||||
list.Add(ERPInfo.Instance.UserId);
|
||||
list.Add(ERPInfo.Instance.UserName);
|
||||
list.Add(ERPInfo.Instance.Password);
|
||||
FormHelper.StartProcess("Lskj.QuickModule", list.ToArray());
|
||||
return;
|
||||
}
|
||||
|
||||
ERPInfo.Instance.selectFormModleId = module.Id;
|
||||
IForm iform = FormHelper.LoadDllForm(module.DllName, args);
|
||||
// 菜单打开的模块默认最大化,界面FormState设置为Normal模式,否则会出现界面不是全屏,会显示默认阴影界面
|
||||
//iform.SubForm.WindowState = _frmMain.WindowState;
|
||||
iform.SubForm.WindowState = FormWindowState.Normal; ;
|
||||
Form form = iform.SubForm; // 表示组成应用程序的用户界面的窗口或对话框。
|
||||
form.Tag = guid;
|
||||
// 这个必须有不然会提示:"不能向tabControl中添加顶级控件"
|
||||
form.TopLevel = isQuickLoad;
|
||||
//form.Location = new Point(0, 0);
|
||||
form.Dock = DockStyle.Fill;//客户需要缩放
|
||||
form.AutoSize = true;
|
||||
//form.Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
|
||||
//form.Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - MinusTheHeight;
|
||||
form.FormBorderStyle = FormBorderStyle.None;
|
||||
//if (isQuickLoad)
|
||||
//{
|
||||
// form.FormBorderStyle = FormBorderStyle.Sizable;
|
||||
// form.StartPosition = FormStartPosition.CenterScreen;
|
||||
// form.TopMost = true;
|
||||
// form.FormClosed += Form_FormClosed;
|
||||
// QuickMenuForm = form;
|
||||
// tp.Dispose();
|
||||
// form.Show();
|
||||
//}
|
||||
|
||||
tp.Text = module.Name;
|
||||
tp.Tag = guid;
|
||||
tp.AutoScroll = true;
|
||||
tp.Controls.Add(form);
|
||||
tp.ShowCloseButton = DefaultBoolean.True;
|
||||
tp.Dock = DockStyle.Fill;
|
||||
|
||||
//module.Tag = "1";
|
||||
module.Tag = guid;
|
||||
module.ModuleForm = form;
|
||||
form.Show();
|
||||
if (args != null && !string.IsNullOrEmpty(args[4] + ""))
|
||||
{
|
||||
ModuleModel moduleModel = new ModuleModel(MainImpl.GetSystemdllTab(args[4] + ""));
|
||||
if (!string.IsNullOrEmpty(moduleModel.SearchCondFormModuleCode))
|
||||
{
|
||||
ModuleConditionsPanelEx mcpex = new ModuleConditionsPanelEx();
|
||||
mcpex.InitializeControl(new ModuleModel(MainImpl.GetSystemdllTab(moduleModel.SearchCondFormModuleCode)), null, null, true);
|
||||
if (StaticControl.ConditionsPanelDic.ContainsKey(args[4] + ""))
|
||||
{
|
||||
StaticControl.ConditionsPanelDic[args[4] + ""].Dispose();
|
||||
StaticControl.ConditionsPanelDic[args[4] + ""] = mcpex;
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticControl.ConditionsPanelDic.Add(args[4] + "", mcpex);
|
||||
}
|
||||
DialogResult dialogResult = mcpex.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
TabMain.TabPages.Add(tp);
|
||||
TabMain.SelectedTabPage = tp;
|
||||
ModuleForms.Add(guid, module);
|
||||
|
||||
//LastModuleForm.Add(module);
|
||||
//Lskj.Main.Model.AutoSizeChange.ControllInitializeSize(form);//调整控件大小
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
string Message = ErrorMessage.PromptErrorMessage(ex);
|
||||
MessageUtil.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
|
||||
LogHelper.Instance.WriteError(ex);
|
||||
//LogUtil.WriteError("打开" + module.Name + "模块失败!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 快速菜单关闭时,清除记录
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private static void Form_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
QuickMenuForm = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>说明:特殊dll模块处理</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2018-04-20 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="dllName">Name of the DLL.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private static string ReplaceDllFileName(string dllName)
|
||||
{
|
||||
switch (dllName.ToLower().Trim())
|
||||
{
|
||||
case "pubspec.dll":
|
||||
dllName = "Lskj.PubSpec.dll";
|
||||
break;
|
||||
}
|
||||
return dllName;
|
||||
}
|
||||
private static void ExitSystem()
|
||||
{
|
||||
try
|
||||
{
|
||||
// 退出系统
|
||||
if (DBConfig.Instance.NoticeExit)
|
||||
{
|
||||
Process[] p1 = Process.GetProcessesByName("Ls_Notice");
|
||||
foreach (Process item in p1)
|
||||
item.Kill();
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.QuickMenuId))
|
||||
{
|
||||
Process[] p2 = Process.GetProcessesByName("Lskj.QuickModule");
|
||||
foreach (Process item in p2)
|
||||
{
|
||||
try
|
||||
{
|
||||
item.Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:启动配置窗口</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-09 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
private static DialogResult RunConfigForm()
|
||||
{
|
||||
FrmConfigSet frmConfigSet = new FrmConfigSet();
|
||||
return frmConfigSet.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开登录界面</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-12 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static DialogResult RunLoginForm()
|
||||
{
|
||||
FrmLogin frmLogin = new FrmLogin();
|
||||
return frmLogin.ShowDialog();
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开子系统</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>System.Windows.Forms.DialogResult.</returns>
|
||||
private static DialogResult RunSubSystemForm()
|
||||
{
|
||||
_frmSubSystem = new FrmSubSystem();
|
||||
DialogResult dialogResult = _frmSubSystem.ShowDialog();
|
||||
BsName = _frmSubSystem.BsName;
|
||||
BsUrl = _frmSubSystem.BsUrl;
|
||||
return dialogResult;
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:打开主程序</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static DialogResult RunMainForm()
|
||||
{
|
||||
_frmMain = new FrmMain();
|
||||
return _frmMain.ShowDialog();
|
||||
}
|
||||
#region 初始化服务器直接连接
|
||||
/// <summary>
|
||||
/// <para>说明:初始化服务器直接连接</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-14 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <returns>DialogResult.</returns>
|
||||
private static void CheckLocalConfig()
|
||||
{
|
||||
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"))
|
||||
{
|
||||
string lastIPPort = string.Format("{0}:{1}", IniHelper.Read("SystemResources.ini", "LocalLastIP"), IniHelper.Read("SystemResources.ini", "LocalLastPort"));
|
||||
string downloadAESStrKey = string.Format("DownloadAESStr_{0}", lastIPPort);
|
||||
string[] downloadAESStrValue = IniHelper.Read("SystemResources.ini", downloadAESStrKey).Split('^');
|
||||
string downloadAESStr = downloadAESStrValue.Length == 2 ? downloadAESStrValue[1] : "";
|
||||
if (!string.IsNullOrEmpty(downloadAESStr))
|
||||
{
|
||||
string args = AESUtil.Decrypt(downloadAESStr);
|
||||
string[] controlAfgs = args.Split('^');
|
||||
if (controlAfgs != null && controlAfgs.Length == 5)
|
||||
{
|
||||
DBConfig.Instance.ServerName = controlAfgs[0];
|
||||
DBConfig.Instance.DataBase = controlAfgs[1];
|
||||
string Connection = "Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5;MultipleActiveResultSets=true";
|
||||
string dephistr = "Provider=SQLOLEDB.1;Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5";
|
||||
Connection = AESUtil.Encrypt(Connection);
|
||||
dephistr = AESUtil.Encrypt(dephistr);
|
||||
DBConfig.Instance.dephiConnection = dephistr;
|
||||
if (DBConfig.Instance.CreateConnection(Connection))
|
||||
{
|
||||
DBConfig.Instance.Connection = Connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 判断私有模块权限表格是否存在
|
||||
/// </summary>
|
||||
private static bool CheckPrivateTable()
|
||||
{
|
||||
try
|
||||
{
|
||||
//日志表列名
|
||||
Dictionary<string, string> colDic = new Dictionary<string, string>();
|
||||
colDic.Add("ObjDll", "varchar(1000)");
|
||||
colDic.Add("DllShowCaption", "varchar(1000)");
|
||||
colDic.Add("LMenuid", "int");
|
||||
colDic.Add("Lsubsysid", "int");
|
||||
colDic.Add("PrivateTag", "int");
|
||||
string isExitApiTab = "select top 1 * from sysObjects where Id=OBJECT_ID(N'P_PrivateDllTab') and xtype='U'";
|
||||
DataTable apiTab = SqlHelper.ExecuteDataTable(isExitApiTab);
|
||||
if (apiTab.Rows.Count > 0)//存在日志表
|
||||
{
|
||||
DataTable columnsTab = SqlHelper.ExecuteDataTable(string.Format("select name from syscolumns where id=object_id('P_PrivateDllTab')"));
|
||||
foreach (KeyValuePair<string, string> colunmField in colDic)
|
||||
{
|
||||
DataRow[] dataRows = columnsTab.Select().Where(n => (n["name"] + "").Equals(colunmField.Key)).ToArray();
|
||||
if (dataRows.Length == 0)
|
||||
{
|
||||
string addColSql = string.Format("alter table P_PrivateDllTab add {0} {1}", colunmField.Key, colunmField.Value);
|
||||
SqlHelper.ExecuteNonQuery(addColSql);//添加列
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string createTabSql = "create table P_PrivateDllTab(id int IDENTITY(1,1) NOT NULL,{0})";
|
||||
string createCol = string.Empty;
|
||||
foreach (KeyValuePair<string, string> colunmField in colDic)
|
||||
{
|
||||
createCol += string.Format("{0} {1},", colunmField.Key, colunmField.Value);
|
||||
}
|
||||
createTabSql = string.Format(createTabSql, createCol.TrimEnd(','));
|
||||
SqlHelper.ExecuteNonQuery(createTabSql);//创建表
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// <para>说明:连接服务器</para>
|
||||
/// <para>创建人:龚宇超</para>
|
||||
/// <para>创建日期:2017-08-09 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
/// <param name="isSave">if set to <c>true</c> [is save].</param>
|
||||
private static bool ConnectServer(string _ip, string _port)
|
||||
{
|
||||
bool isSuccess = false;
|
||||
string serverName = DBConfig.Instance.ServerName;
|
||||
// 测试数据库连接
|
||||
try
|
||||
{
|
||||
string ip = _ip;
|
||||
string defaultPort = ":" + _port;
|
||||
//服务器下载
|
||||
string newServerName = !serverName.StartsWith("http") ? "http://" + ip + defaultPort : ip + defaultPort;
|
||||
newServerName = !newServerName.EndsWith("/") ? newServerName + "/" : newServerName;
|
||||
string newfilePath = Path.Combine(newServerName, "SystemResources.txt");
|
||||
//string name = WebRequest.Create(filePath).GetResponse().GetResponseStream().ToString();
|
||||
string fileName = "SystemResources.txt";//客户端保存的文件名
|
||||
WebClient webClient = new WebClient();
|
||||
webClient.Encoding = Encoding.UTF8;
|
||||
//这里使用DownloadString方法,如果是不需要对文件的文本内容做处理,直接保存,那么可以直接使用功能DownloadFile(url,savepath)直接进行文件保存。
|
||||
string newoutText = newfilePath != filePath ? webClient.DownloadString(newfilePath) : outText;
|
||||
outText = newoutText.Trim();
|
||||
filePath = newfilePath;
|
||||
//File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemResources.txt"), outText);
|
||||
string args = AESUtil.Decrypt(outText);
|
||||
string[] controlAfgs = args.Split('^');
|
||||
if (controlAfgs != null && controlAfgs.Length == 5)
|
||||
{
|
||||
DBConfig.Instance.ServerName = controlAfgs[0];
|
||||
DBConfig.Instance.DataBase = controlAfgs[1];
|
||||
string Connection = "Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5;MultipleActiveResultSets=true";
|
||||
string dephistr = "Provider=SQLOLEDB.1;Server={0};Database={1};Persist Security Info=True;User ID=" + controlAfgs[2] + ";Password=" + controlAfgs[3] + ";Connection Timeout=5";
|
||||
Connection = AESUtil.Encrypt(Connection);
|
||||
dephistr = AESUtil.Encrypt(dephistr);
|
||||
DBConfig.Instance.dephiConnection = dephistr;
|
||||
DBConfig.Instance.Connection = Connection;
|
||||
if (DBConfig.Instance.CreateConnection(Connection))
|
||||
{
|
||||
Dictionary<string, string> sourceDic = IniHelper.GetSectionKeys("SystemResources.ini", "SystemResources");
|
||||
string dicKey = string.Format("DownloadAESStr_{0}{1}", ip, defaultPort);
|
||||
if (sourceDic.ContainsKey(dicKey))
|
||||
{
|
||||
string key = sourceDic[dicKey];
|
||||
string[] keyArgs = dicKey.Split('_');
|
||||
if (keyArgs.Length == 2)
|
||||
{
|
||||
string ztName = sourceDic[dicKey].Split('^')[0];//账套名
|
||||
if (!string.IsNullOrEmpty(ztName))
|
||||
{
|
||||
string IPPort = string.Format("{0}:{1}", _ip, _port);
|
||||
string writeText = string.Format("{0}^{1}", ztName, outText);
|
||||
IniHelper.Write("SystemResources.ini", string.Format("DownloadAESStr_{0}", IPPort), writeText);
|
||||
isSuccess = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//IniHelper.Write("SystemResources.ini", "FrmConfigFlag", "1");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
return isSuccess;
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// <para>说明:强制登录下线</para>
|
||||
/// <para>创建人:唐德馨</para>
|
||||
/// <para>创建日期:2023-10-16 </para>
|
||||
/// <para>修改人:</para>
|
||||
/// <para>修改日期:</para>
|
||||
/// <para>修改备注:</para>
|
||||
/// <para>版本:1.0</para>
|
||||
/// </summary>
|
||||
private static void WhenConstraintLogin()
|
||||
{
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
bool isClose = false;
|
||||
while (SystemInfo.Instance.IsConstraintExit)
|
||||
{
|
||||
string hostName = "";
|
||||
string clientip = "";
|
||||
string loginMacAdress = "";
|
||||
DataTable loginTable = new DataTable();
|
||||
try
|
||||
{
|
||||
loginTable = SqlHelper.ExecuteDataTable("select rtrim(ltrim(substring(hostname,1,100))) as hostname from master.dbo.sysprocesses where loginame = 'lserpAdmin' and (program_name = '' or program_name = '.Net SqlClient Data Provider')");
|
||||
hostName = SqlHelper.ExecuteScalar(string.Format("select hostname from p_LoginHostInfotab where OperatorId = '{0}' and Tagid = 1", ERPInfo.Instance.UserId)) + "";
|
||||
clientip = SqlHelper.ExecuteScalar(string.Format("select clientip from p_employeetab where employeeid = '{0}'", ERPInfo.Instance.UserId)) + "";
|
||||
loginMacAdress = SqlHelper.ExecuteScalar(string.Format("select macAdress from p_employeetab where employeeid = '{0}'", ERPInfo.Instance.UserId)) + "";
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
//!string.IsNullOrEmpty(hostName) && loginTable.Select().Where(n => n["hostname"].Equals(hostName)).Count() > 0 && !loginMacAdress.Equals(ERPInfo.Instance.MacAddress)
|
||||
if (!loginMacAdress.Equals(ERPInfo.Instance.MacAddress))
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_frmSubSystem != null && _frmSubSystem.Visible == true)
|
||||
{
|
||||
_frmSubSystem.Invoke(new Action(() =>
|
||||
{
|
||||
if (!isClose)
|
||||
{
|
||||
_frmSubSystem.Opacity = 0;
|
||||
MessageUtil.Show($"当前用户在另一电脑登录\r\nClientIp:{clientip}\r\nMacAdress:{loginMacAdress}\r\n当前系统即将关闭");
|
||||
isClose = true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
else if (_frmMain != null && _frmMain.Visible == true)
|
||||
{
|
||||
_frmMain.Invoke(new Action(() =>
|
||||
{
|
||||
if (!isClose)
|
||||
{
|
||||
_frmMain.Opacity = 0;
|
||||
MessageUtil.Show($"当前用户在另一电脑登录\r\nClientIp:{clientip}\r\nMacAdress:{loginMacAdress}\r\n当前系统即将关闭");
|
||||
isClose = true;
|
||||
}
|
||||
}));
|
||||
}
|
||||
if (isClose)
|
||||
{
|
||||
if (DBConfig.Instance.NoticeExit)
|
||||
{
|
||||
Process[] p1 = Process.GetProcessesByName("Ls_Notice");
|
||||
foreach (Process item in p1)
|
||||
{
|
||||
try
|
||||
{
|
||||
item.Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(SystemInfo.Instance.QuickMenuId))
|
||||
{
|
||||
Process[] p2 = Process.GetProcessesByName("Lskj.QuickModule");
|
||||
foreach (Process item in p2)
|
||||
{
|
||||
try
|
||||
{
|
||||
item.Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//记录登出日志
|
||||
LogUtil.WriteDebug("", "退出软件", "软件退出", "系统登录");
|
||||
Process[] p = Process.GetProcessesByName("Ls_ERP");
|
||||
foreach (Process item in p)
|
||||
{
|
||||
try
|
||||
{
|
||||
item.Kill();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
//Environment.Exit(0);
|
||||
Application.Exit();
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
/// <summary>
|
||||
/// 锁定程序
|
||||
/// </summary>
|
||||
private static void LockApplication()
|
||||
{
|
||||
Thread thread = new Thread(() =>
|
||||
{
|
||||
while (SystemInfo.Instance.AwaitTime > 10)
|
||||
{
|
||||
if (isAwaitTime == SystemInfo.Instance.AwaitTime)
|
||||
{
|
||||
isAwaitTime = 0;
|
||||
if (_frmMain != null && _frmMain.Visible == true)
|
||||
{
|
||||
_frmMain.Invoke(new Action(() =>
|
||||
{
|
||||
_frmMain.mainPanelControlEx.AwaitControl.BringToFront();
|
||||
_frmMain.mainPanelControlEx.AwaitControl.Visible = true;
|
||||
_frmMain.mainPanelControlEx.AwaitControl.OnFrmAwaitScreenLoad();
|
||||
}));
|
||||
}
|
||||
}
|
||||
isAwaitTime += 1;
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,403 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Lskj.Main.Model
|
||||
{
|
||||
public static class WinAPI
|
||||
{
|
||||
#region 常量声明
|
||||
|
||||
public const int GWL_WNDPROC = -4; //得到窗口回调函数的地址,或者句柄。得到后必须使用CallWindowProc函数来调用
|
||||
public const int GWL_HINSTANCE = -6; //得到应用程序运行实例的句柄
|
||||
public const int GWL_HWNDPARENT = -8; //得到父窗口的句柄
|
||||
public const int GWL_STYLE = -16; //得到窗口风格
|
||||
public const int GWL_EXSTYLE = -20; //得到扩展的窗口风格
|
||||
public const int GWL_USERDATA = -21; //得到和窗口相关联的32位的值(每一个窗口都有一个有意留给创建窗口的应用程序是用的32位的值)
|
||||
public const int GWL_ID = -12; //得到窗口的标识符
|
||||
|
||||
public const int DWL_MSGRESULT = 0;
|
||||
public const int DWL_DLGPROC = 4;
|
||||
public const int DWL_USER = 8;
|
||||
|
||||
public const int HWND_BOTTOM = 1;
|
||||
public const int HWND_TOP = 0;
|
||||
public const int HWND_TOPMOST = -1;
|
||||
public const int HWND_NOTOPMOST = -2;
|
||||
|
||||
public const int SWP_DRAW = 0x20;
|
||||
public const int SWP_HIDEWINDOW = 0x80;
|
||||
public const int SWP_NOACTIVATE = 0x10;
|
||||
public const int SWP_NOMOVE = 0x2;
|
||||
public const int SWP_NOREDRAW = 0x8;
|
||||
public const int SWP_NOSIZE = 0x1;
|
||||
public const int SWP_NOZORDER = 0x4;
|
||||
public const int SWP_SHOWWINDOW = 0x40;
|
||||
|
||||
public const int WS_OVERLAPPED = 0;
|
||||
public const int WS_BORDER = 0x800000;
|
||||
public const int WS_CAPTION = 0xC00000;
|
||||
public const int WS_CHILD = 0x40000000;
|
||||
public const int WS_DLGFRAME = 0x400000;
|
||||
public const int WS_SIZEBOX = 0x40000;
|
||||
public const int WS_MAXIMIZEBOX = 0x10000;
|
||||
public const int WS_MINIMIZEBOX = 0x20000;
|
||||
public const int WS_SYSMENU = 0x80000;
|
||||
public const int WS_HSCROLL = 0x100000;
|
||||
public const int WS_VSCROLL = 0x200000;
|
||||
|
||||
public const int WA_INACTIVE = 0;
|
||||
public const int WA_ACTIVE = 1;
|
||||
public const int WA_CLICKACTIVE = 2;
|
||||
public const int WM_NOTIFY = 0x004E;
|
||||
|
||||
public const int WM_ACTIVATE = 0x0006;
|
||||
public const int WM_NULL = 0x0000;
|
||||
public const int WM_CREATE = 0x0001;
|
||||
public const int WM_DESTROY = 0x0002;
|
||||
public const int WM_MOVE = 0x0003;
|
||||
public const int WM_SIZE = 0x0005;
|
||||
public const int WM_SETFOCUS = 0x0007;
|
||||
public const int WM_MOUSEACTIVATE = 0x0021;
|
||||
public const int WM_CLOSE = 0x0010;
|
||||
public const int WM_QUIT = 0x0012;
|
||||
|
||||
public const int WM_KEYDOWN = 0x0100;
|
||||
public const int WM_KEYUP = 0x0101;
|
||||
public const int WM_CHAR = 0x0102;
|
||||
public const int WM_DEADCHAR = 0x0103;
|
||||
public const int WM_SYSKEYDOWN = 0x0104;
|
||||
public const int WM_SYSKEYUP = 0x0105;
|
||||
public const int WM_SYSCHAR = 0x0106;
|
||||
public const int WM_SYSDEADCHAR = 0x0107;
|
||||
public const int WM_UNICHAR = 0x0109;
|
||||
public const int WM_KEYLAST = 0x0109;
|
||||
public const int UNICODE_NOCHAR = 0xFFFF;
|
||||
|
||||
public const int MK_LBUTTON = 0x0001;
|
||||
public const int MK_RBUTTON = 0x0002;
|
||||
public const int MK_SHIFT = 0x0004;
|
||||
public const int MK_CONTROL = 0x0008;
|
||||
public const int MK_MBUTTON = 0x0010;
|
||||
|
||||
public const int WM_MOUSEFIRST = 0x0200;
|
||||
public const int WM_MOUSEMOVE = 0x0200;
|
||||
public const int WM_LBUTTONDOWN = 0x0201;
|
||||
public const int WM_LBUTTONUP = 0x0202;
|
||||
public const int WM_LBUTTONDBLCLK = 0x0203;
|
||||
public const int WM_RBUTTONDOWN = 0x0204;
|
||||
public const int WM_RBUTTONUP = 0x0205;
|
||||
public const int WM_RBUTTONDBLCLK = 0x0206;
|
||||
public const int WM_MBUTTONDOWN = 0x0207;
|
||||
public const int WM_MBUTTONUP = 0x0208;
|
||||
public const int WM_MBUTTONDBLCLK = 0x0209;
|
||||
public const int WM_MOUSEWHEEL = 0x020A;
|
||||
public const int WM_MDICREATE = 0x0220;
|
||||
|
||||
public const int WM_ERASEBKGND = 0x14;
|
||||
public const int WM_PAINT = 0xF;
|
||||
public const int WM_NC_HITTEST = 0x84;
|
||||
public const int WM_NC_PAINT = 0x85;
|
||||
public const int WM_PRINTCLIENT = 0x318;
|
||||
public const int WM_SETCURSOR = 0x20;
|
||||
|
||||
public const int BM_CLICK = 0x00F5;
|
||||
public const int BM_GETIMAGE = 0x00F6;
|
||||
public const int BM_SETIMAGE = 0x00F7;
|
||||
|
||||
public const int VK_BACK = 0x08;
|
||||
public const int VK_TAB = 0x09;
|
||||
public const int VK_CLEAR = 0x0C;
|
||||
public const int VK_RETURN = 0x0D;
|
||||
public const int VK_SHIFT = 0x10;
|
||||
public const int VK_CONTROL = 0x11;
|
||||
public const int VK_MENU = 0x12;
|
||||
public const int VK_PAUSE = 0x13;
|
||||
public const int VK_CAPITAL = 0x14;
|
||||
public const int VK_KANA = 0x15;
|
||||
public const int VK_HANGEUL = 0x15;
|
||||
public const int VK_HANGUL = 0x15;
|
||||
public const int VK_JUNJA = 0x17;
|
||||
public const int VK_FINAL = 0x18;
|
||||
public const int VK_HANJA = 0x19;
|
||||
public const int VK_KANJI = 0x19;
|
||||
public const int VK_ESCAPE = 0x1B;
|
||||
public const int VK_CONVERT = 0x1C;
|
||||
public const int VK_NONCONVERT = 0x1D;
|
||||
public const int VK_ACCEPT = 0x1E;
|
||||
public const int VK_MODECHANGE = 0x1F;
|
||||
public const int VK_SPACE = 0x20;
|
||||
public const int VK_PRIOR = 0x21;
|
||||
public const int VK_NEXT = 0x22;
|
||||
public const int VK_END = 0x23;
|
||||
public const int VK_HOME = 0x24;
|
||||
public const int VK_LEFT = 0x25;
|
||||
public const int VK_UP = 0x26;
|
||||
public const int VK_RIGHT = 0x27;
|
||||
public const int VK_DOWN = 0x28;
|
||||
public const int VK_SELECT = 0x29;
|
||||
public const int VK_PRINT = 0x2A;
|
||||
public const int VK_EXECUTE = 0x2B;
|
||||
public const int VK_SNAPSHOT = 0x2C;
|
||||
public const int VK_INSERT = 0x2D;
|
||||
public const int VK_DELETE = 0x2E;
|
||||
public const int VK_HELP = 0x2F;
|
||||
|
||||
public const int KEYEVENTF_EXTENDEDKEY = 0x0001;
|
||||
public const int KEYEVENTF_KEYUP = 0x0002;
|
||||
public const int KEYEVENTF_UNICODE = 0x0004;
|
||||
public const int KEYEVENTF_SCANCODE = 0x0008;
|
||||
|
||||
public const int HC_ACTION = 0x0;
|
||||
public const int WH_MOUSELL = 0xE;
|
||||
|
||||
public const int STATUS_SUCCESS = 0x0;
|
||||
#endregion
|
||||
|
||||
#region API函数声明
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetParent")]
|
||||
public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetParent")]
|
||||
public static extern int GetParent(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowLong")]
|
||||
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int GetWindowRect(IntPtr hwnd, out Rect lpRect);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowLong")]
|
||||
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int lNewLong);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
|
||||
public static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int uFlags);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "UpdateWindow")]
|
||||
public static extern bool UpdateWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessage")]
|
||||
public static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "PostMessage")]
|
||||
public static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "PostMessage")]
|
||||
public static extern int PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "keybd_event")]
|
||||
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, long dwExtraInfo);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")]
|
||||
public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int lpdwProcessId);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern void SetForegroundWindow(IntPtr hwnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "DrawMenuBar")]
|
||||
public static extern int DrawMenuBar(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "mouse_event")]
|
||||
public static extern void mouse_event(int dwFlags, int dx, int dy, int dwData, IntPtr dwExtraInfo);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetCursorPos")]
|
||||
public static extern void SetCursorPos(int x, int y);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
|
||||
public static extern bool GetCursorPos(out POINT p);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "SetWindowsHookEx")]
|
||||
public static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hInstance, int threadId);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "UnhookWindowsHookEx")]
|
||||
public static extern int UnhookWindowsHookEx(int idHook);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "CallNextHookEx")]
|
||||
public static extern int CallNextHookEx(int idHook, int nCode, IntPtr wParam, IntPtr lParam);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetWindowDC")]
|
||||
public static extern IntPtr GetWindowDC(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
|
||||
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
||||
|
||||
[DllImport("kernel32.dll")]
|
||||
public static extern IntPtr GetModuleHandle(string name);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr WindowFromPoint(POINT Point);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "GetDoubleClickTime")]
|
||||
public static extern int GetDoubleClickTime();
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "FindWindow")]
|
||||
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport("user32.dll", EntryPoint = "FindWindow")]
|
||||
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 表示 Hook 回调函数。
|
||||
/// </summary>
|
||||
/// <param name="nCode"></param>
|
||||
/// <param name="wParam"></param>
|
||||
/// <param name="lParam"></param>
|
||||
/// <returns></returns>
|
||||
public delegate int HookProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
/// <summary>
|
||||
/// 表示进程间传递的数据结构
|
||||
/// </summary>
|
||||
public struct COPYDATASTRUCT
|
||||
{
|
||||
public IntPtr dwData;
|
||||
public int cbData;
|
||||
[MarshalAs(UnmanagedType.LPStr)]
|
||||
public string lpData;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于通过 API 获取位置信息的结构。
|
||||
/// </summary>
|
||||
public struct Rect
|
||||
{
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 与非托管通信的鼠标位置结构。
|
||||
/// </summary>
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct POINT
|
||||
{
|
||||
public int X;
|
||||
public int Y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鼠标事件标识。
|
||||
/// </summary>
|
||||
public enum MouseEventFlags
|
||||
{
|
||||
Move = 0x0001,
|
||||
LeftDown = 0x0002,
|
||||
LeftUp = 0x0004,
|
||||
RightDown = 0x0008,
|
||||
RightUp = 0x0010,
|
||||
MiddleDown = 0x0020,
|
||||
MiddleUp = 0x0040,
|
||||
Wheel = 0x0800,
|
||||
Absolute = 0x8000
|
||||
}
|
||||
}
|
||||
public class FormatSystemDatetime
|
||||
{
|
||||
[DllImport("kernel32.dll", EntryPoint = "GetSystemDefaultLCID")]
|
||||
public static extern int GetSystemDefaultLCID();
|
||||
[DllImport("kernel32.dll", EntryPoint = "SetLocaleInfoA")]
|
||||
public static extern int SetLocaleInfo(int Locale, int LCType, string lpLCData);
|
||||
[DllImport("user32.dll", EntryPoint = "SendMessageTimeout")]
|
||||
public static extern long SendMessageTimeout(int hWnd, int Msg, int wParam, int lParam, int fuFlags, int uTimeout, ref int lpdwResult);
|
||||
public const int LOCALE_SSHORTDATE = 0x1F;
|
||||
public const int LOCALE_SLONGDATE = 0x20;
|
||||
public const int LOCALE_STIME = 0x1003;
|
||||
public const int HWND_BROADCAST = 0xFFFF;
|
||||
public const int WM_SETTINGCHANGE = 0x001A;
|
||||
public const int SMTO_ABORTIFHUNG = 2;
|
||||
|
||||
public void SetDateTimeFormat()
|
||||
{
|
||||
try
|
||||
{
|
||||
int p = 0;
|
||||
int x = GetSystemDefaultLCID();
|
||||
SetLocaleInfo(x, LOCALE_SSHORTDATE, "yyyy-M-d"); //短日期格式
|
||||
SetLocaleInfo(x, LOCALE_SLONGDATE, "yyyy年M月d日"); //长日期格式
|
||||
SetLocaleInfo(x, LOCALE_STIME, "H:mm:ss"); //时间格式
|
||||
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0, SMTO_ABORTIFHUNG, 10, ref p);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// DevExpress
|
||||
/// </summary>
|
||||
public class AboutDevCompanion
|
||||
{
|
||||
private int Interval;
|
||||
private bool ResidentMode;
|
||||
private bool StopCompanion;
|
||||
private Thread m_Thread;
|
||||
|
||||
/// <summary>
|
||||
/// 按指定的模式创建 <see cref="Wunion.Budget.PowerBasicFramework.AboutDevCompanion"/> 对象实例。
|
||||
/// <param name="interval">检测Dev注册弹框的时间间隔(以毫秒为单位)。</param>
|
||||
/// <param name="resident">检测程序是否以常驻模式运行(默认值 true)。</param>
|
||||
/// </summary>
|
||||
public AboutDevCompanion(int interval, bool resident = true)
|
||||
{
|
||||
Interval = interval;
|
||||
ResidentMode = resident;
|
||||
StopCompanion = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭 DevExpress 控件的注册弹框(如果调用时找到并关闭了DevExpress注册弹框则返回true,否则返回false)。
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private bool CloseAboutDev()
|
||||
{
|
||||
IntPtr devHwnd = WinAPI.FindWindow(null, "About DevExpress");
|
||||
if (devHwnd != IntPtr.Zero)
|
||||
{
|
||||
WinAPI.SendMessage(devHwnd, WinAPI.WM_CLOSE, 0, 0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 运行 Dev 伴侣,对其注册弹框下毒手。
|
||||
/// </summary>
|
||||
public void Run()
|
||||
{
|
||||
if (!StopCompanion)
|
||||
return; // 防止多次运行导致可能的线程错误。
|
||||
StopCompanion = false;
|
||||
m_Thread = new Thread(new ThreadStart(() =>
|
||||
{
|
||||
while (!StopCompanion)
|
||||
{
|
||||
if (ResidentMode)
|
||||
CloseAboutDev();
|
||||
else // 如果非常驻模式,则在检测并关闭Dev注册弹框后应结束程序。
|
||||
StopCompanion = CloseAboutDev();
|
||||
Thread.Sleep(Interval);
|
||||
}
|
||||
m_Thread = null;
|
||||
}));
|
||||
m_Thread.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭程序的运行。
|
||||
/// </summary>
|
||||
public void Stop()
|
||||
{
|
||||
StopCompanion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user