CtrlSysSettings.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using DevExpress.XtraEditors;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.Entity;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Net.Sockets;
  10. using System.Net;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Documents;
  14. using System.Windows.Forms;
  15. using XdCxRhDW.Repostory.EFContext;
  16. using System.IO;
  17. using System.Data.Entity.Migrations;
  18. using XdCxRhDW.Repostory.Model;
  19. using ExtensionsDev;
  20. namespace XdCxRhDW.App.UserControl
  21. {
  22. public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl
  23. {
  24. public CtrlSysSettings()
  25. {
  26. InitializeComponent();
  27. this.layoutControl1.UseDefault();
  28. }
  29. private async void CtrlSysSettings_Load(object sender, EventArgs e)
  30. {
  31. try
  32. {
  33. using (RHDWContext db = new RHDWContext())
  34. {
  35. var res = await db.SysSetings.FirstOrDefaultAsync();
  36. if (res != null)
  37. {
  38. this.txtHttpPort.Text = res.HttpPort.ToString();
  39. if (!string.IsNullOrEmpty(res.XLDirectory))
  40. this.txtXLDirectory.Text = res.XLDirectory.ToString();
  41. if (!string.IsNullOrEmpty(res.MapService))
  42. this.txtMapService.Text = res.MapService.ToString();
  43. if (res.YDPZThreshold > 0)
  44. this.txtYDPZThreshold.Text = res.YDPZThreshold.ToString();
  45. }
  46. }
  47. }
  48. catch (Exception ex)
  49. {
  50. Serilog.Log.Error(ex, "加载配置信息异常");
  51. DxHelper.MsgBoxHelper.ShowError("加载配置信息异常");
  52. }
  53. }
  54. private async void btnSave_Click(object sender, EventArgs e)
  55. {
  56. try
  57. {
  58. using (RHDWContext db = new RHDWContext())
  59. {
  60. var res = await db.SysSetings.FirstOrDefaultAsync();
  61. if (res == null)
  62. {
  63. res = new SysSetings()
  64. {
  65. HttpPort = Convert.ToInt32(txtHttpPort.Text),
  66. XLDirectory = txtXLDirectory.Text,
  67. MapService = txtMapService.Text,
  68. };
  69. db.SysSetings.Add(res);
  70. }
  71. else
  72. {
  73. res.HttpPort = Convert.ToInt32(txtHttpPort.Text);
  74. res.XLDirectory = txtXLDirectory.Text;
  75. res.MapService = txtMapService.Text;
  76. }
  77. await db.SaveChangesAsync();
  78. DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!");
  79. }
  80. }
  81. catch (Exception ex)
  82. {
  83. Serilog.Log.Error(ex, "配置信息保存异常");
  84. DxHelper.MsgBoxHelper.ShowError("配置信息保存异常");
  85. }
  86. }
  87. }
  88. }