删除选中的操作
2015-05-24 15:42:10 访问(1581) 赞(0) 踩(0)
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton_删除_Click(object sender, EventArgs e)
{
try
{
DeleteSelectedClick
(
null
);
}
catch (Exception err)
{
ExcuteException(err);
}
}
/// <summary>
///
/// </summary>
/// <param name="xdbHelper"></param>
protected void DeleteSelectedClick(DBHelper xdbHelper)
{
DataGridView gv = dataGridView_Main;
List<BPageToolBarItemInfoGridList> theList
=
(gv.DataSource as List<BPageToolBarItemInfoGridList>);
if (theList == null || theList.Count == 0)
return;
RefleshGridCtrlStatus();
int checkCount
=
icxba.DataGridViewCountCheckedRows(gv, Column__CheckBox.Name);
bool isNotAll = true;
if (checkCount == 0)
{
if (MessageBox.Show("您尚未勾选要删除的记录,是否删除当前列表的全部记录?", "请选择", MessageBoxButtons.YesNo) == DialogResult.Yes)
isNotAll = false;
else
return;
}
else
{
if (MessageBox.Show("确定删除选中的记录?", "请选择", MessageBoxButtons.YesNo) == DialogResult.No)
return;
}
int dropCount = 0;
bool bIsCreate = true;
if (xdbHelper == null)
{
xdbHelper = SlowX.DAL.Helpers.DBHelper.CreateDBHelper
(
appDBConnectionItemValue
);
}
else
{
// 没有打开链接 //
bIsCreate = xdbHelper.IsNotOpen();
}
try
{
if (bIsCreate)
xdbHelper.OpenDBHelper();
int iCount = theList.Count;
object oValue = null;
string dataColumnCheckBoxName
=
Column__CheckBox.Name;
for (int i = 0; i < iCount; ++i)
{
if (isNotAll)
{
oValue = gv.Rows[i].Cells[dataColumnCheckBoxName].Value;
if (oValue == null)
continue;
if (oValue.ToString() != "1")
continue;
}
icx.ZH.BPageToolBarItemInfoDeleteById
(
theList[i].ID,
xdbHelper
);
++dropCount;
}
if (dropCount == 0)
{
GridLoad(toolStripPager1.PageIndex, toolStripPager1.GetRecordCount(), xdbHelper);
}
else
{
int recordCount = toolStripPager1.GetRecordCount() - dropCount;
int newPageIndex = toolStripPager1.GetChangePageIndex(dropCount);
GridLoad(newPageIndex, recordCount, xdbHelper);
}
if (bIsCreate)
xdbHelper.EndDBHelper();
}
catch (Exception err)
{
if (bIsCreate)
xdbHelper.TranDBHelper();
throw err;
}
finally
{
if (bIsCreate)
xdbHelper.FinallyDBHelper();
}
if (dropCount == 0)
{
MsgForm.MsgShow("没有有效的删除记录。");
}
else
{
MsgForm.MsgShow("成功删除" + dropCount.ToString() + "条记录。");
}
}
标签:
删除选中的操作 


上一条:
下一条:
相关评论
发表评论