123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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
- {
- /// <summary>
- /// 定义AE2Stock对象
- /// </summary>
- public MoAE2Stock item;
- /// <summary>
- /// 定义委托
- /// </summary>
- public delegate void save();
- /// <summary>
- /// 定义事件,保存数据成功后刷新FormAE2Stock中的数据
- /// </summary>
- 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<BlAE2Stock>.Instance.Delete(item.StockId, SysEnvironment.CurrentLoginID);
- if (flag)
- {
- item.StockId = stockId;
- flag = BLLFactory<BlAE2Stock>.Instance.Insert(item);
- }
- }
- else
- {
- flag = BLLFactory<BlAE2Stock>.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<BlAE2Stock>.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));
- }
-
- }
- }
- }
|