/// <summary>
        /// 현금영수증 취소요청
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCashCancel_Click(object sender, EventArgs e)
        {
            try
            {
                string ret = KSNET.Cancel(JobKind.CancelCash,
                                          CashKind.Persnal,
                                          this.txtTid.Text.Trim(),
                                          txtCardNo.Text.Trim(),
                                          "",
                                          "",
                                          this.txtAmt.Text.Trim(),
                                          this.txtOrgRegNo.Text.Trim(),
                                          this.txtOrgRegDate.Text.Trim(),
                                          1,
                                          "");

                ReqClear();
                fnClear();
                Van.frmVanLoading f = new frmVanLoading("현금영수증 승인을 요청합니다.",
                                                        VanType.KSNET,
                                                        frmVanLoading.JobKind.Communication,
                                                        txtServerIP.Text.Trim(),
                                                        int.Parse(txtServerPort.Text.Trim()),
                                                        ret,
                                                        "GetRequest");
                f.ArgJobKinds = JobKind.CancelCash;
                f.Owner       = this;
                f.ShowDialog();

                if (_ReqData.IsAgreeError)
                {
                    Basic.ShowMessage(1, _ReqData.Message);
                    return;
                }

                Application.DoEvents();


                this.gridSend.DataSource    = _ReqData.dsDoc.Tables[0].Copy();
                this.gridRecevie.DataSource = _ReqData.dsDoc.Tables[1].Copy();

                this.gridRecevie.Refresh();
                this.gridSend.Refresh();


                txtSendData.Text     = _ReqData.FullSendData;
                txtReceviedData.Text = _ReqData.FullRequestData;
            }
            catch (Exception ex)
            {
                Basic.ShowMessage(3, ex.Message);
            }
        }
        private void SendData(string str)
        {
            try
            {
                txtSendData.Text     = "";
                txtReceviedData.Text = "";
                string scope = this.txtScope.Text.Trim();

                ReqClear();
                Van.frmVanLoading f = new frmVanLoading("승인요청 중 입니다.",
                                                        VanType.KICC,
                                                        frmVanLoading.JobKind.Communication,
                                                        this.txtKiccIP.Text.Trim(),
                                                        int.Parse(this.txtKiccPort.Text.Trim()),
                                                        str,
                                                        "GetRequest");

                f.Owner = this;
                f.ShowDialog();
                Application.DoEvents();
                if (this.gridSend.DataSource != null)
                {
                    ((DataTable)this.gridSend.DataSource).Dispose();
                    this.gridSend.DataSource = null;
                }

                if (this.gridRecevie.DataSource != null)
                {
                    ((DataTable)this.gridRecevie.DataSource).Dispose();
                    this.gridRecevie.DataSource = null;
                }



                this.gridSend.DataSource    = _ReqData.dsDoc.Tables[0].Copy();
                this.gridRecevie.DataSource = _ReqData.dsDoc.Tables[1].Copy();

                this.gridRecevie.Refresh();
                this.gridSend.Refresh();


                txtSendData.Text     = _ReqData.FullSendData;
                txtReceviedData.Text = _ReqData.FullRequestData;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void btnMSR_Click(object sender, EventArgs e)
        {
            try
            {
                ReqClear();
                Van.frmVanLoading fCash = new frmVanLoading("MSR 입력요청",
                                                            VanType.KICC,
                                                            frmVanLoading.JobKind.MSR,
                                                            "GetRequest");

                fCash.Amount    = 10000;
                fCash.SignPort  = int.Parse(this.txtSignPadPort.Text.Trim());
                fCash.SignSpeed = 57600;
                fCash.Owner     = this;
                fCash.ShowDialog();
                Application.DoEvents();

                if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.PortError).ToString())
                {
                    MessageBox.Show("싸인패드 연결실패 입니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.NotData).ToString())
                {
                    MessageBox.Show("반환된 결과 값이 없습니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.TimeOut).ToString())
                {
                    MessageBox.Show("제한시간 초과 입니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.Communication).ToString())
                {
                    MessageBox.Show("싸인패드와 통신할 수 없습니다.");
                    return;
                }


                txtCardNo.Text = _ReqData.CashRegNumber;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnCardReg_Click(object sender, EventArgs e)
        {
            Van.RecivedData reqdata = new RecivedData();
            try
            {
                string scope = this.txtScope.Text.Trim();
                string str   = Van.KICC.Reg(Van.JobKind.RegCard,
                                            Van.CashKind.None,
                                            this.txtTid.Text.Trim(),
                                            this.txtCardNo.Text.Trim(),
                                            scope,
                                            txtAmtSplit.Text.Trim(),
                                            txtAmt.Text.Trim());

                if (chkSign.Checked)
                {
                    //*********************************************************************************
                    //싸인을 받는다.
                    if (this.pictureEdit1.Image != null)
                    {
                        pictureEdit1.Image.Dispose();
                        pictureEdit1.Image = null;
                    }



                    ReqClear();
                    Van.frmVanLoading fCash = new frmVanLoading("고객싸인요청",
                                                                VanType.KICC,
                                                                frmVanLoading.JobKind.Sign,
                                                                "GetRequest");

                    fCash.Amount         = 10000;
                    fCash.SignPadReqdata = str;
                    fCash.SignPort       = int.Parse(this.txtSignPadPort.Text.Trim());
                    fCash.SignSpeed      = 57600;
                    fCash.Owner          = this;
                    fCash.VanServerIP    = this.txtKiccIP.Text.Trim();
                    fCash.VanServerPort  = int.Parse(this.txtKiccPort.Text.Trim());
                    fCash.ShowDialog();


                    Application.DoEvents();

                    if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.PortError).ToString())
                    {
                        MessageBox.Show("싸인패드 연결실패 입니다.");
                        return;
                    }
                    else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.NotImage).ToString())
                    {
                        MessageBox.Show("싸인이미지가 없습니다.");
                        return;
                    }
                    else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.TimeOut).ToString())
                    {
                        MessageBox.Show("제한시간 초과 입니다.");
                        return;
                    }
                    else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.Communication).ToString())
                    {
                        MessageBox.Show("싸인패드와 통신할 수 없습니다.");
                        return;
                    }
                    else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.NotData).ToString())
                    {
                        MessageBox.Show("데이터가 없습니다..");
                        return;
                    }
                    //*********************************************************************************

                    if (this.pictureEdit1.Image != null)
                    {
                        this.pictureEdit1.Image.Dispose();
                        this.pictureEdit1.Image = null;
                    }

                    Image imgs = mImage.ByteArrayToImage(_ReqData.SignData);

                    this.pictureEdit1.Image = mImage.ByteArrayToImage(_ReqData.SignData);

                    Van.SignViewer f = new SignViewer(imgs);
                    f.ShowDialog();
                }



                if (!_ReqData.IsSignPadAgree)
                {
                    SendData(str);
                }



                reqdata = _ReqData;

                if (reqdata.IsAgreeError)
                {
                    MessageBox.Show(reqdata.Message);
                    return;
                }


                if (_ReqData.IsSignPadAgree)
                {
                    if (this.gridSend.DataSource != null)
                    {
                        ((DataTable)this.gridSend.DataSource).Dispose();
                        this.gridSend.DataSource = null;
                    }

                    if (this.gridRecevie.DataSource != null)
                    {
                        ((DataTable)this.gridRecevie.DataSource).Dispose();
                        this.gridRecevie.DataSource = null;
                    }

                    this.gridSend.DataSource    = _ReqData.dsDoc.Tables[0].Copy();
                    this.gridRecevie.DataSource = _ReqData.dsDoc.Tables[1].Copy();

                    this.gridRecevie.Refresh();
                    this.gridSend.Refresh();


                    txtSendData.Text     = _ReqData.FullSendData;
                    txtReceviedData.Text = _ReqData.FullRequestData;
                }



                txtOrgRegNo.Text        = reqdata.AgreeNo;
                this.txtOrgRegDate.Text = reqdata.AgreeDate.Substring(0, 6);
                InvokeOnClick(btnCardCancel, new EventArgs());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnCashReg_Click(object sender, EventArgs e)
        {
            try
            {
                txtSendData.Text     = "";
                txtReceviedData.Text = "";


                if (!chkSign.Checked)
                {
                    goto _lblReg;
                }
                /*************************************************************************/
                //싸인패드 식별번호 요청
                /*************************************************************************/
                ReqClear();
                Van.frmVanLoading fCash = new frmVanLoading("현금영수증 식별번호 요청",
                                                            VanType.KICC,
                                                            frmVanLoading.JobKind.CashRegNumber,
                                                            "GetRequest");


                fCash.SignPort      = int.Parse(this.txtSignPadPort.Text.Trim());
                fCash.SignSpeed     = 57600;
                fCash.Owner         = this;
                fCash.VanServerIP   = this.txtKiccIP.Text.Trim();
                fCash.VanServerPort = int.Parse(this.txtKiccPort.Text.Trim());

                fCash.ShowDialog();
                Application.DoEvents();

                if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.PortError).ToString())
                {
                    MessageBox.Show("싸인패드 연결실패 입니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.NotData).ToString())
                {
                    MessageBox.Show("반환된 결과 값이 없습니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.TimeOut).ToString())
                {
                    MessageBox.Show("제한시간 초과 입니다.");
                    return;
                }
                else if (_ReqData.RequestCode == ((int)Van.frmVanLoading.RS232Err.Communication).ToString())
                {
                    MessageBox.Show("싸인패드와 통신할 수 없습니다.");
                    return;
                }


                /*************************************************************************/


                txtCardNo.Text = _ReqData.CashRegNumber;
_lblReg:

                string str = Van.KICC.Reg(Van.JobKind.RegCash,
                                          Van.CashKind.Persnal,
                                          this.txtTid.Text.Trim(),
                                          txtCardNo.Text.Trim(),
                                          "",
                                          "",
                                          txtAmt.Text.Trim());
                SendData(str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 신용카드 취소요청
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCardCancel_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.pictureEdit1.Image != null)
                {
                    this.pictureEdit1.Image.Dispose();
                    this.pictureEdit1.Image = null;
                }
                this.txtSign.Text = "";

                string SignDataString = "";
                Image  SignImage      = null;
                ReqClear();
                fnClear();
                GetSignImage(ref SignDataString, ref SignImage);

                string signdatastring = _ReqData.SignStringData == null ? "" : _ReqData.SignStringData;

                this.pictureEdit1.Image = SignImage;
                this.txtSign.Text       = SignDataString;

                string ret = KSNET.Cancel(JobKind.CancelCard,
                                          CashKind.None,
                                          this.txtTid.Text.Trim(),
                                          txtCardNo.Text.Trim(),
                                          txtScope.Text.Trim(),
                                          this.txtAmtSplit.Text.Trim(),
                                          txtAmt.Text.Trim(),
                                          txtOrgRegNo.Text.Trim(),
                                          txtOrgRegDate.Text.Trim(),
                                          1,
                                          signdatastring);

                ReqClear();

                Van.frmVanLoading f = new frmVanLoading(" 승인인을 요청합니다.",
                                                        VanType.KSNET,
                                                        frmVanLoading.JobKind.Communication,
                                                        txtServerIP.Text.Trim(),
                                                        int.Parse(txtServerPort.Text.Trim()),
                                                        ret,
                                                        "GetRequest");
                f.ArgJobKinds      = JobKind.CancelCard;
                f.CardApprovalType = signdatastring == "" ? CARD_APPROVAL_TYPE.DDC : CARD_APPROVAL_TYPE.DSC;

                f.Owner = this;
                f.ShowDialog();

                if (_ReqData.IsAgreeError)
                {
                    Basic.ShowMessage(1, _ReqData.Message);
                    return;
                }

                Application.DoEvents();
                if (this.gridSend.DataSource != null)
                {
                    ((DataTable)this.gridSend.DataSource).Dispose();
                    this.gridSend.DataSource = null;
                }

                if (this.gridRecevie.DataSource != null)
                {
                    ((DataTable)this.gridRecevie.DataSource).Dispose();
                    this.gridRecevie.DataSource = null;
                }

                this.gridSend.DataSource    = _ReqData.dsDoc.Tables[0].Copy();
                this.gridRecevie.DataSource = _ReqData.dsDoc.Tables[1].Copy();

                this.gridRecevie.Refresh();
                this.gridSend.Refresh();


                txtSendData.Text     = _ReqData.FullSendData;
                txtReceviedData.Text = _ReqData.FullRequestData;
            }
            catch (Exception ex)
            {
                Basic.ShowMessage(3, ex.Message);
            }
        }