private void btnPrint_Click(object sender, EventArgs e) { if (this.dataGridView1.SelectedRows.Count > 0) { int myorder = int.Parse(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()); DALStudent myStudent = new DALStudent(); Candidate cand = myStudent.ReadyQueryWithKey(myorder.ToString()); if (cand != null) { DoPrint(cand); } } }
//有条件查询 private void SearchBind() { lblTotel.Text = "总人数:"; lblPass.Text = "合格人数:"; lbkHGL.Text = "合格率:"; bool flag = false; string strCond = ""; if (this.checkBox1.Checked != true) { flag = true; strCond = " DATEDIFF(d,'" + this.txtDate.Text + "',KSRQ)=0 "; } //日期 //姓名、身份证号、准考证号 if (radioButton1.Checked == true && this.txtName.Text != "") { if (flag) { flag = true; strCond += " and XM='" + this.txtName.Text.Trim() + "'"; } else { flag = true; strCond += " XM='" + this.txtName.Text.Trim() + "'"; } } if (radioButton2.Checked == true && this.txtSTZH.Text != "") { if (flag) { flag = true; strCond += " and SFZMHM='" + this.txtSTZH.Text.Trim() + "'"; } else { flag = true; strCond += " SFZMHM='" + this.txtSTZH.Text.Trim() + "'"; } } if (radioButton3.Checked == true && this.txtZKZH.Text != "") { if (flag) { flag = true; strCond += " and ZKZMBH='" + this.txtZKZH.Text.Trim() + "'"; } else { flag = true; strCond += " ZKZMBH='" + this.txtZKZH.Text.Trim() + "'"; } } DALStudent myStudent = new DALStudent(); DataTable dt = null; try { dt = myStudent.ReadyQuery(strCond); } catch { this.dataGridView1.DataSource = null; MessageBox.Show("数据库读写错误"); return; } if (dt.Rows.Count != 0) { this.dataGridView1.DataSource = dt; if (this.dataGridView1.Rows.Count != 0) { if (checkBox1.Checked == false) { int ToltoKsrs = myStudent.getToltoKsrs(this.txtDate.Text); int ToltohgKsrs = myStudent.getToltohgKsrs(this.txtDate.Text); lblTotel.Text = "总人数:" + ToltoKsrs.ToString(); lblPass.Text = "合格人数:" + ToltohgKsrs.ToString(); if (ToltoKsrs != 0) { this.lbkHGL.Text = "合格率:" + ((ToltohgKsrs * 100) / (ToltoKsrs)).ToString() + "%"; } } } FormatTable(); } else { this.dataGridView1.DataSource = null; } this.txtSTZH.Text = ""; this.txtName.Text = ""; this.txtZKZH.Text = ""; }