RefEditor.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using DevExpress.Utils.About;
  2. using DW5S.Entity;
  3. using DW5S.Repostory;
  4. using DW5S.Service;
  5. using ExtensionsDev;
  6. using Serilog;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows.Forms;
  16. namespace DW5S.App.EditForms
  17. {
  18. public partial class RefEditor : DevExpress.XtraEditors.XtraForm
  19. {
  20. public TxInfo info;
  21. private List<TxInfo> infos;
  22. public RefEditor()
  23. {
  24. InitializeComponent();
  25. this.layoutControl1.UseDefault();
  26. this.Text = "添加参考站";
  27. info = new TxInfo();
  28. this.StartPosition = FormStartPosition.CenterParent;
  29. }
  30. public RefEditor(TxInfo info)
  31. : this()
  32. {
  33. this.Text = "编辑参考站";
  34. this.info = info;
  35. }
  36. private async void RefEditor_Load(object sender, EventArgs e)
  37. {
  38. if (this.Text == "编辑参考站" && info != null)
  39. {
  40. this.txtRefTxName.Text = info.Name;
  41. this.txtLon.Text = info.Lon.ToString();
  42. this.txtLat.Text = info.Lat.ToString();
  43. this.txtRemark.EditValue = info.Remark;
  44. }
  45. infos = new List<TxInfo>();
  46. var unitOfWork = IocContainer.UnitOfWork;
  47. var repsRef = unitOfWork.Of<TxInfo>();
  48. var res = await repsRef.GetAllAsync();
  49. infos.AddRange(res);
  50. }
  51. private void btnOk_Click(object sender, EventArgs e)
  52. {
  53. try
  54. {
  55. if (infos.Any(i => i.Id != info.Id && i.Name == txtRefTxName.Text))
  56. {
  57. DxHelper.MsgBoxHelper.ShowError($"参考站[{txtRefTxName.Text}]已经存在!");
  58. return;
  59. }
  60. info.Name= txtRefTxName.Text;
  61. info.Lon=Convert.ToDouble(txtLon.Text);
  62. info.Lat = Convert.ToDouble(txtLat.Text);
  63. info.Remark = txtRemark.Text;
  64. info.TxType = EnumTxType.Ref;
  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. }