public bool DrawPhoto(PrintParameter printPra)
        {
            Image img = null;

            if (printPra.personPhoto.Equals("") || !File.Exists(printPra.personPhoto))
            {
                img = Properties.Resources.blank;
            }
            else
            {
                img = Image.FromFile(printPra.personPhoto);
            }

            if (img.Equals(null))
            {
                return(false);
            }

            float _fwhith = GetHPixel(20.0f);
            float _fHight = GetVPixel(25.0f);

            string[] pos = printPra.photoPos.Split(',');
            float    X   = GetHPixel((float)Convert.ToDouble(pos[0]));
            float    Y   = GetVPixel((float)Convert.ToDouble(pos[1]));

            int ret = PrintPicture((int)X, (int)Y, printPra.personPhoto, (int)_fwhith, (int)_fHight);

            return(true);
        }
        private bool LINE_Format(ref Graphics g, PrintParameter printPra)
        {
            float X = 0;
            float Y = 0;

            string[] pos;

            int iCountParams = printPra.printstr.Length;

            if (true)
            {
                for (int i = 0; i < iCountParams; i++)
                {
                    pos = printPra.position[i].Split(',');
                    X   = GetHPixel((float)Convert.ToDouble(pos[0]));
                    Y   = GetVPixel((float)Convert.ToDouble(pos[1]));
                    g.DrawString(printPra.printstr[i], new Font(new FontFamily("宋体"), 8, System.Drawing.FontStyle.Bold),
                                 System.Drawing.Brushes.Black, X, Y);
                    Y += GetVPixel(4.5f);
                }
            }

            //if (cfg.bNeedPrintCardNo)
            //{
            //    g.DrawString(cfg.printfCardNo, new Font(new FontFamily(cfg.cardNo.fontName), cfg.cardNo.FontSize, System.Drawing.FontStyle.Regular),
            //            System.Drawing.Brushes.Black, GetHPixel(cfg.cardNo.X), GetHPixel(cfg.cardNo.Y));
            //}
            return(true);
        }
        public bool DrawPersonInfo(PrintParameter printPra, ref ZBRGraphics g)
        {
            //float X = 0;
            //float Y = 0;
            string[] pos;

            int iCountParams = printPra.printstr.Length;

            if (true)
            {
                for (int i = 0; i < iCountParams; i++)
                {
                    pos = printPra.position[i].Split(',');

                    //X = GetHPixel((float)Convert.ToDouble(pos[0]));
                    //Y = GetVPixel((float)Convert.ToDouble(pos[1]));

                    int X = Convert.ToInt32(GetHPixel((float)Convert.ToDouble(pos[0])));
                    int Y = Convert.ToInt32(GetVPixel((float)Convert.ToDouble(pos[1])));

                    int err = 0;
                    g.DrawText((int)X, (int)Y, Encoding.Default.GetBytes(printPra.printstr[i]), Encoding.Default.GetBytes("宋体"), 8, 0, 0, out err);
                    g.DrawText((int)X, (int)Y + 1, Encoding.Default.GetBytes(printPra.printstr[i]), Encoding.Default.GetBytes("宋体"), 8, 0, 0, out err);

                    //ret = PrintText((int)X, (int)Y, printPra.printstr[i], 8, "宋体", false);
                    //ret = PrintText((int)X, (int)Y + 1, printPra.printstr[i], 8, "宋体", false);
                }
            }
            return(true);
        }
        public bool DrawPersonInfo(ref Graphics g, PrintParameter printPra)
        {
            bool bDrawReslut = false;

            bDrawReslut = LINE_Format(ref g, printPra);
            return(bDrawReslut);
        }
Ejemplo n.º 5
0
        public void PrintFrontSideOnly(PrintParameter pParas, string drvName, out int jobID, out string msg)
        {
            PrintFormatView pfv = new PrintFormatView();

            jobID = 0;
            msg   = string.Empty;

            int         errValue; // value of 0 indicates no errors
            ZBRGraphics graphics = graphics = new ZBRGraphics();

            try
            {
                if (graphics.InitGraphics(ASCIIEncoding.ASCII.GetBytes(drvName), "job", out jobID, out errValue) == 0)
                {
                    msg = "Printing InitGraphics Error: " + errValue.ToString();
                    return;
                }

                LogHelper.WriteLog(typeof(ZBRPrinter), "InitGraphics 成功");

                //数据位置
                pfv.DrawPersonInfo(pParas, ref graphics);

                LogHelper.WriteLog(typeof(ZBRPrinter), "DrawPersonInfo 成功");

                //头像位置
                pfv.DrawPhoto(pParas, ref graphics);

                LogHelper.WriteLog(typeof(ZBRPrinter), "DrawPhoto 成功");

                if (graphics.PrintGraphics(out errValue) == 0)
                {
                    msg = "Printing PrintGraphics Error: " + errValue.ToString();
                    return;
                }
                LogHelper.WriteLog(typeof(ZBRPrinter), "PrintGraphics 成功");
            }
            catch (Exception ex)
            {
                msg += ex.ToString();
                System.Windows.Forms.MessageBox.Show(ex.ToString(), "PrintFrontSideOnly");
            }
            finally
            {
                if (graphics != null)
                {
                    // Starts the printing process and releases the Graphics Buffer
                    if (graphics.CloseGraphics(out errValue) == 0)
                    {
                        msg = "Printing CloseGraphics Error: " + errValue.ToString();
                    }
                    graphics = null;
                }
            }
        }
        public bool DrawFormat(PrintParameter printPra)
        {
            Bitmap img = new Bitmap(_height, _width);

            img.SetResolution(_dpiX, _dpiY);           //设置图片DPI
            Graphics g = Graphics.FromImage(img);

            if (!DrawFormat(ref g, printPra))   //绘制卡面
            {
                return(false);
            }
            image = img;
            return(true);
        }
        public bool DrawFormat(ref Graphics g, PrintParameter printPra)
        {
            if (!DrawPhotoBack(ref g, printPra.background))
            {
                return(false);
            }

            if (!DrawPhoto(ref g, printPra))
            {
                return(false);
            }

            if (!DrawPersonInfo(ref g, printPra))
            {
                return(false);
            }

            return(true);
        }
        private void tvCardInit_AfterSelect(object sender, TreeViewEventArgs e)
        {
            AccessOperator Accor = new AccessOperator();
            TreeNode       Node  = (TreeNode)tvCardInit.SelectedNode;

            ucFuncButton1.SetButtonEnabled(3, false);
            ucFuncButton1.SetButtonEnabled(4, false);
            if (Node.Parent == null)
            {
                pcPrintView.Image = Properties.Resources.社保正面;
            }
            else
            {
                string    strsql = "SELECT [Status01],[XM27],[SHBZHM28],[XB30],[SGRSBH37],[FullDATA59],[BY60],[BY61] FROM ProductData WHERE [SHBZHM28]='" + Node.Name + "'";
                DataTable dtread = Accor.ExecuteDataTable(strsql);
                if (dtread.Rows.Count > 0)
                {
                    GlobalClass.status     = dtread.Rows[0]["Status01"].ToString();
                    GlobalClass.name       = dtread.Rows[0]["XM27"].ToString();
                    GlobalClass.idcard     = dtread.Rows[0]["SHBZHM28"].ToString();
                    GlobalClass.sex        = dtread.Rows[0]["XB30"].ToString();
                    GlobalClass.provNo     = dtread.Rows[0]["SGRSBH37"].ToString();
                    GlobalClass.fulldata   = dtread.Rows[0]["FullDATA59"].ToString();
                    GlobalClass.idcardType = dtread.Rows[0]["BY60"].ToString();
                    GlobalClass.receipt    = dtread.Rows[0]["BY61"].ToString();

                    if (GlobalClass.status.Equals("1") || GlobalClass.status.Equals("2"))
                    {
                        ucFuncButton1.SetButtonEnabled(3, true);
                    }
                    else if (GlobalClass.status.Equals("3"))
                    {
                        ucFuncButton1.SetButtonEnabled(4, true);
                    }

                    PrintParameter  pp  = new PrintParameter();
                    PrintFormatView pfv = new PrintFormatView();
                    pfv.DrawFormat(pp);
                    pcPrintView.Image = pfv.image;
                }
            }
        }
        private void ProductCard(string name, string idcardType, string idNo, string receipt)
        {
            string ICdata    = "";
            string reportStr = "";
            string strsql    = "";

            ICdata = TCPinterface.WriteICBaseData(name, idcardType, idNo, receipt) + "#" + GlobalClass.fulldata;

            AccessOperator Accor = new AccessOperator();
            PrintParameter pp    = new PrintParameter();

            tvCardInit.Enabled = false;
            int ret = ProductExecute(pp, ICdata, out reportStr);

            if (ret != 0)
            {
                MsgPutOut("制作卡片", "制卡失败。错误:" + ret);
                strsql = "UPDATE ProductData SET [Status01]='2' WHERE [SHBZHM28]='" + idNo + "'";
                int count = Accor.ExecuteNonQuery(strsql);
                if (count <= 0)
                {
                    MsgPutOut("制作卡片", "更新本地数据库失败");
                }
            }
            else
            {
                MsgPutOut("制作卡片", "制卡成功!");
                string[] strrep = reportStr.Split('|');
                strsql = "UPDATE ProductData SET [Status01]='3',[CGBZ02]='1',[SBYY03]='',[KSDM04]='"
                         + strrep[0] + "',[YHKH05]='" + strrep[1] + "',[KSBM06]='" + strrep[2] + "',[ATR07]='" + strrep[3] + "' WHERE [SHBZHM28]='" + idNo + "'";
                int count = Accor.ExecuteNonQuery(strsql);
                if (count <= 0)
                {
                    MsgPutOut("制作卡片", "更新本地数据库失败");
                }
                ReportResult(name, idcardType, idNo, receipt, reportStr);
            }
            RefreshTree();
            tvCardInit.Enabled = true;
        }
        public bool DrawPersonInfo(PrintParameter printPra)
        {
            int   ret = 0;
            float X   = 0;
            float Y   = 0;

            string[] pos;

            int iCountParams = printPra.printstr.Length;

            if (true)
            {
                for (int i = 0; i < iCountParams; i++)
                {
                    pos = printPra.position[i].Split(',');
                    X   = GetHPixel((float)Convert.ToDouble(pos[0]));
                    Y   = GetVPixel((float)Convert.ToDouble(pos[1]));
                    ret = PrintText((int)X, (int)Y, printPra.printstr[i], 8, "宋体", false);
                    ret = PrintText((int)X, (int)Y + 1, printPra.printstr[i], 8, "宋体", false);
                    //Y += GetVPixel(3.5f);
                }
            }
            return(true);
        }
        public bool DrawPhoto(PrintParameter printPra, ref ZBRGraphics g)
        {
            Image img = null;

            LogHelper.WriteLog(typeof(PrintFormatView), "photo path:" + printPra.personPhoto);
            if (printPra.personPhoto.Equals("") || !File.Exists(printPra.personPhoto))
            {
                img = Properties.Resources.blank;
            }
            else
            {
                LogHelper.WriteLog(typeof(PrintFormatView), "printPra.personPhoto:" + printPra.personPhoto);
                img = MyImage.GetFile(printPra.personPhoto);
                //img = Image.FromFile(printPra.personPhoto);
            }

            if (img == null)
            {
                return(false);
            }

            int _fwhith = Convert.ToInt32(GetHPixel(20.0f));
            int _fHight = Convert.ToInt32(GetVPixel(25.0f));

            string[] pos = printPra.photoPos.Split(',');

            int X = Convert.ToInt32(GetHPixel((float)Convert.ToDouble(pos[0])));
            int Y = Convert.ToInt32(GetVPixel((float)Convert.ToDouble(pos[1])));


            //int ret = PrintPicture((int)X, (int)Y, printPra.personPhoto, (int)_fwhith, (int)_fHight);
            int errValue = 0;

            g.DrawImage(Encoding.Default.GetBytes(printPra.personPhoto), (int)X, (int)Y, (int)_fwhith, (int)_fHight, out errValue);
            return(true);
        }
Ejemplo n.º 12
0
        //public int PrintCard(PrintParameter pParas, out int err)
        //{
        //    SampleCodeGraphics prn = null;
        //    string msg = string.Empty;
        //    int jobID = 0;
        //    err = 0;
        //    try
        //    {
        //        if (EndPostionCard(1, 0, out err) == 1)
        //        {
        //            if (MoveToPrintLocation(out err) == 0)
        //            {
        //                return 0;
        //            }

        //            prn = new SampleCodeGraphics();
        //            if (IsPrinterReady(out err) == 1)
        //            {
        //                prn.PrintFrontSideOnly(pParas, printName,out jobID, out msg);
        //                if (string.IsNullOrEmpty(msg))
        //                {
        //                    WaitForJobToComplete(printName, jobID, out msg);
        //                }
        //            }

        //            LogHelper.WriteLog(typeof(ZBRPrinter), "PrintCard: " + msg);
        //        }
        //        return 1;
        //    }
        //    catch (System.Exception ex)
        //    {
        //        msg += ex.Message;
        //        MessageBox.Show(ex.ToString(), "PrintCard");
        //        LogHelper.WriteLog(typeof(ZBRPrinter), "PrintCard: " + msg);
        //        return 0;
        //    }
        //    finally
        //    {
        //        if (prn != null)
        //        {
        //            prn = null;
        //        }
        //    }


        //}


        public int PrintCard(PrintParameter pParas, out int err)
        {
            LogHelper.WriteLog(typeof(FormMain), "PrintCard");

            SampleCodeGraphics prn = null;
            string             msg = string.Empty;
            int jobID = 0;

            err = 0;
            try
            {
                LogHelper.WriteLog(typeof(ZBRPrinter), "EndPostionCard Begin");
                if (EndPostionCard(1, 0, out err) == 1)
                {
                    LogHelper.WriteLog(typeof(ZBRPrinter), "EndPostionCard 成功");

                    LogHelper.WriteLog(typeof(ZBRPrinter), "MoveToPrintLocation Begin");

                    if (MoveToPrintLocation(out err) == 0)
                    {
                        LogHelper.WriteLog(typeof(ZBRPrinter), "MoveToPrintLocation 失败: err +" + err);
                        return(0);
                    }

                    LogHelper.WriteLog(typeof(ZBRPrinter), "MoveToPrintLocation 成功: err +" + err);

                    prn = new SampleCodeGraphics();
                    if (IsPrinterReady(out err) == 1)
                    {
                        LogHelper.WriteLog(typeof(ZBRPrinter), "IsPrinterReady 成功: err +" + err);
                        prn.PrintFrontSideOnly(pParas, printName, out jobID, out msg);

                        LogHelper.WriteLog(typeof(ZBRPrinter), "PrintFrontSideOnly: msg +" + msg);

                        if (string.IsNullOrEmpty(msg))
                        {
                            WaitForJobToComplete(printName, jobID, out msg);
                        }

                        return(1);
                    }
                    else
                    {
                        LogHelper.WriteLog(typeof(ZBRPrinter), "IsPrinterReady 失败: err +" + err);
                        return(0);
                    }
                }
                else
                {
                    LogHelper.WriteLog(typeof(ZBRPrinter), "EndPostionCard 失败: err +" + err);
                    return(0);
                }
            }
            catch (System.Exception ex)
            {
                msg += ex.Message;
                MessageBox.Show(ex.ToString(), "PrintCard");
                LogHelper.WriteLog(typeof(ZBRPrinter), "PrintCard: " + msg);
                return(0);
            }
            finally
            {
                if (prn != null)
                {
                    prn = null;
                }
            }
        }
        public int ProductExecute(PrintParameter printPra, string ICdata, out string outCardData)
        {
            int ret = 0;

            outCardData = "";
            PrintProduct ppro = new PrintProduct();
            //打开打印机
            int printHandle = PrintProduct.OpenPrinter(printName);

            if (printHandle <= 0)
            {
                MsgPutOut("制作卡片", "打开打印机失败");
                return(-101);
            }

            //进卡
            int steps = 100;

            ret = PrintProduct.FeedCard(printHandle, 0, steps);
            if (ret != 1)
            {
                ucFlowChart1.SetStepStatus(1, false);
                MsgPutOut("制作卡片", "进卡失败");
                return(-102);
            }
            ucFlowChart1.SetStepStatus(1, true);
            this.Refresh();

            //写IC
            MsgPutOut("制作卡片", "正在写卡,请耐心等待...");
            ret = WriteIC(ICdata);
            if (ret != 0)
            {
                ucFlowChart1.SetStepStatus(2, false);
                PrintProduct.Eject(printHandle);
                MsgPutOut("制作卡片", "写卡失败,错误代码:" + ret);
                return(-103);
            }

            //读卡
            ret = ReadCardInfo(out outCardData);
            if (ret != 0)
            {
                MsgPutOut("制作卡片", "读卡失败,错误代码:" + ret);
                return(-104);
            }
            ucFlowChart1.SetStepStatus(2, true);
            this.Refresh();

            //排版照片
            if (!ppro.DrawPhoto(printPra))
            {
                MsgPutOut("制作卡片", "排版照片失败");
                return(-105);
            }

            //排版个人信息
            if (!ppro.DrawPersonInfo(printPra))
            {
                MsgPutOut("制作卡片", "排版个人信息失败");
                return(-106);
            }

            //开始打印
            MsgPutOut("制作卡片", "正在打印,请耐心等待...");
            ret = PrintProduct.StartPrint(printHandle, 2, 0);
            if (ret != 1)
            {
                ucFlowChart1.SetStepStatus(3, false);
                MsgPutOut("制作卡片", "打印失败");
                return(-107);
            }
            ucFlowChart1.SetStepStatus(3, true);
            this.Refresh();
            return(0);
        }