CtrlSysSettings.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. using DevExpress.XtraEditors;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Net.Sockets;
  9. using System.Net;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Documents;
  13. using System.Windows.Forms;
  14. using DW5S.Repostory;
  15. using System.IO;
  16. using System.Data.Entity.Migrations;
  17. using ExtensionsDev;
  18. using DevExpress.Utils;
  19. using DevExpress.XtraMap;
  20. using DW5S.WebApi;
  21. using DevExpress.XtraPrinting;
  22. using DW5S.Entity;
  23. using DevExpress.XtraEditors.Controls;
  24. using System.Security.Policy;
  25. using DevExpress.Utils.About;
  26. using DW5S.DTO;
  27. using System.Configuration;
  28. namespace DW5S.App.UserControl
  29. {
  30. public partial class CtrlSysSettings : DevExpress.XtraEditors.XtraUserControl
  31. {
  32. public CtrlSysSettings()
  33. {
  34. InitializeComponent();
  35. this.layoutControl1.UseDefault();
  36. }
  37. private void CtrlSysSettings_Load(object sender, EventArgs e)
  38. {
  39. try
  40. {
  41. txtWmtsSource.Properties.Items.AddEnum<EnumWmtsSource>();
  42. txtLayer.Items.AddEnum<EnumMapLayerType>();
  43. txtLayer.Items.RemoveAt(0);
  44. txtWmtsSource.SelectedIndex = 0;
  45. txtLayer.SelectedIndex = 0;
  46. if (SysConfig.Config != null)
  47. {
  48. this.txtHttpPort.Text = SysConfig.Config.HttpPort.ToString();
  49. this.txtTimeZone.TimeZoneId = SysConfig.Config.TimeZoneID;
  50. if (!string.IsNullOrEmpty(SysConfig.Config.XLDirectory))
  51. this.txtXLDirectory.Text = SysConfig.Config.XLDirectory.ToString();
  52. if (SysConfig.Config.YDPZThreshold > 0)
  53. this.txtYDPZThreshold.Text = SysConfig.Config.YDPZThreshold.ToString();
  54. if (this.txtMapType.SelectedIndex == SysConfig.Config.MapType)
  55. txtMapType_SelectedIndexChanged(null, null);
  56. else
  57. this.txtMapType.SelectedIndex = SysConfig.Config.MapType;
  58. if (txtMapType.SelectedIndex != 0)
  59. {
  60. this.txtWmtsSource.EditValue = SysConfig.Config.WmtsSource;
  61. for (int i = 0; i < txtLayer.Items.Count; i++)
  62. {
  63. if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.SatMap))
  64. {
  65. this.txtLayer.Items[EnumMapLayerType.SatMap].CheckState = CheckState.Checked;
  66. }
  67. if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.RoadMap))
  68. {
  69. this.txtLayer.Items[EnumMapLayerType.RoadMap].CheckState = CheckState.Checked;
  70. }
  71. if (SysConfig.Config.MapLayerType.HasFlag(EnumMapLayerType.XZQH_Map))
  72. {
  73. this.txtLayer.Items[EnumMapLayerType.XZQH_Map].CheckState = CheckState.Checked;
  74. }
  75. }
  76. }
  77. }
  78. }
  79. catch (Exception ex)
  80. {
  81. DW5S.Framework.LogHelper.Error("加载配置信息异常", ex);
  82. DxHelper.MsgBoxHelper.ShowError("加载配置信息异常");
  83. }
  84. layoutControl1.BestFit();
  85. }
  86. private async void btnSave_Click(object sender, EventArgs e)
  87. {
  88. try
  89. {
  90. if (!int.TryParse(txtHttpPort.Text, out int port))
  91. {
  92. DxHelper.MsgBoxHelper.ShowError("Http端口错误!");
  93. return;
  94. }
  95. if (string.IsNullOrWhiteSpace(txtTimeZone.TimeZoneId))
  96. {
  97. DxHelper.MsgBoxHelper.ShowError("系统时区错误!");
  98. return;
  99. }
  100. using (RHDWContext db = new RHDWContext())
  101. {
  102. var res = await db.SysSetings.FirstOrDefaultAsync();
  103. if (res == null) res = new SysSetings();
  104. bool needStartHttpSvr = res.HttpPort != port;
  105. if (!needStartHttpSvr)
  106. {
  107. needStartHttpSvr = res.TimeZoneID != txtTimeZone.TimeZoneId;
  108. }
  109. res.TimeZoneID = txtTimeZone.TimeZoneId;
  110. TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(txtTimeZone.TimeZoneId);
  111. if (tz.DisplayName == "UTC")
  112. {
  113. res.TimeZoneUTC = tz.DisplayName;
  114. res.TimeZoneName = "";
  115. }
  116. else
  117. {
  118. res.TimeZoneUTC = tz.DisplayName.Substring(1, tz.DisplayName.IndexOf(")") - 1).Trim();
  119. res.TimeZoneName = tz.DisplayName.Substring(tz.DisplayName.IndexOf(")") + 1).Trim();
  120. }
  121. res.ZoneHours = tz.BaseUtcOffset.TotalHours;
  122. res.HttpPort = port;
  123. res.XLDirectory = txtXLDirectory.Text;
  124. res.YDPZThreshold = string.IsNullOrWhiteSpace(txtYDPZThreshold.Text) ? 0 : Convert.ToInt32(txtYDPZThreshold.Text);
  125. bool mapChanged = res.MapType != txtMapType.SelectedIndex;
  126. res.MapType = txtMapType.SelectedIndex;
  127. if (txtMapType.SelectedIndex != 0)
  128. {
  129. var wmtsSource= (EnumWmtsSource)txtWmtsSource.EditValue;
  130. if (!mapChanged)
  131. {
  132. mapChanged = res.WmtsSource != wmtsSource;
  133. }
  134. res.WmtsSource = wmtsSource;
  135. EnumMapLayerType layerType = EnumMapLayerType.None;
  136. for (int i = 0; i < txtLayer.Items.Count; i++)
  137. {
  138. if (txtLayer.GetItemChecked(i))
  139. {
  140. layerType |= (EnumMapLayerType)txtLayer.Items[i].Value;
  141. }
  142. }
  143. layerType = layerType & ~EnumMapLayerType.None;//移除
  144. if (!mapChanged)
  145. mapChanged = res.MapLayerType != layerType;
  146. res.MapLayerType = layerType;
  147. }
  148. db.SysSetings.AddOrUpdate(res);
  149. await db.SaveChangesAsync();
  150. SysConfig.Config = res;
  151. if (mapChanged)
  152. Messenger.Defalut.Pub("地图类型改变", res);
  153. Messenger.Defalut.Pub("时区改变", res);
  154. DxHelper.MsgBoxHelper.ShowInfo("配置信息保存成功!");
  155. if (needStartHttpSvr)
  156. {
  157. //var files=Directory.GetFiles("Service", "*.exe.config");
  158. //foreach (var f in files)
  159. //{
  160. // File.ReadAllText(f);
  161. //}
  162. Application.Restart();
  163. }
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. DW5S.Framework.LogHelper.Error("配置信息保存异常", ex);
  169. DxHelper.MsgBoxHelper.ShowError("配置信息保存异常");
  170. }
  171. if (this.Parent is Form frm)
  172. frm.Close();
  173. }
  174. private void txtMapType_SelectedIndexChanged(object sender, EventArgs e)
  175. {
  176. if (txtMapType.SelectedIndex == 0)
  177. {
  178. itemWmtsSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  179. itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
  180. }
  181. else
  182. {
  183. itemWmtsSource.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  184. itemMapLayer.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
  185. }
  186. layoutControl1.BestFit();
  187. }
  188. private void toolTipController1_GetActiveObjectInfo(object sender, ToolTipControllerGetActiveObjectInfoEventArgs e)
  189. {
  190. RadioGroup rg = e.SelectedControl as RadioGroup;
  191. if (rg == null) return;
  192. for (int i = 0; i < rg.Properties.Items.Count; i++)
  193. {
  194. Rectangle rect = rg.GetItemRectangle(i);
  195. if (rect.Contains(e.ControlMousePosition))
  196. {
  197. var val = (EnumWmtsSource)rg.Properties.Items[i].Value;
  198. if (val == EnumWmtsSource.ZCJ)
  199. {
  200. var str =AppConfigHelper.Get("ZCJ_URL","");
  201. e.Info = new ToolTipControlInfo(i, $"{rg.Properties.Items[i].Description}:{str}");
  202. }
  203. else
  204. {
  205. var str = AppConfigHelper.Get("SJZX_URL","");
  206. e.Info = new ToolTipControlInfo(i, $"{rg.Properties.Items[i].Description}:{str}");
  207. }
  208. break;
  209. }
  210. }
  211. }
  212. }
  213. }