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.App.EFContext; using System.IO; using System.Data.Entity.Migrations; namespace XdCxRhDW.App.UserControl { public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl { public CtrlSysSettings() { InitializeComponent(); } 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.MapService)) this.txtMapService.Text = res.MapService.ToString(); } } } catch (Exception ex) { Serilog.Log.Error(ex, "加载配置信息异常"); DxHelper.MsgBoxHelper.ShowError("加载配置信息异常"); } } private async void btnSave_Click(object sender, EventArgs e) { try { using (RHDWContext db = new RHDWContext()) { var res = await db.SysSetings.FirstOrDefaultAsync(); if (res == null) { res = new Model.SysSetings() { HttpPort = Convert.ToInt32(txtHttpPort.Text), XLDirectory = txtXLDirectory.Text, MapService=txtMapService.Text, }; db.SysSetings.Add(res); } else { res.HttpPort = Convert.ToInt32(txtHttpPort.Text); res.XLDirectory = txtXLDirectory.Text; res.MapService = txtMapService.Text; } await db.SaveChangesAsync(); DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!"); } } catch (Exception ex) { Serilog.Log.Error(ex, "配置信息保存异常"); DxHelper.MsgBoxHelper.ShowError("配置信息保存异常"); } } } }