前言
整个机房收费系统有三个不同层次的权限:一般用户,操作员,管理员。他们在系统中都有各自的权限,其中我个人认为操作员是最重要的,因为他不仅要管理下面,还要向上汇报工作,起到了桥梁的作用,承上启下。
但是如果你问我操作员最有范的权限是啥,我一定会告诉你:学习上机状态查看。从表面上看没有什么特别之处,但是你了解内部权限后就明白为什么了。他不仅有查看的权限,更重要的是他可以管理学生的上机,最帅气的是可以让全部学生下机和选中学生下机。个人认为这是操作员最牛的权限,哈哈哈。
当然今天不是炫耀这个的,我是想跟大家分享:如何让你想实现全部人员下机,如何实现选中人员下机。看似简单的功能还是稍微的费了点劲(小白)。
困难点:如何在查出来的数据表中添加标记,然后在数据库中删除添加标记的数据,并且窗体上不显示。
下面先看我对整个窗体的功能梳理,这个有利于写代码和思路的打开。
解决问题的重要代码
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex;
//获取单元格行数
rowIndex = Convert.ToInt32(e.RowIndex.ToString());
dataGridView.Rows[rowIndex].Cells[5].Value = "√";
}
private void dataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rowIndex;
rowIndex = Convert.ToInt32(e.RowIndex.ToString());
dataGridView.Rows[rowIndex].Cells[5].Value = "";
}
流程图
重要代码
DAL层代码
public class StuViewOnLineStatusDAO:IDAL.IStuOnLineState
{
SqlHelper sqlhelper = new SqlHelper();
public DataTable UpdateOnLine(OnLineInfo onlineinfo)
{
string sql = @"select * from [OnLine_Info] ";
DataTable table = sqlhelper.ExecuteQuery(sql,CommandType .Text );
return table;
}
public DataTable DeleteAllStudent(OnLineInfo onlineinfo)
{
string sql = @"delete from OnLine_Info ";
DataTable AllStudent = sqlhelper.ExecuteQuery(sql, CommandType.Text);
return AllStudent;
}
public DataTable DeletePartStudent(OnLineInfo onlineinfo)
{
string sql = @"delete from [OnLine_Info] where cardno=@cardno ";
SqlParameter[] sqlParams = {
new SqlParameter("@cardno", onlineinfo.cardno )
};
DataTable PartStudent = sqlhelper.ExecuteQuery(sql,sqlParams, CommandType.Text);
return PartStudent;
}
}
BLL层代码
public class StuViewOnLineStatusBLL
{
factoryStuViewOnLineStatus fact = new factoryStuViewOnLineStatus();
public DataTable UpdateOnlineBLL(OnLineInfo onlineinfo)
{
IStuOnLineState idal = fact.UpdateOnLine();
DataTable table = idal.UpdateOnLine(onlineinfo);
return table;
}
public DataTable DeleteAllStudent(OnLineInfo onlineinfo)
{
IStuOnLineState idal = fact.DeleteAllStudent();
DataTable AllStudent = idal.DeleteAllStudent(onlineinfo);
return AllStudent;
}
public DataTable DeletePartStudent(OnLineInfo onlineinfo)
{
IStuOnLineState idal = fact.DeletePartStudent();
DataTable PartStudent = idal.DeletePartStudent(onlineinfo);
return PartStudent;
}
}
UI层代码
public partial class frmStuViewOnLineStatus : Form
{
public frmStuViewOnLineStatus()
{
InitializeComponent();
}
//实例化MOdel层
OnLineInfo onlineinfo = new OnLineInfo();
StudentInfo studentinfo = new StudentInfo();
LineInfo lineinfo = new LineInfo();
//实例化外观层
fStuViewOnLineStatus fstuviewonlinestatus = new fStuViewOnLineStatus();
private void MeuAllShow_Click(object sender, EventArgs e)
{
DataTable table = fstuviewonlinestatus.UpdateOnLine(onlineinfo);
int m = table.Rows.Count;
if (table.Rows.Count > 0)
{
dataGridView.DataSource = table;
dataGridView.Columns.Remove("cardtype");
dataGridView.Columns.Remove("studentNo");
dataGridView.Columns.Remove("Department");
dataGridView.Columns.Remove("date");
dataGridView.Columns.Remove("longtime");
return;
}
else
{
MessageBox.Show("没有相关记录!", "提示");
return;
}
}
private void MeuAllDown_Click(object sender, EventArgs e)
{
DataTable AllStudent = fstuviewonlinestatus.DeleteAllStudent(onlineinfo);
if (dataGridView .SelectedRows .Count ==0)
{
dataGridView.DataSource = "null";
}
else
{
MessageBox.Show("没有任何信息可供删除!", "提示");
return;
}
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
int rowIndex;
//获取单元格行数
rowIndex = Convert.ToInt32(e.RowIndex.ToString());
dataGridView.Rows[rowIndex].Cells[5].Value = "√";
}
private void dataGridView_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
int rowIndex;
rowIndex = Convert.ToInt32(e.RowIndex.ToString());
dataGridView.Rows[rowIndex].Cells[5].Value = "";
}
private void MeuPartDown_Click(object sender, EventArgs e)
{
onlineinfo.cardno = dataGridView.Rows[dataGridView.CurrentRow.Index].Cells[1].Value.ToString();
DataTable PartStudent = fstuviewonlinestatus.DeletePartStudent(onlineinfo);
if (dataGridView .SelectedRows .Count ==0)
{
MessageBox.Show("请至少选择一行数据进行删除!");
return;
}
else
{
dataGridView.Rows.Remove(dataGridView.Rows[dataGridView.CurrentRow.Index]);
MessageBox.Show("删除成功!");
}
}
总结
不管困难有多大,不管自己有多菜,凡事一点一点的去做,去试,去思考。总会有一个让你内心惊喜的结果。