RefEditor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using DevExpress.Utils.About;
  2. using DW5S.Entity;
  3. using DW5S.Repostory;
  4. using DW5S.Service;
  5. using ExtensionsDev;
  6. using Serilog;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace DW5S.App.EditForms
  17. {
  18. public partial class RefEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public RefTxInfo info;
  21. private List<RefTxInfo> infos;
  22. public RefEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加参考站";
  27. info = new RefTxInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public RefEditor(RefTxInfo info)
  31. : this()
  32. {
  33. this.Text = "编辑参考站";
  34. this.info = info;
  35. }
  36. private async void RefEditor_Load(object sender, EventArgs e)
  37. {
  38. if (this.Text == "编辑参考站" && info != null)
  39. {
  40. this.txtRefTxName.Text = info.Name;
  41. this.txtLon.Text = info.Lon.ToString();
  42. this.txtLat.Text = info.Lat.ToString();
  43. this.txtAlt.Text = info.Alt.ToString();
  44. this.txtRemark.EditValue = info.Remark;
  45. }
  46. infos = new List<RefTxInfo>();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsRef = unitOfWork.Of<RefTxInfo>();
  49. var res = await repsRef.GetAllAsync();
  50. infos.AddRange(res);
  51. }
  52. private void btnOk_Click(object sender, EventArgs e)
  53. {
  54. try
  55. {
  56. if (infos.Any(i => i.Id != info.Id && i.Name == txtRefTxName.Text))
  57. {
  58. DxHelper.MsgBoxHelper.ShowError($"参考站[{txtRefTxName.Text}]已经存在!");
  59. return;
  60. }
  61. info.Name= txtRefTxName.Text;
  62. info.Lon=Convert.ToDouble(txtLon.Text);
  63. info.Lat = Convert.ToDouble(txtLat.Text);
  64. info.Alt = Convert.ToDouble(txtAlt.Text);
  65. info.Remark = txtRemark.Text;
  66. this.DialogResult = DialogResult.OK;
  67. }
  68. catch (Exception ex)
  69. {
  70. string msg = "编辑参考站信息出错";
  71. IocContainer.Logger.Error(ex, msg);
  72. DxHelper.MsgBoxHelper.ShowError(msg);
  73. }
  74. }
  75. private void btnCancle_Click(object sender, EventArgs e)
  76. {
  77. this.DialogResult = DialogResult.Cancel;
  78. }
  79. }
  80. }