FormEditGroup.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 FormEditGroup : DevExpress.XtraEditors.XtraForm
  19. {
  20. /// <summary>
  21. /// 所属PLCID
  22. /// </summary>
  23. public string plcId { get; set; }
  24. /// <summary>
  25. /// 要修改的数据组对象
  26. /// </summary>
  27. public MoDataGroup group { get; set; }
  28. /// <summary>
  29. /// 定义委托
  30. /// </summary>
  31. public delegate void save();
  32. /// <summary>
  33. /// 定义事件,数据保存成功后刷新FormNode中的树
  34. /// </summary>
  35. public event save saveData;
  36. public FormEditGroup()
  37. {
  38. InitializeComponent();
  39. }
  40. private void FormEditGroup_Load(object sender, EventArgs e)
  41. {
  42. txt_GroupPlcId.Enabled = false;
  43. txt_GroupPlcId.Text = plcId;
  44. BindingSource bs = new BindingSource();
  45. bs.DataSource = SysEnvironment.dirDataGroupType;
  46. this.lookUp_GroupType.Properties.DataSource = bs;
  47. this.lookUp_GroupType.Properties.ValueMember = "Key";
  48. this.lookUp_GroupType.Properties.DisplayMember = "Value";
  49. this.lookUp_GroupType.Properties.NullText = "请您选择";
  50. this.btn_Save.Enabled = false;
  51. if (group != null) //修改功能
  52. {
  53. txt_GroupPlcId.Text = group.DataGroupPlcId.ToString();
  54. txt_GroupName.Text = group.DataGroupName;
  55. this.lookUp_GroupType.EditValue = Convert.ToInt32(group.DataGroupType) ; //设置默认值
  56. this.btn_Save.Enabled = true;
  57. this.btn_Add.Enabled = false;
  58. }
  59. }
  60. private void btn_Cancel_Click(object sender, EventArgs e)
  61. {
  62. this.Close();
  63. }
  64. private void btn_Add_Click(object sender, EventArgs e)
  65. {
  66. try
  67. {
  68. if ( string.IsNullOrEmpty(txt_GroupName.Text) || string.IsNullOrEmpty(txt_GroupPlcId.Text) || lookUp_GroupType.Text == "请您选择")
  69. {
  70. DevExpress.XtraEditors.XtraMessageBox.Show("请将数据组信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  71. return;
  72. }
  73. MoDataGroup dataGroup = new MoDataGroup();
  74. dataGroup.DataGroupName = txt_GroupName.Text;
  75. dataGroup.DataGroupType = Convert.ToInt64(lookUp_GroupType.EditValue);
  76. dataGroup.DataGroupPlcId = Convert.ToInt64(txt_GroupPlcId.Text);
  77. //BlDataGroup blDataGroup = new BlDataGroup();
  78. bool flag = BLLFactory<BlDataGroup>.Instance.Insert(dataGroup);
  79. if (flag)
  80. {
  81. DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  82. saveData();
  83. this.Close();
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  89. LogHelper.log.Error(string.Format("插入数据库data_group出现错误:{0}", ex));
  90. }
  91. }
  92. private void btn_Save_Click(object sender, EventArgs e)
  93. {
  94. try
  95. {
  96. if (string.IsNullOrEmpty(txt_GroupName.Text) || string.IsNullOrEmpty(txt_GroupPlcId.Text) || lookUp_GroupType.Text == "请您选择")
  97. {
  98. DevExpress.XtraEditors.XtraMessageBox.Show("请将数据组信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  99. return;
  100. }
  101. group.DataGroupName = txt_GroupName.Text;
  102. group.DataGroupType = Convert.ToInt64(lookUp_GroupType.EditValue);
  103. //BlDataGroup blDataGroup = new BlDataGroup();
  104. bool flag = BLLFactory<BlDataGroup>.Instance.Update(group,group.DataGroupId);
  105. if (flag)
  106. {
  107. DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  108. saveData();
  109. this.Close();
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  115. LogHelper.log.Error(string.Format("修改数据库data_group出现错误:{0}", ex));
  116. }
  117. }
  118. }
  119. }