RecEditor.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 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 TxInfo info;
  22. private List<TxInfo> infos;
  23. public RecEditor()
  24. {
  25. InitializeComponent();
  26. this.layoutControl1.UseDefault();
  27. this.Text = "添加接收站";
  28. info = new TxInfo();
  29. this.StartPosition = FormStartPosition.CenterParent;
  30. }
  31. public RecEditor(RecTxViewModel info)
  32. : this()
  33. {
  34. this.Text = "编辑接收站";
  35. this.info = info.To<TxInfo>();
  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<TxInfo>();
  47. var unitOfWork = IocContainer.UnitOfWork;
  48. var repsRec = unitOfWork.Of<TxInfo>();
  49. var res = await repsRec.FindAsync(f => f.TxType == EnumTxType.Rec, p => p.Name);
  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 == 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. info.TxType = EnumTxType.Rec;
  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. }