예제 #1
0
        public static bool WaitForCardCompletion(SP75S.CARDIDTYPE lpCardID, string PrintNames, ref string Msg)
        {
            SP75S.CARD_INFO_1 ci1 = new  SP75S.CARD_INFO_1();
            SP75S.CARD_INFO_2 ci2 = new  SP75S.CARD_INFO_2();
            int cbNeeded          = 0;

            ci1.bActive = 1;

            string Messages = "";

            while (IsLoop)
            {
                try
                {
                    if (Messages == "")
                    {
                        Messages = ShowError(PrintNames);
                        if (Messages != "")
                        {
                            Msg = Messages;
                        }
                    }
                }
                catch
                {
                }

                if (SP75S.GetCardStatus(lpCardID, 1, ref ci1,
                                        System.Runtime.InteropServices.Marshal.SizeOf(ci1), ref cbNeeded))
                {
                    if (ci1.bActive != 1)
                    {
                        if (SP75S.GetCardStatus(lpCardID, 2, ref ci2,
                                                System.Runtime.InteropServices.Marshal.SizeOf(ci2), ref cbNeeded))
                        {
                            if (ci2.TimeCompleted.wMonth != 0)
                            {
                                break;
                            }
                        }
                    }
                }
                System.Threading.Thread.Sleep(500);
                Application.DoEvents();
            }
            return((ci1.bActive != 1) && (ci2.TimeCompleted.wMonth != 0));
        }
예제 #2
0
        private void DataCard_SP75S(DataTable dt, string BizCode, bool IsNewData)
        {
            try
            {
                //SP75S.ClearAllCardErrors(PrintName);

                DataCard_SP75_IsNewData = IsNewData;
                DbStatus = DataBaseStatus.LOOP;
                DataTable mdt = dt.Copy();
                for (int i = 0; i < mdt.Rows.Count; i++)
                {
                    rPrintData = null;
                    rPrintData = mdt.Rows[i];

ReTry:

                    using (PrintDocument pd = new PrintDocument())
                    {
                        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

                        pd.PrinterSettings.PrinterName   = PrintName;
                        pd.DefaultPageSettings.Landscape = true;

                        pd.PrinterSettings.Duplex = Duplex.Simplex;

                        pd.Print();
                        pd.Dispose();
                    }

                    int Wait = 0;
                    while (true)
                    {
                        if (DataCard_SP75_hDC != 0 || Wait > 6)
                        {
                            break;
                        }
                        Application.DoEvents();
                        System.Threading.Thread.Sleep(500);
                        Wait++;
                    }

                    string Messages = "";
                    if (!SP75S.WaitForCardCompletion(DataCard_SP75_lpCardIDy, PrintName, ref Messages))
                    {
                        this.RaiseErrorEvent(new Exception("카드를 출력하는 동안 다음 카드를 기다릴 수 없습니다."));
                        return;

                        break;
                    }

                    if (Messages != "")
                    {
                        string str = "위와 같은 오류로 인해 카드가 발급되지 않았습니다." + System.Environment.NewLine + System.Environment.NewLine +
                                     "카드번호 = {0} \n\r\n\r회원번호 = {1} \n\r\n\r회원이름 = {2} \n\r\n\r해당 데이터를 다시 출력 하시겠숩니까?\n\r\r\n\r\n프린터를 중단 하시려면 [취소]를 \r\n\r\n다시 출력 하시려면 [예]를\n\n\r\r다음데이터를 출력하시려면 [아니오]를 \n\r\n\r눌러주세요 ";

                        str = string.Format(str, rPrintData["CARD_ISSUE_NO"].ToString(), rPrintData["MEMBER_NO"].ToString(), rPrintData["MEMBER_NAME_KOR"].ToString());

                        DialogResult dr = MessageBox.Show(Messages += str, "확인", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
                        if (dr == DialogResult.Yes)
                        {
                            goto ReTry;
                        }
                        else if (dr == DialogResult.Cancel)
                        {
                            break;
                        }
                    }
                    else  // 성공했을 경우
                    {
                        DbStatus = DataBaseStatus.LOOP;

                        suSender sender = new suSender();
                        sender.BizCode = BizCode;
                        sender.sucMode = IsNewData ? SucessMode.NewData : SucessMode.Magstripe;

                        this.RaiseDataSucessEvent(sender, rPrintData);


lblWait:
                        int start = System.Environment.TickCount;
                        bool IsLoops = true;
                        //DB처리를 하는 동안 기다린다. 10초 셋트 ....
                        while (DbStatus == DataBaseStatus.LOOP && IsLoops)
                        {
                            int end = System.Environment.TickCount;
                            if (end - start > 10000)
                            {
                                IsLoops = false;
                            }
                            System.Threading.Thread.Sleep(10);
                            Application.DoEvents();
                        }

                        //timeout때문에 빠져나갔다. 다시 물어본다.
                        if (DbStatus == DataBaseStatus.LOOP)
                        {
                            if (MessageBox.Show("DB 처리에 대한 응답이 없어 대기를 종료하고 다음 데이터를 출력합니다. \n\rDB 관련 응답이 올때까지 계속 기다리겠습니까?", "확인", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                goto lblWait;
                            }
                        }
                        else if (DbStatus == DataBaseStatus.FALSE)
                        {
                            if (MessageBox.Show("DB 처리시 에러가 있었습니다. \n\r카드출력을 중지 하시겠습니까?", "확인", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                break;
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.RaiseErrorEvent(ex);
            }
        }
예제 #3
0
        private void  pd_PrintPage(object sender, PrintPageEventArgs e)
        {
            try
            {
                if (!DataCard_SP75_IsNewData)
                {
                    goto ImageSkip;
                }

                Graphics     eg           = e.Graphics;
                StringFormat stringformat = new StringFormat();
                stringformat.LineAlignment = StringAlignment.Near;   //FAR:오른쪽정렬, NEAR:왼쪽정렬
                stringformat.Alignment     = StringAlignment.Near;


                // x 좌우 y 상하 가로출력을 했다.
                //예>eg.DrawString(rPrintData["MEMBER_NAME_KOR"].ToString().Trim(), new System.Drawing.Font("HY헤드라인M", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.Black, new PointF(320, 180), stringformat);
                //예>eg.DrawString(rPrintData["MEMBER_NO"].ToString().Trim(), new System.Drawing.Font("HY헤드라인M", 15.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.Black, new PointF(320, 205), stringformat);
                //eg.DrawString(string.Format("{0000000000:00-000000-00}", int.Parse(rPrintData["MEMBER_NO"].ToString().Trim())),
                //                            new System.Drawing.Font("Arial"    , 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.Black, new PointF(320, 160), stringformat);
                //eg.DrawString(rPrintData["MEMBER_NAME_KOR"].ToString().Trim(),
                //                            new System.Drawing.Font("HY울릉도M", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.Black, new PointF(320, 180), stringformat);

                //MEMBER_NO, MEMBER_NAME_KOR 2010.05.17 YSM
                //MEMBER_NO
                eg.DrawString(string.Format("{0000000000:00-000000-00}", int.Parse(rPrintData["MEMBER_NO"].ToString().Trim())),
//                                             new System.Drawing.Font("HY헤드라인M"          , 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.DarkSlateGray, new PointF(55, 145), stringformat);
                              new System.Drawing.Font("HY울릉도B", 13F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.DarkSlateGray, new PointF(55, 145), stringformat);
                //MEMBER_NAME_KOR
                eg.DrawString(rPrintData["MEMBER_NAME_KOR"].ToString().Trim(),
                              new System.Drawing.Font("HY울릉도B", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.DarkSlateGray, new PointF(55, 165), stringformat);

                //MEMBER_GROUP_CODE_NAME_ENG 2010.05.18
                eg.DrawString(rPrintData["MEMBER_GROUP_CODE_NAME_ENG"].ToString().Trim(),
                              new System.Drawing.Font("Lucida Calligraphy", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))), System.Drawing.Brushes.DarkGreen, new PointF(35, 47), stringformat);

                if (!rPrintData["PHOTO"].Equals(System.DBNull.Value))
                {
                    Image img = byteArrayToImage((Byte[])rPrintData["PHOTO"]);


                    //예> eg.DrawImage(img, 240, 10, 75, 90);//X좌, Y, 6.1cm->2.401517in X 100
//                     eg.DrawImage(img, 255, 49, 60, 72);
                    eg.DrawImage(img, 254, 49, 62, 73);
                    eg.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    eg.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;


                    if (img != null)
                    {
                        img.Dispose();
                        img = null;
                    }
                }

ImageSkip:

                DataCard_SP75_hDC = (int)e.Graphics.GetHdc();
                if (!SP75S.GetCardId(DataCard_SP75_hDC, ref DataCard_SP75_lpCardIDy))
                {
                    this.RaiseErrorEvent(new Exception("카드 출력 정보를 읽을 수 없습니다."));
                    return;
                }



                if (!SP75S.SetMagstripeFormat(DataCard_SP75_hDC,
                                              (int)SP75S.dwTrackFormat.ICE_MS_IAT,
                                              (int)SP75S.dwCoercivity.ICE_MS_COERCIVITY_USE_DRIVER))
                {
                    this.RaiseErrorEvent(new Exception("마그네틱 포멧을 지정 할 수 없습니다."));
                    return;
                }



                SP75S.TRACKDATA pTrack1 = new SP75S.TRACKDATA();
                SP75S.TRACKDATA pTrack2 = new SP75S.TRACKDATA();
                SP75S.TRACKDATA pTrack3 = new SP75S.TRACKDATA();

                byte[] b2      = new byte[256];
                string strData = rPrintData["CARD_ISSUE_NO"].ToString().Trim() + "=" + rPrintData["MEMBER_NO"].ToString().Trim();
                Encoding.ASCII.GetBytes(strData, 0, strData.Length, b2, 0);

                pTrack2.nLength   = strData.Length;
                pTrack2.TrackData = b2;

                //마그네틱 Write
                if (!SP75S.EncodeMagstripe(DataCard_SP75_hDC, ref pTrack1, ref pTrack2, ref pTrack3, 0))
                {
                    this.RaiseErrorEvent(new Exception("마그네틱에 정보를 기록할 수 없습니다."));
                    return;
                }
            }
            catch (Exception ex)
            {
                this.RaiseErrorEvent(ex);
            }
        }