private void BtnPrint_Click(object sender, EventArgs e) { if (txtGroup.Text == "" || txtWorkLocation.Text == "" || txtModel.Text == "" || txtLot.Text == "") { MessageBox.Show("组别、工位、型号、批号不能为空", "打印标签", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //数据库操作 StringBuilder sql = new StringBuilder(); sql.Append(string.Format("Insert Into glue Values (Nextval('id_seq'),'{0}','{1}','{2}','{3}');", txtGroup.Text, txtWorkLocation.Text, txtModel.Text, txtLot.Text)); sql.Append("Select Max(glue_id) From glue;"); DataTable dt = new DataTable(); new DBFactory().ExecuteDataTable(sql.ToString(), ref dt); if (dt.Rows.Count > 0) { lblGlueID.Text = dt.Rows[0]["max"].ToString(); picQRcode.Image = BarcodeHelper.QRcode(lblGlueID.Text, picQRcode.Width, picQRcode.Height); } else { MessageBox.Show("存在错误,操作无效", "数据库", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //确认打印 if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } }
public void BtnPrint_Click(object sender, EventArgs e) { if (txtID0.Text == "") { MessageBox.Show("ID号不能为空", "打印标签", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string model = txtID0.Text.Substring(0, 1); string sql; if (model == "B") { sql = string.Format(@"SELECT type.model,type.assy,type.name,type.lot,type.exp,big.time+(type.exp || 'H')::interval,big.lot,big.glue_parent_id FROM glue_parent as big left join glue_type as type on big.glue_id = type.glue_id where big.glue_parent_id='{0}'" , txtID0.Text); } else if (model == "S") { sql = string.Format(@"select type.model,type.assy,type.name,type.lot,type.exp,small.time+(type.exp || 'H')::interval,big.lot,small.glue_child_id from glue_child as small left join glue_parent as big on small.glue_parent_id=big.glue_parent_id left join glue_type as type on big.glue_id=type.glue_id where small.glue_child_id='{0}'" , txtID0.Text); } else { MessageBox.Show("大胶水或小胶水的ID格式不正确", "胶水ID", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } DataTable dt = new DataTable(); new DBFactory().ExecuteDataTable(sql, ref dt); if (dt.Rows.Count == 1) { txt1.Text = dt.Rows[0][0].ToString(); txt2.Text = dt.Rows[0][1].ToString(); txt3.Text = dt.Rows[0][2].ToString(); txt4.Text = dt.Rows[0][3].ToString(); txt5.Text = dt.Rows[0][4].ToString(); txt6.Text = dt.Rows[0][5].ToString(); txtLot2.Text = txtLot1.Text = dt.Rows[0][6].ToString(); txtID2.Text = txtID1.Text = dt.Rows[0][7].ToString(); picQRcode1.Image = BarcodeHelper.QRcode(txtID1.Text, picQRcode1.Width, picQRcode1.Height); picQRcode2.Image = BarcodeHelper.QRcode(txtID2.Text, picQRcode2.Width, picQRcode2.Height); } else { MessageBox.Show("数据异常", "数据库", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Close(); } if (printDialog1.ShowDialog() == DialogResult.OK) { printDocument1.Print(); } }