public int RunOper(int OperId, int CommandMode, int CommandMode2, int Amount, InpasChk CurrentCheck, string RRN)
        {
            TransactionInProcess = true;
            if (CurrentCheck != null)
            {
                currentCheck = CurrentCheck;
                Amount       = Math.Abs((int)(currentCheck.Ammount));
            }
            string resStr = "";
            int    res    = DApi.Exchange(OperId, CommandMode, CommandMode2, Amount, terminalId, RRN, ExchangeComplited, out resStr);

            if (res != 0)
            {
                TransactionInProcess = false;
                string Mess = "Ошибка старта операции" + OperId + " на терминале пластиковых карт." + Environment.NewLine + resStr;
                Mess += "Код ошибки: " + res;
                Mess += "Описание ошибки: " + resStr;
                Utils.ToCardLog(Mess);
                frmAllertMessage Mf = new frmAllertMessage(Mess);
                Mf.ShowDialog();
            }
            return(res);
        }
        private void ExchangeComplited(int Code, string CodeDescr, ISAPacket response)
        {
            /*
             * if (OnExchangeComplited != null)
             * {
             *  OnExchangeComplited(this, Code, CodeDescr, response.ReceiptData);
             * }
             * */
            string PrintSlipData = "";

            Utils.ToCardLog(string.Format("ExchangeComplited Code={0} ", Code));
            if (Code != 0)
            {
                string Mess = "";   // "Ошибка проведения операции на терминале пластиковых карт." + Environment.NewLine + response.TextResponse;
                Mess += " Ошибка проведения операции" + Environment.NewLine + " на терминале пластиковых карт." + Environment.NewLine;
                Mess += Environment.NewLine;
                Mess += "Терминал: " + terminalId + Environment.NewLine;
                Mess += Environment.NewLine;
                Mess += " Код ошибки: " + Code + Environment.NewLine;
                Mess += " Описание ошибки: " + Environment.NewLine + CodeDescr + Environment.NewLine;
                Mess += Environment.NewLine;
                if (currentCheck != null)
                {
                    foreach (InpasChk Chk2 in currentCheck.AllChks)
                    {
                        Mess += " Чек в Алохе " + Chk2.Num + Environment.NewLine;
                    }
                    Mess += " Сумма " + (double)currentCheck.Ammount / 100D;
                }
                Utils.ToCardLog(Mess);
                frmAllertMessage Mf = new frmAllertMessage(Mess);
                Mf.ShowDialog();

                /*
                 * PrintSlipData = "Ошибка проведения операции" + Environment.NewLine + " на терминале пластиковых карт.";
                 * PrintSlipData += "Код ошибки: " + response.Status;
                 * PrintSlipData += "Описание ошибки: " + response.Status;
                 *
                 * if (currentCheck != null)
                 * {
                 *  PrintSlipData += "Чек в Алохе " + currentCheck.AlohaCheckNum;
                 * }
                 * */
                PrintSlipData += Environment.NewLine;
                PrintSlipData += Environment.NewLine;
                PrintSlipData += Environment.NewLine;
                PrintSlipData += Mess;
                PrintSlipData += Environment.NewLine;
                PrintSlipData += Environment.NewLine;
                PrintSlipData += Environment.NewLine;
                PrintSlipData += "===========================================";
            }
            else
            {
                Utils.ToCardLog(string.Format("ExchangeComplited response.Status ={0} ", response.Status));
                if ((response.Status != 1) && (response.Status != 16))
                {
                    string Mess = "Ошибка результата операции на терминале пластиковых карт." + Environment.NewLine + response.TextResponse + Environment.NewLine;
                    Mess += Environment.NewLine;
                    Mess += "Терминал: " + terminalId + Environment.NewLine;
                    Mess += Environment.NewLine;
                    Mess += "Ошибка проведения операции " + Environment.NewLine + " на терминале пластиковых карт." + Environment.NewLine;
                    Mess += Environment.NewLine;
                    Mess += "  Код операции: " + response.OperationCode + Environment.NewLine;
                    Mess += "  Код ответа: " + response.Status + Environment.NewLine;
                    Mess += "  Дополнительные данные ответа: " + Environment.NewLine + response.TextResponse + Environment.NewLine;
                    Mess += Environment.NewLine;

                    if (currentCheck != null)
                    {
                        foreach (InpasChk Chk2 in currentCheck.AllChks)
                        {
                            Mess += " Чек в Алохе " + Chk2.Num + Environment.NewLine;
                        }
                        Mess += "; Сумма " + (double)currentCheck.Ammount / 100D;
                    }
                    Utils.ToCardLog(Mess);
                    frmAllertMessage Mf = new frmAllertMessage(Mess);
                    Mf.ShowDialog();

                    PrintSlipData += Environment.NewLine;
                    PrintSlipData += Environment.NewLine;
                    PrintSlipData += Environment.NewLine;
                    PrintSlipData += Mess;
                    PrintSlipData += Environment.NewLine;
                    if (response.ReceiptData != null)
                    {
                        PrintSlipData += response.ReceiptData;
                    }
                    PrintSlipData += Environment.NewLine;
                    PrintSlipData += Environment.NewLine;
                    PrintSlipData += "===========================================";
                }
                else
                {
                    if (response.OperationCode == 26)
                    {
                        string Mess = "Проверка соединения завершена успешно." + Environment.NewLine;
                        Mess += Environment.NewLine;
                        Mess += "Терминал: " + terminalId + Environment.NewLine;
                        Mess += Environment.NewLine;
                        Utils.ToCardLog(Mess);
                        frmAllertMessage Mf = new frmAllertMessage(Mess);
                        Mf.ShowDialog();
                    }
                    else
                    {
                        /*
                         * StringConverter Sc = new StringConverter();
                         *
                         * byte[] btOut = new byte[64000];
                         * int btOutLenght = 64000;
                         * int l = Sc.Get1251Bytes(response.ReceiptData, btOut, btOutLenght);
                         * btOut = new byte[l];
                         * btOutLenght = l;
                         * l = Sc.Get1251Bytes(response.ReceiptData, btOut, btOutLenght);
                         * PrintSlipData = Encoding.GetEncoding(1251).GetString(btOut);
                         * //    PrintSlipData =  Encoding.GetEncoding(866).GetString(Encoding.GetEncoding(1251).GetBytes(response.ReceiptData));
                         * */
                        if (currentCheck != null)
                        {
                            foreach (InpasChk Chk2 in currentCheck.AllChks)
                            {
                                PrintSlipData += "Чек в Алохе " + Chk2.Num + Environment.NewLine;
                            }
                        }

                        if ((response.ReceiptData == null) || (response.ReceiptData.Length < 30))
                        {
                            if (response.Status == 1)
                            {
                                PrintSlipData += "Операция выполнена успешно" + Environment.NewLine;
                            }
                            else
                            {
                                PrintSlipData += "Операция отклонна" + Environment.NewLine;
                            }
                            PrintSlipData += "Нет данных для печати" + Environment.NewLine;
                            string Mess = Environment.NewLine;
                            Mess += "Терминал: " + terminalId + Environment.NewLine;
                            Mess += Environment.NewLine;
                            Mess += "Ошибка проведения операции " + Environment.NewLine + " на терминале пластиковых карт." + Environment.NewLine;
                            Mess += Environment.NewLine;
                            Mess += "  Код операции: " + response.OperationCode + Environment.NewLine;
                            Mess += "  Код ответа: " + response.Status + Environment.NewLine;
                            Mess += "  Дополнительные данные ответа: " + Environment.NewLine + response.TextResponse + Environment.NewLine;
                            Mess += Environment.NewLine;

                            if (currentCheck != null)
                            {
                                foreach (InpasChk Chk2 in currentCheck.AllChks)
                                {
                                    Mess += " Чек в Алохе " + Chk2.Num + Environment.NewLine;
                                }
                                Mess += "; Сумма " + (double)currentCheck.Ammount / 100D;
                            }
                            PrintSlipData += Mess;
                            PrintSlipData += response.ReceiptData;
                        }
                        else
                        {
                            PrintSlipData += response.ReceiptData;
                        }
                    }
                }
            }
            TransactionInProcess = false;

            DualConnectorMain.TransactionComplited(response.OperationCode, response.Status, currentCheck, Code, CodeDescr, PrintSlipData);
        }
        private static void ShowMsg(string Mess)
        {
            frmAllertMessage Mf = new frmAllertMessage(Mess);

            Mf.ShowDialog();
        }