RecEditor.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. this.checkEdit.EditValue = info.Enable;
  46. }
  47. infos = new List<RecTxViewModel>();
  48. var unitOfWork = IocContainer.UnitOfWork;
  49. var repsRec = unitOfWork.Of<TxInfo>();
  50. var res = await repsRec.FindAsync(f => f.TxType == EnumTxType.Rec);
  51. infos.AddRange(res.To<List<RecTxViewModel>>());
  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 == txtRecTxName.Text))
  58. {
  59. DxHelper.MsgBoxHelper.ShowError($"接收站[{txtRecTxName.Text}]已经存在!");
  60. return;
  61. }
  62. info.Name = txtRecTxName.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. }