FormEditPoint.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using SIMDP.BLL;
  12. using SIMDP.Model;
  13. using ProjectBase.Data.Logs;
  14. using SIMDP.Util;
  15. using ProjectBase.Data.BaseDAL;
  16. namespace SIMDP
  17. {
  18. public partial class FormEditPoint : DevExpress.XtraEditors.XtraForm
  19. {
  20. /// <summary>
  21. /// 所属PLCID
  22. /// </summary>
  23. public string plcId { get; set; }
  24. /// <summary>
  25. /// 所属组ID
  26. /// </summary>
  27. public string groupId { get; set; }
  28. /// <summary>
  29. /// 要修改的数据组对象
  30. /// </summary>
  31. public MoDataPoint point { get; set; }
  32. /// <summary>
  33. /// 定义委托
  34. /// </summary>
  35. public delegate void save();
  36. /// <summary>
  37. /// 定义事件,数据保存成功后刷新FormNode中的树
  38. /// </summary>
  39. public event save saveData;
  40. public FormEditPoint()
  41. {
  42. InitializeComponent();
  43. }
  44. private void FormEditPoint_Load(object sender, EventArgs e)
  45. {
  46. txt_PointGroupId.Enabled = false;
  47. txt_PointPlcId.Enabled = false;
  48. txt_PointGroupId.Text = groupId;
  49. txt_PointPlcId.Text = plcId;
  50. BindingSource bs = new BindingSource();
  51. bs.DataSource = SysEnvironment.dirType;
  52. this.lookUp_PointType.Properties.DataSource = bs;
  53. this.lookUp_PointType.Properties.ValueMember = "Key";
  54. this.lookUp_PointType.Properties.DisplayMember = "Value";
  55. this.lookUp_PointType.Properties.NullText = "请您选择";
  56. this.btn_Save.Enabled = false;
  57. if (point != null) //修改功能
  58. {
  59. txt_PointGroupId.Text = point.DataPointGroupId.ToString();
  60. txt_PointPlcId.Text = point.DataPointPlcId.ToString();
  61. txt_PointName.Text = point.DataPointName;
  62. this.lookUp_PointType.EditValue = Convert.ToInt32(point.DataPointType);
  63. txt_PointSource.Text = point.DataPointSource;
  64. this.textEdit_DataProc.Text = point.DataProc;
  65. this.btn_Save.Enabled = true;
  66. this.btn_Add.Enabled = false;
  67. }
  68. }
  69. private void btn_Cancel_Click(object sender, EventArgs e)
  70. {
  71. this.Close();
  72. }
  73. private void btn_Add_Click(object sender, EventArgs e)
  74. {
  75. try
  76. {
  77. if (string.IsNullOrEmpty(txt_PointGroupId.Text) || string.IsNullOrEmpty(txt_PointName.Text) || string.IsNullOrEmpty(txt_PointPlcId.Text)
  78. || string.IsNullOrEmpty(txt_PointSource.Text) || lookUp_PointType.Text == "请您选择")
  79. {
  80. DevExpress.XtraEditors.XtraMessageBox.Show("请将数据点信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  81. return;
  82. }
  83. MoDataPoint dataPoint = new MoDataPoint();
  84. dataPoint.DataPointGroupId = Convert.ToInt64(txt_PointGroupId.Text);
  85. dataPoint.DataPointName = txt_PointName.Text;
  86. dataPoint.DataPointPlcId = Convert.ToInt64(txt_PointPlcId.Text);
  87. dataPoint.DataPointSource = txt_PointSource.Text;
  88. dataPoint.DataPointType = Convert.ToInt64(lookUp_PointType.EditValue);
  89. dataPoint.DataProc = textEdit_DataProc.Text.Trim();
  90. //BlDataPoint blDataPoint = new BlDataPoint();
  91. bool flag = BLLFactory<BlDataPoint>.Instance.Insert(dataPoint);
  92. if (flag)
  93. {
  94. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  95. saveData();
  96. this.Close();
  97. }
  98. }
  99. catch (Exception ex)
  100. {
  101. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  102. LogHelper.log.Error(string.Format("插入数据库data_point出现错误:{0}", ex));
  103. }
  104. }
  105. private void btn_Save_Click(object sender, EventArgs e)
  106. {
  107. try
  108. {
  109. if (string.IsNullOrEmpty(txt_PointGroupId.Text) || string.IsNullOrEmpty(txt_PointName.Text) || string.IsNullOrEmpty(txt_PointPlcId.Text)
  110. || string.IsNullOrEmpty(txt_PointSource.Text) || lookUp_PointType.Text == "请您选择")
  111. {
  112. DevExpress.XtraEditors.XtraMessageBox.Show("请将数据点信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  113. return;
  114. }
  115. point.DataPointName = txt_PointName.Text;
  116. point.DataPointSource = txt_PointSource.Text;
  117. point.DataPointType = Convert.ToInt64(lookUp_PointType.EditValue);
  118. point.DataProc = textEdit_DataProc.Text.Trim();
  119. //BlDataPoint blDataPoint = new BlDataPoint();
  120. bool flag = BLLFactory<BlDataPoint>.Instance.Update(point,point.DataPointId);
  121. if (flag)
  122. {
  123. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  124. saveData();
  125. this.Close();
  126. }
  127. }
  128. catch (Exception ex)
  129. {
  130. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  131. LogHelper.log.Error(string.Format("修改数据库data_point出现错误:{0}", ex));
  132. }
  133. }
  134. }
  135. }