using DevExpress.XtraEditors; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; 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 XdCxRhDW.Repostory; using System.IO; using System.Data.Entity.Migrations; using ExtensionsDev; using DevExpress.Utils; using DevExpress.XtraMap; using XdCxRhDW.WebApi; using DevExpress.XtraPrinting; using XdCxRhDW.Entity; namespace XdCxRhDW.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 { using (RHDWContext db = new RHDWContext()) { var res = await db.SysSetings.FirstOrDefaultAsync(); if (res != null) { this.txtHttpPort.Text = res.HttpPort.ToString(); if (!string.IsNullOrEmpty(res.XLDirectory)) this.txtXLDirectory.Text = res.XLDirectory.ToString(); if (!string.IsNullOrEmpty(res.MapAddr)) this.txtMapUrl.Text = res.MapAddr.ToString(); if (res.YDPZThreshold > 0) this.txtYDPZThreshold.Text = res.YDPZThreshold.ToString(); this.txtLayer.Text = res.LayerName; if (this.txtMapType.SelectedIndex == res.MapType) { txtMapType_SelectedIndexChanged(null, null); } else this.txtMapType.SelectedIndex = res.MapType; } } } catch (Exception ex) { Serilog.Log.Error(ex, "加载配置信息异常"); DxHelper.MsgBoxHelper.ShowError("加载配置信息异常"); } layoutControl1.BestFit(); } private async void btnSave_Click(object sender, EventArgs e) { bool needStartHttpSvr = false; try { using (RHDWContext db = new RHDWContext()) { var res = await db.SysSetings.FirstOrDefaultAsync(); if (res == null) { res = new SysSetings() { HttpPort = Convert.ToInt32(txtHttpPort.Text), XLDirectory = txtXLDirectory.Text, YDPZThreshold = string.IsNullOrWhiteSpace(txtYDPZThreshold.Text) ? 0 : Convert.ToInt32(txtYDPZThreshold.Text), MapAddr = txtMapUrl.Text, MapType = txtMapType.SelectedIndex, LayerName = txtLayer.Text, }; db.SysSetings.Add(res); needStartHttpSvr = true; } else { needStartHttpSvr = res.HttpPort != Convert.ToInt32(txtHttpPort.Text); res.HttpPort = Convert.ToInt32(txtHttpPort.Text); res.XLDirectory = txtXLDirectory.Text; res.MapAddr = txtMapUrl.Text; res.YDPZThreshold = string.IsNullOrWhiteSpace(txtYDPZThreshold.Text) ? 0 : Convert.ToInt32(txtYDPZThreshold.Text); res.MapAddr = txtMapUrl.Text; res.MapType = txtMapType.SelectedIndex; res.LayerName = txtLayer.Text; } await db.SaveChangesAsync(); DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!"); Messenger.Defalut.Pub("系统配置改变",await db.SysSetings.FirstOrDefaultAsync()); } } catch (Exception ex) { Serilog.Log.Error(ex, "配置信息保存异常"); DxHelper.MsgBoxHelper.ShowError("配置信息保存异常"); } if (needStartHttpSvr) { try { using (RHDWContext db = new RHDWContext()) { var settings = await db.SysSetings.FirstOrDefaultAsync(); Startup.Start(settings.HttpPort, "多模式融合定位平台.Xml", "XdCxRhDW.Dto.xml"); } } catch (System.Reflection.TargetInvocationException ex) { Serilog.Log.Error(ex, $"启动Http服务失败!"); if (ex.InnerException is HttpListenerException) { DxHelper.MsgBoxHelper.ShowWarning($"{ex.InnerException.Message}"); } else { DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!"); } } catch (Exception ex) { Serilog.Log.Error(ex, $"启动Http服务失败!"); DxHelper.MsgBoxHelper.ShowWarning($"启动Http服务失败!"); } } } private void txtMapType_SelectedIndexChanged(object sender, EventArgs e) { if (txtMapType.SelectedIndex == 0) { itemUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; itemLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; } else if (txtMapType.SelectedIndex == 1) { itemUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; itemUrl.Text = "WMTS地址"; itemLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } else { itemUrl.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; itemUrl.Text = "WMS地址"; itemLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always; } layoutControl1.BestFit(); } } }