FormMainRibbon.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. using SuperMap.Data;
  2. using SuperMap.UI;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Drawing;
  7. using System.Runtime.InteropServices;
  8. using System.Threading;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using WeifenLuo.WinFormsUI.Docking;
  12. using WWPipeLine.Commons;
  13. using WWPipeLine.MapBasic;
  14. using WWPipeLine.MapManager;
  15. namespace WWPipeLine
  16. {
  17. public partial class FormMainRibbon : Sunny.UI.UIForm, IMessageInterface
  18. {
  19. static FormMainRibbon m_Instance;
  20. private MapSetting m_MapSetting;
  21. private EagleEyeMapSetting m_EagleEyeMapSetting;
  22. private MapMeasure m_MapMeasure;
  23. public static FormMainRibbon Instance
  24. {
  25. get
  26. {
  27. if (m_Instance == null)
  28. {
  29. m_Instance = new FormMainRibbon();
  30. }
  31. return m_Instance;
  32. }
  33. }
  34. FormMainRibbon()
  35. {
  36. SplashForm.Instance.TopMost = true;
  37. SplashForm.Instance.TopLevel = true;
  38. SplashForm.Instance.Show();
  39. Application.DoEvents();
  40. SplashForm.Instance.BringToFront();
  41. this.IsMdiContainer = true;
  42. InitializeComponent();
  43. try
  44. {
  45. this.Left = SplashForm.Instance.Left;
  46. this.Top = SplashForm.Instance.Top;
  47. this.Size = SplashForm.Instance.Size;
  48. }
  49. catch (Exception ex)
  50. {
  51. LogHelper.Error(ex.Message);
  52. }
  53. this.dockPanel.DocumentStyle = WeifenLuo.WinFormsUI.Docking.DocumentStyle.SystemMdi;
  54. }
  55. //Supermap重新打开事件 贾海林 这个地方也搞不懂时干啥用的
  56. //private void WorkSpace_MapNewOpenEvent(MapControl mapc, MapControl EagleEyec)
  57. //{
  58. // this.m_MapMeasure.MapControl = mapc;//设置地图测量类MapMeasure的地图控件
  59. // this.m_MapSetting.MapControlMapSeting = mapc;
  60. // //////王国璋 搞不懂为啥要设置这些参数
  61. // ////this.m_MapSetting.MapControl = mapc;
  62. // ////this.m_MapSetting.ViewState = "";
  63. // ////this.m_MapSetting.ExtendNowIndex = 0;
  64. // ////this.m_MapSetting.ExtendRecordsMax = 3;
  65. // ////this.m_MapSetting.Extents.Clear();
  66. // //this.m_EagleEyeMapSetting.MapControlMain = mapc;
  67. // //this.m_EagleEyeMapSetting.MapControlEagleEye = EagleEyec;
  68. //}
  69. ///// <summary>
  70. ///// 一堆乱七八糟的操作后完成功能菜单的Click注册
  71. ///// </summary>
  72. //void UnRegister()
  73. //{
  74. // foreach (var tab in this.ribbonMain.Tabs)
  75. // {
  76. // foreach (var panel in tab.Panels)
  77. // {
  78. // foreach (var item in panel.Items)
  79. // {
  80. // if (item is RibbonButton)
  81. // {
  82. // var btn = item as RibbonButton;
  83. // btn.Click += new System.EventHandler((sender, e) => { UnregisterImpl(); });
  84. // }
  85. // }
  86. // }
  87. // }
  88. //}
  89. ///// <summary>
  90. ///// 功能菜单点击后,将MapControl的Action设置为Pan漫游
  91. ///// </summary>
  92. //void UnregisterImpl()
  93. //{
  94. // if (!MapAdapter.Instance.MapControlMA.IsDisposed)
  95. // {
  96. // MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Pan;
  97. // }
  98. // foreach (var soi in MapOperInterface.AllMapOperInterface.Values)
  99. // {
  100. // soi.UnRegister();
  101. // }
  102. //}
  103. protected override void OnLoad(EventArgs e)
  104. {
  105. this.Text = "潍微科技供水管网地理信息系统";
  106. var iconPath = Paths.ApplicationResourcesDir + "//favorite.ico";
  107. if (System.IO.File.Exists(iconPath))
  108. this.Icon = new System.Drawing.Icon(iconPath);
  109. //根据config里面的menus注册顶部的功能菜单。包括一级菜单和二级菜单
  110. RibbonMenuRegister.Instance.RegisterByConfig(this.ribbonMain);
  111. //this.ribbonButtonExit.Click += RibbonButtonExit_Click;
  112. SplashForm.Instance.SetMessage("初始化场景......");
  113. ComsStatic.Instance.SetDockPanel(this.dockPanel);
  114. ComsStatic.Instance.SetIMessageInterface(FormMainRibbon.Instance);
  115. MapAdapter.Instance.LoadMapControl();
  116. Task.Factory.StartNew(() =>
  117. {
  118. System.Threading.Thread.Sleep(500);
  119. }).ContinueWith((t) =>
  120. {
  121. SplashForm.Instance.SetMessage("场景初始化完成......");
  122. //RibbonMenuRegister.Instance.SetDockPanelRibbonMenuRegister(this.dockPanel);
  123. //UnRegister();
  124. m_MapSetting = new MapSetting(MapAdapter.Instance.MapControlMA, this);
  125. m_MapMeasure = new MapMeasure(MapAdapter.Instance.MapControlMA, this);
  126. m_EagleEyeMapSetting = new EagleEyeMapSetting(MapAdapter.Instance.MapControlOfEagleEyeMA, MapAdapter.Instance.MapControlMA);
  127. //MapAdapter.Instance.NewOpenEvent += WorkSpace_MapNewOpenEvent;
  128. var lastPath = IniHelper.Read(IniHelper.KEY_LAST_WORKSPACE_PATH);
  129. if (!string.IsNullOrEmpty(lastPath))
  130. {
  131. SplashForm.Instance.SetMessage("加载上一次场景......");
  132. MapAdapter.Instance.OpenWorkSpace(lastPath);
  133. }
  134. System.Threading.Thread.Sleep(500);
  135. SplashForm.Instance.CloseIt = true;
  136. WindowState = FormWindowState.Maximized;
  137. this.BringToFront();
  138. this.Invoke((MethodInvoker)delegate ()
  139. {
  140. ControlTools form = new ControlTools(this);
  141. form.Tag = "MainControls";
  142. form.DockPanel = this.dockPanel;
  143. form.DockState = DockState.Float;
  144. form.DockPanel.AllowEndUserDocking = false;
  145. Rectangle r = new Rectangle(Screen.PrimaryScreen.Bounds.Width - 100, Screen.PrimaryScreen.Bounds.Height - 900, 90, 350);
  146. form.Show(this.dockPanel, r);
  147. });
  148. }, TaskScheduler.FromCurrentSynchronizationContext());
  149. MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Select;
  150. MapAdapter.Instance.MapControlMA.Action = SuperMap.UI.Action.Pan;
  151. base.OnLoad(e);
  152. timerGC.Enabled = true;
  153. }
  154. //private void RibbonButtonExit_Click(object sender, EventArgs e)
  155. //{
  156. // MapAdapter.Instance.CloseWorkSpace();
  157. // this.Close();
  158. //}
  159. protected override void OnClosing(CancelEventArgs e)
  160. {
  161. this.TopMost = true;
  162. bool exit = Sunny.UI.UIMessageDialog.ShowAskDialog(this, "确认退出系统吗?", ComsStatic.uiStyleCom);
  163. if (exit)
  164. {
  165. //参照昌乐的 退出系统时,删除 事故点信息
  166. Recordset rd = ComsStatic.dvConfig.Query(" pzlx='事故点' ", CursorType.Dynamic);
  167. if (!rd.IsEmpty) rd.DeleteAll();
  168. LogHelper.Info("系统正常退出");
  169. if (ComsStatic.LoginID != 0)
  170. {
  171. string sql = string.Format("update userlogin set outtime='{0}' where id={1}", DateTime.Now.ToLocalTime(), ComsStatic.LoginID);
  172. new NpgsqlHelper().ExecuteNonQuery(sql);
  173. }
  174. Application.Exit();
  175. e.Cancel = false;
  176. }
  177. else
  178. {
  179. this.TopMost = false;
  180. e.Cancel = true;
  181. }
  182. }
  183. //protected override void WndProc(ref Message m)
  184. //{
  185. // const int WM_SYSCOMMAND = 0x0112;
  186. // const int SC_CLOSE = 0xF060;
  187. // const int WM_SETFOCUS = 0x0007;//获得焦点后
  188. // const int WM_KILLFOCUS = 0x0008;//失去焦点
  189. // //if (m.Msg == WM_SYSCOMMAND && (int)m.WParam == SC_CLOSE)
  190. // if (m.Msg == WM_KILLFOCUS)
  191. // {
  192. // }
  193. // base.WndProc(ref m);
  194. //}
  195. //protected override void OnActivated(EventArgs e)
  196. //{
  197. // FormCollection fc = Application.OpenForms;
  198. // foreach (Form f in fc)
  199. // {
  200. // if (f == this) continue;
  201. // else if (f.GetType() == typeof(ToolWindowExtend)) continue;
  202. // else if (f.GetType() == typeof(LayersTreeEx)) continue;
  203. // else if (f.GetType() == typeof(EagleEyeEx)) continue;
  204. // else if (f.TopLevel && f.TopMost) continue;
  205. // else if (!f.Visible) continue;
  206. // else
  207. // {
  208. // if (f.InvokeRequired)
  209. // {
  210. // f.Invoke(new System.Action(() => { f.BringToFront(); }));
  211. // }
  212. // else
  213. // {
  214. // f.BringToFront();
  215. // }
  216. // }
  217. // }
  218. // base.OnActivated(e);
  219. //}
  220. #region 状态栏消息显示
  221. /// <summary>
  222. /// 状态栏消息显示 Color.Black
  223. /// </summary>
  224. /// <param name="msg"></param>
  225. public void ShowInfo(string msg)
  226. {
  227. ShowMessage(msg, "Info");
  228. }
  229. /// <summary>
  230. /// 状态栏消息显示 Color.Red;
  231. /// </summary>
  232. /// <param name="msg"></param>
  233. public void ShowError(string msg)
  234. {
  235. ShowMessage(msg, "Error");
  236. }
  237. /// <summary>
  238. /// 状态栏消息显示 Color.Gold;
  239. /// </summary>
  240. /// <param name="msg"></param>
  241. public void ShowWarn(string msg)
  242. {
  243. ShowMessage(msg, "Warn");
  244. }
  245. private void ShowMessage(string Message, string type)
  246. {
  247. this.Invoke(new System.Action(() =>
  248. {
  249. if (type == "Error")
  250. {
  251. this.uiLabelMessage.ForeColor = System.Drawing.Color.Red;
  252. }
  253. else if (type == "Info")
  254. {
  255. this.uiLabelMessage.ForeColor = System.Drawing.Color.Black;
  256. }
  257. else if (type == "Warn")
  258. {
  259. this.uiLabelMessage.ForeColor = System.Drawing.Color.Gold;
  260. }
  261. this.uiLabelMessage.Text = Message;
  262. }));
  263. }
  264. #endregion
  265. #region 内存回收
  266. [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")]
  267. public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);
  268. private void timerGC_Tick(object sender, EventArgs e)
  269. {
  270. GC.Collect();
  271. GC.WaitForPendingFinalizers();
  272. if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
  273. {
  274. SetProcessWorkingSetSize(System.Diagnostics.Process.GetCurrentProcess().Handle, -1, -1);
  275. }
  276. }
  277. #endregion
  278. }
  279. }