void main_program(object sender, programEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                if (e.cardAvaible == 2 && programEventArgs.Page == 2)
                {
                    List<string> result = SL500.readCard();                    

                    if (result.Count <= 2 && result != null)
                    {
                        
                        string s = SQL.isInDb(result[0]);
                           SQL.addToDb(result[0], 0);

                           MessageBox.Show(s);
                       
                        this.card.Content = result[0];
                        this.state.Content = "Not active";
                        this.update.Visibility = Visibility.Hidden;
                        controlstate(2);

                    }else if(result.Count == 3)
                    {
                        controlstate(4, "Sorry, this card is activated for another owner, please remove card from reader");
                    }                        
                    else if (result != null && result[1] != "6")
                    {
                        this.card.Content = result[0];

                       //if (!SQL.isInDb(result[0])) 
                        string s = SQL.isInDb(result[0]);
                        SQL.addToDb(result[0], 0);

                        MessageBox.Show(s);

                        SQL.addToDb(result[0], 0);

                        switch (result[1])
                        {
                            case "0":
                                this.type.SelectedIndex = 4;
                                break;
                            case "1":
                                this.type.SelectedIndex = 0;
                                this.subtype.SelectedIndex = 0;
                                break;
                            case "2":
                                if(debit())
                                {
                                    this.type.SelectedIndex = 0;
                                    this.subtype.SelectedIndex = 1;
                                }
                                else
                                {
                                    this.type.SelectedIndex = 0;
                                    this.subtype.SelectedIndex = 0;
                                }
                                break;
                            case "3":
                                this.type.SelectedIndex = 1;
                                break;
                            case "4":
                                this.type.SelectedIndex = 2;
                                break;
                            case "5":
                                this.type.SelectedIndex = 3;
                                break;
                        }
                        this.name.Text = result[3];
                        this.surname.Text = result[4];
                        this.function.Text = result[5];
                        this.dis_amount.Text = result[6];
                        this.state.Content = "Activated";
                        this.update.Visibility = Visibility.Visible;
                        this.deactivate.Visibility = Visibility.Visible;

                        SQL.updateCard(result);

                        controlstate(0);
                    }
                    else if (result[1] == "6")
                    {
                        this.card.Content = result[0];
                        controlstate(4, "Sorry, this card is only for activation of application or manage machine, please remove card from reader and insert another card");
                    }

                }
                else if (e.cardAvaible == 1)
                {
                    controlstate(1);
                }

                if(e.page == 1)
                {
                    controlstate(1);
                }
            }));

        }
        void main_program(object sender, programEventArgs e)
        {
            this.Dispatcher.Invoke((Action)(() =>
              {
                  #region READ SECTION
                  if (e.cardAvaible == 2 && programEventArgs.Page == 3)
                  {
                      List<string> result = SL500.readCard();
                      
                      if (result != null && result.Count > 3)
                      {
                         // if (!SQL.isInDb(result[0])) SQL.addToDb(result[0], 0);
                          this.card.Content = result[0];

                          int type = 0;

                          switch (result[1])
                          {
                              case "1":
                                  this.creditDebet.Content = "credit";
                                  this.delQuestion.Content = "Are you sure, you want delete all credits?";
                                  this.btn_show_del.Content = "delete credit";
                                  typeOfCard = 1;
                                  break;
                              case "2":
                                  if (CManager_3._0._0.Properties.Settings.Default.debit == 0)
                                  {
                                      controlstate(4, "This application is not activated for debit", "Manager is available for credit cards only");
                                      type = 1;
                                      typeOfCard = 0;
                                  }
                                  else
                                  {
                                      this.creditDebet.Content = "debit";
                                      this.delQuestion.Content = "Are you sure, you want delete debet credit?";
                                      this.btn_show_del.Content = "delete debit";
                                      typeOfCard = 2;
                                  }
                                  
                                  break;
                              case "0":
                              case "3":
                              case "4":
                              case "5":
                                  controlstate(4, "You can't manage credit or debit at this card", "Manager is available for customer card only. To change type of card go to activation section");
                                  type = 1;
                                  typeOfCard = 0;
                                  break;
                              case "6":
                                  controlstate(4, "ERROR OCCURED", "Sorry, this card is only for activation of application or manage machine, please remove card from reader and insert another card");
                                  type = 1;
                                  typeOfCard = 0;
                                  break;

                          }                          

                          if(type == 0)
                          {                          
                          char[] _trim = new char[] { '\0' };

                          // work with credit / debet
                          
                          if(result[2] != "0")
                          {
                              double double_credit = double.Parse(result[2])/100;
                              this.amount.Content = double_credit.ToString("F2", CultureInfo.CreateSpecificCulture("en-US"));
                              
                              if(result[1] == "1")
                              {
                                  this.btn_show_add.Visibility = Visibility.Visible;
                                  this.btn_show_del.Visibility = Visibility.Visible;
                              }
                              else if (result[1] == "2")
                              {
                                  this.btn_show_add.Visibility = Visibility.Hidden;
                                  this.btn_show_del.Visibility = Visibility.Visible;
                              }
                          }
                          else
                          {
                              this.amount.Content = "0.00";

                              if (result[1] == "1")
                              {
                                  this.btn_show_add.Visibility = Visibility.Visible;
                                  this.btn_show_del.Visibility = Visibility.Hidden;
                              }
                              else if (result[1] == "2")
                              {
                                  this.btn_show_add.Visibility = Visibility.Hidden;
                                  this.btn_show_del.Visibility = Visibility.Hidden;
                              }
                          }

                          this.name.Content = result[3];
                          this.surname.Content = result[4];
                          this.function.Content = result[5];

                          SQL.updateCard(result);

                          controlstate(0);
                          }
                      }else if( result.Count == 3)
                      {
                          this.card.Content = result[0];
                          controlstate(4, "ERROR OCCURED", "Sorry, this card is activated for another owner, please remove card from reader and push button");
                      }

                  }
                  else if (e.cardAvaible == 1)
                  {
                      controlstate(1);
                  }
                  #endregion

                  if(e.page == 1)
                  {
                      this.controlstate(1);
                  }
              }));
        }