CtrlSysSettings.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. }
  44. }
  45. }
  46. catch (Exception ex)
  47. {
  48. Serilog.Log.Error(ex, "加载配置信息异常");
  49. DxHelper.MsgBoxHelper.ShowError("加载配置信息异常");
  50. }
  51. }
  52. private async void btnSave_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. using (RHDWContext db = new RHDWContext())
  57. {
  58. var res = await db.SysSetings.FirstOrDefaultAsync();
  59. if (res == null)
  60. {
  61. res = new SysSetings()
  62. {
  63. HttpPort = Convert.ToInt32(txtHttpPort.Text),
  64. XLDirectory = txtXLDirectory.Text,
  65. MapService=txtMapService.Text,
  66. };
  67. db.SysSetings.Add(res);
  68. }
  69. else
  70. {
  71. res.HttpPort = Convert.ToInt32(txtHttpPort.Text);
  72. res.XLDirectory = txtXLDirectory.Text;
  73. res.MapService = txtMapService.Text;
  74. }
  75. await db.SaveChangesAsync();
  76. DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!");
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. Serilog.Log.Error(ex, "配置信息保存异常");
  82. DxHelper.MsgBoxHelper.ShowError("配置信息保存异常");
  83. }
  84. }
  85. }
  86. }