using ICSharpCode.Core;
using Mesnac.Action.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.Package
{
class DeleteAction : ChemicalWeighingAction, IAction
{
#region 事件定义
///
/// 删除事件定义
///
public static event EventHandler OnDelete;
#endregion
#region 字段定义
private RuntimeParameter _runtime;
private DbMCControl _clientGridControl = null; //物料信息控件
#endregion
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
this._runtime = runtime;
DbMCControl materialDGV = this.GetDbMCControlByKey(Mesnac.Basic.DataSourceFactory.MCDbType.Local, "Hw_Package").FirstOrDefault();
if (materialDGV == null)
{
ICSharpCode.Core.LoggingService.Error("删除物料失败:未知列表项");
return;
}
this._clientGridControl = materialDGV;
this.DoWork();
}
#region 删除方法定义
///
/// 根据ID删除
///
protected void DoWork()
{
this._runtime.BaseControl.MCEnabled = false;
try
{
DataGridView clientGridView = this._clientGridControl.BaseControl as DataGridView;
if (clientGridView.SelectedRows.Count == 1)
{
int Id = (int)clientGridView.SelectedRows[0].Cells["ID"].Value;
string msg1 = "确认删除吗?";
DialogResult result = MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//删除本地数据库中信息
PackageHelper.delete(Id.ToString());
#region 触发事件
if (OnDelete != null)
{
OnDelete(_runtime, System.EventArgs.Empty);
}
#endregion
}
}
else
{
string msg2 = "请选择一条要删除料桶信息!"; //请选择一条要删除物料信息!
MessageBox.Show(msg2, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService.Error("删除料桶异常:" + ex.Message, ex);
MessageBox.Show(ex.Message, Mesnac.Basic.LanguageHelper.WarnCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
finally
{
this._runtime.BaseControl.MCEnabled = true;
}
}
#endregion
}
}