CtrlSysSettings.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. namespace XdCxRhDW.App.UserControl
  20. {
  21. public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl
  22. {
  23. public CtrlSysSettings()
  24. {
  25. InitializeComponent();
  26. }
  27. private async void CtrlSysSettings_Load(object sender, EventArgs e)
  28. {
  29. try
  30. {
  31. using (RHDWContext db = new RHDWContext())
  32. {
  33. var res = await db.SysSetings.FirstOrDefaultAsync();
  34. if (res != null)
  35. {
  36. this.txtHttpPort.Text = res.HttpPort.ToString();
  37. if (!string.IsNullOrEmpty(res.XLDirectory))
  38. this.txtXLDirectory.Text = res.XLDirectory.ToString();
  39. if (!string.IsNullOrEmpty(res.MapService))
  40. this.txtMapService.Text = res.MapService.ToString();
  41. }
  42. }
  43. }
  44. catch (Exception ex)
  45. {
  46. Serilog.Log.Error(ex, "加载配置信息异常");
  47. DxHelper.MsgBoxHelper.ShowError("加载配置信息异常");
  48. }
  49. }
  50. private async void btnSave_Click(object sender, EventArgs e)
  51. {
  52. try
  53. {
  54. using (RHDWContext db = new RHDWContext())
  55. {
  56. var res = await db.SysSetings.FirstOrDefaultAsync();
  57. if (res == null)
  58. {
  59. res = new SysSetings()
  60. {
  61. HttpPort = Convert.ToInt32(txtHttpPort.Text),
  62. XLDirectory = txtXLDirectory.Text,
  63. MapService=txtMapService.Text,
  64. };
  65. db.SysSetings.Add(res);
  66. }
  67. else
  68. {
  69. res.HttpPort = Convert.ToInt32(txtHttpPort.Text);
  70. res.XLDirectory = txtXLDirectory.Text;
  71. res.MapService = txtMapService.Text;
  72. }
  73. await db.SaveChangesAsync();
  74. DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!");
  75. }
  76. }
  77. catch (Exception ex)
  78. {
  79. Serilog.Log.Error(ex, "配置信息保存异常");
  80. DxHelper.MsgBoxHelper.ShowError("配置信息保存异常");
  81. }
  82. }
  83. }
  84. }