RefEditor.cs 2.8 KB

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