private void btnPrintSet_Click(object sender, EventArgs e) { try { if (!Directory.Exists(sProPath + "\\print")) { Directory.CreateDirectory(sProPath + "\\print"); } if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } Rep.ShowDesignerDialog(); DialogResult d = MessageBox.Show("是否保存?模板调整将在下次打开窗体时体现\n是:保存打印模板\n", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk); if (DialogResult.Yes == d) { Rep.SaveLayoutToXml(sPrintLayOutMod); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "设置打印模板失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnPrint_Click(object sender, EventArgs e) { try { if (txt单据号.Text.Trim() == "") { throw new Exception("请选择需要打印的单据"); } string sSQL = @" select cast(0 as bit) as bchoose,*,b.iSum as 金额 from [dbo].[_高开返利核销单_SZ] a left join [dbo].[_高开返利单_SZ] b on a.FLD_iID = b.iID where a.cCode = '{0}' "; sSQL = string.Format(sSQL, txt单据号.Text.Trim()); DataTable dt = DbHelperSQL.Query(sSQL); if (dt == null || dt.Rows.Count == 0) { throw new Exception("获取单据信息失败"); } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dt.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; Rep.ShowPreview(); Rep.PrintingSystem.ShowMarginsWarning = false; } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnPrint_Click(object sender, EventArgs e) { try { if (!clsUserRight.chkRight(sUserID, 8030)) { throw new Exception("没有权限"); } if (txtCode.Text.Trim() == "") { throw new Exception("请选择单据"); } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables.Clear(); string sSQL = @" select * from _Scrap where cCode = N'111111' "; sSQL = sSQL.Replace("111111", txtCode.Text.Trim()); DataTable dt = DbHelperSQL.Query(sSQL); DataTable dtHead = dt.Copy(); dtHead.TableName = "dtHead"; Rep.dsPrint.Tables.Add(dtHead); sSQL = @" select * ,b.InvName,b.InvStd from _Scraps a left join _FrockClamp b on a.SerialNo = b.SerialNo where a.cCode = N'111111' order by a.iID "; sSQL = sSQL.Replace("111111", txtCode.Text.Trim()); dt = DbHelperSQL.Query(sSQL); DataTable dtGrid = dt.Copy(); dtGrid.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtGrid); if (Rep.dsPrint == null) { throw new Exception("没有需要打印的数据"); } Rep.ShowPreview(); } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "打印失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnPrintSet_Click(object sender, EventArgs e) { try { bool bMod = false; if (sUserID == "demo") { bMod = true; } if (!Directory.Exists(sProPath + "\\print")) { Directory.CreateDirectory(sProPath + "\\print"); } if (!Directory.Exists(sProPath + "\\print\\Model")) { Directory.CreateDirectory(sProPath + "\\print\\Model"); } if (!Directory.Exists(sProPath + "\\print\\User")) { Directory.CreateDirectory(sProPath + "\\print\\User"); } if (bMod) { if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } } else { if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } } Rep.ShowDesignerDialog(); DialogResult d = MessageBox.Show("是否保存?模板调整将在下次打开窗体时体现\n是:保存打印模板\n否:恢复默认打印模板\n", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Asterisk); if (DialogResult.Yes == d) { if (bMod) { Rep.SaveLayoutToXml(sPrintLayOutMod); } else { Rep.SaveLayoutToXml(sPrintLayOutUser); } } else if (DialogResult.No == d) { if (File.Exists(sPrintLayOutUser)) { File.Delete(sPrintLayOutUser); } } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "设置打印模板失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
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; } string sErr = ""; string sWarn = ""; if (Rep.dsPrint == null) { throw new Exception("没有需要打印的数据"); } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { Rep.dsPrint.Tables.Clear(); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); string sSQL = "select getdate()"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; DateTime dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]); if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1")) { throw new Exception("获得系统日期失败"); } sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like '" + dDateSer.ToString("yyMMdd") + "%' "; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sMaxCode = ""; if (dt != null && dt.Rows.Count > 0) { sMaxCode = dt.Rows[0][0].ToString().Trim(); } long lMaxID = 0; if (sMaxCode != "") { lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(6)); } Guid sGuid = Guid.NewGuid(); for (int i = 0; i < gridView1.RowCount; i++) { if (BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { decimal dQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQuantity)); if (dQuantity < 0) { dQuantity = -1 * dQuantity; } decimal dBatch = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol包装批量)); if (dBatch == 0) { dBatch = dQuantity; } int iCount = BaseFunction.ReturnInt(Math.Ceiling(dQuantity / dBatch)); for (int j = 0; j < iCount; j++) { Model_BarCodeList model = new Model_BarCodeList(); lMaxID += 1; string sBarCode = getBaseData.GetBarCode(dDateSer, lMaxID); model.cInvCode = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim(); model.cInvName = gridView1.GetRowCellValue(i, gridColcInvName).ToString().Trim(); model.cInvStd = gridView1.GetRowCellValue(i, gridColcInvStd).ToString().Trim(); model.BarCode = sBarCode; model.ExsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColAutoID)); model.ExCode = gridView1.GetRowCellValue(i, gridColcCode).ToString().Trim(); model.ExType = "采购入库单"; model.ExRowNo = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColirowno)); model.ExVenCode = gridView1.GetRowCellValue(i, gridColcVenCode).ToString().Trim(); model.ExVenName = gridView1.GetRowCellValue(i, gridColcVenName).ToString().Trim(); model.ExQuantity = dQuantity; model.ExBatchQty = dBatch; model.GUID = sGuid; model.cWhCode = gridView1.GetRowCellValue(i, gridColcWhCode).ToString().Trim(); model.cWhName = gridView1.GetRowCellValue(i, gridColcWhName).ToString().Trim(); model.ExcPTName = gridView1.GetRowCellValue(i, gridColcPTName).ToString().Trim(); model.ExcInvDefine3 = gridView1.GetRowCellValue(i, gridColcInvDefine3).ToString().Trim(); model.ExcComUnitName = gridView1.GetRowCellValue(i, gridColcComUnitName).ToString().Trim(); model.ExcPTCode = gridView1.GetRowCellValue(i, gridColcPTCode).ToString().Trim(); //国外供应商批号: R+采购订单号(后7位)+日期+订单行号 //国内供应商批号:采购订单号(后7位)+日期+订单行号 sSQL = @" select a.cVenCode,b.cVCCode ,b. cVCName from Vendor a inner join VendorClass b on a.cVCCode = b.cVCCode where a.cVenCode = '111111' "; sSQL = sSQL.Replace("111111", gridView1.GetRowCellValue(0, gridColcVenCode).ToString().Trim()); DataTable dtVen = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string scVCCode = dtVen.Rows[0]["cVCCode"].ToString().Trim(); string sDDCode = gridView1.GetRowCellValue(i, gridColcPOID).ToString().Trim(); if (sDDCode.Length >= 7) { sDDCode = sDDCode.Substring(sDDCode.Length - 7); } if (scVCCode == "20") { model.Batch = "R" + sDDCode + "-" + dDateSer.ToString("yyMMdd") + "-" + gridView1.GetRowCellValue(i, gridColPORowNo).ToString().Trim(); } else { model.Batch = "" + sDDCode + "-" + dDateSer.ToString("yyMMdd") + "-" + gridView1.GetRowCellValue(i, gridColPORowNo).ToString().Trim(); } model.CreateUserName = sUserName; model.CreateDate = dDateSer; model.ExDepCode = gridView1.GetRowCellValue(i, gridColcDepCode).ToString().Trim(); model.ExDepName = gridView1.GetRowCellValue(i, gridColcDepName).ToString().Trim(); model.valid = true; model.Used = 0; model.ExcMemo = gridView1.GetRowCellValue(i, gridColcMemo).ToString().Trim(); model.ExcInvDefine4 = gridView1.GetRowCellValue(i, gridColcInvDefine4).ToString().Trim(); model.ExcInvDefine5 = gridView1.GetRowCellValue(i, gridColcInvDefine5).ToString().Trim(); if (j != iCount - 1) { model.iQty = dBatch; } else { model.iQty = dQuantity - dBatch * (iCount - 1); } model.PosCode = gridView1.GetRowCellValue(i, gridCol货位).ToString().Trim(); sSQL = DAL.Add(model); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } } sSQL = @" select a.* from [_BarCodeList] a where GUID = '" + sGuid.ToString().Trim() + "'"; DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtPrint.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtPrint.Copy()); if (dtPrint.Rows.Count < 1) { if (sErr.Length > 0) { throw new Exception(sErr); } else { throw new Exception("没有要打印的单据"); } } if (sErr.Trim() != "") { throw new Exception(sErr); } if (iCou == 0) { throw new Exception("请选择需要保存的数据"); } //Rep.Print(); Rep.ShowPreview(); tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "打印失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } Rep = new RepBaseGrid(); Rep.dsPrint.Tables.Clear(); if (radioCG.Checked) { sPrintLayOutMod = Application.StartupPath + "\\UAP\\Runtime\\print\\Model\\历史条形码打印Mod.dll"; sPrintLayOutUser = Application.StartupPath + "\\UAP\\Runtime\\print\\User\\历史条形码打印User.dll"; if (radioBarCode.Checked) { if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } } if (radioBarCodeBox.Checked) { if (File.Exists(sPrintLayOutUser2)) { Rep.LoadLayout(sPrintLayOutUser2); } else if (File.Exists(sPrintLayOutMod2)) { Rep.LoadLayout(sPrintLayOutMod2); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } } string sErr = ""; string sWarn = ""; if (Rep.dsPrint == null) { throw new Exception("没有需要打印的数据"); } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { Rep.dsPrint.Tables.Clear(); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); string sSQL = "select getdate()"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; DateTime dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]); if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1")) { throw new Exception("获得系统日期失败"); } string sCode = dDateSer.ToString("yyMMrrhhmmss"); long lMaxID = 0; if (radioBarCode.Checked) { sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like '" + dDateSer.ToString("yyMMdd") + "%' "; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sMaxCode = ""; if (dt != null && dt.Rows.Count > 0) { sMaxCode = dt.Rows[0][0].ToString().Trim(); } if (sMaxCode != "") { lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(6)); } } if (radioBarCodeBox.Checked) { sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode not like '" + dDateSer.ToString("yyMMdd") + "%' "; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sMaxCode = ""; if (dt != null && dt.Rows.Count > 0) { sMaxCode = dt.Rows[0][0].ToString().Trim(); } if (sMaxCode != "") { lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(7)); } } Guid sGuid = Guid.NewGuid(); for (int i = 0; i < gridView1.RowCount; i++) { if (BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { string sBarCodeHis = gridView1.GetRowCellValue(i, gridColBarCode).ToString().Trim(); DataRow[] drList = dtGrid.Select("BarCode = '" + sBarCodeHis + "'"); DataRow dr = drList[0]; Model_BarCodeList model = new Model_BarCodeList(); lMaxID += 1; string sBarCode = ""; if (radioBarCode.Checked) { sBarCode = getBaseData.GetBarCode(dDateSer, lMaxID); } if (radioBarCodeBox.Checked) { sBarCode = getBaseData.GetBarCodeBox(dDateSer, lMaxID); } model = DAL.DataRowToModel(dr); model.BarCode = sBarCode; model.BarCodeHis = sBarCodeHis; model.ExQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQty)); model.iQty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColUseQty)); model.CreateUserName = sUserName; model.CreateDate = dDateSer; model.valid = true; model.Used = 0; model.GUID = sGuid; sSQL = DAL.Add(model); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); sSQL = "update _BarCodeList set valid = 0 where BarCode = '" + sBarCodeHis + "'"; DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); if (radioBarCode.Checked) { //登记源条码作废 Model_BarCodeRD modelRD = new Model_BarCodeRD(); DAL_BarCodeRD dalRD = new DAL_BarCodeRD(); modelRD.sCode = sCode; modelRD.BarCode = sBarCodeHis; modelRD.sType = "历史条码打印"; modelRD.cInvCode = gridView1.GetRowCellValue(i, gridColcInvCode).ToString().Trim(); modelRD.Qty = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColUseQty)); modelRD.CreateUid = sUserName; modelRD.CreateDate = dDateSer; modelRD.ExCode = sBarCodeHis; modelRD.RDType = 2; sSQL = dalRD.Add(modelRD); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); modelRD.BarCode = sBarCode; modelRD.RDType = 1; sSQL = dalRD.Add(modelRD); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } } sSQL = "select * from [_BarCodeList] where GUID = '" + sGuid.ToString().Trim() + "'"; DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtPrint.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtPrint.Copy()); if (dtPrint.Rows.Count < 1) { throw new Exception("没有要打印的单据"); } if (sErr.Trim() != "") { throw new Exception(sErr); } if (iCou == 0) { throw new Exception("请选择需要保存的数据"); } //Rep.Print(); Rep.ShowPreview(); tran.Commit(); btnRefresh_Click(null, null); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } if (radioQC.Checked) { sPrintLayOutMod = Application.StartupPath + "\\UAP\\Runtime\\print\\Model\\期初条形码打印Mod.dll"; sPrintLayOutUser = Application.StartupPath + "\\UAP\\Runtime\\print\\User\\期初条形码打印User.dll"; if (radioBarCode.Checked) { if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } } DataTable dtPrint = (DataTable)gridControl1.DataSource; DataTable dtPrTemp = dtPrint.Copy(); for (int i = dtPrTemp.Rows.Count - 1; i >= 0; i--) { bool b = BaseFunction.ReturnBool(dtPrTemp.Rows[i]["choose"]); if (!b) { dtPrTemp.Rows.RemoveAt(i); } } dtPrTemp.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtPrTemp.Copy()); if (dtPrint.Rows.Count < 1) { throw new Exception("没有要打印的单据"); } //Rep.Print(); Rep.ShowPreview(); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "打印失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnPrint_Click(object sender, EventArgs e) { string sErr = ""; try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); dtGrid.TableName = "dtGrid"; DataColumn dc = new DataColumn(); dc.ColumnName = "BarCreateDate"; dtGrid.Columns.Add(dc); Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } for (int i = 0; i < gridView1.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { continue; } string sBarCode = gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim(); if (sBarCode == "") { continue; } sSQL = @" select a.barCode, a.SaleOrderNo, a.SaleOrderRowNo, a.iSOsID, a.cInvCode, a.cInvName, a.cInvStd, Inv.cInvDepCode as DEPT ,b.cDepName as DEPTName, CUST,ORDERNO AS ORDNO, CUSTDO, LOTNO, ORDERQTY, LOTQTY, RECDate, DueDate, Creater, CreateDate ,PrintTime, PrintCount, a.cInvCode AS ITEMNO, a.cInvName AS ITEMDESC ,RECDate,DueDate ,cast(null as varchar(50)) as RECDate2,cast(null as varchar(50)) as DueDate2 ,ORDERQTY as ORDQTY ,CUSTLOT ,'Printed on ' as PrintInfo ,c.cMemo ,Inv.cInvDefine6 ,Inv.cComUnitCode as cUnitID from _BarCodeLabel a inner join Inventory Inv on a.cInvCode = Inv.cInvCode left join Department b on Inv.cInvDepCode = b.cDepCode left join SO_SODetails c on c.iSOsID = a.iSOsID where a.BarCode = '{0}' and a.iSOsID = '{1}' order by a.barCode "; sSQL = string.Format(sSQL, sBarCode, txtiSOsID.Text.Trim()); DataTable dtBarCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtBarCode.Rows[0]["PrintInfo"] = "Printed on " + dNow.ToString("yyyy/MM/dd HH:mm:ss"); dtBarCode.Rows[0]["RECDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[0]["RECDate"]).ToString("yyyy-MM-dd"); dtBarCode.Rows[0]["DueDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[0]["DueDate"]).ToString("yyyy-MM-dd"); Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtBarCode.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; if (radioPreview.Checked) { Rep.ShowPreview(); } if (radioPrint.Checked) { if (lookUpEditPrinter.Text.Trim() == "") { lookUpEditPrinter.Focus(); throw new Exception("Please choose printer"); } Rep.PrinterName = lookUpEditPrinter.Text.Trim(); Rep.Print(); } } tran.Commit(); } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnPrint_Click(object sender, EventArgs e) { try { Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUser)) { Rep.LoadLayout(sPrintLayOutUser); } else if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } string sErr = ""; string sWarn = ""; if (Rep.dsPrint == null) { throw new Exception("没有需要打印的数据"); } int iBoxCount = BaseFunction.ReturnInt(textEditBoxQTY.Text.Trim()); if (iBoxCount <= 0) { textEditBoxQTY.Focus(); throw new Exception("请输入箱数"); } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { Rep.dsPrint.Tables.Clear(); string sSQL = "select getdate()"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; DateTime dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]); if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1")) { throw new Exception("获得系统日期失败"); } sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like 'X" + dDateSer.ToString("yyMMdd") + "%' "; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sMaxCode = ""; if (dt != null && dt.Rows.Count > 0) { sMaxCode = dt.Rows[0][0].ToString().Trim(); } long lMaxID = 0; if (sMaxCode != "") { lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(7)); } Guid sGuid = Guid.NewGuid(); for (int i = 0; i < iBoxCount; i++) { decimal dQuantity = BaseFunction.ReturnDecimal(textEditQTY.Text.Trim()); if (dQuantity < 0) { dQuantity = -1 * dQuantity; } Model_BarCodeList model = new Model_BarCodeList(); lMaxID += 1; string sBarCode = getBaseData.GetBarCodeBox(dDateSer, lMaxID); model.BarCode = sBarCode; model.ExCode = textEditMomCode.Text.Trim(); model.ExQuantity = dQuantity; model.Used = 0; model.iQty = dQuantity; model.CreateUserName = sUserName; model.CreateDate = dDateSer; model.ExType = "生产箱码"; model.GUID = sGuid; model.valid = true; model.Batch = textEditBatch.Text.Trim(); model.PosCode = textEditHW.Text.Trim(); sSQL = DAL.Add(model); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } sSQL = "select * from [_BarCodeList] where GUID = '" + sGuid.ToString().Trim() + "'"; DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtPrint.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtPrint.Copy()); if (dtPrint.Rows.Count < 1) { throw new Exception("没有要打印的单据"); } if (sErr.Trim() != "") { throw new Exception(sErr); } if (iCou == 0) { throw new Exception("请选择需要保存的数据"); } if (sErr.Length > 0) { throw new Exception(sErr); } Rep.ShowPreview(); tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "打印失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnPrintBox_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutUserBox)) { Rep.LoadLayout(sPrintLayOutUserBox); } else if (File.Exists(sPrintLayOutModBox)) { Rep.LoadLayout(sPrintLayOutModBox); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } string sErr = ""; string sWarn = ""; if (Rep.dsPrint == null) { throw new Exception("没有需要打印的数据"); } int iCou = 0; SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString); conn.Open(); //启用事务 SqlTransaction tran = conn.BeginTransaction(); try { Rep.dsPrint.Tables.Clear(); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); string sSQL = "select getdate()"; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; DateTime dDateSer = BaseFunction.ReturnDate(dt.Rows[0][0]); if (dDateSer.Date < BaseFunction.ReturnDate("2014-8-1")) { throw new Exception("获得系统日期失败"); } sSQL = "select max(BarCode) from dbo._BarCodeList where BarCode like 'X" + dDateSer.ToString("yyMMdd") + "%' "; dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; string sMaxCode = ""; if (dt != null && dt.Rows.Count > 0) { sMaxCode = dt.Rows[0][0].ToString().Trim(); } long lMaxID = 0; if (sMaxCode != "") { lMaxID = BaseFunction.ReturnLong(sMaxCode.Substring(7)); } Guid sGuid = Guid.NewGuid(); for (int i = 0; i < gridView1.RowCount; i++) { if (BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { decimal dQuantity = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridColiQuantity)); if (dQuantity < 0) { dQuantity = -1 * dQuantity; } decimal dBatch = BaseFunction.ReturnDecimal(gridView1.GetRowCellValue(i, gridCol包装批量)); if (dBatch == 0) { sErr = sErr + "行" + (i + 1).ToString().Trim() + "请设置包装批量\n"; continue; } int iCount = BaseFunction.ReturnInt(Math.Ceiling(dQuantity / dBatch)); for (int j = 0; j < iCount; j++) { Model_BarCodeList model = new Model_BarCodeList(); lMaxID += 1; string sBarCode = getBaseData.GetBarCodeBox(dDateSer, lMaxID); model.BarCode = sBarCode; model.ExsID = BaseFunction.ReturnLong(gridView1.GetRowCellValue(i, gridColAutoID)); model.ExCode = gridView1.GetRowCellValue(i, gridColcCode).ToString().Trim(); model.ExRowNo = BaseFunction.ReturnInt(gridView1.GetRowCellValue(i, gridColirowno)); model.ExQuantity = dQuantity; model.ExDepCode = gridView1.GetRowCellValue(i, gridColcDepCode).ToString().Trim(); model.ExDepName = gridView1.GetRowCellValue(i, gridColcDepName).ToString().Trim(); model.ExBatchQty = dBatch; model.Used = 0; if (j == iCount - 1) { model.iQty = dQuantity - dBatch * (iCount - 1); } else { model.iQty = dBatch; } model.CreateUserName = sUserName; model.CreateDate = dDateSer; model.ExType = "生产订单"; model.GUID = sGuid; model.valid = true; model.PosCode = gridView1.GetRowCellValue(i, gridCol货位).ToString().Trim(); sSQL = DAL.Add(model); iCou = iCou + DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } } } sSQL = "select * from [_BarCodeList] where GUID = '" + sGuid.ToString().Trim() + "'"; DataTable dtPrint = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; dtPrint.TableName = "dtGrid"; Rep.dsPrint.Tables.Add(dtPrint.Copy()); if (dtPrint.Rows.Count < 1) { throw new Exception("没有要打印的单据"); } if (sErr.Trim() != "") { throw new Exception(sErr); } if (iCou == 0) { throw new Exception("请选择需要保存的数据"); } if (sErr.Length > 0) { throw new Exception(sErr); } Rep.ShowPreview(); tran.Commit(); } catch (Exception error) { tran.Rollback(); throw new Exception(error.Message); } } catch (Exception ee) { FrmMsgBox f = new FrmMsgBox(); f.Text = "打印失败"; f.richTextBox1.Text = ee.Message; f.ShowDialog(); } }
private void btnRePrint_Click(object sender, EventArgs e) { string sErr = ""; int iCount = 0; try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); dtGrid.TableName = "dtGrid"; DataColumn dc = new DataColumn(); dc.ColumnName = "BarCreateDate"; dtGrid.Columns.Add(dc); dc = new DataColumn(); dc.ColumnName = "RECDate2"; dtGrid.Columns.Add(dc); dc = new DataColumn(); dc.ColumnName = "DueDate2"; dtGrid.Columns.Add(dc); dc = new DataColumn(); dc.ColumnName = "PrintInfo"; dtGrid.Columns.Add(dc); for (int i = dtGrid.Rows.Count - 1; i >= 0; i--) { if (!BaseFunction.ReturnBool(dtGrid.Rows[i]["choose"])) { dtGrid.Rows.RemoveAt(i); } } for (int i = 0; i < dtGrid.Rows.Count; i++) { string sBarCode = dtGrid.Rows[i]["BarCode"].ToString().Trim(); sSQL = "select count(1) from [_BarCodeLabel] where [BarCode] = '" + sBarCode + "' and iSOsID = " + dtGrid.Rows[i]["iSOsID"].ToString() + " and [RDsID] = '" + dtGrid.Rows[i]["RdsAutoid"].ToString().Trim() + "'";; DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (BaseFunction.ReturnInt(dt.Rows[0][0], -1) == 0) { sErr = sErr + dtGrid.Rows[i]["ORDNO"] + " " + dtGrid.Rows[i]["iRowNo"] + " is not printe\n"; continue; } int iPrintCount = BaseFunction.ReturnInt(dtGrid.Rows[i]["PrintCount"]) + 1; long lSOsID = BaseFunction.ReturnLong(dtGrid.Rows[i]["iSOsID"].ToString().Trim()); sSQL = "update [_BarCodeLabel] set PrintTime = '{0}',PrintCount = {1} where BarCode='{2}' and iSOsID = {3}"; sSQL = string.Format(sSQL, dNow.ToString("yyyy-MM-dd HH:mm:ss"), iPrintCount, sBarCode, lSOsID); dtGrid.Rows[i]["BarCreateDate"] = "Printed on " + dNow.ToString("yyyy/MM/dd HH:mm:ss"); dtGrid.Rows[i]["PrintTime"] = dNow; dtGrid.Rows[i]["PrintCount"] = iPrintCount; dtGrid.Rows[i]["PrintInfo"] = "Printed on " + BaseFunction.ReturnDate(dtGrid.Rows[i]["PrintTime"]).ToString("yyyy/MM/dd HH:mm:ss"); dtGrid.Rows[i]["RECDate2"] = BaseFunction.ReturnDate(dtGrid.Rows[i]["RECDTE"]).ToString("yyyy-MM-dd"); dtGrid.Rows[i]["DueDate2"] = BaseFunction.ReturnDate(dtGrid.Rows[i]["DUEDTE"]).ToString("yyyy-MM-dd"); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } if (iCount == 0) { throw new Exception("Please choose data"); } if (sErr.Length > 0) { throw new Exception(sErr); } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtGrid); if (radioPreview.Checked) { Rep.ShowPreview(); } if (radioPrint.Checked) { if (lookUpEditPrinter.Text.Trim() == "") { lookUpEditPrinter.Focus(); throw new Exception("Please choose printer"); } Rep.PrinterName = lookUpEditPrinter.Text.Trim(); Rep.Print(); } if (iCount > 0) { tran.Commit(); GetGrid(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnPrint_Click(object sender, EventArgs e) { string sErr = ""; int iCount = 0; try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } SqlConnection conn = new SqlConnection(Conn); conn.Open(); SqlTransaction tran = conn.BeginTransaction(); try { string sSQL = "select getdate()"; DateTime dNow = BaseFunction.ReturnDate(DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0].Rows[0][0]); DateTime dNowDate = BaseFunction.ReturnDate(dNow.ToString("yyyy-MM-dd")); DataTable dtGrid = ((DataTable)gridControl1.DataSource).Copy(); dtGrid.TableName = "dtGrid"; DataColumn dc = new DataColumn(); dc.ColumnName = "BarCreateDate"; dtGrid.Columns.Add(dc); for (int i = dtGrid.Rows.Count - 1; i >= 0; i--) { if (!BaseFunction.ReturnBool(dtGrid.Rows[i]["choose"])) { dtGrid.Rows.RemoveAt(i); } } sSQL = @" select MAX(SUBSTRING(BarCode,9,4)) from _BarCodeLabel where SUBSTRING(BarCode,3,6) = 'aaaaaa' "; sSQL = sSQL.Replace("aaaaaa", dNowDate.ToString("yyMMdd")); DataTable dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; long lBarList = BaseFunction.ReturnLong(dt.Rows[0][0]); for (int i = 0; i < dtGrid.Rows.Count; i++) { long iLotSize = BaseFunction.ReturnLong(dtGrid.Rows[0]["LotSize"]); if (iLotSize <= 0) { sErr = sErr + "Row " + (i + 1).ToString() + " lot qty err\n"; continue; } sSQL = "select count(1) from [_BarCodeLabel] where 1=1 and isnull(printCount,0) >0 and [iSOsID] = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim() + " and [RDsID] = '" + dtGrid.Rows[i]["RdsAutoid"].ToString().Trim() + "'"; if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os") { sSQL = sSQL.Replace("1=1", "1=1 and Batch = '" + dtGrid.Rows[i]["cBatch"].ToString().Trim() + "'"); } dt = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; if (BaseFunction.ReturnInt(dt.Rows[0][0], -1) != 0) { sErr = sErr + dtGrid.Rows[i]["ORDNO"] + " " + dtGrid.Rows[i]["iRowNo"] + " is printed\n"; continue; } long dOrderQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]); long dLOTQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["LOTQTY"]); if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "") { dLOTQTY = 1; } if (dLOTQTY == 1 || dtGrid.Rows[i]["LOTNO"].ToString().Trim() != "") { dLOTQTY = dOrderQTY; } ////OS 业务使用入库单作为 dOrderQTY用于判断打印循环 //if (dtGrid.Rows[i]["cSTCode"].ToString().ToLower().Trim() == "os") //{ // dOrderQTY = dLOTQTY; //} while (dOrderQTY > 0) { lBarList += 1; Model._BarCodeLabel model = new UFIDA.U8.UAP.CustomApp.ControlForm.Model._BarCodeLabel(); dtGrid.Rows[i]["BarCreateDate"] = "Printed on " + dNow.ToString("yyyy/MM/dd HH:mm:ss"); if (dtGrid.Rows[i]["LOTNO"].ToString().Trim() == "") { string sBarList = lBarList.ToString(); while (sBarList.Length < 4) { sBarList = "0" + sBarList; } model.BarCode = dtGrid.Rows[i]["cSTCode"].ToString().Trim() + dNowDate.ToString("yyMMdd") + sBarList; } else { model.BarCode = dtGrid.Rows[i]["LOTNO"].ToString().Trim(); } dtGrid.Rows[i]["barcode"] = model.BarCode; model.SaleOrderNo = dtGrid.Rows[i]["ORDNO"].ToString().Trim(); model.SaleOrderRowNo = BaseFunction.ReturnLong(dtGrid.Rows[i]["iRowNo"]); model.iSOsID = BaseFunction.ReturnLong(dtGrid.Rows[i]["iSOsID"]); model.cInvCode = dtGrid.Rows[i]["ITEMNO"].ToString().Trim(); model.cInvName = dtGrid.Rows[i]["ITEMDESC"].ToString().Trim(); model.DEPT = dtGrid.Rows[i]["DEPT"].ToString().Trim(); model.CUST = dtGrid.Rows[i]["CUST"].ToString().Trim(); model.ORDERNO = dtGrid.Rows[i]["ORDNO"].ToString().Trim(); model.CUSTDO = dtGrid.Rows[i]["CUSTDO"].ToString().Trim(); model.LOTNO = dtGrid.Rows[i]["LOTNO"].ToString().Trim(); model.ORDERQTY = BaseFunction.ReturnLong(dtGrid.Rows[i]["ORDQTY"]); model.CUSTLOT = dtGrid.Rows[i]["CUSTLOT"].ToString().Trim(); model.LotSize = BaseFunction.ReturnDecimal(dtGrid.Rows[i]["LotSize"], 2); model.Batch = dtGrid.Rows[i]["cBatch"].ToString().Trim(); model.RDsID = BaseFunction.ReturnLong(dtGrid.Rows[i]["RdsAutoid"]); model.RDType = dtGrid.Rows[i]["RDsType"].ToString().Trim(); model.Process = dtGrid.Rows[i]["cWhCode"].ToString().Trim(); if (dOrderQTY >= dLOTQTY) { model.LOTQTY = dLOTQTY; dOrderQTY = dOrderQTY - dLOTQTY; } else { model.LOTQTY = dOrderQTY; dOrderQTY = 0; } model.LOTQTY2 = model.LOTQTY; model.RECDate = BaseFunction.ReturnDate(dtGrid.Rows[i]["RECDTE"]); model.DueDate = BaseFunction.ReturnDate(dtGrid.Rows[i]["DUEDTE"]); model.Creater = sUserID; model.CreateDate = dNow; model.PrintTime = dNow; model.PrintCount = 1; model.Status = "新增"; DAL._BarCodeLabel dal = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL._BarCodeLabel(); sSQL = dal.Add(model); iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); Model.BarStatus models = new UFIDA.U8.UAP.CustomApp.ControlForm.Model.BarStatus(); models.BarCode = model.BarCode; models.Type = "新增"; models.UpdateTime = dNow; models.QTY = model.LOTQTY; models.CreateDate = dNowDate; models.CreateUid = sUserID; models.iSOsID = model.iSOsID; models.RoutingFrom = "新增"; models.RoutingTo = model.Process; DAL.BarStatus dals = new UFIDA.U8.UAP.CustomApp.ControlForm.DAL.BarStatus(); sSQL = dals.Add(models); DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); } //} //else //{ // sSQL = "update _BarCodeLabel set Status = '新增', printTime = getdate(), PrintCount = 1, createdate = '" + dNow + "' where BarCode = '" + dtGrid.Rows[i]["LOTNO"].ToString().Trim() + "' and iSOsID = " + dtGrid.Rows[i]["iSOsID"].ToString().Trim(); // iCount += DbHelperSQL.ExecuteNonQuery(tran, CommandType.Text, sSQL); //} } if (sErr.Length > 0) { throw new Exception(sErr); } if (iCount == 0) { throw new Exception("Please choose data\n" + sErr); } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } sSQL = @" select a.barCode, a.SaleOrderNo, a.SaleOrderRowNo, a.iSOsID, a.cInvCode, a.cInvName, a.cInvStd, Inv.cInvDepCode as DEPT ,b.cDepName as DEPTName, CUST,ORDERNO AS ORDNO, CUSTDO, LOTNO, ORDERQTY, LOTQTY, RECDate, DueDate, Creater, CreateDate ,PrintTime, PrintCount, a.cInvCode AS ITEMNO, a.cInvName AS ITEMDESC ,RECDate,DueDate ,cast(null as varchar(50)) as RECDate2,cast(null as varchar(50)) as DueDate2 ,ORDERQTY as ORDQTY ,CUSTLOT ,'Printed on ' as PrintInfo ,c.cMemo ,Inv.cInvDefine6 ,Inv.cComUnitCode as cUnitID from _BarCodeLabel a inner join Inventory Inv on a.cInvCode = Inv.cInvCode left join Department b on Inv.cInvDepCode = b.cDepCode left join SO_SODetails c on c.iSOsID = a.iSOsID where creater = '{0}' and createdate = '{1}' order by a.barCode "; sSQL = string.Format(sSQL, sUserID, dNow); DataTable dtBarCode = DbHelperSQL.ExecuteDataset(tran, CommandType.Text, sSQL).Tables[0]; for (int i = 0; i < dtBarCode.Rows.Count; i++) { dtBarCode.Rows[i]["PrintInfo"] = "Printed on " + BaseFunction.ReturnDate(dtBarCode.Rows[i]["PrintTime"]).ToString("yyyy/MM/dd HH:mm:ss"); dtBarCode.Rows[i]["RECDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["RECDate"]).ToString("yyyy-MM-dd"); dtBarCode.Rows[i]["DueDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["DueDate"]).ToString("yyyy-MM-dd"); } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtBarCode.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; if (radioPreview.Checked) { Rep.ShowPreview(); } if (radioPrint.Checked) { if (lookUpEditPrinter.Text.Trim() == "") { lookUpEditPrinter.Focus(); throw new Exception("Please choose printer"); } Rep.PrinterName = lookUpEditPrinter.Text.Trim(); Rep.Print(); } if (iCount > 0) { tran.Commit(); GetGrid(); } } catch (Exception ee) { tran.Rollback(); throw new Exception(ee.Message); } } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } GetBarCodeStatus(btnTxtBarCode.Text.Trim()); Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } string sID = ""; string sSOsID = ""; for (int i = 0; i < gridView1.RowCount; i++) { bool b = BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose)); if (!b) { continue; } if (sID == "") { sID = "'" + gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim() + "'"; sSOsID = gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim(); } else { sID = sID + ",'" + gridView1.GetRowCellValue(i, gridColLotNO).ToString().Trim() + "'"; sSOsID = sSOsID + "," + gridView1.GetRowCellValue(i, gridColiSOsID).ToString().Trim(); } } Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } if (sID == "") { throw new Exception("Please choose"); } string sSQL = @" select barCode, SaleOrderNo, SaleOrderRowNo, iSOsID, cInvCode, cInvName, cInvStd, DEPT,b.cDepName as DEPTName, CUST, ORDERNO AS ORDNO, CUSTDO, LOTNO, ORDERQTY, LOTQTY, RECDate, DueDate, Creater, CreateDate, PrintTime, PrintCount, cInvCode AS ITEMNO, cInvName AS ITEMDESC, RECDate AS RECDTE, DueDate AS DUEDTE,ORDERQTY as ORDQTY ,CUSTLOT ,'Printed on ' as PrintInfo ,cast(null as varchar(50)) as RECDate2, cast(null as varchar(50)) as DueDate2 from _BarCodeLabel a left join Department b on a.DEPT = b.cDepCode where barCode in (aaaaaaaa) and iSOsID in (bbbbbbbb) "; sSQL = sSQL.Replace("aaaaaaaa", sID); sSQL = sSQL.Replace("bbbbbbbb", sSOsID); DataTable dtBarCode = DbHelperSQL.Query(sSQL); for (int i = 0; i < dtBarCode.Rows.Count; i++) { dtBarCode.Rows[i]["PrintInfo"] = "Printed on " + BaseFunction.ReturnDate(dtBarCode.Rows[i]["PrintTime"]).ToString("yyyy/MM/dd HH:mm:ss"); dtBarCode.Rows[i]["RECDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["RECDate"]).ToString("yyyy-MM-dd"); dtBarCode.Rows[i]["DueDate2"] = BaseFunction.ReturnDate(dtBarCode.Rows[i]["DueDate"]).ToString("yyyy-MM-dd"); } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtBarCode.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; Rep.ShowPreview(); } catch (Exception ee) { MessageBox.Show(ee.Message); } }
private void btnPrint_Click(object sender, EventArgs e) { try { try { gridView1.FocusedRowHandle -= 1; gridView1.FocusedRowHandle += 1; } catch { } string sSQL = ""; //DataTable dt = ((DataView)gridView1.DataSource).ToTable(); for (int i = 0; i < gridView1.RowCount; i++) { if (!BaseFunction.ReturnBool(gridView1.GetRowCellValue(i, gridColchoose))) { continue; } decimal dPrint = BaseFunction.ReturnDecimal(gridView1.GetRowCellDisplayText(i, gridColPrintQTY)); if (dPrint > 0) { sSQL = @" SELECT row_number() over (order by A.cSTCode) as rowid ,getdate() as dtmNow ,A.cSTCode,a.dDate ,A.cSOCode AS ORDNO,b.iSOsID,b.iRowNo,c.cInvDepCode AS DEPT ,A.cCusCode AS CUST ,NULL AS vend ,b.cinvcode AS ITEMNO,b.cInvName AS ITEMDESC ,b.cDefine25 AS CUSTLOT,a.cDefine10 AS CUSTDO ,CAST(b.iQuantity AS DECIMAL(16,2)) AS ORDQTY ,cast(bbbbbb as decimal(16,2)) AS LOTQTY ,CONVERT(char(10), A.dDate, 120) as RECDTE ,CONVERT(char(10), B.dPreDate, 120) as DUEDTE ,'gggggg' AS LOTNO ,d.creater,d.createdate ,c.cComUnitCode as cUnitID ,d.PrintCount,GETDATE() AS PrintTime ,d.barcode ,d.iID ,e.* ,cast('eeeeee' as varchar(50)) as MC ,cast('ffffff' as varchar(50)) as POT ,cast('cccccc' as varchar(50)) as RACK ,cast('dddddd' as varchar(50)) as PRODLINE FROM dbo.SO_SOMain A INNER JOIN dbo.SO_SODetails B ON A.ID = B.ID INNER JOIN inventory c ON b.cInvCode = c.cInvCode inner JOIN [dbo].[_BarCodeLabel] d ON b.iSOsID = d.iSOsID LEFT JOIN ( SELECT a.Status, a.ProcessCode, a.Seq, a.PlatingProcess, a.Condition, a.Thichness, a.Time, a.Density, a.AMP , b.ItemCode, b.Material, b.XRayFile, b.FinishingSpec, b.CommonPltSpec, b.Grade, b.UnitSurfaceArea, b.UnitWeight, b.Note1, b.Note2, b.Note3,b.Color FROM [dbo].[_ProcessList] a INNER JOIN [dbo].[_PlatingProcess] b ON a.ProcessCode = b.ProcessCode where a.Status <> 'No' )e ON c.cinvcode = e.ItemCode WHERE 1=1 and d.barcode = 'aaaaaa' and b.iSOsID in (select max(iSOsID) from [_BarCodeLabel] where barcode = 'aaaaaa' group by barcode) ORDER BY b.cinvcode,a.cSOCode, b.AutoID ,e.Seq "; sSQL = sSQL.Replace("aaaaaa", gridView1.GetRowCellDisplayText(i, gridColBarCode).ToString().Trim()); sSQL = sSQL.Replace("bbbbbb", dPrint.ToString().Trim()); sSQL = sSQL.Replace("cccccc", gridView1.GetRowCellDisplayText(i, gridColRACK).ToString().Trim()); sSQL = sSQL.Replace("dddddd", gridView1.GetRowCellDisplayText(i, gridColPRODLINE).ToString().Trim()); sSQL = sSQL.Replace("eeeeee", gridView1.GetRowCellDisplayText(i, gridColMC).ToString().Trim()); sSQL = sSQL.Replace("ffffff", gridView1.GetRowCellDisplayText(i, gridColPOT).ToString().Trim()); sSQL = sSQL.Replace("gggggg", gridView1.GetRowCellDisplayText(i, gridColLOTNO).ToString().Trim()); DataTable dtPrint = DbHelperSQL.Query(sSQL); Rep = new RepBaseGrid(); if (File.Exists(sPrintLayOutMod)) { Rep.LoadLayout(sPrintLayOutMod); } else { MessageBox.Show("加载报表模板失败,请与管理员联系"); return; } Rep.dsPrint.Tables.Clear(); Rep.dsPrint.Tables.Add(dtPrint.Copy()); Rep.dsPrint.Tables[0].TableName = "dtGrid"; if (radioPreview.Checked) { Rep.ShowPreview(); } if (radioPrint.Checked) { if (lookUpEditPrinter.Text.Trim() == "") { lookUpEditPrinter.Focus(); throw new Exception("Please choose printer"); } Rep.PrinterName = lookUpEditPrinter.Text.Trim(); Rep.Print(); } } } } catch (Exception ee) { MessageBox.Show(ee.Message); } }