WinForm应用程序框架设计之WinAction(删除数据)
我们来先看看WinAction的删除数据的流程:
具体的参考代码:
public virtual void DeleteEntity(object entity, object caller, object sender, EventArgs e)
{
if (caller is IDataListView)
{
IDataListView listForm = caller as IDataListView;
if (null == listForm.DataList || (listForm.DataList is ICollection && (listForm.DataList as ICollection).Count == 0))
return;
}
if (MessageBox.Show("确实要删除当前记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
//判断当前删除的是否是新增的记录。(如果是新增的那条,其id为-1)
if (entity is Entity && (entity as Entity).IsNewEntity)
{
Form eForm = CallEditForm(caller);
if (eForm.Visible)
eForm.Close();
return;
}
useBll.Delete((T)entity);
if (updateFreshByDB && caller is IDataListView && (caller as IDataListView).RefreshEntityList != null)
(caller as IDataListView).RefreshEntityList((caller as IDataListView).SearchEntity, caller, sender, e);
}
{
if (caller is IDataListView)
{
IDataListView listForm = caller as IDataListView;
if (null == listForm.DataList || (listForm.DataList is ICollection && (listForm.DataList as ICollection).Count == 0))
return;
}
if (MessageBox.Show("确实要删除当前记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
return;
//判断当前删除的是否是新增的记录。(如果是新增的那条,其id为-1)
if (entity is Entity && (entity as Entity).IsNewEntity)
{
Form eForm = CallEditForm(caller);
if (eForm.Visible)
eForm.Close();
return;
}
useBll.Delete((T)entity);
if (updateFreshByDB && caller is IDataListView && (caller as IDataListView).RefreshEntityList != null)
(caller as IDataListView).RefreshEntityList((caller as IDataListView).SearchEntity, caller, sender, e);
}
原创作品出自努力偷懒,转载请说明文章出处:http://blog.csdn.net/kfarvid或 http://www.cnblogs.com/kfarvid/