public void Execute(object parameter)
 {
     mainWindow.tableDock.Background        = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.importDock.Background       = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.stockChartDock.Background   = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.tableMenuTop.Visibility     = System.Windows.Visibility.Hidden;
     mainWindow.importMenuTop.Visibility    = System.Windows.Visibility.Hidden;
     mainWindow.portfolioMenuTop.Visibility = System.Windows.Visibility.Hidden;
     if (buttonContent.Equals("Import"))
     {
         ImportPageBank.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
         mainWindow.MainFrame.Content        = ImportPageBank.getInstance(mainWindow);
         mainWindow.importMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.importDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
     }
     else if (buttonContent.Equals("Database"))
     {
         TransactionMain.getInstance(mainWindow).setTableAttributes();
         mainWindow.MainFrame.Content       = TransactionMain.getInstance(mainWindow);
         mainWindow.tableMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.tableDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
     }
     else if (buttonContent.Equals("stockMarketData"))
     {
         if (mainWindow.webStockStopwatch.Elapsed == TimeSpan.FromMilliseconds(0))
         {
             mainWindow.webStockStopwatch.Start();
             StockChart stockChart = new StockChart(mainWindow);
             mainWindow.MainFrame.Content           = stockChart;
             mainWindow.portfolioMenuTop.Visibility = System.Windows.Visibility.Visible;
             mainWindow.stockChartDock.Background   = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         }
         else
         {
             if (mainWindow.webStockStopwatch.Elapsed <= TimeSpan.FromMinutes(0.2))
             {
                 MessageBox.Show("Please wait for " + (TimeSpan.FromMinutes(0.2) - mainWindow.webStockStopwatch.Elapsed) + " seconds!");
             }
             else
             {
                 mainWindow.webStockStopwatch.Stop();
                 mainWindow.webStockStopwatch.Reset();
             }
         }
     }
     else if (buttonContent.Equals("Exit"))
     {
         mainWindow.Close();
     }
 }
示例#2
0
 public void MyAction(string commandName)
 {
     mainWindow.tableDock.Background        = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.importDock.Background       = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.stockChartDock.Background   = new SolidColorBrush(Color.FromRgb(217, 133, 59));
     mainWindow.tableMenuTop.Visibility     = System.Windows.Visibility.Hidden;
     mainWindow.importMenuTop.Visibility    = System.Windows.Visibility.Hidden;
     mainWindow.portfolioMenuTop.Visibility = System.Windows.Visibility.Hidden;
     mainWindow.bankImport.Background       = Brushes.Transparent;
     mainWindow.stockImport.Background      = Brushes.Transparent;
     mainWindow.bankDatabase.Background     = Brushes.Transparent;
     mainWindow.stockDatabase.Background    = Brushes.Transparent;
     mainWindow.stockChart.Background       = Brushes.Transparent;
     mainWindow.stockDatagrid.Background    = Brushes.Transparent;
     if (commandName == "bankImportPushed")
     {
         ImportPageBank.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
         mainWindow.MainFrame.Content        = ImportPageBank.getInstance(mainWindow);
         mainWindow.importMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.importDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.bankImport.Background    = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "stockImportPushed")
     {
         ImportPageStock.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
         mainWindow.MainFrame.Content        = ImportPageStock.getInstance(mainWindow);
         mainWindow.importMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.importDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.stockImport.Background   = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "bankDatabasePushed")
     {
         DatabaseDataBank.getInstance(mainWindow).setTableAttributes();
         mainWindow.MainFrame.Content       = DatabaseDataBank.getInstance(mainWindow);
         mainWindow.tableMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.tableDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.bankDatabase.Background = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "stockDatabasePushed")
     {
         DatabaseDataStock.getInstance(mainWindow).setTableAttributes();
         mainWindow.MainFrame.Content        = DatabaseDataStock.getInstance(mainWindow);
         mainWindow.tableMenuTop.Visibility  = System.Windows.Visibility.Visible;
         mainWindow.tableDock.Background     = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.stockDatabase.Background = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "stockChartPushed")
     {
         StockChart stockChart = new StockChart(mainWindow);
         mainWindow.MainFrame.Content           = stockChart;
         mainWindow.portfolioMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.stockChartDock.Background   = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.stockChart.Background       = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "stockDatagridPushed")
     {
         mainWindow.MainFrame.Content           = new StockDataGrid(mainWindow);
         mainWindow.portfolioMenuTop.Visibility = System.Windows.Visibility.Visible;
         mainWindow.stockChartDock.Background   = new SolidColorBrush(Color.FromRgb(198, 61, 15));
         mainWindow.stockChart.Background       = new SolidColorBrush(Color.FromRgb(255, 140, 105));
     }
     else if (commandName == "Exit")
     {
         mainWindow.Close();
     }
 }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            mConn.Open();
            using (SQLiteCommand mCmd = new SQLiteCommand("CREATE TABLE IF NOT EXISTS [UserInfo] " +
                                                          "(id INTEGER PRIMARY KEY AUTOINCREMENT, 'Username' TEXT, 'Password' TEXT, 'AccountNumber' TEXT);", mConn))
            {
                mCmd.ExecuteNonQuery();
            }
            string            usernameInUseQuery = "select * from [UserInfo] where Username= '******'";
            SQLiteCommand     command            = new SQLiteCommand(usernameInUseQuery, mConn);
            DataTable         dtb     = new DataTable();
            SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);

            adapter.Fill(dtb);
            if (dtb.Rows.Count == 1)
            {
                string decryptedPassword = decryptString(dtb.Rows[0][2].ToString());
                if (decryptedPassword == passwordTextbox.Password.ToString())
                {
                    failedLogins = 0;
                    User currentUser = new User();
                    currentUser.setUsername(usernameTextbox.Text.ToString());
                    currentUser.setAccountNumber(dtb.Rows[0][3].ToString());
                    mainWindow.currentUserLabel.Content = currentUser.getUsername(); //notification label
                    mainWindow.setCurrentUser(currentUser);
                    this.Visibility = Visibility.Hidden;
                    ImportPageBank.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
                    mainWindow.MainFrame.Content        = ImportPageBank.getInstance(mainWindow);
                    mainWindow.importMenuTop.Visibility = Visibility.Visible;
                    mainWindow.importDock.Background    = new SolidColorBrush(Color.FromRgb(198, 61, 15));
                    mainWindow.bankImport.Background    = new SolidColorBrush(Color.FromRgb(255, 140, 105));
                }
                else
                {
                    failedLogins++;
                    if (failedLogins >= 3)
                    {
                        timer1          = new DispatcherTimer();
                        tik             = 30;
                        timer1.Interval = new TimeSpan(0, 0, 0, 1);
                        timer1.Tick    += new EventHandler(timer1_Tick);
                        timer1.Start();
                    }
                    MessageBox.Show("Wrong username or password!");
                }
            }
            else
            {
                failedLogins++;
                if (failedLogins >= 3)
                {
                    timer1          = new DispatcherTimer();
                    tik             = 30;
                    timer1.Interval = new TimeSpan(0, 0, 0, 1);
                    timer1.Tick    += new EventHandler(timer1_Tick);
                    timer1.Start();
                }
                MessageBox.Show("Wrong username or password!");
            }
            mConn.Close();

            /*
             * SqlConnection sqlConn = new SqlConnection("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=LoginDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
             * string loginQuery = "Select * From [UserDatas] where username = '******'";
             * SqlDataAdapter sda = new SqlDataAdapter(loginQuery,sqlConn);
             * DataTable dtb = new DataTable();
             * sda.Fill(dtb);
             * if(dtb.Rows.Count==1)
             * {
             *  string decryptedPassword = decryptString(dtb.Rows[0][1].ToString());
             *  if (decryptedPassword == passwordTextbox.Password.ToString())
             *  {
             *      failedLogins = 0;
             *      User currentUser = new User();
             *      currentUser.setUsername(usernameTextbox.Text.ToString());
             *      currentUser.setAccountNumber(dtb.Rows[0][2].ToString());
             *      mainWindow.currentUserLabel.Content = currentUser.getUsername(); //notification label
             *      mainWindow.setCurrentUser(currentUser);
             *      Visibility = System.Windows.Visibility.Hidden;
             *      ImportPageBank.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
             *      mainWindow.MainFrame.Content = ImportPageBank.getInstance(mainWindow);
             *      mainWindow.importMenuTop.Visibility = System.Windows.Visibility.Visible;
             *      mainWindow.importDock.Background = new SolidColorBrush(Color.FromRgb(198, 61, 15));
             *      mainWindow.bankImport.Background = new SolidColorBrush(Color.FromRgb(255, 140, 105));
             *  }
             *  else
             *  {
             *      MessageBox.Show("Wrong username or password!");
             *      failedLogins++;
             *      if (failedLogins > 3)
             *      {
             *          timer1 = new DispatcherTimer();
             *          tik = 30;
             *          timer1.Interval = new TimeSpan(0, 0, 0, 1);
             *          timer1.Tick += new EventHandler(timer1_Tick);
             *          timer1.Start();
             *      }
             *  }
             * }
             * else
             * {
             *  MessageBox.Show("Wrong username or password!");
             *  failedLogins++;
             *  if (failedLogins > 3)
             *  {
             *      timer1 = new DispatcherTimer();
             *      tik = 30;
             *      timer1.Interval = new TimeSpan(0, 0, 0, 1);
             *      timer1.Tick += new EventHandler(timer1_Tick);
             *      timer1.Start();
             *  }
             * }
             */
        }
示例#4
0
 private void Button_Click_1(object sender, RoutedEventArgs e)
 {
     mainWindow.MainFrame.Content = ImportPageBank.getInstance(mainWindow, "switch");
 }
示例#5
0
        private List <Transaction> newTransactions(List <Transaction> importedTransactions) //check if the transaction is already exported or not
        {
            List <Transaction> savedTransactions  = SavedTransactions.getSavedTransactionsBank();
            List <Transaction> neededTransactions = new List <Transaction>();

            importerAccountNumber = importedTransactions[0].getAccountNumber();//account number is the same for all
            ThreadStart threadStart = delegate
            {
                writeAccountNumberToSql(importerAccountNumber);
            };
            Thread sqlThread = new Thread(threadStart);

            sqlThread.IsBackground = true;
            sqlThread.Start();
            sqlThread.Join();
            mainWindow.setAccountNumber(importerAccountNumber);
            if (savedTransactions.Count != 0)//if the export file was not empty we scan the list
            {
                List <Transaction> tempTransactions = new List <Transaction>();
                foreach (var saved in savedTransactions)
                {
                    //egy külön listába tesszük azokat az elemeket a már elmentet tranzakciókból ahol a bankszámlaszám
                    //megegyezik az importálandó bankszámlaszámmal
                    if (saved.getAccountNumber().Equals(importerAccountNumber))
                    {
                        tempTransactions.Add(saved);
                    }
                }
                if (tempTransactions.Count != 0)//ha van olyan már elmentett tranzakció aminek az  a bankszámlaszáma mint amit importálni akarunk
                {
                    int          explicitImported = 0;
                    StreamWriter logFile          = new StreamWriter("C:\\Users\\Tocki\\Desktop\\transactionsLog.txt", append: true);
                    foreach (var imported in importedTransactions)
                    {
                        bool redundant = false;
                        foreach (var saved in tempTransactions)
                        {
                            if (saved.getTransactionDate().Equals(imported.getTransactionDate()) &&
                                saved.getTransactionPrice().Equals(imported.getTransactionPrice()) &&
                                saved.getBalance_rn() == imported.getBalance_rn())
                            {
                                redundant = true;
                                if (ImportPageBank.getInstance(mainWindow).alwaysAsk == true)
                                {
                                    if (MessageBox.Show("This transaction is most likely to be in the Databse already!\n -- Transaction date: " + imported.getTransactionDate() + "\n-- Transaction price: " + imported.getTransactionPrice()
                                                        + "\n-- Imported on: " + saved.getWriteDate().Substring(0, 12) + "\nWould you like to import it anyways?",
                                                        "Imprt alert!",
                                                        MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                                    {
                                        neededTransactions.Add(imported);
                                        explicitImported++;
                                        logFile.WriteLine("AccountNumber: " + imported.getAccountNumber() +
                                                          "\n ImportDate: " + imported.getTransactionDate() +
                                                          "\n TransactionPrice: "
                                                          + imported.getTransactionPrice() + " *");
                                    }
                                }
                                break;
                            }
                        }
                        if (redundant == false)
                        {
                            neededTransactions.Add(imported);;
                        }
                    }
                    logFile.Close();
                    if (MessageBox.Show("You have imported " + neededTransactions.Count + " new transaction(s)!\n" +
                                        "(" + (tempTransactions.Count - explicitImported) + " was already imported)", "Import alert!",
                                        MessageBoxButton.OK, MessageBoxImage.Information) == MessageBoxResult.OK)
                    {
                        return(neededTransactions);
                    }
                    return(neededTransactions);
                }
                else //nincs olyan elmentett tranzakció aminek az lenne a bankszámlaszáma mint amit importálni akarunk
                     //tehát az összeset importáljuk
                {
                    //mainWindow.setTableAttributes(importedTransactions,"empty");
                    if (MessageBox.Show("You have imported " + importedTransactions.Count + " new transaction(s)!\n", "Import alert!",
                                        MessageBoxButton.OK, MessageBoxImage.Information) == MessageBoxResult.OK)
                    {
                        return(importedTransactions);
                    }
                    return(importedTransactions);
                }
            }
            else // még nincs elmentett tranzakció
                 // tehát az összeset importáljuk
            {
                //mainWindow.setTableAttributes(importedTransactions,"empty");
                if (MessageBox.Show("You have imported " + importedTransactions.Count + " new transaction(s)!\n", "Import alert!",
                                    MessageBoxButton.OK, MessageBoxImage.Information) == MessageBoxResult.OK)
                {
                    return(importedTransactions);
                }
                return(importedTransactions);
            }
        }
示例#6
0
        public ExportTransactions(List <Transaction> transactions, MainWindow mainWindow, string currentFileName)
        {
            this.mainWindow = mainWindow;
            for (int i = 0; i < transactions.Count; i++)
            {
                string [] spaceSplitted = transactions[i].getTransactionDate().Split(' ');
                string    dateString    = "";
                for (int j = 0; j < spaceSplitted.Length; j++)
                {
                    dateString += spaceSplitted[j];
                }
                Console.WriteLine(dateString.Substring(0, 11));
            }
            MessageBox.Show("Exporting data from: " + currentFileName, "", MessageBoxButton.OK);
            //BUT FIRST - check if the transaction is already exported or not
            List <Transaction> neededTransactions = newTransactions(transactions);

            SavedTransactions.addToSavedTransactionsBank(neededTransactions);//adding the freshyl imported transactions to the saved
            WriteWorkbook  = excel.Workbooks.Open(@"C:\Users\Tocki\Desktop\Kimutatas.xlsx");
            WriteWorksheet = WriteWorkbook.Worksheets[1];
            if (neededTransactions != null)
            {
                string todaysDate = DateTime.Now.ToString("yyyy-MM-dd");
                int    row_number = 1;
                while (WriteWorksheet.Cells[row_number, 1].Value != null)
                {
                    row_number++; // get the current last row
                }
                foreach (var transctn in neededTransactions)
                {
                    WriteWorksheet.Cells[row_number, 1].Value = todaysDate;
                    WriteWorksheet.Cells[row_number, 2].Value = transctn.getTransactionDate();
                    WriteWorksheet.Cells[row_number, 3].Value = transctn.getBalance_rn();
                    WriteWorksheet.Cells[row_number, 7].Value = transctn.getTransactionPrice();
                    if (transctn.getTransactionPrice() < 0)
                    {
                        WriteWorksheet.Cells[row_number, 9].Value  = transctn.getTransactionPrice();
                        WriteWorksheet.Cells[row_number, 11].Value = transctn.getTransactionPrice();
                        WriteWorksheet.Cells[row_number, 15].Value = "havi";
                    }
                    else
                    {
                        WriteWorksheet.Cells[row_number, 8].Value  = transctn.getTransactionPrice();
                        WriteWorksheet.Cells[row_number, 10].Value = transctn.getTransactionPrice();
                        WriteWorksheet.Cells[row_number, 11].Value = transctn.getTransactionPrice();
                        WriteWorksheet.Cells[row_number, 15].Value = "havi";
                    }
                    WriteWorksheet.Cells[row_number, 14].Value = transctn.getTransactionDescription();
                    WriteWorksheet.Cells[row_number, 16].Value = transctn.getAccountNumber();
                    row_number++;
                    Range line = (Range)WriteWorksheet.Rows[row_number];
                    line.Insert();
                }
                try
                {
                    //WriteWorkbook.SaveAs(@"C:\Users\Tocki\Desktop\Kimutatas.xlsx");
                    excel.ActiveWorkbook.Save();
                    excel.Workbooks.Close();
                    excel.Quit();
                }
                catch (Exception e)
                {
                }
                ImportPageBank.getInstance(mainWindow).setUserStatistics(mainWindow.getCurrentUser());
            }
            else
            {
                return;
            }
        }