private void butClear_Click(object sender, EventArgs e) { if (MessageBox.Show("该操作将会清空所有该实验报告的图片,确定继续吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK) { MyMC.deletepic(DataClass.Experiment.Experiment_ID_forStudent, DataClass.MyMeans.Login_ID.ToString()); pic.Clear(); Pic_listView.Clear(); pic_pictureBox.Image = null; Pic_listView.Clear(); } /* * int a = 0; * foreach (Image p in pic)//遍历整个list表 * { * a++; * if (!MyMC.insertpic(p, DataClass.Experiment.Experiment_ID_forStudent, DataClass.MyMeans.Login_ID)) * { * MessageBox.Show("插入第" + a.ToString() + "张图片失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); * } * else * { * MessageBox.Show("插入第" + a.ToString() + "张图片成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); * } * } * if (a == pic.Count) * MessageBox.Show("所有图片保存成功!","提示");*/ }
private void butDelete_Click(object sender, EventArgs e) { if (MessageBox.Show("确定要删除所选实验吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) //判断是否在弹出的对话框中单击"确定"按钮 { for (int i = 0; i < dataGridView1.Rows.Count; i++) //循环遍历DataGridView控件中的每一行 { try { if (dataGridView1.Rows[i].Cells[0].Value != null) //当当前单元格的内容不为空时 { //当该行处于选定状态时 if (bool.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString()) == true) { //当未提交未批改的报告才可以删除 if ((bool.Parse(dataGridView1.Rows[i].Cells[13].Value.ToString()) != true) && (bool.Parse(dataGridView1.Rows[i].Cells[12].Value.ToString()) != true)) { string idr = dataGridView1.Rows[i].Cells[1].Value.ToString(); string ide = dataGridView1.Rows[i].Cells[2].Value.ToString(); dataGridView1.Rows.RemoveAt(i); //移除处于选定状态的记录 MyClass.getsqlcom("Delete from tb_Report where IDR='" + idr.ToString() + "'"); //执行SQL语句,删除报告 MyMC.deletepic(ide.ToString(), DataClass.MyMeans.Login_ID.ToString()); //MyClass.getsqlcom("Delete from tb_Picture where IDE='" + dataGridView1.Rows[i].Cells[2].Value.ToString() + "' and IDS='" + DataClass.MyMeans.Login_ID.ToString() + "'");//执行SQL语句删除图片 i--;//不改变循环变量的i的值 } else { MessageBox.Show("包含已经提交或批改的报告,将跳过!", "提示"); } } } } catch (Exception ex) //捕获异常 { MessageBox.Show(ex.Message); //弹出异常提示信息 } } MessageBox.Show("删除成功!", "操作", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示消息 Showall(); } }