123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- 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;
- namespace XdCxRhDW.App.UserControl
- {
- public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl
- {
- public CtrlSysSettings()
- {
- InitializeComponent();
- }
- private async void CtrlSysSettings_Load(object sender, EventArgs e)
- {
- try
- {
- txtIp.Properties.Items.Add("127.0.0.1");
- string name = Dns.GetHostName();
- IPAddress[] ipadrlist = Dns.GetHostAddresses(name);
- foreach (IPAddress ipa in ipadrlist)
- {
- if (ipa.AddressFamily == AddressFamily.InterNetwork)
- txtIp.Properties.Items.Add(ipa.ToString());
- }
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, "获取本机IPv4地址出错");
- }
- try
- {
- txtIp.SelectedIndex = 0;
- using (RHDWContext db = new RHDWContext())
- {
- var res = await db.SysSetings.FirstOrDefaultAsync();
- if (res != null)
- {
- this.txtIp.Text = res.ServerIp;
- this.txtPort.Text = res.Port.ToString();
- 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()
- {
- ServerIp = txtIp.Text,
- Port = Convert.ToInt32(txtPort.Text),
- HttpPort = Convert.ToInt32(txtHttpPort.Text),
- XLDirectory = txtXLDirectory.Text,
- MapService=txtMapService.Text,
- };
- db.SysSetings.Add(res);
- }
- else
- {
- res.ServerIp = txtIp.Text;
- res.Port = Convert.ToInt32(txtPort.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("配置信息保存异常");
- }
- }
- }
- }
|