ab56a9bcf7
SVN-Revision: r240
479 lines
18 KiB
C#
479 lines
18 KiB
C#
/******************************
|
|
* 说明:主界面
|
|
* 创建人:龚宇超
|
|
* 创建日期: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.Main3.Model;
|
|
using Lskj.Main3.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.Main3.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.Main3
|
|
{
|
|
|
|
/// <summary>
|
|
/// 主界面
|
|
/// </summary>
|
|
public partial class FrmMain : Form
|
|
{
|
|
|
|
/// <summary>
|
|
/// 屏幕dpix、dpiy
|
|
/// </summary>
|
|
private float _dpiX, _dpiY;
|
|
/// <summary>
|
|
/// 是否鼠标按下
|
|
/// </summary>
|
|
private bool _isMouseDown;
|
|
/// <summary>
|
|
/// 记录窗口位置
|
|
/// </summary>
|
|
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);
|
|
/// <summary>
|
|
/// <para>说明:释放内存</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-09-29 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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
|
|
/// <summary>
|
|
/// <para>说明:窗口加载</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-25 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void FrmMain_Load(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//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();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
string Message = ErrorMessage.PromptErrorMessage(ex);
|
|
MessageUtil.Show(Message, ex.Message);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:通过分辨率界面重绘方法</para>
|
|
/// <para>创建人:曹屹峰</para>
|
|
/// <para>创建日期:2021-11-01 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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+ "已复制到粘贴板上!");
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:通过分辨率界面重绘方法</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-08-23 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
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
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:重置窗口大小</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-02-27 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
private void ResetFormState()
|
|
{
|
|
foreach (string item in Manager.ModuleForms.Keys)
|
|
{
|
|
DllModule module = Manager.ModuleForms[item];
|
|
//(module.ModuleForm as Form).WindowState = FormWindowState.Maximized;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭窗口</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="e"></param>
|
|
private void OnCloseButtonCallBack(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:窗口最大化</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:窗口最小化</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2018-04-26 </para>
|
|
/// <para>修改人:</para>
|
|
/// <para>修改日期:</para>
|
|
/// <para>修改备注:</para>
|
|
/// <para>版本:1.0</para>
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// <para>说明:关闭界面后清除之前打开的模块</para>
|
|
/// <para>创建人:龚宇超</para>
|
|
/// <para>创建日期:2017-08-21 </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="FormClosingEventArgs"/> instance containing the event data.</param>
|
|
private void OnFormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
Manager.ModuleForms.Clear();
|
|
}
|
|
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 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);
|
|
}
|
|
|
|
}
|
|
/// <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 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);
|
|
}
|
|
|
|
}
|
|
/// <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 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
|
|
|
|
/// <summary>
|
|
/// <para>说明:检测当前内容占用清空</para>
|
|
/// <para>创建人:王一帆</para>
|
|
/// <para>创建日期:2021-06-02 </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 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;
|
|
}
|
|
}
|
|
} |