CtrlSysSettings.cs 2.9 KB

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