예제 #1
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            try
            {
                try
                {
                    gridView1.FocusedRowHandle -= 1;
                    gridView1.FocusedRowHandle += 1;
                }
                catch { }

                string    sSQL   = "";
                DataTable dtHead = new DataTable();
                dtHead.TableName = "dtHead";
                DataColumn dc = new DataColumn();
                dc.ColumnName = "Date";
                dtHead.Columns.Add(dc);
                dc            = new DataColumn();
                dc.ColumnName = "Time";
                dtHead.Columns.Add(dc);
                DataRow dr = dtHead.NewRow();
                dr["Date"] = DateTime.Now.ToString("dd/MM/yyyy");
                dr["Time"] = DateTime.Now.ToString("HH:mm:ss");
                dtHead.Rows.Add(dr);

                DataTable dt = (DataTable)gridControl1.DataSource;

                Rep.dsPrint.Tables.Clear();
                Rep.dsPrint.Tables.Add(dt.Copy());
                Rep.dsPrint.Tables[0].TableName = "dtGrid";
                Rep.dsPrint.Tables.Add(dtHead.Copy());
                Rep.dsPrint.Tables[1].TableName = "dtHead";

                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);
            }
        }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        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);
            }
        }