RecEditor.cs 2.8 KB

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