123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- using SuperMap.Data;
- using SuperMap.UI;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.Commons;
- using WWPipeLine.MapBasic;
- using WWPipeLine.MapManager;
- namespace WWPipeLine
- {
- public partial class FormMainRibbon : Sunny.UI.UIForm, IMessageInterface
- {
- static FormMainRibbon m_Instance;
- private MapSetting m_MapSetting;
- private EagleEyeMapSetting m_EagleEyeMapSetting;
- private MapMeasure m_MapMeasure;
- public static FormMainRibbon Instance
- {
- get
- {
- if (m_Instance == null)
- {
- m_Instance = new FormMainRibbon();
- }
- return m_Instance;
- }
- }
- FormMainRibbon()
- {
- SplashForm.Instance.TopMost = true;
- SplashForm.Instance.TopLevel = true;
- SplashForm.Instance.Show();
- Application.DoEvents();
- SplashForm.Instance.BringToFront();
- this.IsMdiContainer = true;
- InitializeComponent();
- try
- {
- this.Left = SplashForm.Instance.Left;
- this.Top = SplashForm.Instance.Top;
- this.Size = SplashForm.Instance.Size;
- }
- catch (Exception ex)
- {
- LogHelper.Error(ex.Message);
- }
- this.dockPanel.DocumentStyle = WeifenLuo.WinFormsUI.Docking.DocumentStyle.SystemMdi;
- }
- //Supermap重新打开事件 贾海林 这个地方也搞不懂时干啥用的
- //private void WorkSpace_MapNewOpenEvent(MapControl mapc, MapControl EagleEyec)
- //{
- // this.m_MapMeasure.MapControl = mapc;//设置地图测量类MapMeasure的地图控件
- // this.m_MapSetting.MapControlMapSeting = mapc;
- // //////王国璋 搞不懂为啥要设置这些参数
- // ////this.m_MapSetting.MapControl = mapc;
- // ////this.m_MapSetting.ViewState = "";
- // ////this.m_MapSetting.ExtendNowIndex = 0;
- // ////this.m_MapSetting.ExtendRecordsMax = 3;
- // ////this.m_MapSetting.Extents.Clear();
- // //this.m_EagleEyeMapSetting.MapControlMain = mapc;
- // //this.m_EagleEyeMapSetting.MapControlEagleEye = EagleEyec;
- //}
- ///// <summary>
- ///// 一堆乱七八糟的操作后完成功能菜单的Click注册
- ///// </summary>
- //void UnRegister()
- //{
- // foreach (var tab in this.ribbonMain.Tabs)
- // {
- // foreach (var panel in tab.Panels)
- // {
- // foreach (var item in panel.Items)
- // {
- // if (item is RibbonButton)
- // {
- // var btn = item as RibbonButton;
- // btn.Click += new System.EventHandler((sender, e) => { UnregisterImpl(); });
- // }
- // }
- // }
- // }
- //}
- ///// <summary>
- ///// 功能菜单点击后,将MapControl的Action设置为Pan漫游
- ///// </summary>
- //void UnregisterImpl()
- //{
- // if (!MapAdapter.Instance.MapControlMA.IsDisposed)
- // {
- // MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Pan;
- // }
- // foreach (var soi in MapOperInterface.AllMapOperInterface.Values)
- // {
- // soi.UnRegister();
- // }
- //}
- protected override void OnLoad(EventArgs e)
- {
- this.Text = "潍微科技供水管网地理信息系统";
- var iconPath = Paths.ApplicationResourcesDir + "//favorite.ico";
- if (System.IO.File.Exists(iconPath))
- this.Icon = new System.Drawing.Icon(iconPath);
- //根据config里面的menus注册顶部的功能菜单。包括一级菜单和二级菜单
- RibbonMenuRegister.Instance.RegisterByConfig(this.ribbonMain);
- //this.ribbonButtonExit.Click += RibbonButtonExit_Click;
- SplashForm.Instance.SetMessage("初始化场景......");
- ComsStatic.Instance.SetDockPanel(this.dockPanel);
- ComsStatic.Instance.SetIMessageInterface(FormMainRibbon.Instance);
- MapAdapter.Instance.LoadMapControl();
- Task.Factory.StartNew(() =>
- {
- System.Threading.Thread.Sleep(500);
- }).ContinueWith((t) =>
- {
- SplashForm.Instance.SetMessage("场景初始化完成......");
- //RibbonMenuRegister.Instance.SetDockPanelRibbonMenuRegister(this.dockPanel);
- //UnRegister();
- m_MapSetting = new MapSetting(MapAdapter.Instance.MapControlMA, this);
- m_MapMeasure = new MapMeasure(MapAdapter.Instance.MapControlMA, this);
- m_EagleEyeMapSetting = new EagleEyeMapSetting(MapAdapter.Instance.MapControlOfEagleEyeMA, MapAdapter.Instance.MapControlMA);
- //MapAdapter.Instance.NewOpenEvent += WorkSpace_MapNewOpenEvent;
- var lastPath = IniHelper.Read(IniHelper.KEY_LAST_WORKSPACE_PATH);
- if (!string.IsNullOrEmpty(lastPath))
- {
- SplashForm.Instance.SetMessage("加载上一次场景......");
- MapAdapter.Instance.OpenWorkSpace(lastPath);
- }
- System.Threading.Thread.Sleep(500);
- SplashForm.Instance.CloseIt = true;
- WindowState = FormWindowState.Maximized;
- this.BringToFront();
- this.Invoke((MethodInvoker)delegate ()
- {
- ControlTools form = new ControlTools(this);
- form.Tag = "MainControls";
- form.DockPanel = this.dockPanel;
- form.DockState = DockState.Float;
- form.DockPanel.AllowEndUserDocking = false;
- Rectangle r = new Rectangle(Screen.PrimaryScreen.Bounds.Width - 100, Screen.PrimaryScreen.Bounds.Height - 900, 90, 350);
- form.Show(this.dockPanel, r);
- });
- }, TaskScheduler.FromCurrentSynchronizationContext());
- MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Select;
- MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Pan;
- base.OnLoad(e);
- timerGC.Enabled = true;
- }
- //private void RibbonButtonExit_Click(object sender, EventArgs e)
- //{
- // MapAdapter.Instance.CloseWorkSpace();
- // this.Close();
- //}
- protected override void OnClosing(CancelEventArgs e)
- {
- this.TopMost = true;
- bool exit = Sunny.UI.UIMessageDialog.ShowAskDialog(this, "确认退出系统吗?", ComsStatic.uiStyleCom);
- if (exit)
- {
- //参照昌乐的 退出系统时,删除 事故点信息
- Recordset rd = ComsStatic.dvConfig.Query(" pzlx='事故点' ", CursorType.Dynamic);
- if (!rd.IsEmpty) rd.DeleteAll();
- LogHelper.Info("系统正常退出");
- if (ComsStatic.LoginID != 0)
- {
- string sql = string.Format("update userlogin set outtime='{0}' where id={1}", DateTime.Now.ToLocalTime(), ComsStatic.LoginID);
- new NpgsqlHelper().ExecuteNonQuery(sql);
- }
- Application.Exit();
- e.Cancel = false;
- }
- else
- {
- this.TopMost = false;
- e.Cancel = true;
- }
- }
- //protected override void WndProc(ref Message m)
- //{
- // const int WM_SYSCOMMAND = 0x0112;
- // const int SC_CLOSE = 0xF060;
- // const int WM_SETFOCUS = 0x0007;//获得焦点后
- // const int WM_KILLFOCUS = 0x0008;//失去焦点
- // //if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
- // if (m.Msg == WM_KILLFOCUS)
- // {
- // }
- // base.WndProc(ref m);
- //}
- //protected override void OnActivated(EventArgs e)
- //{
- // FormCollection fc = Application.OpenForms;
- // foreach (Form f in fc)
- // {
- // if (f == this) continue;
- // else if (f.GetType() == typeof(ToolWindowExtend)) continue;
- // else if (f.GetType() == typeof(LayersTreeEx)) continue;
- // else if (f.GetType() == typeof(EagleEyeEx)) continue;
- // else if (f.TopLevel && f.TopMost) continue;
- // else if (!f.Visible) continue;
- // else
- // {
- // if (f.InvokeRequired)
- // {
- // f.Invoke(new System.Action(() => { f.BringToFront(); }));
- // }
- // else
- // {
- // f.BringToFront();
- // }
- // }
- // }
- // base.OnActivated(e);
- //}
- #region 状态栏消息显示
- /// <summary>
- /// 状态栏消息显示 Color.Black
- /// </summary>
- /// <param name="msg"></param>
- public void ShowInfo(string msg)
- {
- ShowMessage(msg, "Info");
- }
- /// <summary>
- /// 状态栏消息显示 Color.Red;
- /// </summary>
- /// <param name="msg"></param>
- public void ShowError(string msg)
- {
- ShowMessage(msg, "Error");
- }
- /// <summary>
- /// 状态栏消息显示 Color.Gold;
- /// </summary>
- /// <param name="msg"></param>
- public void ShowWarn(string msg)
- {
- ShowMessage(msg, "Warn");
- }
- private void ShowMessage(string Message, string type)
- {
- this.Invoke(new System.Action(() =>
- {
- if (type == "Error")
- {
- this.uiLabelMessage.ForeColor = System.Drawing.Color.Red;
- }
- else if (type == "Info")
- {
- this.uiLabelMessage.ForeColor = System.Drawing.Color.Black;
- }
- else if (type == "Warn")
- {
- this.uiLabelMessage.ForeColor = System.Drawing.Color.Gold;
- }
- this.uiLabelMessage.Text = Message;
- }));
- }
- #endregion
- #region 内存回收
- [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
- public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
- private void timerGC_Tick(object sender, EventArgs e)
- {
- GC.Collect();
- GC.WaitForPendingFinalizers();
- if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
- {
- SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
- }
- }
- #endregion
- }
- }
|