1
wtt
2025-08-18 823d41cfb4d4a2e679d883ce3cac680f94e02b75
LMES/XiaoZhuGe_autoGetData.cs
@@ -15,15 +15,75 @@
        public XiaoZhuGe_autoGetData()
        {
            InitializeComponent();
            //为系统托盘图标增加 右击菜单项
            ContextMenu contextMenu = new ContextMenu();
            MenuItem exitMenuItem = new MenuItem("退出");
            exitMenuItem.Click += ExitMenuItem_Click;
            contextMenu.MenuItems.Add(exitMenuItem);
            notifyIcon_Icon.ContextMenu = contextMenu;
            //页面初始化
            set_initPage();
        }
        private void button1_Click(object sender, EventArgs e)
        #region 页面初始化
        public void set_initPage()
        {
            XZG_DataSynchronizationController t = new XZG_DataSynchronizationController();
            //t.getAddMaterAsync_1();
            t.icmoInfoSyncFromERPToXZG();
            timer1.Enabled = true;
        }
        #endregion
        #region 定时器1:用于隐藏页面与任务栏图标
        private void timer1_Tick(object sender, EventArgs e)
        {
            //系统托盘显示软件图标
            this.notifyIcon_Icon.Visible = true;
            // 隐藏主窗体
            this.Hide();
            // 隐藏任务栏软件图标
            this.ShowInTaskbar = false;
            timer1.Enabled = false;
        }
        #endregion
        #region 定时器2:用于定时同步数据
        private void timer2_Tick(object sender, EventArgs e)
        {
            try
            {
                XZG_DataSynchronizationController t = new XZG_DataSynchronizationController();
                t.dataAnsy();
            }catch(Exception e1)
            {
                string sErrMsg = "";
            }
        }
        #endregion
        #region 系统托盘点击图标后图标仍存在
        private void notifyIcon_Icon_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && e.Clicks == 2) // 双击左键事件示例
            {
                // 处理双击事件,例如显示或隐藏主窗体等。
                //this.Show(); // 示例:显示主窗体(如果之前是隐藏的)
                //this.WindowState = FormWindowState.Normal; // 确保窗口处于正常状态(非最小化)
                //系统托盘显示软件图标
                this.notifyIcon_Icon.Visible = true;        //保证系统托盘图标仍旧存在
            }
        }
        #endregion
        #region 系统托盘图标 右击功能菜单退出按钮事件
        private void ExitMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit(); // 这将关闭整个应用程序
        }
        #endregion
    }
}