作者:郑凯丰
开发工具:VS、SQL Server、WPF
编写日期:2019年6月27日
代码:
1.现在数据库里面写好删除的代码;
–删除员工信息
IF(@Type=‘btn_Delete_Click_DelectStaff’)
BEGIN
if exists(select 0 from t_operators where staff_id !=@staff_id)
begin
--删除账号
DELETE t_operators
WHERE t_operators.staff_id=@staff_id
--删除员工信息
DELETE t_staff
WHERE t_staff.staff_id=@staff_id
End
else
begin
DELETE t_staff
WHERE t_staff.staff_id=@staff_id
end
END
2.数据库代码写好后,我们就可以在服务端写连接数据库的代码;
3.写删除的代码
//1.5 删除按钮
private void btn_Delete_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult dr = MessageBox.Show(“是否删除?”, “系统提示”, MessageBoxButton.OKCancel, MessageBoxImage.Question);
//弹出确定对话框
if (dr == MessageBoxResult.OK) //如果点了确定按钮
{ //1、获取选中行的数据
int staffid = Convert.ToInt32(((DataRowView)dgStaff.CurrentItem).Row[“staff_id”]); // 获取所点击的会员类别ID
if (staffid != 0) //如果会员类别ID不为0
{ //2、执行删除操作
myClient.btn_Delete_Click_DelectStaff(staffid); //执行删除事件
SelectdgStaff();//刷新页面表格数据
} else
{
MessageBox.Show(“请选择要删除的行。。”);
}
}
}