/// <summary>
        /// 打印条形码
        /// </summary>
        /// <param name="cvtCode">条形码信息</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcode(string cvtCode)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x, y, width;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_Rectangle(42, 2, 97, 18, 5);
            bRet &= BarcodePrint.UTC_SetFont("黑体", 21, true, false, false, false);

            x = 44;
            y = 4;

            width = 51;
            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, cvtCode, "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
            x     = x + (width - BarcodePrint.UTC_GetTextWidth(cvtCode)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 10, cvtCode, 0);

            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
        /// <summary>
        /// 打印TCU箱的条形码
        /// </summary>
        /// <param name="bigBoxTCUCode">条形码信息</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcode_120X30(string code)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x = 18, y = 3, width = 72;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_Rectangle(10, 1, 98, 29, 5);
            bRet &= BarcodePrint.UTC_SetFont("黑体", 25, true, false, false, false);

            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 15, code, "CODE128B", 0, false);

            x     = x + (width - BarcodePrint.UTC_GetTextWidth(code)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 16, code, 0);

            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
        /// <summary>
        /// 打印TCU箱的条形码
        /// </summary>
        /// <param name="bigBoxTCUCode">条形码信息</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcode_60X20(string code)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x = 12, y = 3, width = 43;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_Rectangle(8, 1, 58, 19, 5);
            bRet &= BarcodePrint.UTC_SetFont("黑体", 11, true, false, false, false);

            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 10, code, "CODE128B", 0, false);

            x     = x + (width - BarcodePrint.UTC_GetTextWidth(code)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 11, code, 0);

            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
        /// <summary>
        /// 打印实物卡片条形码
        /// </summary>
        /// <param name="cvtNumber">CVT编号</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcodeCVTNumberList_BoxNo(string boxNo)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x, y = 0, width;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);
            bRet &= BarcodePrint.UTC_Rectangle(14, 1, 98, 28, 7);
            x     = 16;
            y     = 3;

            width = 51;
            x    += 16;
            y    += 5;
            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, boxNo, "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("黑体", 12, true, false, false, false);
            x     = x + (width - BarcodePrint.UTC_GetTextWidth(boxNo)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 10, boxNo, 0);

            bRet &= BarcodePrint.UTC_End(); //分页
            return(bRet);
        }
        /// <summary>
        /// 打印整车对应条形码(按整车厂要求)
        /// </summary>
        /// <param name="cvtCode">条形码信息</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcodeForVehicle(string cvtCode)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x, y, width;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_SetFont("仿宋_GB2312", 21, true, false, false, false);

            x = 42;
            y = 2;

            width = 55;
            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 10, cvtCode, "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("仿宋_GB2312", 11, true, false, false, false);
            x     = x + (width - BarcodePrint.UTC_GetTextWidth(cvtCode)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 11, cvtCode, 0);

            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
        /// <summary>
        /// 打印TCU盒的条形码
        /// </summary>
        /// <param name="strCodeFrist">第一个条码信息</param>
        /// <param name="strCodeSecond">第二个条码信息</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcodeBoxTCU(string strCodeFrist, string strCodeSecond)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x, y, width;

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_Rectangle(14, 1, 98, 30, 5);
            bRet &= BarcodePrint.UTC_SetFont("黑体", 21, true, false, false, false);

            //第一个条码
            x = 15;
            y = 2;

            width = 70;
            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 8, strCodeFrist, "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
            x     = x + (width - BarcodePrint.UTC_GetTextWidth(strCodeFrist)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 10, strCodeFrist, 0);

            //第二个条码
            x     = 15;
            y     = 15;
            width = 70;
            bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 8, strCodeFrist, "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
            x     = x + (width - BarcodePrint.UTC_GetTextWidth(strCodeFrist)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 10, strCodeFrist, 0);

            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
        /// <summary>
        /// 打印实物卡片条形码
        /// </summary>
        /// <param name="barcodeInfo">打印条形码时所需信息</param>
        /// <param name="amount">数量</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static public bool PrintBarcodeList(View_S_InDepotGoodsBarCodeTable barcodeInfo, decimal amount)
        {
            IntPtr hDC = IntPtr.Zero;
            bool   bRet = true;
            double x, y, width = 0;

            if (barcodeInfo.条形码.ToString().Length <= 4)
            {
                width = 15;
            }
            else
            {
                width = 30;
            }

            bRet &= BarcodePrint.UTC_Begin(hDC, false);

            bRet &= BarcodePrint.UTC_Rectangle(14, 1, 98, 30, 5);
            x     = 15;
            y     = 2.0;

            bRet &= BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false);

            //图号型号
            string goodsCode = "图号/型号:" + barcodeInfo.图号型号;

            bRet &= BarcodePrint.UTC_Text(x, y, goodsCode, 0);

            //产品名称
            string goodsName = "产品名称 :" + barcodeInfo.物品名称;

            bRet &= BarcodePrint.UTC_Text(x, y + 4, goodsName, 0);

            //规格
            string spec = "规    格 :" + barcodeInfo.规格;

            if (spec.Length > 34)
            {
                BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false);

                bRet &= BarcodePrint.UTC_Text(x, y + 8, spec, 0);

                BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false);
            }
            else if (spec.Length > 29)
            {
                bRet &= BarcodePrint.UTC_Text(x, y + 8, spec, 0);
            }
            else
            {
                bRet &= BarcodePrint.UTC_Text(x, y + 8, spec, 0);
            }

            //供应商
            string provider = "供 应 商 :" + barcodeInfo.供货单位;

            if (amount > 0)
            {
                provider += "   数量 :" + amount.ToString("F2");
            }

            bRet &= BarcodePrint.UTC_Text(x, y + 12, provider, 0);

            //批次
            string batchCode = "批    次 :" + barcodeInfo.批次号;

            if (barcodeInfo.材料类别名称 == "回收件" || barcodeInfo.材料类别名称 == "返修件")
            {
                batchCode += "(" + barcodeInfo.材料类别名称 + ")";
            }

            bRet &= BarcodePrint.UTC_Text(x, y + 16, batchCode, 0);

            //货架
            string shelf = string.Format("货    架 :{0}  层:{1}  列:{2}", barcodeInfo.货架, barcodeInfo.层, barcodeInfo.列);

            bRet &= BarcodePrint.UTC_Text(x, y + 20, shelf, 0);

            if (barcodeInfo.工位 != null)
            {
                //工位
                string workBench = string.Format("工    位 :{0}", barcodeInfo.工位);

                bRet &= BarcodePrint.UTC_Text(x, y + 24, workBench, 0);
            }

            if (spec.Length > 20)
            {
                x     += 9;
                width -= 2;
            }

            if (barcodeInfo.条形码.ToString().Length < 2)
            {
                x += 5;
            }

            bRet &= bRet = BarcodePrint.UTC_Barcode(x + 52, y + 5, width, 15, barcodeInfo.条形码.ToString(), "CODE128B", 0, false);

            bRet &= BarcodePrint.UTC_SetFont("黑体", 14, true, false, false, false);

            string barCodeText = barcodeInfo.条形码.ToString();

            x     = x + 48 + (width - BarcodePrint.UTC_GetTextWidth(barCodeText)) / 2;
            bRet &= BarcodePrint.UTC_Text(x, y + 21, barCodeText, 0);
            bRet &= BarcodePrint.UTC_End(); //分页

            return(bRet);
        }
Beispiel #8
0
        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="barcode">装配用管理条形码信息</param>
        /// <param name="err">错误信息, 如果没有则输出值为null</param>
        /// <returns>成功返回true, 失败返回false</returns>
        static private bool Print(AssemblyManagementBarcode barcode, out string err)
        {
            // 小条码纸适用
            err = null;

            IntPtr hDC         = IntPtr.Zero;
            bool   bRet        = true;
            double x           = 50;
            double y           = 0;
            double width       = 42;
            string barcodeType = "ETN-128";

            try
            {
                foreach (string barcodeContent in barcode.Barcode)
                {
                    //x = 45;
                    //bRet &= BarcodePrint.UTC_Begin(hDC, false);

                    //if (barcodeContent.Length <= 7)
                    //{
                    //    y = 4;

                    //    width = 22;     // OK, 扫描很快

                    //    // width = 25;  // OK, 扫描很快
                    //    // width = 30;  // OK, 扫描很快

                    //    // width = 15;  // NG, 效果不好
                    //    // width = 18;  // NG, 效果不好
                    //    // width = 20;  // NG, 效果不好

                    //    bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barcodeContent, barcodeType, 0, false);

                    //    bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
                    //    x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2;
                    //    bRet &= BarcodePrint.UTC_Text(x, y + 10, barcodeContent, 0);
                    //}
                    //else if (barcodeContent.Length < 15)
                    //{
                    //    y = 4;

                    //    width = 38;

                    //    bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barcodeContent, barcodeType, 0, false);

                    //    bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
                    //    x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2;
                    //    bRet &= BarcodePrint.UTC_Text(x, y + 10, barcodeContent, 0);
                    //}
                    //else
                    //{
                    //    y = 1;

                    //    width = 40;

                    //    int len = barcodeContent.Length / 2;
                    //    string data1 = barcodeContent.Substring(0, len);
                    //    string data2 = barcodeContent.Substring(len, barcodeContent.Length - len);

                    //    bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 6, data1, barcodeType, 0, false);
                    //    bRet &= bRet = BarcodePrint.UTC_Barcode(x, y + 8, width, 6, data2, barcodeType, 0, false);

                    //    bRet &= BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false);
                    //    x = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2;
                    //    bRet &= BarcodePrint.UTC_Text(x, y + 15, barcodeContent, 0);
                    //}

                    if (barcode.PartCode.Contains("RDC"))
                    {
                        x = 35;
                        y = 6;

                        bRet &= BarcodePrint.UTC_Begin(hDC, false);
                        bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, 50, 9,
                                                                barcode.PartCode, barcodeType, 0, false);

                        y += 11;

                        bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, 40, 9,
                                                                barcodeContent.Replace(barcode.PartCode, "").Trim(), barcodeType, 0, false);

                        y += 11;

                        bRet &= BarcodePrint.UTC_SetFont("黑体", 8, true, false, false, false);
                        x     = x + (width - BarcodePrint.UTC_GetTextWidth(barcodeContent)) / 2;
                        bRet &= BarcodePrint.UTC_Text(x, y, barcodeContent, 0);
                    }
                    else
                    {
                        string barCode = barcodeContent;
                        x     = 35;
                        y     = 6;
                        width = 38;

                        bRet &= BarcodePrint.UTC_Begin(hDC, false);
                        bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
                        double x1 = x + (width - BarcodePrint.UTC_GetTextWidth(barcode.PartName)) / 2;
                        bRet &= BarcodePrint.UTC_Text(x1, y, barcode.PartName, 0);

                        y += 5;

                        bRet &= bRet = BarcodePrint.UTC_Barcode(x, y, width, 9, barCode, barcodeType, 0, false);
                        bRet &= BarcodePrint.UTC_SetFont("黑体", 10, true, false, false, false);
                        double x2 = x + (width - BarcodePrint.UTC_GetTextWidth(barCode)) / 2;
                        bRet &= BarcodePrint.UTC_Text(x2, y + 10, barCode, 0);
                    }

                    bRet &= BarcodePrint.UTC_End(); //分页

                    if (!bRet)
                    {
                        return(bRet);
                    }
                }
            }
            catch (Exception exce)
            {
                err  = exce.Message;
                bRet = false;
            }

            return(bRet);
        }