/****************************** * 说明:主界面 * 创建人:龚宇超 * 创建日期:2018-04-25 * 修改人: * 修改日期: * 修改备注: * 版本: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.Main4.Model; using Lskj.Main4.Properties; using DevExpress.XtraEditors; using Lskj.Model; using Lskj.Control; using Lskj.Data; using Lskj.Control.Model; using Lskj.Business; using Lskj.Util; using Lskj.Main4.Control; using Lskj.Business.Impl; using DevExpress.XtraTab; using DevExpress.XtraEditors.Controls; using System.IO; using System.Threading; using System.Diagnostics; using System.Runtime.InteropServices; namespace Lskj.Main4 { /// /// 主界面 /// public partial class FrmMain : Form { /// /// 屏幕dpix、dpiy /// private float _dpiX, _dpiY; /// /// 是否鼠标按下 /// private bool _isMouseDown; /// /// 记录窗口位置 /// private Point _mousePostion; public FrmMain() { Graphics graphics = this.CreateGraphics(); _dpiX = graphics.DpiX; _dpiY = graphics.DpiY; InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); } #region 内存回收 [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); /// /// 说明:释放内存 /// 创建人:王一帆 /// 创建日期:2021-09-29 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// public static void ClearMemory() { GC.Collect(); GC.WaitForPendingFinalizers(); if (Environment.OSVersion.Platform == PlatformID.Win32NT) { //FrmMian为我窗体的类名 FrmMain.SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1); } } #endregion /// /// 说明:窗口加载 /// 创建人:龚宇超 /// 创建日期:2018-04-25 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// private void FrmMain_Load(object sender, EventArgs e) { try { this.mainPanelControlEx.Hide(); //FrmAutoSqlLoad frm = new FrmAutoSqlLoad(); //frm.ShowDialog(); this.KeyPreview = true;//主窗体允许使用事件 this.mainPanelControlEx.DpiX = _dpiX; this.mainPanelControlEx.DpiY = _dpiY; this.mainPanelControlEx.OnLoad(); this.mainPanelControlEx.OnCloseButtonCallBack += new EventHandler(OnCloseButtonCallBack); this.mainPanelControlEx.OnMaxButtonCallBack += new EventHandler(OnTopPanelMouseDoubleClickCallBack); this.mainPanelControlEx.OnMinButtonCallBack += new EventHandler(OnMinButtonCallBack); this.mainPanelControlEx.OnTopMouseDownCallback += new MouseEventHandler(OnTopMouseDownCallback); this.mainPanelControlEx.OnTopMouseMoveCallBack += new MouseEventHandler(OnTopMouseMoveCallBack); this.mainPanelControlEx.OnTopMouseUpCallBack += new MouseEventHandler(OnTopMouseUpCallBack); this.mainPanelControlEx.OnTopPanelMouseDoubleClickCallBack += new EventHandler(OnTopPanelMouseDoubleClickCallBack); if (SystemInfo.Instance.DetectionMemory) { this.TheMemoryTest.Start(); } this.mainPanelControlEx.State = this.WindowState; } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } finally { this.mainPanelControlEx.Show(); } } /// /// U盾状态改变 /// /// protected override void WndProc(ref Message m) { base.WndProc(ref m);//调用父类方法,以确保其他功能正常 switch (m.WParam.ToInt32()) { //U盾改变事件 case 7: if (SystemInfo.Instance.IsDogVerify) { int[] keyHandles = ERPInfo.Instance.keyHandles = new int[8]; int[] keyNumber = ERPInfo.Instance.keyNumber = new int[8]; int rtn = Lskj.Core.SmartX1Api.SmartX1Find("Ls_ERP", keyHandles, keyNumber); if (rtn != 0) { if (Manager.DogVerifyModuleForms.Count > 0) { this.mainPanelControlEx.TabMain.Invoke(new Action(() => { foreach (DevExpress.XtraTab.XtraTabPage page in Manager.DogVerifyModuleForms) { if (this.mainPanelControlEx.TabMain.TabPages.Contains(page)) { this.mainPanelControlEx.TabMain.TabPages.Remove(page); page.Dispose(); } } })); Manager.DogVerifyModuleForms.Clear(); MessageUtil.Show("U盾已断开连接,当前权限模块已关闭"); } } } break; } } /// /// 说明:通过分辨率界面重绘方法 /// 创建人:曹屹峰 /// 创建日期:2021-11-01 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// private void OnClickKeyboard(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.F3) { IntPtr hWnd = GetForegroundWindow(); //获取活动窗口句柄 int calcID = 0; //进程ID pid int calcTD = 0; //线程ID calcTD = GetWindowThreadProcessId(hWnd, out calcID); Clipboard.SetData(DataFormats.Text, (Object)calcID); MessageUtil.Show("程序PID码:" + calcID + "已复制到粘贴板上!"); } } /// /// 说明:通过分辨率界面重绘方法 /// 创建人:王一帆 /// 创建日期:2021-08-23 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// public void AutoLoadSize(System.Windows.Forms.Control Control) { foreach (System.Windows.Forms.Control C in Control.Controls) { if (C.Controls.Count > 0) { AutoLoadSize(C); } else { } } } /// /// 说明:重置窗口大小 /// 创建人:龚宇超 /// 创建日期:2018-02-27 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void ResetFormState() { foreach (string item in Manager.ModuleForms.Keys) { DllModule module = Manager.ModuleForms[item]; //(module.ModuleForm as Form).WindowState = FormWindowState.Maximized; //(module.ModuleForm as Form).WindowState = this.WindowState; ////(module.ModuleForm as Form).ModuleForm = DockStyle.Fill; //(module.ModuleForm as Form).Width = this.Width - 6; } } /// /// 说明:关闭窗口 /// 创建人:龚宇超 /// 创建日期:2018-04-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// /// private void OnCloseButtonCallBack(object sender, EventArgs e) { this.Close(); } /// /// 说明:窗口最大化 /// 创建人:龚宇超 /// 创建日期:2018-04-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnTopPanelMouseDoubleClickCallBack(object sender, EventArgs e) { try { this.WindowState = this.WindowState == FormWindowState.Normal ? FormWindowState.Maximized : FormWindowState.Normal; this.mainPanelControlEx.State = this.WindowState; this.StartPosition = FormStartPosition.CenterScreen; this.ResetFormState(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:窗口最小化 /// 创建人:龚宇超 /// 创建日期:2018-04-26 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// private void OnMinButtonCallBack(object sender, EventArgs e) { try { this.WindowState = FormWindowState.Minimized; this.ResetFormState(); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } /// /// 说明:关闭界面后清除之前打开的模块 /// 创建人:龚宇超 /// 创建日期:2017-08-21 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnFormClosing(object sender, FormClosingEventArgs e) { try { Manager.ModuleForms.Clear(); } 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 OnTopMouseDownCallback(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); } } /// /// 说明:鼠标按下 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnTopMouseMoveCallBack(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); } } /// /// 说明:鼠标移动 /// 创建人:龚宇超 /// 创建日期:2017-08-14 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void OnTopMouseUpCallBack(object sender, MouseEventArgs e) { try { base.OnMouseUp(e); _isMouseDown = false; //this.Focus(); this.mainPanelControlEx.pic_search.Focus();//点击界面失去焦点 } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } #region 无标题栏窗体最大化最小化 protected override CreateParams CreateParams { get { const int WS_MINIMIZEBOX = 0x00020000; // Winuser.h中定义 CreateParams cp = base.CreateParams; cp.Style = cp.Style | WS_MINIMIZEBOX; // 允许最小化操作 return cp; } } #endregion /// /// 说明:检测当前内容占用清空 /// 创建人:王一帆 /// 创建日期:2021-06-02 /// 修改人: /// 修改日期: /// 修改备注: /// 版本:1.0 /// /// The source of the event. /// The instance containing the event data. private void ContentDetection(object sender, EventArgs e) { try { MEMORY_INFO MemInfo; MemInfo = new MEMORY_INFO(); GlobalMemoryStatus(ref MemInfo); //Console.WriteLine(MemInfo.dwMemoryLoad.ToString() + "%的内存正在使用"); string footprint = MemInfo.dwMemoryLoad.ToString(); ClearMemory(); //if (double.Parse(footprint) >= 90) //{ //} //int WorkingSetLinex = System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet.ToInt32(); //string WorkingSetLinex2 = (WorkingSetLinex / 1024 / 1024).ToString(); //string WorkingSetLinex = Marshal.PtrToStringAnsi(System.Diagnostics.Process.GetCurrentProcess().MaxWorkingSet); //PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", name); //float ram2 = ramCounter.NextValue(); //string ram = String.Format("{0:F}", ramCounter.NextValue() / 1024 / 1024); //PerformanceCounter AllocateRam = new PerformanceCounter("Process", "Working Set - Private", name); //float pf = AllocateRam.NextValue(); //string workingSe = String.Format("{0:F}", AllocateRam.NextValue() / 1024 ); //PerformanceCounter sqdx = new PerformanceCounter("Process", "Virtual Bytes", name); //float sqdx1 = sqdx.NextValue(); //string sqdx2 = String.Format("{0:F}", sqdx.NextValue() / 1024 / 1024); } catch (Exception ex) { string Message = ErrorMessage.PromptErrorMessage(ex); MessageUtil.Show(Message, ex.Message); } } [DllImport("User32.dll")] public static extern IntPtr GetForegroundWindow(); //获取活动窗口句柄 [DllImport("User32.dll", CharSet = CharSet.Auto)] public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID); //获取线程ID [DllImport("kernel32")] public static extern void GetSystemDirectory(StringBuilder SysDir, int count); [DllImport("kernel32")] public static extern void GetSystemInfo(ref CPU_INFO cpuinfo); [DllImport("kernel32")] public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo); [DllImport("kernel32")] public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo); [StructLayout(LayoutKind.Sequential)] public struct CPU_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } //定义内存的信息结构 [StructLayout(LayoutKind.Sequential)] public struct MEMORY_INFO { public uint dwLength; public uint dwMemoryLoad; public uint dwTotalPhys; public uint dwAvailPhys; public uint dwTotalPageFile; public uint dwAvailPageFile; public uint dwTotalVirtual; public uint dwAvailVirtual; } //定义系统时间的信息结构 [StructLayout(LayoutKind.Sequential)] public struct SYSTEMTIME_INFO { public ushort wYear; public ushort wMonth; public ushort wDayOfWeek; public ushort wDay; public ushort wHour; public ushort wMinute; public ushort wSecond; public ushort wMilliseconds; } } }