#define forCG

extern alias global1;

using System;
using System.Net;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;
using System.Data;
using System.Reflection;
using System.Xml;
using System.Diagnostics;
using Microsoft.VisualBasic;

using global::Infragistics.Win.UltraWinExplorerBar;
using global::Infragistics.Win.UltraWinTree;
using global::Infragistics.Win.UltraWinToolbars;
using G = global::Infragistics.Win;
using G1 = global1::Infragistics.Win;

using Core.Mes.ClientFrameWork;
using System.Runtime.InteropServices;
using Core.Mes.IBaseInterface;
using System.Threading;


namespace Core.Mes.ClientManager
{
    /// <summary>
    /// 平台客户端主窗体
    /// </summary>
    public class MainForm : System.Windows.Forms.Form
    {

        #region	"	窗体自动生成	"

        public MainForm()
        {
            //
            // Windows 窗体设计器支持所必需的
            //
            InitializeComponent();

            //
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            //		
        }

        /// <summary>
        /// 清理所有正在使用的资源。
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
            try
            {
                foreach (System.Diagnostics.Process pr in System.Diagnostics.Process.GetProcessesByName("Core.Mes.ClientManager.vshost"))
                {
                    try
                    {
                        pr.Kill();
                    }
                    catch { }
                }
            }
            catch { }
        }

        #region Windows 窗体设计器生成的代码

        private G.UltraWinToolbars.UltraToolbarsManager ultraToolbarsManager1;
        private G.UltraWinToolbars.UltraToolbarsDockArea _MainForm_Toolbars_Dock_Area_Left;
        private G.UltraWinToolbars.UltraToolbarsDockArea _MainForm_Toolbars_Dock_Area_Right;
        private G.UltraWinToolbars.UltraToolbarsDockArea _MainForm_Toolbars_Dock_Area_Top;
        private G.UltraWinToolbars.UltraToolbarsDockArea _MainForm_Toolbars_Dock_Area_Bottom;
        private System.Windows.Forms.Panel panel1;
        private G.UltraWinMaskedEdit.UltraMaskedEdit ultraMaskedEdit2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.Timer timer1;
        private G.UltraWinDock.UltraDockManager ultraDockManager1;
        private G.UltraWinDock.UnpinnedTabArea _MainFormUnpinnedTabAreaLeft;
        private G.UltraWinDock.UnpinnedTabArea _MainFormUnpinnedTabAreaRight;
        private G.UltraWinDock.UnpinnedTabArea _MainFormUnpinnedTabAreaTop;
        private G.UltraWinDock.UnpinnedTabArea _MainFormUnpinnedTabAreaBottom;
        private G.UltraWinDock.AutoHideControl _MainFormAutoHideControl;
        private System.Windows.Forms.Timer timer2;
        private System.Windows.Forms.ToolTip toolTip1;
        private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.RichTextBox richTextBox2;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Button button2;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private Infragistics.Win.Misc.UltraPopupControlContainer MainPopup;
        private Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager ultraTabbedMdiManager1;
        private Infragistics.Win.UltraWinStatusBar.UltraStatusBar ultraStatusBar1;
        private System.ComponentModel.IContainer components;
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            Infragistics.Win.UltraWinToolbars.UltraToolbar ultraToolbar1 = new Infragistics.Win.UltraWinToolbars.UltraToolbar("UltraToolbar1");
            Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton autoRepeatEditorButton1 = new Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton("First");
            Infragistics.Win.Appearance appearance1 = new Infragistics.Win.Appearance();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
            Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton autoRepeatEditorButton2 = new Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton("Previous");
            Infragistics.Win.Appearance appearance2 = new Infragistics.Win.Appearance();
            Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton autoRepeatEditorButton3 = new Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton("Next");
            Infragistics.Win.Appearance appearance3 = new Infragistics.Win.Appearance();
            Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton autoRepeatEditorButton4 = new Infragistics.Win.UltraWinEditors.AutoRepeatEditorButton("Last");
            Infragistics.Win.Appearance appearance4 = new Infragistics.Win.Appearance();
            Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
            Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel2 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
            Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel3 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
            Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel4 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
            Infragistics.Win.UltraWinStatusBar.UltraStatusPanel ultraStatusPanel5 = new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel();
            this.ultraToolbarsManager1 = new Infragistics.Win.UltraWinToolbars.UltraToolbarsManager(this.components);
            this._MainForm_Toolbars_Dock_Area_Left = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
            this._MainForm_Toolbars_Dock_Area_Right = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
            this._MainForm_Toolbars_Dock_Area_Top = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
            this._MainForm_Toolbars_Dock_Area_Bottom = new Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea();
            this.panel1 = new System.Windows.Forms.Panel();
            this.ultraMaskedEdit2 = new Infragistics.Win.UltraWinMaskedEdit.UltraMaskedEdit();
            this.button1 = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.timer1 = new System.Windows.Forms.Timer(this.components);
            this.ultraDockManager1 = new Infragistics.Win.UltraWinDock.UltraDockManager(this.components);
            this._MainFormUnpinnedTabAreaLeft = new Infragistics.Win.UltraWinDock.UnpinnedTabArea();
            this._MainFormUnpinnedTabAreaRight = new Infragistics.Win.UltraWinDock.UnpinnedTabArea();
            this._MainFormUnpinnedTabAreaTop = new Infragistics.Win.UltraWinDock.UnpinnedTabArea();
            this._MainFormUnpinnedTabAreaBottom = new Infragistics.Win.UltraWinDock.UnpinnedTabArea();
            this._MainFormAutoHideControl = new Infragistics.Win.UltraWinDock.AutoHideControl();
            this.timer2 = new System.Windows.Forms.Timer(this.components);
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.ultraStatusBar1 = new Infragistics.Win.UltraWinStatusBar.UltraStatusBar();
            this.panel2 = new System.Windows.Forms.Panel();
            this.richTextBox2 = new System.Windows.Forms.RichTextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.button2 = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.MainPopup = new Infragistics.Win.Misc.UltraPopupControlContainer(this.components);
            this.ultraTabbedMdiManager1 = new Infragistics.Win.UltraWinTabbedMdi.UltraTabbedMdiManager(this.components);
            ((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).BeginInit();
            this.panel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.ultraDockManager1)).BeginInit();
            this.panel2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.ultraTabbedMdiManager1)).BeginInit();
            this.SuspendLayout();
            // 
            // ultraToolbarsManager1
            // 
            this.ultraToolbarsManager1.DesignerFlags = 1;
            this.ultraToolbarsManager1.DockWithinContainer = this;
            this.ultraToolbarsManager1.LockToolbars = true;
            this.ultraToolbarsManager1.ShowFullMenusDelay = 500;
            this.ultraToolbarsManager1.ShowQuickCustomizeButton = false;
            ultraToolbar1.DockedColumn = 0;
            ultraToolbar1.DockedRow = 0;
            ultraToolbar1.Text = "UltraToolbar1";
            this.ultraToolbarsManager1.Toolbars.AddRange(new Infragistics.Win.UltraWinToolbars.UltraToolbar[] {
            ultraToolbar1});
            this.ultraToolbarsManager1.ToolClick += new Infragistics.Win.UltraWinToolbars.ToolClickEventHandler(this.ultraToolbarsManager1_ToolClick);
            // 
            // _MainForm_Toolbars_Dock_Area_Left
            // 
            this._MainForm_Toolbars_Dock_Area_Left.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
            this._MainForm_Toolbars_Dock_Area_Left.BackColor = System.Drawing.SystemColors.Control;
            this._MainForm_Toolbars_Dock_Area_Left.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Left;
            this._MainForm_Toolbars_Dock_Area_Left.ForeColor = System.Drawing.SystemColors.ControlText;
            this._MainForm_Toolbars_Dock_Area_Left.Location = new System.Drawing.Point(0, 18);
            this._MainForm_Toolbars_Dock_Area_Left.Name = "_MainForm_Toolbars_Dock_Area_Left";
            this._MainForm_Toolbars_Dock_Area_Left.Size = new System.Drawing.Size(0, 357);
            this._MainForm_Toolbars_Dock_Area_Left.ToolbarsManager = this.ultraToolbarsManager1;
            // 
            // _MainForm_Toolbars_Dock_Area_Right
            // 
            this._MainForm_Toolbars_Dock_Area_Right.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
            this._MainForm_Toolbars_Dock_Area_Right.BackColor = System.Drawing.SystemColors.Control;
            this._MainForm_Toolbars_Dock_Area_Right.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Right;
            this._MainForm_Toolbars_Dock_Area_Right.ForeColor = System.Drawing.SystemColors.ControlText;
            this._MainForm_Toolbars_Dock_Area_Right.Location = new System.Drawing.Point(1105, 18);
            this._MainForm_Toolbars_Dock_Area_Right.Name = "_MainForm_Toolbars_Dock_Area_Right";
            this._MainForm_Toolbars_Dock_Area_Right.Size = new System.Drawing.Size(0, 357);
            this._MainForm_Toolbars_Dock_Area_Right.ToolbarsManager = this.ultraToolbarsManager1;
            // 
            // _MainForm_Toolbars_Dock_Area_Top
            // 
            this._MainForm_Toolbars_Dock_Area_Top.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
            this._MainForm_Toolbars_Dock_Area_Top.BackColor = System.Drawing.SystemColors.Control;
            this._MainForm_Toolbars_Dock_Area_Top.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Top;
            this._MainForm_Toolbars_Dock_Area_Top.ForeColor = System.Drawing.SystemColors.ControlText;
            this._MainForm_Toolbars_Dock_Area_Top.Location = new System.Drawing.Point(0, 0);
            this._MainForm_Toolbars_Dock_Area_Top.Name = "_MainForm_Toolbars_Dock_Area_Top";
            this._MainForm_Toolbars_Dock_Area_Top.Size = new System.Drawing.Size(1105, 18);
            this._MainForm_Toolbars_Dock_Area_Top.ToolbarsManager = this.ultraToolbarsManager1;
            // 
            // _MainForm_Toolbars_Dock_Area_Bottom
            // 
            this._MainForm_Toolbars_Dock_Area_Bottom.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
            this._MainForm_Toolbars_Dock_Area_Bottom.BackColor = System.Drawing.SystemColors.Control;
            this._MainForm_Toolbars_Dock_Area_Bottom.DockedPosition = Infragistics.Win.UltraWinToolbars.DockedPosition.Bottom;
            this._MainForm_Toolbars_Dock_Area_Bottom.ForeColor = System.Drawing.SystemColors.ControlText;
            this._MainForm_Toolbars_Dock_Area_Bottom.Location = new System.Drawing.Point(0, 375);
            this._MainForm_Toolbars_Dock_Area_Bottom.Name = "_MainForm_Toolbars_Dock_Area_Bottom";
            this._MainForm_Toolbars_Dock_Area_Bottom.Size = new System.Drawing.Size(1105, 0);
            this._MainForm_Toolbars_Dock_Area_Bottom.ToolbarsManager = this.ultraToolbarsManager1;
            // 
            // panel1
            // 
            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
            this.panel1.Controls.Add(this.ultraMaskedEdit2);
            this.panel1.Controls.Add(this.button1);
            this.panel1.Controls.Add(this.richTextBox1);
            this.panel1.Location = new System.Drawing.Point(480, 24);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(208, 136);
            this.panel1.TabIndex = 26;
            this.panel1.Visible = false;
            // 
            // ultraMaskedEdit2
            // 
            this.ultraMaskedEdit2.BorderStyle = Infragistics.Win.UIElementBorderStyle.InsetSoft;
            appearance1.Image = ((object)(resources.GetObject("appearance1.Image")));
            appearance1.ImageHAlign = Infragistics.Win.HAlign.Center;
            appearance1.ImageVAlign = Infragistics.Win.VAlign.Middle;
            autoRepeatEditorButton1.Appearance = appearance1;
            autoRepeatEditorButton1.ButtonStyle = Infragistics.Win.UIElementButtonStyle.ButtonSoftExtended;
            autoRepeatEditorButton1.Interval = 100;
            autoRepeatEditorButton1.Key = "First";
            autoRepeatEditorButton1.Text = "";
            appearance2.Image = ((object)(resources.GetObject("appearance2.Image")));
            appearance2.ImageHAlign = Infragistics.Win.HAlign.Center;
            appearance2.ImageVAlign = Infragistics.Win.VAlign.Middle;
            autoRepeatEditorButton2.Appearance = appearance2;
            autoRepeatEditorButton2.ButtonStyle = Infragistics.Win.UIElementButtonStyle.ButtonSoftExtended;
            autoRepeatEditorButton2.Interval = 100;
            autoRepeatEditorButton2.Key = "Previous";
            autoRepeatEditorButton2.Text = "";
            this.ultraMaskedEdit2.ButtonsLeft.Add(autoRepeatEditorButton1);
            this.ultraMaskedEdit2.ButtonsLeft.Add(autoRepeatEditorButton2);
            appearance3.Image = ((object)(resources.GetObject("appearance3.Image")));
            appearance3.ImageHAlign = Infragistics.Win.HAlign.Center;
            appearance3.ImageVAlign = Infragistics.Win.VAlign.Middle;
            autoRepeatEditorButton3.Appearance = appearance3;
            autoRepeatEditorButton3.ButtonStyle = Infragistics.Win.UIElementButtonStyle.ButtonSoftExtended;
            autoRepeatEditorButton3.Interval = 100;
            autoRepeatEditorButton3.Key = "Next";
            autoRepeatEditorButton3.Text = "";
            appearance4.Image = ((object)(resources.GetObject("appearance4.Image")));
            appearance4.ImageHAlign = Infragistics.Win.HAlign.Center;
            appearance4.ImageVAlign = Infragistics.Win.VAlign.Middle;
            autoRepeatEditorButton4.Appearance = appearance4;
            autoRepeatEditorButton4.ButtonStyle = Infragistics.Win.UIElementButtonStyle.ButtonSoftExtended;
            autoRepeatEditorButton4.Interval = 100;
            autoRepeatEditorButton4.Key = "Last";
            this.ultraMaskedEdit2.ButtonsRight.Add(autoRepeatEditorButton3);
            this.ultraMaskedEdit2.ButtonsRight.Add(autoRepeatEditorButton4);
            this.ultraMaskedEdit2.EditAs = Infragistics.Win.UltraWinMaskedEdit.EditAsType.UseSpecifiedMask;
            this.ultraMaskedEdit2.ImageTransparentColor = System.Drawing.Color.Magenta;
            this.ultraMaskedEdit2.InputMask = "nnn \\o\\f\\ \\5\\0\\0";
            this.ultraMaskedEdit2.Location = new System.Drawing.Point(0, 108);
            this.ultraMaskedEdit2.MaxValue = 500;
            this.ultraMaskedEdit2.MinValue = 1;
            this.ultraMaskedEdit2.Name = "ultraMaskedEdit2";
            this.ultraMaskedEdit2.PromptChar = ' ';
            this.ultraMaskedEdit2.ReadOnly = true;
            this.ultraMaskedEdit2.SelectedTextBackColor = System.Drawing.SystemColors.Window;
            this.ultraMaskedEdit2.SelectedTextForeColor = System.Drawing.SystemColors.WindowText;
            this.ultraMaskedEdit2.Size = new System.Drawing.Size(144, 21);
            this.ultraMaskedEdit2.TabIndex = 102;
            this.ultraMaskedEdit2.Text = " of 500";
            this.ultraMaskedEdit2.EditorButtonClick += new Infragistics.Win.UltraWinEditors.EditorButtonEventHandler(this.ultraMaskedEdit2_EditorButtonClick);
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(144, 108);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(56, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "确认";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // richTextBox1
            // 
            this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Top;
            this.richTextBox1.Location = new System.Drawing.Point(0, 0);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.ReadOnly = true;
            this.richTextBox1.Size = new System.Drawing.Size(206, 104);
            this.richTextBox1.TabIndex = 0;
            this.richTextBox1.Text = "richTextBox1";
            // 
            // timer1
            // 
            this.timer1.Interval = 180000;
            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
            // 
            // ultraDockManager1
            // 
            this.ultraDockManager1.HostControl = this;
            // 
            // _MainFormUnpinnedTabAreaLeft
            // 
            this._MainFormUnpinnedTabAreaLeft.Dock = System.Windows.Forms.DockStyle.Left;
            this._MainFormUnpinnedTabAreaLeft.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this._MainFormUnpinnedTabAreaLeft.Location = new System.Drawing.Point(0, 18);
            this._MainFormUnpinnedTabAreaLeft.Name = "_MainFormUnpinnedTabAreaLeft";
            this._MainFormUnpinnedTabAreaLeft.Owner = this.ultraDockManager1;
            this._MainFormUnpinnedTabAreaLeft.Size = new System.Drawing.Size(0, 357);
            this._MainFormUnpinnedTabAreaLeft.TabIndex = 27;
            // 
            // _MainFormUnpinnedTabAreaRight
            // 
            this._MainFormUnpinnedTabAreaRight.Dock = System.Windows.Forms.DockStyle.Right;
            this._MainFormUnpinnedTabAreaRight.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this._MainFormUnpinnedTabAreaRight.Location = new System.Drawing.Point(1105, 18);
            this._MainFormUnpinnedTabAreaRight.Name = "_MainFormUnpinnedTabAreaRight";
            this._MainFormUnpinnedTabAreaRight.Owner = this.ultraDockManager1;
            this._MainFormUnpinnedTabAreaRight.Size = new System.Drawing.Size(0, 357);
            this._MainFormUnpinnedTabAreaRight.TabIndex = 28;
            // 
            // _MainFormUnpinnedTabAreaTop
            // 
            this._MainFormUnpinnedTabAreaTop.Dock = System.Windows.Forms.DockStyle.Top;
            this._MainFormUnpinnedTabAreaTop.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this._MainFormUnpinnedTabAreaTop.Location = new System.Drawing.Point(0, 18);
            this._MainFormUnpinnedTabAreaTop.Name = "_MainFormUnpinnedTabAreaTop";
            this._MainFormUnpinnedTabAreaTop.Owner = this.ultraDockManager1;
            this._MainFormUnpinnedTabAreaTop.Size = new System.Drawing.Size(1105, 0);
            this._MainFormUnpinnedTabAreaTop.TabIndex = 29;
            // 
            // _MainFormUnpinnedTabAreaBottom
            // 
            this._MainFormUnpinnedTabAreaBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
            this._MainFormUnpinnedTabAreaBottom.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this._MainFormUnpinnedTabAreaBottom.Location = new System.Drawing.Point(0, 375);
            this._MainFormUnpinnedTabAreaBottom.Name = "_MainFormUnpinnedTabAreaBottom";
            this._MainFormUnpinnedTabAreaBottom.Owner = this.ultraDockManager1;
            this._MainFormUnpinnedTabAreaBottom.Size = new System.Drawing.Size(1105, 0);
            this._MainFormUnpinnedTabAreaBottom.TabIndex = 30;
            // 
            // _MainFormAutoHideControl
            // 
            this._MainFormAutoHideControl.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this._MainFormAutoHideControl.Location = new System.Drawing.Point(0, 0);
            this._MainFormAutoHideControl.Name = "_MainFormAutoHideControl";
            this._MainFormAutoHideControl.Owner = this.ultraDockManager1;
            this._MainFormAutoHideControl.Size = new System.Drawing.Size(0, 0);
            this._MainFormAutoHideControl.TabIndex = 31;
            // 
            // timer2
            // 
            this.timer2.Interval = 3000;
            this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
            // 
            // ultraStatusBar1
            // 
            this.ultraStatusBar1.Location = new System.Drawing.Point(0, 375);
            this.ultraStatusBar1.Name = "ultraStatusBar1";
            ultraStatusPanel1.Width = 600;
            ultraStatusPanel2.MinWidth = 100;
            ultraStatusPanel4.MinWidth = 400;
            ultraStatusPanel4.Text = "湖南视拓信息技术股份有限公司";
            ultraStatusPanel4.Width = 180;
            ultraStatusPanel5.Width = 150;
            this.ultraStatusBar1.Panels.AddRange(new Infragistics.Win.UltraWinStatusBar.UltraStatusPanel[] {
            ultraStatusPanel1,
            ultraStatusPanel2,
            ultraStatusPanel3,
            ultraStatusPanel4,
            ultraStatusPanel5});
            this.ultraStatusBar1.Size = new System.Drawing.Size(1105, 22);
            this.ultraStatusBar1.TabIndex = 43;
            this.toolTip1.SetToolTip(this.ultraStatusBar1, "双击弹出所要通告");
            this.ultraStatusBar1.PanelDoubleClick += new Infragistics.Win.UltraWinStatusBar.PanelClickEventHandler(this.ultraStatusBar1_PanelDoubleClick);
            this.ultraStatusBar1.PanelClick += new Infragistics.Win.UltraWinStatusBar.PanelClickEventHandler(this.ultraStatusBar1_PanelClick);
            this.ultraStatusBar1.DoubleClick += new System.EventHandler(this.ultraStatusBar1_DoubleClick);
            // 
            // panel2
            // 
            this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
            this.panel2.Controls.Add(this.richTextBox2);
            this.panel2.Controls.Add(this.label4);
            this.panel2.Controls.Add(this.label3);
            this.panel2.Controls.Add(this.label2);
            this.panel2.Controls.Add(this.button2);
            this.panel2.Controls.Add(this.label1);
            this.panel2.Location = new System.Drawing.Point(0, 231);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(600, 144);
            this.panel2.TabIndex = 37;
            this.panel2.Visible = false;
            // 
            // richTextBox2
            // 
            this.richTextBox2.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.richTextBox2.Location = new System.Drawing.Point(0, 24);
            this.richTextBox2.Name = "richTextBox2";
            this.richTextBox2.ReadOnly = true;
            this.richTextBox2.Size = new System.Drawing.Size(600, 120);
            this.richTextBox2.TabIndex = 0;
            this.richTextBox2.Text = "";
            // 
            // label4
            // 
            this.label4.Location = new System.Drawing.Point(360, 8);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(48, 24);
            this.label4.TabIndex = 5;
            this.label4.Text = "   普通";
            // 
            // label3
            // 
            this.label3.ForeColor = System.Drawing.Color.Blue;
            this.label3.Location = new System.Drawing.Point(304, 8);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(48, 24);
            this.label3.TabIndex = 4;
            this.label3.Text = "   重要";
            // 
            // label2
            // 
            this.label2.ForeColor = System.Drawing.Color.Red;
            this.label2.Location = new System.Drawing.Point(248, 8);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(48, 24);
            this.label2.TabIndex = 3;
            this.label2.Text = "   紧急";
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(552, 2);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(40, 23);
            this.button2.TabIndex = 2;
            this.button2.Text = "关闭";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(16, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(100, 23);
            this.label1.TabIndex = 1;
            this.label1.Text = "通知";
            // 
            // ultraTabbedMdiManager1
            // 
            this.ultraTabbedMdiManager1.MdiParent = this;
            this.ultraTabbedMdiManager1.TabActivated += new Infragistics.Win.UltraWinTabbedMdi.MdiTabEventHandler(this.ultraTabbedMdiManager1_TabActivated);
            // 
            // MainForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            this.ClientSize = new System.Drawing.Size(1105, 397);
            this.Controls.Add(this._MainFormAutoHideControl);
            this.Controls.Add(this.panel2);
            this.Controls.Add(this.panel1);
            this.Controls.Add(this._MainFormUnpinnedTabAreaTop);
            this.Controls.Add(this._MainFormUnpinnedTabAreaBottom);
            this.Controls.Add(this._MainFormUnpinnedTabAreaLeft);
            this.Controls.Add(this._MainFormUnpinnedTabAreaRight);
            this.Controls.Add(this._MainForm_Toolbars_Dock_Area_Left);
            this.Controls.Add(this._MainForm_Toolbars_Dock_Area_Right);
            this.Controls.Add(this._MainForm_Toolbars_Dock_Area_Top);
            this.Controls.Add(this._MainForm_Toolbars_Dock_Area_Bottom);
            this.Controls.Add(this.ultraStatusBar1);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.IsMdiContainer = true;
            this.Name = "MainForm";
            this.Text = "新钢公司MES系统";
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
            ((System.ComponentModel.ISupportInitialize)(this.ultraToolbarsManager1)).EndInit();
            this.panel1.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.ultraDockManager1)).EndInit();
            this.panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.ultraTabbedMdiManager1)).EndInit();
            this.ResumeLayout(false);

        }
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        //[STAThread]
        //static void Main() 
        //{
        //    try
        //    {
        //        Process[] myProcesses = Process.GetProcessesByName("Core.Mes.ClientManager.vshost");
        //        if(myProcesses.Length  == 1 )
        //        {
        //            Application.Run(new MainForm());
        //        }
        //    }
        //    catch
        //    {
        //        Application.Run(new MainForm());
        //    }
        //}
        #endregion

        #endregion

        #region "	Init Form	"
        int FreeTime = 600;

        private void Update_UPM()
        {
            UpdaterManager.Update_UPM();
            UpdaterManager.Update_Shortcut();
        }

        private void MainForm_Load(object sender, System.EventArgs e)
        {
            //if (System.DateTime.Today > new System.DateTime(2007,1,1))	return;	
            Thread t_update = new Thread(new ThreadStart(Update_UPM));
            t_update.Start();

            if (ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["Title"].Value.ToString() != null)
                this.Text = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["Title"].Value.ToString();
            this.BackgroundImage = System.Drawing.Image.FromFile(@"MainBackPic.jpg");

            FrmCover frm = new FrmCover();
            frm._mainForm = this;
            frm.ReLoginType = 0;
            frm.ShowDialog(this);

            if (frm._loginFlag > 0)
            {
                //正常启动显示登录框
                InitForm(frm.ReLoginType);
            }
            else
            {
                Application.Exit();
            }
        }
        private bool keyexit(string key)
        {
            for (int i = 0; i < ultraToolbarsManager1.Toolbars[0].Tools.Count; i++)
            {
                if (!keyisexist(key, ultraToolbarsManager1.Toolbars[0].Tools[i]))
                    return false;
            }
            return true;
        }
        private bool keyisexist(string key, object Menu)
        {
            if (Menu.GetType() == typeof(Infragistics.Win.UltraWinToolbars.PopupMenuTool))
            {
                Infragistics.Win.UltraWinToolbars.PopupMenuTool tmpPMenu = (Menu as Infragistics.Win.UltraWinToolbars.PopupMenuTool);
                if (tmpPMenu.Tools.Exists(key))
                    return false;
                for (int i = 0; i < tmpPMenu.Tools.Count; i++)
                {
                    keyisexist(key, tmpPMenu.Tools[i]);
                }
            }
            else
            {
                return true;
            }
            return true;
        }
        public void InitForm(int ReLoginType)
        {
            try
            {
                if (ReLoginType == 0)
                {
                    CreateMenu();
                    AjustTime();
                    //InitMessageBox();
                    //GetUserMessage();
                    //timer2_Tick( null, new System.EventArgs() );
                    //this.timer1.Start();
                    //this.timer2.Start();
                }
                else if (ReLoginType == 1)
                {
                    this.ultraToolbarsManager1.Tools.Clear();
                    this.ultraToolbarsManager1.Toolbars[0].Tools.Clear();

                    CreateMenu();

                    foreach (Form frm in this.MdiChildren)
                    {
                        frm.Close();
                    }
                }
                else
                {
                    foreach (Form frm in this.MdiChildren)
                    {
                        frm.Show();
                    }
                    try
                    {
                        if (LastActiveForm != null)
                        {
                            LastActiveForm.Activate();
                        }
                    }
                    catch { }
                }

                this.ultraStatusBar1.Panels[1].Text = ClientCommon._UserInfo.UserName;

                string bc = this.GetBc(ClientCommon._UserInfo.UserBc);
                string bb = this.GetBb(ClientCommon._UserInfo.UserBb);

                if (bc == bb)
                    this.ultraStatusBar1.Panels[2].Text = bb;
                else
                    this.ultraStatusBar1.Panels[2].Text = bc + "  " + bb;

            }
            catch (Exception ex)
            {
                MessageBox.Show("权限文件信息错误！请与管理员联系。\n" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

            }

            try
            {
                ClientCommon.GetServerConfig();
                DataRow[] dr = ClientCommon.ServerConfig.Select("KEY_NAME='FREETIME'");
                if (dr != null && dr.GetLength(0) > 0)
                {
                    int.TryParse(dr[0]["KEY_VALUE"].ToString(), out FreeTime);
                }
            }
            catch { }

            timer2.Enabled = true;
            if (_dsMessage != null) _dsMessage.Clear();
            //GetMessage();
        }

        #region "	班次、班别	"

        private G.ValueList _vlBc;
        private string GetBc(string str)
        {
            if (_vlBc == null)
            {
                _vlBc = new G.ValueList();
                _vlBc.ValueListItems.Add("300201", "早班");
                _vlBc.ValueListItems.Add("300202", "中班");
                _vlBc.ValueListItems.Add("300203", "晚班");
                _vlBc.ValueListItems.Add("300205", "常白班");
            }
            if (_vlBc.FindByDataValue(str) != null)
                return _vlBc.FindByDataValue(str).DisplayText;
            return "常白班";
        }
        private G.ValueList _vlBb;
        private string GetBb(string str)
        {
            if (_vlBb == null)
            {
                _vlBb = new G.ValueList();
                _vlBb.ValueListItems.Add("300301", "甲班");
                _vlBb.ValueListItems.Add("300302", "乙班");
                _vlBb.ValueListItems.Add("300303", "丙班");
                _vlBb.ValueListItems.Add("300304", "丁班");
                _vlBb.ValueListItems.Add("300305", "常白班");
            }

            if (_vlBb.FindByDataValue(str) != null)
                return _vlBb.FindByDataValue(str).DisplayText;
            return "常白班";
        }
        #endregion
        private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            DialogResult dr = MessageBox.Show(string.Format("是否确认退出{0}？", this.Text), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.No)
            {
                e.Cancel = true;
                return;
            }

            string ipaddress = ClientCommon.GetIp();
            string strOut = "";
            ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "RecodeExitInfo",
                new object[]{ClientCommon._UserInfo.LoginID, ClientCommon._UserInfo.UserName, 
								Dns.GetHostName(), ipaddress}, out strOut);
        }

        #endregion

        #region "	Menu Manager	"

        #region "	Menu Events	"

        private void CreateMenu()
        {
            string strOut = "";
            try
            {
                DataSet obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetBuildMenuInfo",
                    new object[] { ClientCommon._UserInfo.LoginID }, out strOut) as DataSet;

                if (strOut != "")
                {
                    MessageBox.Show(strOut); return;
                }
                for (int i = 0; i < obj.Tables[0].Rows.Count; i++)
                {
                    string strSetInfo = obj.Tables[0].Rows[i]["SETINFO"].ToString();
                    string strBtName = obj.Tables[0].Rows[i]["CAPTION"].ToString();
                    string strBtKey = obj.Tables[0].Rows[i]["KEY_"].ToString();
                    string strBtCat = obj.Tables[0].Rows[i]["CATEGORY"].ToString();
                    string strType = obj.Tables[0].Rows[i]["TYPE"].ToString();

                    #region old code
                    //int iCount = 0;
                    //for (int j = 0; j < obj.Tables[0].Rows.Count; j++)
                    //{
                    //    if (obj.Tables[0].Rows[j]["SETINFO"].ToString().StartsWith(strSetInfo))
                    //    {
                    //        iCount++;
                    //    }
                    //}
                    //if (iCount > 1)
                    //{
                    //    if (strSetInfo.Length == 3)
                    //    {
                    //        try
                    //        {
                    //            Infragistics.Win.UltraWinToolbars.PopupMenuTool pmt = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                    //            Infragistics.Win.UltraWinToolbars.PopupMenuTool pmtb = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                    //            pmtb.SharedProps.Caption = strBtName;

                    //            this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmtb });

                    //            this.ultraToolbarsManager1.Toolbars[0].Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmt });

                    //            pmt.SharedProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
                    //        }
                    //        catch(Exception ex) {
                    //            MessageBox.Show(ex.Message);
                    //            return;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        try
                    //        {
                    //            Infragistics.Win.UltraWinToolbars.PopupMenuTool pmt = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                    //            Infragistics.Win.UltraWinToolbars.PopupMenuTool pmtb = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                    //            pmtb.SharedProps.Caption = strBtName;

                    //            this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmtb });

                    //            this.ultraToolbarsManager1.Toolbars[strSetInfo.Substring(0, strSetInfo.Length - 3)].Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmt });

                    //            pmt.SharedProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
                    //        }
                    //        catch { }
                    //    }
                    //}
                    //else
                    //{
                    //    try
                    //    {
                    //        string strPkey = "";
                    //        for (int j = 0; j < obj.Tables[0].Rows.Count; j++)
                    //        {
                    //            if (obj.Tables[0].Rows[j]["SETINFO"].ToString() == strSetInfo.Substring(0, strSetInfo.Length - 3))
                    //            {
                    //                strPkey = obj.Tables[0].Rows[j]["CAPTION"].ToString();
                    //            }
                    //        }

                    //        Infragistics.Win.UltraWinToolbars.ButtonTool bt = new Infragistics.Win.UltraWinToolbars.ButtonTool(strBtName);
                    //        Infragistics.Win.UltraWinToolbars.ButtonTool btb = new Infragistics.Win.UltraWinToolbars.ButtonTool(strBtName);
                    //        btb.SharedProps.Caption = strBtName;
                    //        this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { btb });

                    //        Infragistics.Win.UltraWinToolbars.PopupMenuTool pmtb;
                    //        if (strSetInfo.Length == 3)
                    //        {
                    //            this.ultraToolbarsManager1.Toolbars[0].Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { bt });
                    //            btb.SharedProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;
                    //        }
                    //        else
                    //        {
                    //            pmtb = this.ultraToolbarsManager1.Tools[strPkey] as PopupMenuTool;

                    //            pmtb.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { bt });
                    //        }

                    //        bt.Key = strBtKey;
                    //        bt.SharedProps.Category = strBtCat;

                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        Console.WriteLine(ex.Message);
                    //    }
                    //}
                    #endregion

                    //if (ultraToolbarsManager1.Tools.Exists(strBtKey))
                    //{
                    //    for (int extKey = 0; extKey < 5; extKey++)
                    //    {
                    //        if (!ultraToolbarsManager1.Tools.Exists(strBtKey + "@" + extKey.ToString()))
                    //        {
                    //            strBtKey = strBtKey + "@" + extKey.ToString();
                    //            break;
                    //        }
                    //    }
                    //}
                    strBtKey = strBtKey + "@" + System.Guid.NewGuid().ToString();
                    obj.Tables[0].Rows[i]["KEY_"] = strBtKey;
                    obj.Tables[0].AcceptChanges();
                    if (strType == "MENU")
                    {
                        PopupMenuTool menu = new PopupMenuTool(strBtKey);
                        PopupMenuTool menub = new PopupMenuTool(strBtKey);
                        menub.SharedProps.Caption = strBtName;
                        ultraToolbarsManager1.Tools.AddRange(new ToolBase[] { menub });

                        if (strSetInfo.Length > 3)
                        {
                            string strPKey = "";
                            for (int j = 0; j < obj.Tables[0].Rows.Count; j++)
                            {
                                if (obj.Tables[0].Rows[j]["SETINFO"].ToString() == strSetInfo.Substring(0, strSetInfo.Length - 3))
                                {
                                    strPKey = obj.Tables[0].Rows[j]["KEY_"].ToString();
                                    break;
                                }
                            }

                            ((PopupMenuTool)ultraToolbarsManager1.Tools[strPKey]).Tools.AddRange(new ToolBase[] { menu });
                        }
                        else
                        {
                            ultraToolbarsManager1.Toolbars[0].Tools.AddRange(new ToolBase[] { menu });
                        }
                    }
                    else
                    {
                        ButtonTool btn = new ButtonTool(strBtKey);
                        ButtonTool btnb = new ButtonTool(strBtKey);
                        btnb.SharedProps.Category = strBtCat;
                        btnb.SharedProps.Caption = strBtName;
                        btnb.SharedProps.DisplayStyle = ToolDisplayStyle.ImageAndText;
                        ultraToolbarsManager1.Tools.AddRange(new ToolBase[] { btnb });

                        if (strSetInfo.Length > 3)
                        {
                            string strPKey = "";
                            for (int j = 0; j < obj.Tables[0].Rows.Count; j++)
                            {
                                if (obj.Tables[0].Rows[j]["SETINFO"].ToString() == strSetInfo.Substring(0, strSetInfo.Length - 3))
                                {
                                    strPKey = obj.Tables[0].Rows[j]["KEY_"].ToString();
                                    break;
                                }
                            }

                            ((PopupMenuTool)ultraToolbarsManager1.Tools[strPKey]).Tools.AddRange(new ToolBase[] { btn });
                        }
                        else
                        {
                            ultraToolbarsManager1.Toolbars[0].Tools.AddRange(new ToolBase[] { btn });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //this.ultraToolbarsManager1.LoadFromXml(ClientCommon._UserInfo.MenuConfigStream);
            AddBasePoupToolBarItem("系统", "System");
        }
        private void AddBasePoupToolBarItem(string strBtName, string strKey)
        {
            try
            {
                Infragistics.Win.UltraWinToolbars.PopupMenuTool pmt = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                Infragistics.Win.UltraWinToolbars.PopupMenuTool pmtb = new Infragistics.Win.UltraWinToolbars.PopupMenuTool(strBtName);
                pmtb.SharedProps.Caption = strBtName;

                this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmtb });

                this.ultraToolbarsManager1.Toolbars[0].Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { pmt });

                pmt.SharedProps.DisplayStyle = Infragistics.Win.UltraWinToolbars.ToolDisplayStyle.ImageAndText;

                AddBaseButtonToolBarItem("重新登录", "reLogin", pmtb);
                AddBaseButtonToolBarItem("修改密码", "passwd", pmtb);
                AddBaseButtonToolBarItem("设置班组", "setBz", pmtb);
#if forCG
                AddBaseButtonToolBarItem("我的有效菜单", "mymenu", pmtb);
#endif
                AddBaseButtonToolBarItem("帮助", "help", pmtb);
                AddBaseButtonToolBarItem("关于", "about", pmtb);
                AddBaseButtonToolBarItem("退出", "close", pmtb);

                this.ultraToolbarsManager1.LockToolbars = true;
                this.ultraToolbarsManager1.ShowQuickCustomizeButton = false;
                this.ultraToolbarsManager1.Style = Infragistics.Win.UltraWinToolbars.ToolbarStyle.OfficeXP;

            }
            catch { }
        }
        private void AddBaseButtonToolBarItem(string strBtName, string strBtKey, PopupMenuTool pmt)
        {
            try
            {
                Infragistics.Win.UltraWinToolbars.ButtonTool bt = new Infragistics.Win.UltraWinToolbars.ButtonTool(strBtName);
                Infragistics.Win.UltraWinToolbars.ButtonTool btb = new Infragistics.Win.UltraWinToolbars.ButtonTool(strBtName);
                btb.SharedProps.Caption = strBtName;
                this.ultraToolbarsManager1.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { btb });

                pmt.Tools.AddRange(new Infragistics.Win.UltraWinToolbars.ToolBase[] { bt });

                bt.Key = strBtKey;
                if (strBtKey == "reLogin")
                {
                    btb.InstanceProps.IsFirstInGroup = true;
                }
            }
            catch { }
        }

        private void ReLogin()
        {
            FrmCover frm = new FrmCover();
            frm.ReLoginFlag = true;
            frm._mainForm = this;
            frm.ReLoginType = 1;
            frm.ShowDialog();
            if (frm._loginFlag > 0)
            {
                //手动重登陆显示登录框（允许切换用户名）
                InitForm(frm.ReLoginType);
            }
        }

        Form LastActiveForm = null;
        private void ReLoginWithoutInit()
        {
            if (this.MdiChildren.GetLength(0) > 0)
            {
                LastActiveForm = this.ActiveMdiChild;
                foreach (Form frm in this.MdiChildren)
                {
                    frm.Hide();
                }
            }
            else
            {
                LastActiveForm = null;
            }

            this.ultraStatusBar1.Panels[0].Text = "闲置时间过长，请重新登录！";
            this.ShowPopUpMsg("闲置时间过长，请重新登录！               ", this, new Point(this.Width > 1000 ? 1000 : this.Width, this.ultraStatusBar1.Top));
            do
            {
                FrmCover frm = new FrmCover(ClientCommon._UserInfo.LoginID);
                frm.ReLoginFlag = true;
                frm._mainForm = this;
                frm.Text = "闲置时间过长，请重新登录！";
                frm.ReLoginType = 2;
                frm.ShowDialog(this);
                if (frm._loginFlag > 0)
                {
                    //锁定重登陆显示登录框（不允许切换用户名）
                    InitForm(frm.ReLoginType);
                    break;
                }
                else if (frm._loginFlag == -1)
                {
                    DialogResult dr = MessageBox.Show(string.Format("是否确认退出{0}？", this.Text), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (dr == DialogResult.Yes)
                    {
                        Application.Exit();
                        break;
                    }
                }
            } while (true);
        }

        #endregion
        //未激活的界面将线程开关关闭
        private void ultraTabbedMdiManager1_TabActivated(object sender, Infragistics.Win.UltraWinTabbedMdi.MdiTabEventArgs e)
        {
            foreach (Form frmMdi in this.MdiChildren)
            {
                FrmBase frm = frmMdi as FrmBase;
                frm.On_Off_Thread = false;
            }
            ((FrmBase)e.Tab.Form).On_Off_Thread = true;
        }

        private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            switch (e.Tool.Key)
            {
                case "reLogin":
                    ReLogin();
                    break;
                case "close":
                    this.Close();
                    break;
                case "help":
                    if (System.IO.File.Exists(@"CoreHelp.chm"))
                    {
                        try
                        {
                            ProcessStartInfo p = new ProcessStartInfo(@"CoreHelp.chm");
                            p.WorkingDirectory = @"CoreHelp.chm";
                            Process.Start(p);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    break;
                case "about":
                    FrmAbout frm = new FrmAbout();
                    if (ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["About"].Value.ToString() != null)
                        frm.InitPic(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["About"].Value.ToString());
                    frm.ShowDialog();
                    break;
                case "passwd":
                    FrmPasswd frm1 = new FrmPasswd();
                    frm1.ShowDialog();
                    break;
                case "setBz":
                    FrmSetBz frm2 = new FrmSetBz();
                    frm2.ShowDialog();
                    if (frm2._boFlag)
                    {
                        string bc = this.GetBc(ClientCommon._UserInfo.UserBc);
                        string bb = this.GetBb(ClientCommon._UserInfo.UserBb);

                        if (bc == bb)
                            this.ultraStatusBar1.Panels[2].Text = bb;
                        else
                            this.ultraStatusBar1.Panels[2].Text = bc + "  " + bb;
                    }
                    break;
                case "mymenu":
                    frmMyMenuInfo frmMyMenuInfo_1 = new frmMyMenuInfo();
                    frmMyMenuInfo_1.ShowDialog();
                    break;
                default:
                    {
                        OpenChildForm(e);
                        break;
                    }
            }
        }
        #endregion

        #region "	ExplorerBar Manager	"



        /// <summary>
        /// 打开子窗体
        /// </summary>
        /// <param name="xn">存放子窗体信息的xmlnode</param>
        private void OpenChildForm(ToolClickEventArgs e)
        {
            foreach (Form mdiChild in this.MdiChildren)
            {
                if ((mdiChild as FrmBase).Key == e.Tool.Key)
                {
                    mdiChild.Activate();
                    return;
                }
            }

            //实例化窗体并打开
            try
            {
                string assemblyName = e.Tool.SharedProps.Category;
                string className = e.Tool.Key.Split('@')[0];
                Assembly baseFormAssembly = Assembly.Load(assemblyName);
                Type type = baseFormAssembly.GetType(className);

                System.Diagnostics.Debug.Assert(type.IsSubclassOf(typeof(FrmBase)));

                FrmBase form = Activator.CreateInstance(type, true) as FrmBase;
                form.MdiParent = this;
                form.Text = e.Tool.SharedProps.Caption;
                form.Key = e.Tool.Key;

                form.Show();

                this.ultraStatusBar1.Panels[0].Text = "打开" + form.Text + "窗体。";
                ClientCommon.RecodeOperateInfo("打开", form.Text, "");
            }
            catch (Exception ex)
            {
                this.ultraStatusBar1.Panels[0].Text = ex.Message;
            }
        }

        #endregion

        #region "	Message	"
        private void InitMessageBox()
        {
            Infragistics.Win.UltraWinDock.DockAreaPane dockAreaPane1 = new Infragistics.Win.UltraWinDock.DockAreaPane(
                Infragistics.Win.UltraWinDock.DockedLocation.Floating);

            Infragistics.Win.UltraWinDock.DockableControlPane dockableControlPane1 = new Infragistics.Win.UltraWinDock.DockableControlPane();

            dockAreaPane1.FloatingLocation = new System.Drawing.Point(1024 - 210, 780 - 150 - 50);
            dockableControlPane1.Control = this.panel1;
            dockableControlPane1.Text = "消息";
            dockAreaPane1.Panes.AddRange(new Infragistics.Win.UltraWinDock.DockablePaneBase[] {
																								  dockableControlPane1});
            dockAreaPane1.Size = new System.Drawing.Size(200, 150);
            this.ultraDockManager1.DockAreas.AddRange(new Infragistics.Win.UltraWinDock.DockAreaPane[] {
																										   dockAreaPane1});
            this.ultraDockManager1.ControlPanes[0].Closed = true;
            this.panel1.Visible = true;
        }
        private void ShowMessageBox()
        {
            _RowCount = _dsMessage.Tables[0].Rows.Count;

            this.ultraMaskedEdit2.InputMask = string.Format(@"nnn \o\f\ \{0}", _RowCount.ToString());
            this.ultraMaskedEdit2.Text = string.Format("1 of {0}", _RowCount.ToString());
            SetRichText(1);
            this.ultraDockManager1.ControlPanes[0].Closed = false;
        }

        private int _RowCount = 0;
        private DataSet _dsMessage;

        private void timer1_Tick(object sender, System.EventArgs e)
        {
            //GetMessage();
            GetUserMessage();
        }

        private void GetUserMessage()
        {
            string strOut = "";
            DataSet ds = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetUserMessage",
                null, out strOut) as DataSet;

            if (strOut == "" && ds.Tables[0].Rows.Count > 0)
            {
                this.dtUserMessage = ds.Tables[0];
            }
            else
            {
                this.dtUserMessage = null;
            }

        }

        private DataTable dtUserMessage;
        private int _iCount = 0;

        private void timer2_Tick(object sender, System.EventArgs e)
        {
            GetLastCall();
            if (this.dtUserMessage == null) return;

            if (_iCount < this.dtUserMessage.Rows.Count)
            {
                string str = this.GetNoNullStr(this.dtUserMessage.Rows[_iCount][0]);
                str = str + "  " + this.GetNoNullStr(this.dtUserMessage.Rows[_iCount][1]);
                str = str + "  " + Convert.ToDateTime(this.dtUserMessage.Rows[_iCount][2]).ToString("MM月dd日 HH时mm分");

                this.ultraStatusBar1.Panels[0].Text = str;

                if (this.dtUserMessage.Rows[_iCount]["PRI_"].ToString() == "2")
                    this.ultraStatusBar1.Panels[0].Appearance.ForeColor = Color.Red;
                else if (this.dtUserMessage.Rows[_iCount]["PRI_"].ToString() == "1")
                    this.ultraStatusBar1.Panels[0].Appearance.ForeColor = Color.Blue;
                else
                    this.ultraStatusBar1.Panels[0].Appearance.ForeColor = Color.Black;


                _iCount++;

            }
            else
            {
                _iCount = 0;
            }
        }

        private void GetLastCall()
        {
            CallingMessage cm = new CallingMessage();
            DateTime ldt = ClientCommon._RemotingHelp.GetLastExecute(out cm);
            TimeSpan ts = (DateTime.Now - ldt);

            ultraStatusBar1.Panels[4].Text = string.Format("空闲时间 {0,3}'{1,2}\"", ts.Minutes, ts.Seconds);

            if (ts.TotalSeconds > FreeTime)
            {
                timer2.Stop();
                ReLoginWithoutInit();
            }
        }

        private string GetNoNullStr(object obj)
        {
            if (obj == null || obj == DBNull.Value) return "";

            return obj.ToString();
        }

        private void GetMessage()
        {
            string strOut = "";
            DataSet ds = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "GetMessage",
                new object[] { ClientCommon._UserInfo.UserID }, out strOut) as DataSet;

            if (strOut != "" || ds.Tables[0].Rows.Count == 0)
            {
                if (_dsMessage != null) _dsMessage.Clear();
                this.ultraDockManager1.ControlPanes[0].Closed = true;
                return;
            }

            if (!this.ultraDockManager1.ControlPanes[0].Closed) return;

            if (_dsMessage == null)
                _dsMessage = ds;
            else
            {
                _dsMessage.Clear();
                _dsMessage.Merge(ds);
            }

            ShowMessageBox();
        }
        private int newValue = 1;
        private void ultraMaskedEdit2_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
        {
            int min = (int)this.ultraMaskedEdit2.MinValue;
            int max = (int)this.ultraMaskedEdit2.MaxValue;
            newValue = min;

            Infragistics.Win.EditorWithMask maskEdit = e.Button.Editor as Infragistics.Win.EditorWithMask;

            try
            {
                string maskText = maskEdit.GetText(Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw);

                if (!Convert.IsDBNull(maskText))
                    newValue = int.Parse(maskText);
            }
            catch { }

            switch (e.Button.Key)
            {
                case "First":
                    newValue = min;
                    break;
                case "Last":
                    newValue = max;
                    break;
                case "Next":
                    newValue++;
                    break;
                case "Previous":
                    newValue--;
                    break;
            }

            if (newValue < 1)
                newValue = 1;
            else if (newValue > _RowCount)
                newValue = _RowCount;

            e.Button.Editor.Value = newValue;
            SetRichText(newValue);
        }
        private void SetRichText(int rowIndex)
        {
            try
            {
                this.richTextBox1.Text = this._dsMessage.Tables[0].Rows[rowIndex - 1]["INFO"].ToString();
                this.richTextBox1.Text += "\n----------";
                this.richTextBox1.Text += this._dsMessage.Tables[0].Rows[rowIndex - 1]["SENDPERSON"].ToString() + Convert.ToDateTime(this._dsMessage.Tables[0].Rows[rowIndex - 1]["SENDTIME"]).ToString("MM-dd HH:mm");

                this.richTextBox1.Tag = this._dsMessage.Tables[0].Rows[rowIndex - 1]["ID_"].ToString();
            }
            catch
            {
                this.richTextBox1.Text = "错误！";
            }
        }
        private void button1_Click(object sender, System.EventArgs e)
        {
            string strOut = "";
            object obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "AffirmMessage",
                new object[] { this.richTextBox1.Tag.ToString() }, out strOut);

            if (strOut != "") { MessageBox.Show(strOut); return; }

            this._dsMessage.Tables[0].Rows.RemoveAt(newValue - 1);
            this._dsMessage.AcceptChanges();
            if (this._dsMessage.Tables[0].Rows.Count == 0) this.ultraDockManager1.ControlPanes[0].Closed = true;
            GetMessage();
        }
        #endregion

        private void ultraStatusBar1_DoubleClick(object sender, System.EventArgs e)
        {
            if (this.dtUserMessage != null && this.dtUserMessage.Rows.Count > 0)
            {
                this.richTextBox2.Clear();
                for (int i = 0; i < this.dtUserMessage.Rows.Count; i++)
                {
                    DataRow dr = this.dtUserMessage.Rows[i];
                    string str = Convert.ToString(i + 1) + "、 " + this.GetNoNullStr(dr[0]);
                    str = str + "  " + this.GetNoNullStr(dr[1]);
                    str = str + "  " + Convert.ToDateTime(dr[2]).ToString("MM月dd日 HH时mm分");
                    str = str + " \n";


                    if (dr["PRI_"].ToString() == "2")
                        this.richTextBox2.SelectionColor = Color.Red;
                    else if (dr["PRI_"].ToString() == "1")
                        this.richTextBox2.SelectionColor = Color.Blue;
                    else
                        this.richTextBox2.SelectionColor = Color.Black;
                    this.richTextBox2.SelectedText = str;

                }
                this.panel2.Visible = true;
            }
        }

        private void ultraStatusBar1_PanelClick(object sender, Infragistics.Win.UltraWinStatusBar.PanelClickEventArgs e)
        {
            if (e.Panel.Index == 4)
            {
                CallingMessage cm = new CallingMessage();
                DateTime ldt = ClientCommon._RemotingHelp.GetLastExecute(out cm);

                ShowPopUpMsg(string.Format("{0}\n{1}\n{2}", cm.ServerName, cm.ClassName, cm.MethodName),
                    string.Format("最后调用：{0}", ldt.ToString("yyyy-MM-dd HH:mm:ss")));
            }
        }

        private void ultraStatusBar1_PanelDoubleClick(object sender, Infragistics.Win.UltraWinStatusBar.PanelClickEventArgs e)
        {
            try
            {
                if (e.Panel.Index == 3)
                {
                    ShowPopUpMsg(ultraTabbedMdiManager1.ActiveTab.Form.GetType().FullName);
                }
            }
            catch { }
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            this.panel2.Visible = false;
        }

        void AjustTime()
        {
            string strOut = "";
            DateTime time1 = DateTime.Now;
            try
            {
                object obj = ClientCommon._RemotingHelp.ExecuteMethod("ServerCommon", "Core.Mes.ServerCommon.UserInfoManager", "getDBSrvTime",
                    new object[] { }, out strOut);
                if (obj != null)
                {
                    DateTime srvTime = ((DateTime)obj);
                    DateTime time2 = DateTime.Now;
                    srvTime.Add(time2 - time1);
                    DateAndTime.Today = srvTime.Date;
                    DateAndTime.TimeOfDay = srvTime;
                }
            }
            catch
            {
            }
        }

        #region 气泡提示函数
        //////////////////////////////////////////////////////////////////////////
        private G1.UltraWinToolTip.UltraToolTipManager ToolTipManager1 = new G1.UltraWinToolTip.UltraToolTipManager();
        public delegate void ShowPopUpMsgDelegate(string strmsg, string prompt);
        public delegate void ShowPopUpMsgDelegate_1(string strmsg, Control control);
        public void ShowPopUpMsg(string strMsg)
        {
            ShowPopUpMsg(strMsg, "");
        }

        public void ShowPopUpMsg(string strMsg, string Prompt)
        {
            if (this.InvokeRequired)
            {
                ShowPopUpMsgDelegate act_Show = new ShowPopUpMsgDelegate(ShowPopUpMsg);
                this.Invoke(act_Show, strMsg, Prompt);
            }
            else
            {
                Form frm = this.MdiParent;
                if (frm == null) frm = this;

                int min_len = 40;
                string[] lines = strMsg.Trim().Split(new char[] { '\n' });
                if (lines == null)
                {
                    strMsg = "".PadRight(min_len, ' ');
                }
                else
                {
                    lines[0] = lines[0].PadRight(min_len, ' ');
                    strMsg = string.Join("\n", lines);
                }
                G1.UltraWinToolTip.UltraToolTipInfo toolTipInfo = new G1.UltraWinToolTip.UltraToolTipInfo
                    (strMsg, G1.ToolTipImage.Info, Prompt, G1.DefaultableBoolean.Default);

                toolTipInfo.Appearance.BackColor = Color.FromArgb(255, 255, 200);
                //toolTipInfo.Appearance.BackColor2 = Color.Chartreuse;
                toolTipInfo.Appearance.BackColor2 = Color.LightGoldenrodYellow;
                toolTipInfo.Appearance.BackGradientStyle = G1.GradientStyle.Circular;
                toolTipInfo.Appearance.ForeColor = Color.Red;
                toolTipInfo.Appearance.FontData.Bold = G1.DefaultableBoolean.True;
                toolTipInfo.Appearance.FontData.SizeInPoints = 11f;
                toolTipInfo.ToolTipTitleAppearance.ForeColor = Color.Navy;


                int delay_time = (strMsg.Length + Prompt.Length) / 3 * 1000;
                ToolTipManager1.AutoPopDelay = delay_time < 5 ? 5 : delay_time;
                ToolTipManager1.SetUltraToolTip(this, toolTipInfo);
                ToolTipManager1.ShowToolTip(this, new Point(frm.ClientSize.Width - 20, frm.ClientSize.Height - 10));
            }
        }


        public void ShowPopUpMsg(string strMsg, Control control)
        {
            if (control == null) return;

            if (control.InvokeRequired)
            {
                ShowPopUpMsgDelegate_1 act_Show = new ShowPopUpMsgDelegate_1(ShowPopUpMsg);
                control.Invoke(act_Show, strMsg);
            }
            else
            {
                G1.UltraWinToolTip.UltraToolTipManager _ToolTipManager = new G1.UltraWinToolTip.UltraToolTipManager();
                G1.UltraWinToolTip.UltraToolTipInfo toolTipInfo = new G1.UltraWinToolTip.UltraToolTipInfo
                    (strMsg, G1.ToolTipImage.None, "", G1.DefaultableBoolean.Default);

                toolTipInfo.Appearance.BackColor = Color.WhiteSmoke;
                toolTipInfo.Appearance.BackColor2 = Color.Yellow;
                toolTipInfo.Appearance.BackGradientStyle = G1.GradientStyle.Circular;
                toolTipInfo.Appearance.ForeColor = Color.Red;
                toolTipInfo.Appearance.FontData.Bold = G1.DefaultableBoolean.True;
                toolTipInfo.Appearance.FontData.SizeInPoints = 11f;
                toolTipInfo.ToolTipTitleAppearance.ForeColor = Color.Navy;

                Rectangle rect = control.RectangleToScreen(control.ClientRectangle);
                rect.Height -= 15;
                rect.Width -= 15;
                Point screen_pos = control.PointToScreen(new Point(control.Location.X + control.Size.Width - 15, control.Location.Y + control.Height - 15));

                int delay_time = strMsg.Length / 3 * 1000;
                _ToolTipManager.AutoPopDelay = delay_time < 5 ? 5 : delay_time;
                _ToolTipManager.SetUltraToolTip(this, toolTipInfo);
                _ToolTipManager.ShowToolTip(this, rect, screen_pos);
            }
        }

        public void ShowPopUpMsg(string strMsg, Control control, Point _offset)
        {
            if (control == null) return;

            if (control.InvokeRequired)
            {
                ShowPopUpMsgDelegate_1 act_Show = new ShowPopUpMsgDelegate_1(ShowPopUpMsg);
                control.Invoke(act_Show, strMsg);
            }
            else
            {
                G1.UltraWinToolTip.UltraToolTipManager _ToolTipManager = new G1.UltraWinToolTip.UltraToolTipManager();
                G1.UltraWinToolTip.UltraToolTipInfo toolTipInfo = new G1.UltraWinToolTip.UltraToolTipInfo
                    (strMsg, G1.ToolTipImage.None, "", G1.DefaultableBoolean.Default);

                toolTipInfo.Appearance.BackColor = Color.WhiteSmoke;
                toolTipInfo.Appearance.BackColor2 = Color.Yellow;
                toolTipInfo.Appearance.BackGradientStyle = G1.GradientStyle.Circular;
                toolTipInfo.Appearance.ForeColor = Color.Red;
                toolTipInfo.Appearance.FontData.Bold = G1.DefaultableBoolean.True;
                toolTipInfo.Appearance.FontData.SizeInPoints = 11f;
                toolTipInfo.ToolTipTitleAppearance.ForeColor = Color.Navy;

                Rectangle rect = control.RectangleToScreen(control.ClientRectangle);
                rect.Height -= 15;
                rect.Width -= 15;
                Point screen_pos = control.PointToScreen(new Point(control.Location.X, control.Location.Y));
                screen_pos.Offset(_offset);

                int delay_time = strMsg.Length / 3 * 1000;
                _ToolTipManager.AutoPopDelay = delay_time < 5 ? 5 : delay_time;
                _ToolTipManager.SetUltraToolTip(this, toolTipInfo);
                _ToolTipManager.ShowToolTip(this, screen_pos);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////
        /*                  拦截窗口消息，检测按钮点击                          */
        //////////////////////////////////////////////////////////////////////////
        //  一些定义
        [DllImport("user32.dll", EntryPoint = "WindowFromPoint")]//指定坐标处窗体句柄
        public static extern int WindowFromPoint(
            int xPoint,
            int yPoint
        );

        const int WM_PARENTNOTIFY = 0x0210;
        const int WM_LBUTTONDOWN = 0x0201;
        const int WM_RBUTTONDOWN = 0x0204;
        const int WM_MBUTTONDOWN = 0x0207;
        //////////////////////////////////////////////////////////////////////////
        protected override void WndProc(ref Message m)
        {
            //Debug.Print(string.Format("{0,8:x} -- {1,10},{2,10}", m.Msg, m.WParam, m.LParam));
            try
            {
                if (m.Msg == WM_PARENTNOTIFY)
                {
                    int LO_WPARAM = ((int)m.WParam & 0xFFFF);
                    int HI_WPARAM = ((int)m.WParam >> 16);

                    if (LO_WPARAM == WM_LBUTTONDOWN)
                    {
                        int LO_LPARAM = ((int)m.LParam & 0xFFFF);
                        int HI_LPARAM = ((int)m.LParam >> 16);

                        Point p = new Point(LO_LPARAM, HI_LPARAM);
                        Point p1 = PointToScreen(p);

                        string p_Text = "";
                        int hwnd = WindowFromPoint(p1.X, p1.Y);
                        Control c = Control.FromHandle((IntPtr)hwnd);
                        Control pc = c;

                        while (pc.Parent != null)
                        {
                            pc = pc.Parent;
                            if (pc.GetType() == typeof(Form) || typeof(Form).IsAssignableFrom(pc.GetType()))
                            {
                                p_Text = pc.Text;
                                break;
                            }
                        }

                        if (c.GetType().ToString().ToUpper().Contains("BUTTON"))
                        {
                            ClientCommon.RecordUserEvent("点击", "按钮", c.Text.Trim(), p_Text, (string.IsNullOrEmpty(p_Text) ? "" : pc.Name), "");
                        }
                    }
                }
            }
            catch
            {

            }
            base.WndProc(ref m);
        }

    }

}
