CdbEditor.cs 2.6 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 CdbEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public TxInfo info;
  21. private List<TxInfo> infos;
  22. public CdbEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加超短波";
  27. info = new TxInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public CdbEditor(TxInfo info)
  31. : this()
  32. {
  33. this.Text = "编辑超短波";
  34. this.info = info;
  35. }
  36. private async void CdbEditor_Load(object sender, EventArgs e)
  37. {
  38. if (this.Text == "编辑超短波" && info != null)
  39. {
  40. this.txtCdbTxName.Text = info.Name;
  41. this.txtLon.Text = info.Lon.ToString();
  42. this.txtLat.Text = info.Lat.ToString();
  43. this.txtRemark.EditValue = info.Remark;
  44. }
  45. infos = new List<TxInfo>();
  46. var unitOfWork = IocContainer.UnitOfWork;
  47. var repsCdb = unitOfWork.Of<TxInfo>();
  48. var res = await repsCdb.GetAllAsync(p => p.Name);
  49. infos.AddRange(res);
  50. }
  51. private void btnOk_Click(object sender, EventArgs e)
  52. {
  53. try
  54. {
  55. if (infos.Any(i => i.Id != info.Id && i.Name == txtCdbTxName.Text))
  56. {
  57. DxHelper.MsgBoxHelper.ShowError($"超短波[{txtCdbTxName.Text}]已经存在!");
  58. return;
  59. }
  60. info.Name= txtCdbTxName.Text;
  61. info.Lon=Convert.ToDouble(txtLon.Text);
  62. info.Lat = Convert.ToDouble(txtLat.Text);
  63. info.Remark = txtRemark.Text;
  64. info.TxType = EnumTxType.Cdb;
  65. this.DialogResult = DialogResult.OK;
  66. }
  67. catch (Exception ex)
  68. {
  69. string msg = "编辑超短波信息出错";
  70. IocContainer.Logger.Error(ex, msg);
  71. DxHelper.MsgBoxHelper.ShowError(msg);
  72. }
  73. }
  74. private void btnCancle_Click(object sender, EventArgs e)
  75. {
  76. this.DialogResult = DialogResult.Cancel;
  77. }
  78. }
  79. }