using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using SIMDP.BLL;
using SIMDP.Model;
using ProjectBase.Data.Logs;
using SIMDP.Util;
using ProjectBase.Data.BaseDAL;
namespace SIMDP
{
public partial class FormEditGroup : DevExpress.XtraEditors.XtraForm
{
///
/// 所属PLCID
///
public string plcId { get; set; }
///
/// 要修改的数据组对象
///
public MoDataGroup group { get; set; }
///
/// 定义委托
///
public delegate void save();
///
/// 定义事件,数据保存成功后刷新FormNode中的树
///
public event save saveData;
public FormEditGroup()
{
InitializeComponent();
}
private void FormEditGroup_Load(object sender, EventArgs e)
{
txt_GroupPlcId.Enabled = false;
txt_GroupPlcId.Text = plcId;
BindingSource bs = new BindingSource();
bs.DataSource = SysEnvironment.dirDataGroupType;
this.lookUp_GroupType.Properties.DataSource = bs;
this.lookUp_GroupType.Properties.ValueMember = "Key";
this.lookUp_GroupType.Properties.DisplayMember = "Value";
this.lookUp_GroupType.Properties.NullText = "请您选择";
this.btn_Save.Enabled = false;
if (group != null) //修改功能
{
txt_GroupPlcId.Text = group.DataGroupPlcId.ToString();
txt_GroupName.Text = group.DataGroupName;
this.lookUp_GroupType.EditValue = Convert.ToInt32(group.DataGroupType) ; //设置默认值
this.btn_Save.Enabled = true;
this.btn_Add.Enabled = false;
}
}
private void btn_Cancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void btn_Add_Click(object sender, EventArgs e)
{
try
{
if ( string.IsNullOrEmpty(txt_GroupName.Text) || string.IsNullOrEmpty(txt_GroupPlcId.Text) || lookUp_GroupType.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请将数据组信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
MoDataGroup dataGroup = new MoDataGroup();
dataGroup.DataGroupName = txt_GroupName.Text;
dataGroup.DataGroupType = Convert.ToInt64(lookUp_GroupType.EditValue);
dataGroup.DataGroupPlcId = Convert.ToInt64(txt_GroupPlcId.Text);
//BlDataGroup blDataGroup = new BlDataGroup();
bool flag = BLLFactory.Instance.Insert(dataGroup);
if (flag)
{
DevExpress.XtraEditors.XtraMessageBox.Show("添加成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
saveData();
this.Close();
}
}
catch (Exception ex)
{
DevExpress.XtraEditors.XtraMessageBox.Show("添加失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.log.Error(string.Format("插入数据库data_group出现错误:{0}", ex));
}
}
private void btn_Save_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(txt_GroupName.Text) || string.IsNullOrEmpty(txt_GroupPlcId.Text) || lookUp_GroupType.Text == "请您选择")
{
DevExpress.XtraEditors.XtraMessageBox.Show("请将数据组信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
group.DataGroupName = txt_GroupName.Text;
group.DataGroupType = Convert.ToInt64(lookUp_GroupType.EditValue);
//BlDataGroup blDataGroup = new BlDataGroup();
bool flag = BLLFactory.Instance.Update(group,group.DataGroupId);
if (flag)
{
DevExpress.XtraEditors.XtraMessageBox.Show("修改成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
saveData();
this.Close();
}
}
catch (Exception ex)
{
DevExpress.XtraEditors.XtraMessageBox.Show("修改失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
LogHelper.log.Error(string.Format("修改数据库data_group出现错误:{0}", ex));
}
}
}
}