Exemple #1
0
        public string DeductBalance(string bank, string ipv4, string TIDSettlement, string operator_name, int amount = 1)
        {
            try
            {
                // check if deducted amount is sufficient within balance range and the balance must be greater than 0
                int cardBalance = Int32.Parse(this.GetCardBalance());
                if (cardBalance > 0 && (cardBalance - amount) > 0)
                {
                    string result = bni.debitProcess(this.readerList[2].ToString(), this.selectedReader.ToString(), amount, Properties.Settings.Default.TID);

                    // store deduct result card to server
                    string created = tk.ConvertDatetimeToDefaultFormat(tk.GetCurrentDatetime());
                    string query   = "INSERT INTO deduct_card_results (result, amount, transaction_dt, bank, ipv4, operator, ID_reader, created) VALUES('" + result + "', '" + amount +
                                     "', '" + created + "', '" + bank + "', '" + ipv4 + "', '" + operator_name + "', '" + TIDSettlement + "', '" + created + "')";
                    try
                    {
                        database.Insert(query);

                        Console.WriteLine("Successfully Deducted for Rp. " + amount + ",-.");
                        Console.WriteLine("Current Balance : " + String.Format("{0:n}", Int32.Parse(this.GetCardBalance())));

                        //this.CreateSettlement(result);

                        acr123u.connectDirect();
                        int repeat      = 3;
                        int onDuration  = 5;
                        int OffDuration = 10;
                        acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                        this.LEDStatus  = LEDGreen;
                        this.LEDStatus |= LEDAntGreen;
                        acr123u.LCDBacklightControl(0xFF);
                        this.acr123u.setLEDControl(this.LEDStatus);
                        this.SetLCDDisplayText("Success ...");
                        acr123u.disconnect();

                        return("OK");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                        return(ex.Message);
                    }
                }
                else
                {
                    acr123u.connectDirect();
                    this.SetLCDDisplayText("Insufficient Bal");
                    Console.WriteLine("Can't Deduct : Insufficient Balance.");
                    int repeat      = 2;
                    int onDuration  = 5;
                    int OffDuration = 10;
                    acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                    this.LEDStatus  = LEDRed;
                    this.LEDStatus |= LEDAntRed;
                    acr123u.LCDBacklightControl(0xFF);
                    this.acr123u.setLEDControl(this.LEDStatus);
                    acr123u.disconnect();
                    return("Can't Deduct : Insufficient Balance.");
                }
            }
            catch (Exception ex)
            {
                acr123u.connectDirect();
                this.SetLCDDisplayText("Fail to Process.");
                Console.WriteLine(ex.Message);
                int repeat      = 2;
                int onDuration  = 5;
                int OffDuration = 10;
                acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                this.LEDStatus  = LEDRed;
                this.LEDStatus |= LEDAntRed;
                acr123u.LCDBacklightControl(0xFF);
                this.acr123u.setLEDControl(this.LEDStatus);
                acr123u.disconnect();
                return(ex.Message);
            }
        }
Exemple #2
0
        public DataDeduct DeductBalance(string bank, string ipv4, string TIDSettlement, string operator_name, int amount = 1)
        {
            DataDeduct dataDeduct = null;

            try
            {
                // check if deducted amount is sufficient within balance range and the balance must be greater than 0
                int cardBalance = Int32.Parse(this.GetCardBalance());
                if (cardBalance > 0 && (cardBalance - amount) > 0)
                {
                    string result        = bni.debitProcess(this.readerList[2].ToString(), this.selectedReader.ToString(), amount, Properties.Settings.Default.TID);
                    string returnMessage = RCList.ContainsKey(result) ? RCList[result] : Constant.MESSAGE_OK;
                    if (returnMessage != Constant.MESSAGE_OK)
                    {
                        dataDeduct = new DataDeduct(true, returnMessage);
                        return(dataDeduct);
                    }
                    Console.WriteLine("Successfully Deducted for Rp. " + amount + ",-.");
                    Console.WriteLine("Current Balance : " + String.Format("{0:n}", Int32.Parse(this.GetCardBalance())));

                    acr123u.connectDirect();
                    int repeat      = 3;
                    int onDuration  = 5;
                    int OffDuration = 10;
                    acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                    this.LEDStatus  = Constant.LED_GREEN;
                    this.LEDStatus |= Constant.LED_ANT_GREEN;
                    acr123u.LCDBacklightControl(0xFF);
                    this.acr123u.setLEDControl(this.LEDStatus);
                    this.SetLCDDisplayText(Constant.MESSAGE_SUCCESS_DEDUCT);
                    acr123u.disconnect();

                    dataDeduct = new DataDeduct(result, amount, bank, operator_name, TIDSettlement);
                }
                else
                {
                    acr123u.connectDirect();
                    this.SetLCDDisplayText(Constant.ERROR_MESSAGE_INSUFFICIENT_BALANCE);
                    Console.WriteLine(Constant.ERROR_MESSAGE_CANNOT_DEDUCT_INSUFFICIENT_BALANCE);
                    int repeat      = 2;
                    int onDuration  = 5;
                    int OffDuration = 10;
                    acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                    this.LEDStatus  = Constant.LED_RED;
                    this.LEDStatus |= Constant.LED_ANT_RED;
                    acr123u.LCDBacklightControl(0xFF);
                    this.acr123u.setLEDControl(this.LEDStatus);
                    acr123u.disconnect();
                    dataDeduct = new DataDeduct(true, Constant.ERROR_MESSAGE_CANNOT_DEDUCT_INSUFFICIENT_BALANCE);
                }
            }
            catch (Exception ex)
            {
                acr123u.connectDirect();
                this.SetLCDDisplayText(Constant.ERROR_FAIL_PROCESS);
                Console.WriteLine(ex.Message);
                int repeat      = 2;
                int onDuration  = 5;
                int OffDuration = 10;
                acr123u.setBuzzerControl((byte)repeat, (byte)onDuration, (byte)OffDuration);
                this.LEDStatus  = Constant.LED_RED;
                this.LEDStatus |= Constant.LED_ANT_RED;
                acr123u.LCDBacklightControl(0xFF);
                this.acr123u.setLEDControl(this.LEDStatus);
                acr123u.disconnect();
                dataDeduct = new DataDeduct(true, ex.Message);
            }
            GC.Collect();
            GC.WaitForPendingFinalizers();
            return(dataDeduct);
        }