private void OnCreatedErogato(object source, FileSystemEventArgs e)
        {
            Debug.Log("CashmaticApp", "OnCreatedErogato");
            FileInfo file = new FileInfo(e.FullPath);

            while (Helper.isFileLocked(file))
            {
                Thread.Sleep(50);
            }
            try
            {
                int erogato = CashmaticCommands.ReadErogato();
                int resto   = Global.pagato - Global.subtotale;
                if ((resto - erogato) > 0)
                {
                    file.Delete();
                    StopListeners();
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Background, new Action(() => Application.Current.MainWindow.Content = new RefundingProces(_ob, true)));
                }
            }
            catch (Exception ex)
            {
                Debug.Log("CashmaticApp", ex.ToString());
            }
        }
        private void InitPayment()
        {
            Debug.Log("CashmaticApp", "InitPayment");
            int amountLeft = Global.subtotale;

            if (_ob.panda.OnPayment)
            {
                int saldato = CashmaticCommands.ReadSaldato();
                amountLeft = Global.subtotale - saldato;
            }
            else
            {
                CashmaticCommands.DeleteCashmaticFiles();
                CashmaticCommands.WriteSubtotale(Global.subtotale);
                _ob.panda.OnPayment = true;
            }

            tblPrice.Text = String.Format("{0:0.00}€", amountLeft / (double)100);

            SetSaldatoChangeListener();
            SetPagatoChangeListener();
            SetErogatoChangeListener();
            SetNonerogatoChangeListener();
            SetErogazioneChangeListener();
        }
        private void OnCreatedErogato(object source, FileSystemEventArgs e)
        {
            Debug.Log("CashmaticApp", "OnCreatedErogato");
            FileInfo file = new FileInfo(e.FullPath);

            while (Helper.isFileLocked(file))
            {
                Thread.Sleep(50);
            }
            try
            {
                int erogato = CashmaticCommands.ReadErogato();
                if (erogato == Global.pagato)
                {
                    file.Delete();
                    _fileWatcher.EnableRaisingEvents = false;
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Background, new Action(() => Application.Current.MainWindow.Content = new PaymentSummaryPage(_ob)));
                }
            }
            catch (Exception ex)
            {
                Debug.Log("CashmaticApp", ex.ToString());
            }
        }
        public RefundingProces(RootObject ob, bool CannotDispense)
        {
            Debug.Log("CashmaticApp", "Initializing refunding process");
            InitializeComponent();
            _ob = ob;
            if (!CannotDispense)
            {
                _fileWatcher                     = new FileSystemWatcher();
                _fileWatcher.Path                = Global.cashmaticBasePath;
                _fileWatcher.Filter              = "annulla.txt";
                _fileWatcher.Deleted            += new FileSystemEventHandler(OnDeletedAnnuala);
                _fileWatcher.EnableRaisingEvents = true;

                CashmaticCommands.WriteAnnulla();
            }
            else
            {
                _fileWatcher                     = new FileSystemWatcher();
                _fileWatcher.Path                = Global.cashmaticBasePath;
                _fileWatcher.Filter              = "erogato.txt";
                _fileWatcher.Created            += new FileSystemEventHandler(OnCreatedErogato);
                _fileWatcher.EnableRaisingEvents = true;

                CashmaticCommands.DeleteCashmaticFiles();
                CashmaticCommands.WriteSubtotale(Global.pagato * (-1));
            }
            _ob.panda.OnPayment = false;
        }
 private void btnRetry_Click(object sender, RoutedEventArgs e)
 {
     if (CashmaticCommands.IsConnected())
     {
         Debug.Log("CashmaticApp", "Button retry click");
         _ob.ready2order.paymentMethod_id       = _ob.panda.paymentMethodCASH;
         Application.Current.MainWindow.Content = new PaymentPandingCash(_ob);
     }
 }
        private void OnCreatedNonerogato(object source, FileSystemEventArgs e)
        {
            Debug.Log("CashmaticApp", "OnCreatedNonerogato");
            FileInfo file = new FileInfo(e.FullPath);

            while (Helper.isFileLocked(file))
            {
                Thread.Sleep(50);
            }
            try
            {
                int nonerogato = CashmaticCommands.ReadNonerogato();
            }
            catch (Exception ex)
            {
                Debug.Log("CashmaticApp", ex.ToString());
            }
        }
        private void OnErogazioneChange(object source, FileSystemEventArgs e)
        {
            Debug.Log("CashmaticApp", "OnErogazioneChange");
            FileInfo file = new FileInfo(e.FullPath);

            while (Helper.isFileLocked(file))
            {
                Thread.Sleep(50);
            }
            try
            {
                int saldato    = CashmaticCommands.ReadSaldato();
                int erogazione = CashmaticCommands.ReadErogazione();
                int pagato     = CashmaticCommands.ReadPagato();
                saldato = (Global.subtotale - saldato);

                if (saldato < 0)
                {
                    saldato = saldato * -1;
                }
                saldato = saldato - erogazione;

                Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background, new Action(() => tblPrice.Text = String.Format("{0:0.00}€", saldato / (double)100)));

                pagato = pagato - erogazione;

                if (pagato == Global.subtotale)
                {
                    file.Delete();
                    StopListeners();
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Background, new Action(() => Application.Current.MainWindow.Content = new ThankYouCash(_ob)));
                }
            }
            catch (Exception ex)
            {
                Debug.Log("CashmaticApp", ex.ToString());
            }
        }
        private void OnChangeSaldato(object source, FileSystemEventArgs e)
        {
            Debug.Log("CashmaticApp", "OnChangeSaldato");
            FileInfo file = new FileInfo(e.FullPath);

            while (Helper.isFileLocked(file))
            {
                Thread.Sleep(50);
            }
            try
            {
                int saldato = CashmaticCommands.ReadSaldato();
                Global.pagato = saldato;
                saldato       = Global.subtotale - saldato;

                int signChanger = saldato < 0 ? -1:1;
                if (saldato <= 0)
                {
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Background, new Action(() => tblPrice.Foreground = green));
                }

                Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background, new Action(() => tblPrice.Text = String.Format("{0:0.00}€", (saldato * signChanger) / (double)100)));

                if (signChanger < 0)
                {
                    Application.Current.Dispatcher.BeginInvoke(
                        DispatcherPriority.Background, new Action(() => tblRemaining.Text = (string)FindResource("titleRemainReturn")));
                }
            }
            catch (Exception ex)
            {
                Debug.Log("CashmaticApp", ex.ToString());
            }
        }