DataSet dsPrint = new DataSet(); //打印模板数据源 private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } DataTable dt = ((DataTable)grdDetail.DataSource).Copy(); for (int i = dt.Rows.Count - 1; i >= 0; i--) { if (!Convert.ToBoolean(dt.Rows[i]["选择"])) { dt.Rows.RemoveAt(i); } } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Clear(); Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dt); Rep.DataMember = "dtGrid"; Rep.ShowPreview(); //Rep.Print(); sState = "print"; } catch (Exception ee) { MessageBox.Show("打印失败:" + ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
DataSet dsPrint = new DataSet(); //打印模板数据源 private void btnPrint_Click(object sender, EventArgs e) { try { if (txt行号.Text.Trim() == "") { MessageBox.Show("请先输入行号"); txt行号.Focus(); return; } if (txt存货编码.Text.Trim() == "") { MessageBox.Show("请先输入生产订单信息"); lookUpEdit生产订单号1.Focus(); return; } decimal d净重 = ReturnObjectToDecimal(txt净重.Text.Trim(), 6); if (d净重 <= 0) { MessageBox.Show("获得产品重量失败"); txt净重.Focus(); return; } decimal d毛重 = ReturnObjectToDecimal(txt毛重.Text.Trim(), 6); if (d毛重 <= 0) { MessageBox.Show("称重数据不正确,请核实"); txt毛重.Focus(); return; } string sSQL2 = "select getdate()"; DateTime d当前日期 = Convert.ToDateTime(SqlHelper.ExecuteScalar(Conn, CommandType.Text, sSQL2)); string s条码单据号 = d当前日期.ToString("yyyyMMddHHmmss"); SqlConnection conn = new SqlConnection(Conn); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select a.*,b.cInvName,b.cInvStd,isnull(b.bInvBatch ,0) as bInvBatch ,isnull(b.bFree1 ,0) as bFree1 from 条形码信息 a inner join inventory b on a.存货编码 = b.cInvCode where guid = '" + txtGuid.Text.Trim() + "'"; DataTable dt = SqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt != null && dt.Rows.Count > 0) { DialogResult d = MessageBox.Show("该条码已经打印\n Y:继续打印 \n N:返回 ", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (d == DialogResult.No) { return; } } sSQL = "select * from inventory where cInvcode = '" + txt存货编码.Text.Trim() + "'"; DataTable dtinv = SqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dtinv == null || dtinv.Rows.Count < 1) { throw new Exception("存货信息不存在"); } int iBatch = ReturnObjectToInt(dtinv.Rows[0]["bInvBatch"]); if (iBatch == 1 && txt批号.Text.Trim() == "") { throw new Exception(txt存货编码.Text.Trim() + "是批次管理,请输入批号"); } int iFree1 = ReturnObjectToInt(dtinv.Rows[0]["bFree1"]); if (iFree1 == 1 && txt长度.Text.Trim() == "") { throw new Exception(txt存货编码.Text.Trim() + "必须输入长度"); } if (dt.Rows.Count == 0) { sSQL = "INSERT INTO [条形码信息]([存货编码] ,[长度],[批号] ,[炉号] ,[数量] ,[毛重]" + ",[保存人] ,[保存日期],[打印次数],[生产订单号],[行号] " + " ,[最后一次打印人] ,[最后一次打印日期],条码单据号,guid) " + " VALUES ('" + txt存货编码.Text.Trim() + "','" + txt长度.Text.Trim() + "','" + txt批号.Text.Trim() + "','" + txt炉号.Text.Trim() + "'," + txt净重.Text.Trim() + "," + txt毛重.Text.Trim() + " " + ",'" + sUserID + "',getdate(),1,'" + lookUpEdit生产订单号1.Text.Trim() + "','" + txt行号.Text.Trim() + "' " + ",'" + sUserID + "',getdate(),'" + s条码单据号 + "','" + txtGuid.Text.Trim() + "')"; SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); } sSQL = "select * from 条形码信息 where guid = '" + txtGuid.Text.Trim() + "'"; DataTable dtTemp = SqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; txt条形码.Text = dtTemp.Rows[0]["条形码"].ToString().Trim(); Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables["dtHead"].Rows.Clear(); Rep.dsPrint.Tables["dtHead"].Columns.Clear(); //设置报表表头数据表列 for (int i = 0; i < dt.Columns.Count; i++) { DataColumn dcRep = new DataColumn(); dcRep.ColumnName = dt.Columns[i].ColumnName; Rep.dsPrint.Tables["dtHead"].Columns.Add(dcRep); } DataRow dr = Rep.dsPrint.Tables["dtHead"].NewRow(); dr["条形码"] = ReturnBarCode(txt条形码.Text.Trim()); dr["存货编码"] = txt存货编码.Text.Trim(); dr["cInvName"] = txt存货名称.Text.Trim(); dr["cInvStd"] = txt规格型号.Text.Trim(); dr["长度"] = txt长度.Text.Trim(); dr["批号"] = txt批号.Text.Trim(); dr["炉号"] = txt炉号.Text.Trim(); dr["数量"] = txt净重.Text.Trim(); dr["毛重"] = txt毛重.Text.Trim(); dr["生产订单号"] = lookUpEdit生产订单号1.Text.Trim() + " / " + txt行号.Text.Trim(); Rep.dsPrint.Tables["dtHead"].Rows.Add(dr); Rep.ShowPreview(); //Rep.Print(); tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } string sSQL3 = "select * from 条形码信息 where guid = '" + txtGuid.Text.Trim() + "'"; DataTable dt2 = SqlHelper.ExecuteDataset(Conn, CommandType.Text, sSQL3).Tables[0]; if (dt2 != null && dt2.Rows.Count > 0) { txt条形码.Text = dt2.Rows[0]["条形码"].ToString().Trim(); } } catch (Exception ee) { MessageBox.Show(ee.Message); } /* * Rep = new RepBaseGrid(); * if (File.Exists(sPrintLayOutUser)) * { * Rep.LoadLayout(sPrintLayOutUser); * } * else if (File.Exists(sPrintLayOutMod)) * { * Rep.LoadLayout(sPrintLayOutMod); * } * else * { * MessageBox.Show("加载报表模板失败,请与管理员联系"); * return; * } * Rep.dsPrint.Tables["dtHead"].Rows.Clear(); * Rep.dsPrint.Tables["dtHead"].Columns.Clear(); * //设置报表表头数据表列 * //try * //{ * // for (int i = 0; i < this.dsPrint.Tables["dtHead"].Columns.Count; i++) * // { * // DataColumn dc = new DataColumn(); * // dc = this.dsPrint.Tables["dtHead"].Columns[i]; * // DataColumn dcRep = new DataColumn(); * // dcRep.ColumnName = dc.ColumnName; * // Rep.dsPrint.Tables["dtHead"].Columns.Add(dcRep); * // } * //} * //catch { } * * //if (this.dsPrint.Tables["dtHead"] != null) * //{ * // for (int i = 0; i < this.dsPrint.Tables["dtHead"].Rows.Count; i++) * // { * // DataRow dr = Rep.dsPrint.Tables["dtHead"].NewRow(); * // for (int j = 0; j < Rep.dsPrint.Tables["dtHead"].Columns.Count; j++) * // { * // dr[j] = this.dsPrint.Tables["dtHead"].Rows[i][j]; * // } * // Rep.dsPrint.Tables["dtHead"].Rows.Add(dr); * // } * //} * * //设置报表表体数据表列 * * Rep.dsPrint.Tables["dtGrid"].Clear(); * Rep.dsPrint.Tables["dtGrid"].Columns.Clear(); * for (int i = 0; i < gridView1.Columns.Count; i++) * { * DataColumn dcGrid = new DataColumn(); * dcGrid.ColumnName = gridView1.Columns[i].Caption; * Rep.dsPrint.Tables["dtGrid"].Columns.Add(dcGrid); * } * if (grdDetail.DataSource != null) * { * for (int i = 0; i < gridView1.RowCount; i++) * { * if (Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) * { * DataRow dr = Rep.dsPrint.Tables["dtGrid"].NewRow(); * for (int j = 0; j < Rep.dsPrint.Tables["dtGrid"].Columns.Count; j++) * { * if (gridView1.Columns[j].Caption == "条形码") * { * dr[j] = ReturnBarCode(gridView1.GetRowCellDisplayText(i, gridView1.Columns[j])); * } * else * { * dr[j] = gridView1.GetRowCellDisplayText(i, gridView1.Columns[j]); * } * } * Rep.dsPrint.Tables["dtGrid"].Rows.Add(dr); * } * } * } * * Rep.DataMember = "dtGrid"; * Rep.ShowPreview(); * * * SqlConnection conn = new SqlConnection(Conn); * conn.Open(); * //启用事务 * SqlTransaction tran = conn.BeginTransaction(); * try * { * for (int i = 0; i < gridView1.RowCount; i++) * { * if (Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) * { * string sSQL = "update 条形码信息 set 打印次数 = isnull(打印次数,0) + 1,最后一次打印人 = '" + sUserID + "',最后一次打印日期 = getdate() where 条形码 = " + gridView1.GetRowCellValue(i, gridCol条形码).ToString().Trim(); * SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); * } * } * tran.Commit(); * } * catch (Exception error) * { * tran.Rollback(); * throw new Exception(error.Message); * } * */ }
DataSet dsPrint = new DataSet(); //打印模板数据源 private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables["dtHead"].Rows.Clear(); Rep.dsPrint.Tables["dtHead"].Columns.Clear(); //设置报表表头数据表列 //try //{ // for (int i = 0; i < this.dsPrint.Tables["dtHead"].Columns.Count; i++) // { // DataColumn dc = new DataColumn(); // dc = this.dsPrint.Tables["dtHead"].Columns[i]; // DataColumn dcRep = new DataColumn(); // dcRep.ColumnName = dc.ColumnName; // Rep.dsPrint.Tables["dtHead"].Columns.Add(dcRep); // } //} //catch { } //if (this.dsPrint.Tables["dtHead"] != null) //{ // for (int i = 0; i < this.dsPrint.Tables["dtHead"].Rows.Count; i++) // { // DataRow dr = Rep.dsPrint.Tables["dtHead"].NewRow(); // for (int j = 0; j < Rep.dsPrint.Tables["dtHead"].Columns.Count; j++) // { // dr[j] = this.dsPrint.Tables["dtHead"].Rows[i][j]; // } // Rep.dsPrint.Tables["dtHead"].Rows.Add(dr); // } //} //设置报表表体数据表列 Rep.dsPrint.Tables["dtGrid"].Clear(); Rep.dsPrint.Tables["dtGrid"].Columns.Clear(); for (int i = 0; i < gridView1.Columns.Count; i++) { DataColumn dcGrid = new DataColumn(); dcGrid.ColumnName = gridView1.Columns[i].Caption; Rep.dsPrint.Tables["dtGrid"].Columns.Add(dcGrid); } if (grdDetail.DataSource != null) { for (int i = 0; i < gridView1.RowCount; i++) { if (Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) { DataRow dr = Rep.dsPrint.Tables["dtGrid"].NewRow(); for (int j = 0; j < Rep.dsPrint.Tables["dtGrid"].Columns.Count; j++) { if (gridView1.Columns[j].Caption == "条形码") { dr[j] = ReturnBarCode(gridView1.GetRowCellDisplayText(i, gridView1.Columns[j])); } else { dr[j] = gridView1.GetRowCellDisplayText(i, gridView1.Columns[j]); } } Rep.dsPrint.Tables["dtGrid"].Rows.Add(dr); } } } Rep.DataMember = "dtGrid"; Rep.ShowPreview(); //Rep.Print(); SqlConnection conn = new SqlConnection(Conn); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { for (int i = 0; i < gridView1.RowCount; i++) { if (Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) { string sSQL = "update 条形码信息 set 打印次数 = isnull(打印次数,0) + 1,最后一次打印人 = '" + sUserID + "',最后一次打印日期 = getdate() where 条形码 = " + gridView1.GetRowCellValue(i, gridCol条形码).ToString().Trim(); SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } sState = "print"; } catch (Exception ee) { MessageBox.Show("打印失败:" + ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
DataSet dsPrint = new DataSet(); //打印模板数据源 private void btnPrint_Click(object sender, EventArgs e) { try { string sSQL = "select getdate()"; DateTime d当前日期 = Convert.ToDateTime(SqlHelper.ExecuteScalar(Conn, CommandType.Text, sSQL)); string s条码单据号 = d当前日期.ToString("yyyyMMddHHmmss"); SqlConnection conn = new SqlConnection(Conn); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables.Clear(); string sGuid = Guid.NewGuid().ToString(); for (int i = 0; i < gridView1.RowCount; i++) { if (!Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) { continue; } sSQL = "select * from 条形码信息 where 存货编码 = '" + gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim() + "' and 批号 = '" + gridView1.GetRowCellValue(i, gridCol批号).ToString().Trim() + "' and 长度 = '" + gridView1.GetRowCellValue(i, gridCol长度).ToString().Trim() + "' and 炉号 = '" + gridView1.GetRowCellValue(i, gridCol炉号).ToString().Trim() + "'"; DataTable dt = SqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (dt == null || dt.Rows.Count == 0) { string s毛重 = gridView1.GetRowCellValue(i, gridCol毛重).ToString().Trim(); int iKG = s毛重.IndexOf("KG"); s毛重 = s毛重.Substring(0, iKG); sSQL = "INSERT INTO [条形码信息]([存货编码] ,[长度],[批号] ,[炉号] ,[数量] ,[毛重]" + ",[保存人] ,[保存日期],[打印次数],[生产订单号],[行号] " + " ,[最后一次打印人] ,[最后一次打印日期],条码单据号,guid) " + " VALUES ('" + gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim() + "','" + gridView1.GetRowCellValue(i, gridCol长度).ToString().Trim() + "','" + gridView1.GetRowCellValue(i, gridCol批号).ToString().Trim() + "','" + gridView1.GetRowCellValue(i, gridCol炉号).ToString().Trim() + "'," + gridView1.GetRowCellValue(i, gridCol净重).ToString().Trim() + "," + s毛重 + " " + ",'" + sUserID + "',getdate(),1,'" + gridView1.GetRowCellValue(i, gridCol生产订单号).ToString().Trim().Trim() + "','" + gridView1.GetRowCellValue(i, gridCol行号).ToString().Trim().Trim() + "' " + ",'" + sUserID + "',getdate(),'" + s条码单据号 + "','" + sGuid + "')"; SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); } else { sSQL = "update 条形码信息 set 打印次数 = isnull(打印次数,0) + 1,最后一次打印日期 = getdate(),GUID = '" + sGuid + "' where 存货编码 = '" + gridView1.GetRowCellValue(i, gridCol存货编码).ToString().Trim() + "' and 批号 = '" + gridView1.GetRowCellValue(i, gridCol批号).ToString().Trim() + "' and 长度 = '" + gridView1.GetRowCellValue(i, gridCol长度).ToString().Trim() + "' and 炉号 = '" + gridView1.GetRowCellValue(i, gridCol炉号).ToString().Trim() + "'"; SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } sSQL = @" select right(cast('000000000'+rtrim(条形码) as varchar(20)),10) as 条形码, 存货编码, 长度, 批号, 炉号, 数量, 毛重, 保存人, 保存日期, 打印次数, 最后一次打印人 ,最后一次打印日期, 条码单据号, 修改人, 修改日期, 关闭人, 关闭日期, 采购订单号, 生产订单号, 销售订单号, 行号, GUID ,采购入库单号, 采购入库单行号, 产成品入库单号, 产成品入库单行号 ,b.cInvName,b.cInvStd from 条形码信息 a inner join Inventory b on a.存货编码 = b.cInvCode where guid = '" + sGuid + "'"; DataTable dtHead = SqlHelper.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtHead.TableName = "dtHead"; Rep.dsPrint.Tables.Add(dtHead.Copy()); Rep.ShowPreview(); //Rep.Print(); tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
DataSet dsPrint = new DataSet(); //打印模板数据源 private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } DataTable dt = ((DataTable)grdDetail.DataSource).Copy(); SqlConnection conn = new SqlConnection(Conn); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToBoolean(dt.Rows[i]["选择"])) { string sSQL = "if exists(select * from dbo.条形码信息 where 采购入库单号 = '" + dt.Rows[i]["采购入库单号"].ToString().Trim() + "' and 采购入库单行号 = '" + dt.Rows[i]["采购入库单行号"].ToString().Trim() + "' and 存货编码 = '" + dt.Rows[i]["存货编码"].ToString().Trim() + "' )" + " update 条形码信息 set 最后一次打印人 = '" + sUserID + "' ,最后一次打印日期 = GETDATE(),打印次数 = ISNULL(打印次数,0) + 1 where 采购入库单号 = '" + dt.Rows[i]["采购入库单号"].ToString().Trim() + "' and 采购入库单行号 = '" + dt.Rows[i]["采购入库单行号"].ToString().Trim() + "' and 存货编码 = '" + dt.Rows[i]["存货编码"].ToString().Trim() + "' " + " else " + " insert into 条形码信息(最后一次打印人,最后一次打印日期,保存人,保存日期,打印次数,采购入库单号,采购入库单行号,存货编码,guid)values " + " ('" + sUserID + "',getdate(),'" + sUserID + "',GETDATE(),'1','" + dt.Rows[i]["采购入库单号"].ToString().Trim() + "','" + dt.Rows[i]["采购入库单行号"].ToString().Trim() + "','" + dt.Rows[i]["存货编码"].ToString().Trim() + "','" + dt.Rows[i]["GUID"].ToString().Trim() + "')"; SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } for (int i = 0; i < gridView1.RowCount; i++) { if (!Convert.ToBoolean(gridView1.GetRowCellValue(i, gridCol选择))) { continue; } if (gridView1.GetRowCellValue(i, gridCol条形码).ToString().Trim() == "") { string s = "select 条形码 from 条形码信息 where guid = '" + gridView1.GetRowCellValue(i, gridColGUID).ToString().Trim() + "'"; object o = SqlHelper.ExecuteScalar(conn, CommandType.Text, s); gridView1.SetRowCellValue(i, gridCol条形码, o); } } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Clear(); Rep.dsPrint.Tables.Clear(); dt = (DataTable)grdDetail.DataSource; DataColumn dc = dt.Columns["条形码"]; for (int i = 0; i < dt.Rows.Count; i++) { if (!Convert.ToBoolean(dt.Rows[i]["选择"])) { continue; } int iLeng = dt.Rows[i]["条形码"].ToString().Trim().Length; for (int ii = iLeng; ii < 10; ii++) { dt.Rows[i]["条形码"] = "0" + dt.Rows[i]["条形码"].ToString().Trim(); } } DataView dv = dt.DefaultView; dv.RowFilter = " isnull(选择,0) = 1 "; dt.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dv.ToTable()); Rep.DataMember = "dtGrid"; Rep.ShowPreview(); //Rep.Print(); sState = "print"; } catch (Exception ee) { MessageBox.Show("打印失败:" + ee.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }