using KGIS.Framework.Maps;
using KGIS.Framework.Platform;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using Kingo.PluginServiceInterface;
using System;
using System.Collections.Generic;
namespace Kingo.Plugin.BGSetting.Views
{
    /// 
    /// 系统设置 的交互逻辑
    /// 
    public partial class UCOpenSystemSet : BaseWindow
    {
        public SystemConfig2 SystemCfg { get; set; }
        public UCOpenSystemSet()
        {
            InitializeComponent();
            if (Platform.Instance.SystemType == SystemTypeEnum.BGFWCG)
            {
                SJJZ.Visibility = System.Windows.Visibility.Collapsed;
                WYXX.Visibility = System.Windows.Visibility.Collapsed;
                TCZDPZ.Visibility = System.Windows.Visibility.Collapsed;
                tabControl.SelectedIndex = 5;
            }
            ISystemCfg cfg2 = UIShell.OSGi.BundleRuntime.Instance.GetFirstOrDefaultService();
            SystemCfg = cfg2.Load();
            if (SystemCfg.JcLayerLoadCfg == null)
            {
                SystemCfg.JcLayerLoadCfg = new List();
            }
            this.DataContext = this;
            if (MapsManager.Instance.CurrProjectInfo != null)
            {
                if ((MapsManager.Instance.CurrProjectInfo as ProjectInfo).KZMJ == null)
                    (MapsManager.Instance.CurrProjectInfo as ProjectInfo).KZMJ = new KZMJInfo();
                //CtrlKZMJ.DataContext = (MapsManager.Instance.CurrProjectInfo as ProjectInfo).KZMJ;
            }
        }
        private void btnCancel_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Close();
        }
        /// 
        /// 保存按钮
        /// 
        /// 
        /// 
        private void btnSave_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                SystemCfg.Save();
                Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "SaveProject" });
                //Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "InitProject" });
                MessageHelper.Show("保存成功!");
            }
            catch (Exception ex)
            {
                LogAPI.Debug("保存系统配置文件失败:" + ex);
                MessageHelper.Show("系统配置文件保存失败!");
            }
        }
        private void btnOK_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            try
            {
                SystemCfg.Save();
                //Platform.Instance.SendMsg(new KGIS.Framework.Utils.Interface.NotifyMsgPackage() { MsgType = "InitProject" });
                this.Close();
            }
            catch (Exception ex)
            {
                LogAPI.Debug("保存系统配置文件失败:" + ex);
                MessageHelper.Show("系统配置文件保存失败!");
            }
        }
        private void BaseWindow_Loaded(object sender, System.Windows.RoutedEventArgs e)
        {
        }
    }
}