123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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.Model;
- using SIMDP.BLL;
- using ProjectBase.Data.Logs;
- using SIMDP.Util;
- using ProjectBase.Data.BaseDAL;
- namespace SIMDP
- {
- public partial class FormEditPLC : DevExpress.XtraEditors.XtraForm
- {
- /// <summary>
- /// 定义PLC对象
- /// </summary>
- public MoPlcInfo plc;
- /// <summary>
- /// 定义委托
- /// </summary>
- public delegate void save();
- /// <summary>
- /// 定义事件,保存数据成功后刷新FormPLC中的数据
- /// </summary>
- public event save saveData;
- public FormEditPLC(MoPlcInfo plcInfo)
- {
- InitializeComponent();
- BindingSource bs = new BindingSource();
- bs.DataSource = SysEnvironment.dirPlcLinkType;
- this.lookUp_Type.Properties.DataSource = bs;
- this.lookUp_Type.Properties.ValueMember = "Key";
- this.lookUp_Type.Properties.DisplayMember = "Value";
- this.lookUp_Type.Properties.NullText = "请您选择";
- this.btn_Save.Enabled = false;
- if (plcInfo != null) //修改功能
- {
- plc = plcInfo;
- txt_Name.Text = plcInfo.PlcName.ToString();
- this.lookUp_Type.EditValue = plcInfo.LinkType; //设置默认值
- txt_Config.Text = plcInfo.LinkConfig.ToString();
- this.btn_Save.Enabled = true;
- this.btn_Add.Enabled = false;
- }
- }
- private void btn_Cancel_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void btn_Save_Click(object sender, EventArgs e)
- {
- try
- {
- plc.PlcName = txt_Name.Text;
- plc.LinkType = Convert.ToInt64(lookUp_Type.EditValue);
- plc.LinkConfig = txt_Config.Text;
- bool flag = BLLFactory<BlPlcInfo>.Instance.Update(plc, plc.PlcId);
- 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("修改数据库plc_info出现错误:{0}", ex));
- }
-
- }
- private void btn_Add_Click(object sender, EventArgs e)
- {
- try
- {
- if (string.IsNullOrEmpty(txt_Name.Text) || string.IsNullOrEmpty(txt_Config.Text) || lookUp_Type.Text == "请您选择")
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("请将信息填写完整。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- MoPlcInfo plc = new MoPlcInfo();
- plc.PlcName = txt_Name.Text;
- plc.LinkType = Convert.ToInt64(lookUp_Type.EditValue);
- plc.LinkConfig = txt_Config.Text;
- //BlPlcInfo bl = new BlPlcInfo();
- bool flag = BLLFactory<BlPlcInfo>.Instance.Insert(plc);
- 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("插入数据库plc_info出现错误:{0}", ex));
- }
-
- }
- }
- }
|