RecEditor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using DevExpress.Utils.About;
  2. using DW5S.Entity;
  3. using DW5S.Repostory;
  4. using DW5S.Service;
  5. using ExtensionsDev;
  6. using Newtonsoft.Json;
  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 RecEditor : DevExpress.XtraEditors.XtraForm
  20. {
  21. public RecTxViewModel info;
  22. private List<RecTxViewModel> infos;
  23. public RecEditor()
  24. {
  25. InitializeComponent();
  26. this.layoutControl1.UseDefault();
  27. this.Text = "添加接收站";
  28. info = new RecTxViewModel();
  29. this.StartPosition = FormStartPosition.CenterParent;
  30. }
  31. public RecEditor(RecTxViewModel info)
  32. : this()
  33. {
  34. this.Text = "编辑接收站";
  35. this.info = info.To<RecTxViewModel>();
  36. }
  37. private async void RecEditor_Load(object sender, EventArgs e)
  38. {
  39. if (this.Text == "编辑接收站" && info != null)
  40. {
  41. this.txtRecTxName.Text = info.Name;
  42. this.txtLon.Text = info.Lon.ToString();
  43. this.txtLat.Text = info.Lat.ToString();
  44. this.txtRemark.EditValue = info.Remark;
  45. }
  46. infos = new List<RecTxViewModel>();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsRec = unitOfWork.Of<TxInfo>();
  49. var res = await repsRec.FindAsync(f => f.TxType == EnumTxType.Rec);
  50. infos.AddRange(res.To<List<RecTxViewModel>>());
  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 == txtRecTxName.Text))
  57. {
  58. DxHelper.MsgBoxHelper.ShowError($"接收站[{txtRecTxName.Text}]已经存在!");
  59. return;
  60. }
  61. info.Name = txtRecTxName.Text;
  62. info.Lon = Convert.ToDouble(txtLon.Text);
  63. info.Lat = Convert.ToDouble(txtLat.Text);
  64. info.Remark = txtRemark.Text;
  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. }