RefEditor.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 RefTxViewModel info;
  21. private List<RefTxViewModel> infos;
  22. public RefEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加参考站";
  27. info = new RefTxViewModel();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public RefEditor(RefTxViewModel 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.txtRemark.EditValue = info.Remark;
  44. }
  45. infos = new List<RefTxViewModel>();
  46. var unitOfWork = IocContainer.UnitOfWork;
  47. var repsRef = unitOfWork.Of<TxInfo>();
  48. var res = await repsRef.FindAsync(f=>f.TxType== EnumTxType.Ref);
  49. infos.AddRange(res.To<List<RefTxViewModel>>());
  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 == txtRefTxName.Text))
  56. {
  57. DxHelper.MsgBoxHelper.ShowError($"参考站[{txtRefTxName.Text}]已经存在!");
  58. return;
  59. }
  60. info.Name= txtRefTxName.Text;
  61. info.Lon=Convert.ToDouble(txtLon.Text);
  62. info.Lat = Convert.ToDouble(txtLat.Text);
  63. info.Remark = txtRemark.Text;
  64. this.DialogResult = DialogResult.OK;
  65. }
  66. catch (Exception ex)
  67. {
  68. string msg = "编辑参考站信息出错";
  69. IocContainer.Logger.Error(ex, msg);
  70. DxHelper.MsgBoxHelper.ShowError(msg);
  71. }
  72. }
  73. private void btnCancle_Click(object sender, EventArgs e)
  74. {
  75. this.DialogResult = DialogResult.Cancel;
  76. }
  77. }
  78. }