MainForm.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using DevExpress.XtraBars;
  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.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. using DevExpress.XtraBars.Docking2010.Views;
  12. using XdCxRhDW.App.UserControl;
  13. using DevExpress.XtraBars.Ribbon;
  14. using System.Threading;
  15. using XdCxRhDw.CpuCgTools;
  16. using DevExpress.XtraEditors;
  17. using ExtensionsDev;
  18. using DevExpress.XtraBars.Forms;
  19. using XdCxRhDW.App.CorTools;
  20. using XdCxRhDW.App.EFContext;
  21. using System.Data.Entity;
  22. namespace XdCxRhDW
  23. {
  24. public partial class MainForm : DevExpress.XtraBars.Ribbon.RibbonForm
  25. {
  26. Dictionary<string, Type> ctrlTypes = new Dictionary<string, Type>();
  27. public MainForm()
  28. {
  29. InitializeComponent();
  30. ribbon.UseDefault();
  31. tabbedView1.UseDefault();
  32. ctrlTypes.Add("任务管理", typeof(CtrlHome));
  33. ctrlTypes.Add("参估结果", typeof(CtrlCgRes));
  34. ctrlTypes.Add("测向结果", typeof(CtrlCxRes));
  35. ctrlTypes.Add("定位结果", typeof(CtrlPosRes));
  36. ctrlTypes.Add("星历管理", typeof(CtrlXl));
  37. ctrlTypes.Add("天线管理", typeof(CtrlTx));
  38. ctrlTypes.Add("卫星管理", typeof(CtrlSat));
  39. ctrlTypes.Add("系统设置", typeof(CtrlSysSettings));
  40. ctrlTypes.Add("参估工具", typeof(CorToolForm));
  41. btn_ItemClick(null, null);
  42. }
  43. private void btn_ItemClick(object sender, ItemClickEventArgs e)
  44. {
  45. var btnTxt = e?.Item?.Caption ?? "任务管理";
  46. BaseDocument doc = null;
  47. doc = tabbedView1.Documents.Find(p => p.Control.GetType() == ctrlTypes[btnTxt]).FirstOrDefault();
  48. if (doc == null)
  49. {
  50. doc = tabbedView1.AddDocument((Control)Activator.CreateInstance(ctrlTypes[btnTxt]), btnTxt);
  51. if (doc.Control is Form form)
  52. {
  53. form.Text = "";
  54. doc.Caption = btnTxt;
  55. }
  56. if (btnTxt == "任务管理")
  57. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.False;
  58. else
  59. doc.Properties.AllowClose = DevExpress.Utils.DefaultBoolean.True;
  60. }
  61. tabbedView1.ActivateDocument(doc.Control);
  62. }
  63. protected override void OnFormClosing(FormClosingEventArgs e)
  64. {
  65. if (e.CloseReason == CloseReason.UserClosing)
  66. {
  67. if (!DxHelper.MsgBoxHelper.ShowConfirm("确定要退出当前系统吗?"))
  68. {
  69. e.Cancel = true;
  70. return;
  71. }
  72. }
  73. Application.Exit();
  74. }
  75. private async void btnOpenApi_ItemClick(object sender, ItemClickEventArgs e)
  76. {
  77. using (RHDWContext db = new RHDWContext())
  78. {
  79. var settings = await db.SysSetings.FirstOrDefaultAsync();
  80. if (settings == null)
  81. {
  82. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  83. return;
  84. }
  85. if (string.IsNullOrEmpty(settings.ServerIp))
  86. {
  87. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  88. return;
  89. }
  90. if (settings.HttpPort<1)
  91. {
  92. DxHelper.MsgBoxHelper.ShowWarning($"请在系统设置中配置IP地址和Http端口");
  93. return;
  94. }
  95. string addr = $"http://{settings.ServerIp}:{settings.HttpPort}/swagger";
  96. try
  97. {
  98. System.Diagnostics.Process.Start(addr);
  99. }
  100. catch
  101. {
  102. db.Dispose();
  103. DxHelper.MsgBoxHelper.ShowError($"无法打开默认浏览器,请手动查看接口文档.地址{addr}");
  104. }
  105. }
  106. }
  107. }
  108. }