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 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; using Serilog; using DW5S.Service; namespace DW5S.App.UserControl { public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl { public CtrlSysSettings() { InitializeComponent(); this.layoutControl1.UseDefault(); } private async void CtrlSysSettings_Load(object sender, EventArgs e) { try { txtWmtsSource.Properties.Items.AddEnum(); txtLayer.Items.AddEnum(); txtLayer.Items.RemoveAt(0); txtWmtsSource.SelectedIndex = 0; txtLayer.SelectedIndex = 0; var unitOfWork = IocContainer.UnitOfWork; var settings = await unitOfWork.Of().FirstOrDefaultAsync(); if (settings != null) { this.txtHttpPort.Text = settings.HttpPort.ToString(); this.txtTimeZone.TimeZoneId = settings.TimeZoneID; this.txtSampleDire.Text = settings.SampleDirectory; if (!string.IsNullOrEmpty(settings.XLDirectory)) this.txtXLDirectory.Text = settings.XLDirectory.ToString(); if (this.txtMapType.SelectedIndex == settings.MapType) txtMapType_SelectedIndexChanged(null, null); else this.txtMapType.SelectedIndex = settings.MapType; if (txtMapType.SelectedIndex != 0) { this.txtWmtsSource.EditValue = settings.WmtsSource; for (int i = 0; i < txtLayer.Items.Count; i++) { if (settings.MapLayerType.HasFlag(EnumMapLayerType.SatMap)) { this.txtLayer.Items[EnumMapLayerType.SatMap].CheckState = CheckState.Checked; } if (settings.MapLayerType.HasFlag(EnumMapLayerType.RoadMap)) { this.txtLayer.Items[EnumMapLayerType.RoadMap].CheckState = CheckState.Checked; } if (settings.MapLayerType.HasFlag(EnumMapLayerType.XZQH_Map)) { this.txtLayer.Items[EnumMapLayerType.XZQH_Map].CheckState = CheckState.Checked; } } } } } catch (Exception ex) { string msg = "加载配置信息异常"; IocContainer.Logger.Error(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } 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; } if (string.IsNullOrWhiteSpace(txtSampleDire.Text)) { DxHelper.MsgBoxHelper.ShowError("请输入样本存储目录!"); return; } try { Directory.CreateDirectory(txtSampleDire.Text); } catch (Exception ex) { DxHelper.MsgBoxHelper.ShowError($"创建样本存储目录失败,{ex.Message}!"); return; } var unitOfWork = IocContainer.UnitOfWork; var repsSys = unitOfWork.Of(); var res = await repsSys.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.SampleDirectory = txtSampleDire.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; } await repsSys.AddOrUpdateAsync(res); await unitOfWork.SaveAsync(); 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) { string msg = "配置信息保存异常"; IocContainer.Logger.Error(ex, msg); DxHelper.MsgBoxHelper.ShowError(msg); } 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; } } } } }