using System; using System.Windows.Forms; using SIMDP.Model; using SIMDP.BLL; using ProjectBase.Data.Logs; using ProjectBase.Data.BaseDAL; using ProjectBase.Util; namespace SIMDP.Project { public partial class FormEditAE2Stock : DevExpress.XtraEditors.XtraForm { /// /// 定义AE2Stock对象 /// public MoAE2Stock item; /// /// 定义委托 /// public delegate void save(); /// /// 定义事件,保存数据成功后刷新FormAE2Stock中的数据 /// public event save saveData; public FormEditAE2Stock(MoAE2Stock stock) { InitializeComponent(); BindingSource bs = new BindingSource(); this.btn_Save.Enabled = false; if (stock != null) //修改功能 { item = stock; txtValue1.Text = stock.StockId.ToString(); txtValue2.Text = stock.PlcCode.ToString(); txtValue3.Text = stock.State.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 { int stockId = Convert.ToInt32(txtValue1.Text); item.PlcCode = Convert.ToInt32(txtValue2.Text); item.State = Convert.ToInt32(txtValue3.Text); bool flag; if (stockId != item.StockId) { flag = BLLFactory.Instance.Delete(item.StockId, SysEnvironment.CurrentLoginID); if (flag) { item.StockId = stockId; flag = BLLFactory.Instance.Insert(item); } } else { flag = BLLFactory.Instance.Update(item, item.StockId); } 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("修改数据表ae2stock出现错误:{0}", ex)); } } private void btn_Add_Click(object sender, EventArgs e) { try { MoAE2Stock item = new MoAE2Stock(); item.StockId = Convert.ToInt32(txtValue1.Text); item.PlcCode = Convert.ToInt32(txtValue2.Text); item.State = Convert.ToInt32(txtValue3.Text); bool flag = BLLFactory.Instance.Insert(item); 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("插入数据表ae2stock出现错误:{0}", ex)); } } } }