年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
8.9 KiB

4 months ago
using DevExpress.LookAndFeel;
using DevExpress.XtraBars.Docking;
using ESRI.ArcGIS.Controls;
using KGIS.Framework.Core.Services;
using KGIS.Framework.Menus;
using KGIS.Framework.Menus.Services;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using KGIS.Framework.Views;
using Kingo.PluginServiceInterface;
using System;
using System.Drawing;
using System.Windows.Forms;
using UIShell.OSGi;
namespace Kingo.PlatformPlugin.Services
{
class PlatformService : IPlatformService
{
FrmMain _win;
private IBundleContext _context;
private Timer _timer;
//private UCDataCatalog ucDataCatalog;
//private UCMapControl ucMapCtrl;
private IBaseMainView baseMainViewService;
public PlatformService(IBundleContext context)
{
_context = context;
_win = FrmMain.GetInstance(context);
_win.Load += _win_Load;
_win.Closing += _win_Closing;
}
private void _win_Load(object sender, EventArgs e)
{
}
/// <summary>
/// 程序右上角X号,关闭当前程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void _win_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
EngineEditor editor = new EngineEditorClass();
if (editor.EditState == esriEngineEditState.esriEngineStateEditing)
{
MessageHelper.ShowTips("当前工程正处于编辑状态,请先关闭编辑!");
e.Cancel = true;
return;
}
if (MessageHelper.ShowYesNoAndTips(sender as IWin32Window, "是否退出系统?") != DialogResult.Yes)
{
e.Cancel = true;
}
else
{
System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcessesByName("adb.exe");
foreach (System.Diagnostics.Process p in pro)
{
if (!string.IsNullOrEmpty(p.ProcessName))
{
try
{
p.Kill();
}
catch (Exception ex)
{
LogAPI.Debug(ex);
}
}
}
//GC.Collect();
//20231030 王冠杰 注释 软件关闭 未响应
//Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
System.Environment.Exit(0);
//Application.ExitThread();
//Application.Exit();
}
}
catch (Exception ex)
{
LogAPI.Debug("关闭当前程序报错:" + ex.Message);
}
}
public Form Instance => _win;
public void InitUI(object args)
{
try
{
System.Windows.Forms.Application.DoEvents();
//设置系统风格
//DevExpress.UserSkins.BonusSkins.Register();
//DevExpress.Skins.SkinManager.EnableFormSkins();
UserLookAndFeel.Default.SetSkinStyle("Office 2016 Colorful");
switch (Platform.Instance.SystemType)
{
case SystemTypeEnum.NDBGJK:
break;
case SystemTypeEnum.WYZS:
break;
case SystemTypeEnum.TBBG:
UserLookAndFeel.Default.SetSkinMaskColors(Color.FromArgb(255, 135, 206, 235), Color.White);
UserLookAndFeel.Default.SkinMaskColor = Color.FromArgb(255, 135, 206, 235);
break;
case SystemTypeEnum.BGFWCG:
UserLookAndFeel.Default.SetSkinMaskColors(Color.FromArgb(255, 240, 128, 128), Color.White);
UserLookAndFeel.Default.SkinMaskColor = Color.FromArgb(255, 240, 128, 128);
break;
default:
break;
}
//DevExpress.XtraEditors.WindowsFormsSettings.DefaultLookAndFeel.SetSkinStyle("Office 2013 White");
baseMainViewService = _context.GetFirstOrDefaultService<IBaseMainView>();
DockManager dockManager = null;
if (baseMainViewService != null)
{
if (baseMainViewService.DocumentView is IDockManage)
{
dockManager = (baseMainViewService.DocumentView as IDockManage).dockManager;
}
}
_context.AddService<IMenuService>(new MenuService(_win.RibControl));
//_context.AddService<IAppMenuService>(new AppMenuService(_win.backViewControl));
_context.AddService<IViewService>(new ViewService(_win.dockManager, dockManager, _win.tabbedView, _win.WorkPath));
if (baseMainViewService != null)
{
baseMainViewService.InitUI();
IRefreshMenuStatus t = baseMainViewService as IRefreshMenuStatus;
t.InitUI(_win.RibControl);
//object hook = null;
//if (baseMainViewService.DocumentView is KGIS.Framework.AE.IKMap)
//{
// hook = (baseMainViewService.DocumentView as KGIS.Framework.AE.IKMap).Hook;
//}
//初始化菜单
Platform.Instance.InitMainMenu(baseMainViewService.Hook);
}
//初始化系统开始菜单
//Platform.Instance.AppMenuManager.InitAppMenu(hook);
//初始化数据目录右键菜单
//Platform.Instance.InitCatalogContextMenus(hook);
//Platform.Instance.MapsManager.InitMapTools();
_timer = new Timer();
_timer.Tick += _timer_Tick;
_timer.Interval = 1000;
_timer.Start();
}
catch (Exception ex)
{
LogAPI.Debug("InitUI异常:" + ex.Message);
LogAPI.Debug("InitUI异常:" + ex.StackTrace);
}
}
/// <summary>
/// 初始化相关服务
/// </summary>
/// <param name="context"></param>
public void InitService()
{
baseMainViewService = _context.GetFirstOrDefaultService<IBaseMainView>();
DockManager dockManager = null;
if (baseMainViewService != null)
{
//baseMainViewService.InitUI();
if (baseMainViewService.DocumentView is IDockManage)
{
dockManager = (baseMainViewService.DocumentView as IDockManage).dockManager;
}
_context.AddService<IMenuService>(new MenuService(_win.RibControl));
//_context.AddService<IAppMenuService>(new AppMenuService(_win.backViewControl));
_context.AddService<IViewService>(new ViewService(_win.dockManager, dockManager, _win.tabbedView, _win.WorkPath));
}
}
int num = 0;
private void _timer_Tick(object sender, EventArgs e)
{
if (num <= 1)
num++;
if (num == 1)
{
if (baseMainViewService != null)
{
//初始化数据目录
//ucDataCatalog.Text = "数据目录";
Platform.Instance.OpenView(baseMainViewService.DefaultLeftDockPanel, false);
//初始化地图控件
Platform.Instance.ViewManager.AddDocument(baseMainViewService.DocumentView);
}
if (Platform.Instance.SystemType == SystemTypeEnum.BGFWCG)
{
IUcZYQMagrHelper ucZYQMagrHelper = BundleRuntime.Instance.GetFirstOrDefaultService<IUcZYQMagrHelper>();
if (ucZYQMagrHelper != null)
{
ucZYQMagrHelper.InitView();
}
}
IWorkCatalog _workCatalog = _context.GetFirstOrDefaultService<IWorkCatalog>();
if (_workCatalog != null)
{
_workCatalog.Open();
}
}
Platform.Instance.RefreshMenuState();
if (baseMainViewService != null)
baseMainViewService.RefreshMenuOrToolState();
//Platform.Instance.MapsManager.RefreshToolState();
}
}
}