123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- using DevExpress.XtraEditors;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Net.Sockets;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Documents;
- using System.Windows.Forms;
- using DW5S.Repostory;
- using System.IO;
- using System.Data.Entity.Migrations;
- using ExtensionsDev;
- using DevExpress.Utils;
- using DevExpress.XtraMap;
- using DW5S.WebApi;
- using DevExpress.XtraPrinting;
- using DW5S.Entity;
- using DevExpress.XtraEditors.Controls;
- using System.Security.Policy;
- using DevExpress.Utils.About;
- using DW5S.DTO;
- using System.Configuration;
- namespace DW5S.App.UserControl
- {
- public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl
- {
- public CtrlSysSettings()
- {
- InitializeComponent();
- this.layoutControl1.UseDefault();
- }
- private void CtrlSysSettings_Load(object sender, EventArgs e)
- {
- try
- {
- txtWmtsSource.Properties.Items.AddEnum<EnumWmtsSource>();
- txtLayer.Items.AddEnum<EnumMapLayerType>();
- txtLayer.Items.RemoveAt(0);
- txtWmtsSource.SelectedIndex = 0;
- txtLayer.SelectedIndex = 0;
- if (SysConfig.Config != null)
- {
- this.txtHttpPort.Text = SysConfig.Config.HttpPort.ToString();
- this.txtTimeZone.TimeZoneId = SysConfig.Config.TimeZoneID;
- if (!string.IsNullOrEmpty(SysConfig.Config.XLDirectory))
- this.txtXLDirectory.Text = SysConfig.Config.XLDirectory.ToString();
- if (SysConfig.Config.YDPZThreshold > 0)
- this.txtYDPZThreshold.Text = SysConfig.Config.YDPZThreshold.ToString();
- if (this.txtMapType.SelectedIndex == SysConfig.Config.MapType)
- txtMapType_SelectedIndexChanged(null, null);
- else
- this.txtMapType.SelectedIndex = SysConfig.Config.MapType;
- if (txtMapType.SelectedIndex != 0)
- {
- this.txtWmtsSource.EditValue = SysConfig.Config.WmtsSource;
- for (int i = 0; i < txtLayer.Items.Count; i++)
- {
- if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.SatMap))
- {
- this.txtLayer.Items[EnumMapLayerType.SatMap].CheckState = CheckState.Checked;
- }
- if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.RoadMap))
- {
- this.txtLayer.Items[EnumMapLayerType.RoadMap].CheckState = CheckState.Checked;
- }
- if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.XZQH_Map))
- {
- this.txtLayer.Items[EnumMapLayerType.XZQH_Map].CheckState = CheckState.Checked;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- DW5S.Framework.LogHelper.Error("加载配置信息异常", ex);
- DxHelper.MsgBoxHelper.ShowError("加载配置信息异常");
- }
- layoutControl1.BestFit();
- }
- private async void btnSave_Click(object sender, EventArgs e)
- {
- try
- {
- if (!int.TryParse(txtHttpPort.Text, out int port))
- {
- DxHelper.MsgBoxHelper.ShowError("Http端口错误!");
- return;
- }
- if (string.IsNullOrWhiteSpace(txtTimeZone.TimeZoneId))
- {
- DxHelper.MsgBoxHelper.ShowError("系统时区错误!");
- return;
- }
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.SysSetings.FirstOrDefaultAsync();
- if (res == null) res = new SysSetings();
- bool needStartHttpSvr = res.HttpPort != port;
- if (!needStartHttpSvr)
- {
- needStartHttpSvr = res.TimeZoneID != txtTimeZone.TimeZoneId;
- }
- res.TimeZoneID = txtTimeZone.TimeZoneId;
- TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(txtTimeZone.TimeZoneId);
- if (tz.DisplayName == "UTC")
- {
- res.TimeZoneUTC = tz.DisplayName;
- res.TimeZoneName = "";
- }
- else
- {
- res.TimeZoneUTC = tz.DisplayName.Substring(1, tz.DisplayName.IndexOf(")") - 1).Trim();
- res.TimeZoneName = tz.DisplayName.Substring(tz.DisplayName.IndexOf(")") + 1).Trim();
- }
- res.ZoneHours = tz.BaseUtcOffset.TotalHours;
- res.HttpPort = port;
- res.XLDirectory = txtXLDirectory.Text;
- res.YDPZThreshold = string.IsNullOrWhiteSpace(txtYDPZThreshold.Text) ? 0 : Convert.ToInt32(txtYDPZThreshold.Text);
- bool mapChanged = res.MapType != txtMapType.SelectedIndex;
- res.MapType = txtMapType.SelectedIndex;
- if (txtMapType.SelectedIndex != 0)
- {
- var wmtsSource= (EnumWmtsSource)txtWmtsSource.EditValue;
- if (!mapChanged)
- {
- mapChanged = res.WmtsSource != wmtsSource;
- }
- res.WmtsSource = wmtsSource;
- EnumMapLayerType layerType = EnumMapLayerType.None;
- for (int i = 0; i < txtLayer.Items.Count; i++)
- {
- if (txtLayer.GetItemChecked(i))
- {
- layerType |= (EnumMapLayerType)txtLayer.Items[i].Value;
- }
- }
- layerType = layerType & ~EnumMapLayerType.None;//移除
- if (!mapChanged)
- mapChanged = res.MapLayerType != layerType;
- res.MapLayerType = layerType;
- }
- db.SysSetings.AddOrUpdate(res);
- await db.SaveChangesAsync();
- SysConfig.Config = res;
- if (mapChanged)
- Messenger.Defalut.Pub("地图类型改变", res);
- Messenger.Defalut.Pub("时区改变", res);
- DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!");
- if (needStartHttpSvr)
- {
- //var files=Directory.GetFiles("Service", "*.exe.config");
- //foreach (var f in files)
- //{
- // File.ReadAllText(f);
- //}
- Application.Restart();
- }
- }
- }
- catch (Exception ex)
- {
- DW5S.Framework.LogHelper.Error("配置信息保存异常", ex);
- DxHelper.MsgBoxHelper.ShowError("配置信息保存异常");
- }
- if (this.Parent is Form frm)
- frm.Close();
- }
- private void txtMapType_SelectedIndexChanged(object sender, EventArgs e)
- {
- if (txtMapType.SelectedIndex == 0)
- {
- itemWmtsSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
- itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
- }
- else
- {
- itemWmtsSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
- itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
- }
- layoutControl1.BestFit();
- }
- private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
- {
- RadioGroup rg = e.SelectedControl as RadioGroup;
- if (rg == null) return;
- for (int i = 0; i < rg.Properties.Items.Count; i++)
- {
- Rectangle rect = rg.GetItemRectangle(i);
- if (rect.Contains(e.ControlMousePosition))
- {
- var val = (EnumWmtsSource)rg.Properties.Items[i].Value;
- if (val == EnumWmtsSource.ZCJ)
- {
- var str =AppConfigHelper.Get("ZCJ_URL","");
- e.Info = new ToolTipControlInfo(i, $"{rg.Properties.Items[i].Description}:{str}");
- }
- else
- {
- var str = AppConfigHelper.Get("SJZX_URL","");
- e.Info = new ToolTipControlInfo(i, $"{rg.Properties.Items[i].Description}:{str}");
- }
- break;
- }
- }
- }
- }
- }
|