📄 formmain.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
using System.Reflection ;
using System.Diagnostics;
using CommCLB.Comm;
using CommCLB.sysmanagefrm;
namespace GPRSDrvWinApp
{
/// <summary>
/// FormMain 的摘要说明。
/// </summary>
public class FormMain : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu;
private System.Windows.Forms.NotifyIcon notifyIcon_Main;
private System.Windows.Forms.ContextMenu contextMenu_Main;
private System.Windows.Forms.MenuItem menuItem_ShowWin;
private System.Windows.Forms.MenuItem menuItem_HideWin;
private System.Windows.Forms.MenuItem menuItem_ExitWin;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem_AboutWin;
private System.Windows.Forms.ToolBar toolBar_Main;
private System.Windows.Forms.ToolBarButton toolBarButton_Help;
private System.Windows.Forms.ToolBarButton toolBarButton_About;
private System.Windows.Forms.ToolBarButton toolBarButton_Exit;
private System.Windows.Forms.ImageList imageList_Main;
private System.ComponentModel.IContainer components;
/// <summary>
/// 自定义变量
/// </summary>
private static string SplashImg=".\\ico\\face.jpg"; //splash图象文件位置
private static FormFlash SplashWin; //splash窗体
private static string Title ="自来水供水管网调度系统-GPRS驱动服务系统 V2.0";
private static string User="合肥";
private static string IconTIP="GPRS驱动服务系统";
private static string ModuleTag="GPRS驱动系统"; //本子系统的标识
private static string TopModuleAlias="GPRSDRV"; //系统菜单配置中最顶级的菜单别名
private static string AsswHelpFile="Assw_Help.chm"; //帮助文件
private static string RunOnce="0"; //允许运行多个实例 1是0否
private static int _Refresh=900000; //定时器工作时间 缺省15分钟
private static string LastUser; //上次登录用户ID
private string TopModuleNo;
private System.Windows.Forms.MenuItem menuItem2;//系统菜单配置中最顶级的菜单号,由系统通过别名查询得到
private Assembly assembly; //当前程序集合
private string appName; //当前程序集合名称
private DataSet menuDS=null;
private System.Windows.Forms.StatusBar stbMain;
private System.Windows.Forms.StatusBarPanel stbpmsg;
private System.Windows.Forms.StatusBarPanel stbpuserinfo;
private System.Windows.Forms.Timer tmRefresh;
private System.Windows.Forms.ContextMenu ctmWin;
private System.Windows.Forms.MenuItem menuItem_ToolBar;
private System.Windows.Forms.MenuItem menuItem_StatusBar;
private System.Windows.Forms.StatusBarPanel stbpIP; //授权菜单数据集合
private bool bCloseWin=false;//是否点选“退出”菜单
public FormMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
//取得当前程序集
if (!this.LoadMyAssembly())
{
Application.Exit();
return;
}
notifyIcon_Main.Text=IconTIP;
this.Visible=true;
this.notifyIcon_Main.Visible=false;
//设置定时器
this.tmRefresh.Enabled=true;
this.tmRefresh.Interval=_Refresh;
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(FormMain));
this.mainMenu = new System.Windows.Forms.MainMenu();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.notifyIcon_Main = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu_Main = new System.Windows.Forms.ContextMenu();
this.menuItem_ShowWin = new System.Windows.Forms.MenuItem();
this.menuItem_HideWin = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem_AboutWin = new System.Windows.Forms.MenuItem();
this.menuItem_ExitWin = new System.Windows.Forms.MenuItem();
this.toolBar_Main = new System.Windows.Forms.ToolBar();
this.toolBarButton_About = new System.Windows.Forms.ToolBarButton();
this.toolBarButton_Help = new System.Windows.Forms.ToolBarButton();
this.toolBarButton_Exit = new System.Windows.Forms.ToolBarButton();
this.imageList_Main = new System.Windows.Forms.ImageList(this.components);
this.stbMain = new System.Windows.Forms.StatusBar();
this.stbpmsg = new System.Windows.Forms.StatusBarPanel();
this.stbpIP = new System.Windows.Forms.StatusBarPanel();
this.stbpuserinfo = new System.Windows.Forms.StatusBarPanel();
this.tmRefresh = new System.Windows.Forms.Timer(this.components);
this.ctmWin = new System.Windows.Forms.ContextMenu();
this.menuItem_ToolBar = new System.Windows.Forms.MenuItem();
this.menuItem_StatusBar = new System.Windows.Forms.MenuItem();
((System.ComponentModel.ISupportInitialize)(this.stbpmsg)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.stbpIP)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.stbpuserinfo)).BeginInit();
this.SuspendLayout();
//
// mainMenu
//
this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "test";
this.menuItem2.Visible = false;
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// notifyIcon_Main
//
this.notifyIcon_Main.ContextMenu = this.contextMenu_Main;
this.notifyIcon_Main.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon_Main.Icon")));
this.notifyIcon_Main.Text = "ASSW";
this.notifyIcon_Main.Visible = true;
this.notifyIcon_Main.DoubleClick += new System.EventHandler(this.menuItem_ShowWin_Click);
//
// contextMenu_Main
//
this.contextMenu_Main.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem_ShowWin,
this.menuItem_HideWin,
this.menuItem1,
this.menuItem_AboutWin,
this.menuItem_ExitWin});
//
// menuItem_ShowWin
//
this.menuItem_ShowWin.Index = 0;
this.menuItem_ShowWin.Text = "显示窗口";
this.menuItem_ShowWin.Click += new System.EventHandler(this.menuItem_ShowWin_Click);
//
// menuItem_HideWin
//
this.menuItem_HideWin.Index = 1;
this.menuItem_HideWin.Text = "隐藏窗口";
this.menuItem_HideWin.Click += new System.EventHandler(this.menuItem_HideWin_Click);
//
// menuItem1
//
this.menuItem1.Index = 2;
this.menuItem1.Text = "-";
//
// menuItem_AboutWin
//
this.menuItem_AboutWin.Index = 3;
this.menuItem_AboutWin.Text = "关于...";
this.menuItem_AboutWin.Click += new System.EventHandler(this.menuItem_About_Click);
//
// menuItem_ExitWin
//
this.menuItem_ExitWin.Index = 4;
this.menuItem_ExitWin.Text = "退出";
this.menuItem_ExitWin.Click += new System.EventHandler(this.menuItem_Exit_Click);
//
// toolBar_Main
//
this.toolBar_Main.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton_About,
this.toolBarButton_Help,
this.toolBarButton_Exit});
this.toolBar_Main.DropDownArrows = true;
this.toolBar_Main.ImageList = this.imageList_Main;
this.toolBar_Main.Location = new System.Drawing.Point(0, 0);
this.toolBar_Main.Name = "toolBar_Main";
this.toolBar_Main.ShowToolTips = true;
this.toolBar_Main.Size = new System.Drawing.Size(760, 28);
this.toolBar_Main.TabIndex = 1;
this.toolBar_Main.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar_Main_ButtonClick);
//
// toolBarButton_About
//
this.toolBarButton_About.ImageIndex = 0;
this.toolBarButton_About.ToolTipText = "关于";
//
// toolBarButton_Help
//
this.toolBarButton_Help.ImageIndex = 1;
this.toolBarButton_Help.ToolTipText = "帮助";
//
// toolBarButton_Exit
//
this.toolBarButton_Exit.ImageIndex = 2;
this.toolBarButton_Exit.ToolTipText = "退出系统";
//
// imageList_Main
//
this.imageList_Main.ImageSize = new System.Drawing.Size(16, 16);
this.imageList_Main.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList_Main.ImageStream")));
this.imageList_Main.TransparentColor = System.Drawing.Color.Transparent;
//
// stbMain
//
this.stbMain.AllowDrop = true;
this.stbMain.Location = new System.Drawing.Point(0, 515);
this.stbMain.Name = "stbMain";
this.stbMain.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.stbpmsg,
this.stbpIP,
this.stbpuserinfo});
this.stbMain.ShowPanels = true;
this.stbMain.Size = new System.Drawing.Size(760, 22);
this.stbMain.TabIndex = 4;
//
// stbpmsg
//
this.stbpmsg.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Spring;
this.stbpmsg.Width = 724;
//
// stbpIP
//
this.stbpIP.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.stbpIP.Width = 10;
//
// stbpuserinfo
//
this.stbpuserinfo.AutoSize = System.Windows.Forms.StatusBarPanelAutoSize.Contents;
this.stbpuserinfo.Width = 10;
//
// tmRefresh
//
this.tmRefresh.Interval = 900000;
this.tmRefresh.Tick += new System.EventHandler(this.tmRefresh_Tick);
//
// ctmWin
//
this.ctmWin.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem_ToolBar,
this.menuItem_StatusBar});
//
// menuItem_ToolBar
//
this.menuItem_ToolBar.Checked = true;
this.menuItem_ToolBar.Index = 0;
this.menuItem_ToolBar.Text = "工具条";
this.menuItem_ToolBar.Click += new System.EventHandler(this.menuItem_ToolBar_Click);
//
// menuItem_StatusBar
//
this.menuItem_StatusBar.Checked = true;
this.menuItem_StatusBar.Index = 1;
this.menuItem_StatusBar.Text = "状态条";
this.menuItem_StatusBar.Click += new System.EventHandler(this.menuItem_StatusBar_Click);
//
// FormMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(760, 537);
this.ContextMenu = this.ctmWin;
this.Controls.Add(this.stbMain);
this.Controls.Add(this.toolBar_Main);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.IsMdiContainer = true;
this.Menu = this.mainMenu;
this.Name = "FormMain";
this.Closing += new System.ComponentModel.CancelEventHandler(this.FormMain_Closing);
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.stbpmsg)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.stbpIP)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.stbpuserinfo)).EndInit();
this.ResumeLayout(false);
}
#endregion
//取得当前程序集合
private bool LoadMyAssembly()
{
//取得当前执行程序的程序集对象
assembly=Assembly.GetExecutingAssembly();
if (assembly==null)
{
Class_Comm.MsgBox("装载程序集错误,请和系统管理员联系!");
return false;
}
appName=assembly.GetName().Name;
return true;
}
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//打开splash窗口
SplashWin=new FormFlash(SplashImg);
SplashWin.Show();
Application.DoEvents();
//为整个应用加入定制错误处理类
Class_CustomExceptionHandler eh = new Class_CustomExceptionHandler();
Application.ThreadException += new ThreadExceptionEventHandler(eh.OnThreadException);
//设置全局变量
if (!InitParameters())
{
SplashWin.Close();
Application.Exit();
return;
}
//检测是否已经启动该程序
if (RunOnce=="1" && RunningInstance()!=null)
{
Class_Comm.MsgBox("您不能多次启动该程序!");
SplashWin.Close();
Application.Exit();
return;
}
//登录
if (!Login())
{
SplashWin.Close();
Application.Exit();
return;
}
Application.DoEvents();
//运行主程序
Application.Run(new FormMain());
}
//设置全局参数
private static bool InitParameters()
{
try
{
//设置WebIp,MyCookie
TopModuleAlias=Class_Comm.GetParamByKey("TopModuleAlias");
Class_Comm.WebIp =Class_Comm.GetParamByKey("WebIP");
ModuleTag=Class_Comm.GetParamByKey("ModuleTag");
IconTIP=Class_Comm.GetParamByKey("IconTIP");
User=Class_Comm.GetParamByKey("User");
Title=Class_Comm.GetParamByKey("Title");
AsswHelpFile=Class_Comm.GetParamByKey("AsswHelpFile");
RunOnce=Class_Comm.GetParamByKey("RunOnce");
_Refresh=Convert.ToInt32(Class_Comm.GetParamByKey("Refresh"));
if (_Refresh<=0)
_Refresh=900000; //15分钟
LastUser=Class_Comm.GetParamByKey("LastUser");
//设置皮肤
Class_Comm.Skinindex = Convert.ToInt32(Class_Comm.GetParamByKey("Skinindex"));
Class_Comm.MyCookie=new System.Net.CookieContainer();
return true;
}
catch(Exception exp)
{
Class_Comm.ErrMsgBox("读取本地配置文件出错,请和系统管理员联系!\n\n错误信息:"+exp.Message);
return false;
}
}
//登录
private static bool Login()
{
FormLogin frm=new FormLogin(ModuleTag,LastUser);
frm.ShowDialog ();
bool ret=frm.IsLogin ;
if (ret) //登录正确
{
//设置登录用户ID
Class_Comm.UserID =frm.UserID;
Class_Comm.PassWD=frm.PassWD;
Class_Comm.EmployeeSeq=frm.EmployeeSeq;
Class_Comm.EmployeeName=frm.EmplyeeName;
Class_Comm.IsManager=frm.IsManager;
Class_Comm.SetParamValue("LastUser",Class_Comm.UserID);
}
return ret;
}
//退出
private void menuItem_Exit_Click(object sender, System.EventArgs e)
{
this.bCloseWin=true;
this.Close();
}
//关闭提示
private void FormMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (this.bCloseWin)
{
if (Class_Comm.QueryBox("确定退出该程序吗?"))
{
e.Cancel =false;
try
{
Class_Comm.GetServiceSys().LogOut();
}
catch(Exception exp)
{
string msg=exp.Message;
}
}
else
{
this.bCloseWin=false;
e.Cancel =true;
}
}
else
{
e.Cancel=true;
this.HideWin();
}
}
//关于
private void menuItem_About_Click(object sender, System.EventArgs e)
{
Class_Comm.AboutBox(Title);
}
//帮助
private void menuItem_Hlp_Click(object sender, System.EventArgs e)
{
Class_Comm.ShowHelp(this,AsswHelpFile);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -