SigDelayEditor.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using DevExpress.Data.Browsing;
  2. using DevExpress.Utils.Gesture;
  3. using DevExpress.XtraEditors;
  4. using DevExpress.XtraTreeList;
  5. using ExtensionsDev;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Data;
  10. using System.Data.Entity;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Runtime.Remoting.Metadata.W3cXsd2001;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Documents;
  17. using System.Windows.Forms;
  18. using XdCxRhDW.Entity;
  19. using XdCxRhDW.Repostory;
  20. namespace XdCxRhDW.App.EditForms
  21. {
  22. public partial class SigDelayEditor : DevExpress.XtraEditors.XtraForm
  23. {
  24. public SigDelay info;
  25. public int sigId;
  26. public SigDelayEditor(int sigId)
  27. {
  28. InitializeComponent();
  29. this.layoutControl1.UseDefault();
  30. this.Text = "添加转发延迟";
  31. info = new SigDelay();
  32. this.StartPosition = FormStartPosition.CenterParent;
  33. this.sigId = sigId;
  34. }
  35. public SigDelayEditor(SigDelay info, int sigId)
  36. : this(sigId)
  37. {
  38. this.Text = "编辑转发延迟";
  39. this.info = info;
  40. this.sigId = sigId;
  41. }
  42. private async void SatEditor_Load(object sender, EventArgs e)
  43. {
  44. using (RHDWContext db = new RHDWContext())
  45. {
  46. var sats = await db.SatInfos.ToListAsync();
  47. this.txtSat.UseDefault().SetData(sats, nameof(SatInfo.Sat)).UseDoubleClickToSelectAll();
  48. if (this.Text == "编辑转发延迟" && info != null)
  49. {
  50. this.txtSat.EditValue = sats.FirstOrDefault(f=>f.SatCode== info.SatInfoSatCode);
  51. this.txtDelay.EditValue = info.Delay;
  52. }
  53. }
  54. }
  55. private void btnCancel_Click(object sender, EventArgs e)
  56. {
  57. this.DialogResult = DialogResult.Cancel;
  58. }
  59. private async void btnOk_Click(object sender, EventArgs e)
  60. {
  61. try
  62. {
  63. dxErrorProvider.ClearErrors();
  64. if (txtSat.EditValue == null)
  65. {
  66. dxErrorProvider.SetError(txtSat, "请选择卫星");
  67. return;
  68. }
  69. if (txtDelay.EditValue == null)
  70. {
  71. dxErrorProvider.SetError(txtDelay, "请输入转发延迟");
  72. return;
  73. }
  74. var satInfo = (SatInfo)txtSat.EditValue;
  75. using (RHDWContext db = new RHDWContext())
  76. {
  77. var list = await db.SigDelays.Where(w => w.SigInfoId == sigId).ToListAsync();
  78. if (list.Where(w => w.ID != info.ID).Any(a => a.SatInfoSatCode == satInfo.SatCode))
  79. {
  80. DxHelper.MsgBoxHelper.ShowInfo("已添加该卫星");
  81. return;
  82. }
  83. }
  84. info.SigInfoId = sigId;
  85. info.SatInfoSatCode = satInfo.SatCode;
  86. info.Sat = $"[{satInfo.SatLon}°]{satInfo.SatName}({satInfo.SatCode})";
  87. info.Delay = Convert.ToDouble(txtDelay.EditValue);
  88. this.DialogResult = DialogResult.OK;
  89. }
  90. catch (Exception ex)
  91. {
  92. XdCxRhDW.Framework.LogHelper.Error("编辑转发延迟出错", ex);
  93. DxHelper.MsgBoxHelper.ShowError("编辑转发延迟出错");
  94. }
  95. }
  96. }
  97. }