Пример #1
0
        public Cryptocurrencies Read(String symbol)
        {
            Cryptocurrencies crypto = new Cryptocurrencies();

            string        connectionString = @"Data Source=(localdb)\LocalDBKN;Initial Catalog=FinMarketsAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();

            string     query   = @"SELECT * FROM Cryptocurrencies WHERE symbol = " + "'" + symbol.Trim() + "'";
            SqlCommand command = new SqlCommand(query, connection);

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                crypto.idCrypto  = Convert.ToInt32(reader["idCrypto"]);
                crypto.Name      = reader["name"].ToString();
                crypto.Symbol    = reader["symbol"].ToString();
                crypto.Price     = reader["price"].ToString();
                crypto.Change7d  = reader["change7d"].ToString();
                crypto.Change24h = reader["change24h"].ToString();
            }

            connection.Close();
            return(crypto);
        }
Пример #2
0
        public List <Cryptocurrencies> search(string searchText)
        {
            List <Cryptocurrencies> listCrpyto = new List <Cryptocurrencies>();

            string        connectionString = @"Data Source=(localdb)\LocalDBKN;Initial Catalog=FinMarketsAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();

            string     query   = @"SELECT * FROM Cryptocurrencies WHERE symbol like " + "'%" + searchText.Trim() + "%'";
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Cryptocurrencies crypto = new Cryptocurrencies();
                crypto.Name      = reader["name"].ToString();
                crypto.Symbol    = reader["symbol"].ToString();
                crypto.Price     = reader["price"].ToString();
                crypto.Change7d  = reader["change7d"].ToString();
                crypto.Change24h = reader["change24h"].ToString();
                listCrpyto.Add(crypto);
            }

            connection.Close();

            return(listCrpyto);
        }
Пример #3
0
        private void RemoveFromWalletBtn_Click(object sender, EventArgs e)
        {
            if (walletSymbolTextBox.Text != "" & walletNameTextBox.Text != "")
            {
                if (MessageBox.Show("Do you want remove this asset from your wallet?", "Warning",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    Cryptocurrencies crypto    = new Cryptocurrencies();
                    ConnectDB        connectDb = new ConnectDB();
                    crypto = connectDb.Read(walletSymbolTextBox.Text); // to get crypto id from symbol Text Box
                    WalletsC walletsC  = new WalletsC();
                    WalletsC walletsC2 = new WalletsC();

                    Users user = new Users();
                    user            = connectDb.checkLoggedUser();
                    walletsC.idUser = user.idUsers;

                    walletsC.idWalletC = 1; // też sprzawdzam użytkonika a póżniej jego crytpo wallet
                    walletsC.idCrypto  = crypto.idCrypto;
                    walletsC.quantity  = walletQuantityTextBox.Text;
                    walletsC.sum       = 0.ToString();
                    walletsC.idAlert   = 1; // bede pewnie z gui bral dla alertu wzrostoego 1 a dla malejacego 2

                    walletsC2 = connectDb.readWalletsC(walletsC.idUser, walletsC.idWalletC, walletsC.idCrypto);
                    if (walletsC2.idCrypto != 0)
                    {
                        connectDb.deleteWalletsC(walletsC);
                        this.viewWalletTableAdapter1.Fill(this.finMarketsAppDBDataSet21.ViewWallet);
//                        this.viewWalletTableAdapter.Fill(this.finMarketsAppDBDataSet1.ViewWallet);
                        calculateWalletbalance();
                        refreshWallet();
                        try
                        {
                            if (walletDataGridView.CurrentRow.Index != -1)
                            {
                                walletNameTextBox.Text     = walletDataGridView.CurrentRow.Cells[0].Value.ToString();
                                walletSymbolTextBox.Text   = walletDataGridView.CurrentRow.Cells[1].Value.ToString();
                                walletPriceTextBox.Text    = walletDataGridView.CurrentRow.Cells[2].Value.ToString();
                                walletQuantityTextBox.Text = walletDataGridView.CurrentRow.Cells[3].Value.ToString();
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        MessageBox.Show("You do not have this asset in your wallet", "Warning", MessageBoxButtons.OK,
                                        MessageBoxIcon.Warning);
                    }
                }
            }
            else
            {
                MessageBox.Show("Select asset to remowe", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Пример #4
0
        private void removeFromDBButton_Click(object sender, EventArgs e)
        {
            Cryptocurrencies crypto = new Cryptocurrencies();

            crypto.Symbol = "'" + adminSymbolTextBox.Text + "'";
            ConnectDB connectDb = new ConnectDB();

            connectDb.deleteFromDB(crypto);
            this.cryptocurrenciesTableAdapter.Fill(this.finMarketsAppDBDataSet.Cryptocurrencies);
        }
Пример #5
0
        public bool Save(Cryptocurrencies crypto)
        {
            string        connectionString = @"Data Source=(localdb)\LocalDBKN;Initial Catalog=FinMarketsAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();

            string     query   = @"INSERT INTO Cryptocurrencies VALUES (" + crypto.Name + "," + crypto.Symbol + "," + crypto.Price + "," + crypto.Change24h + "," + crypto.Change7d + ")";
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            connection.Close();
            return(true);
        }
Пример #6
0
        public bool deleteFromDB(Cryptocurrencies crypto)
        {
            string        connectionString = @"Data Source=(localdb)\LocalDBKN;Initial Catalog=FinMarketsAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();

            string     query   = @"DELETE FROM Cryptocurrencies WHERE symbol = " + crypto.Symbol + "";
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            connection.Close();
            return(true);
        }
Пример #7
0
        public bool Update(Cryptocurrencies crypto)
        {
            string        connectionString = @"Data Source=(localdb)\LocalDBKN;Initial Catalog=FinMarketsAppDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
            SqlConnection connection       = new SqlConnection(connectionString);

            connection.Open();

            string query = @"UPDATE Cryptocurrencies SET name = " + crypto.Name + ",price=" + crypto.Price + ",change7d=" + crypto.Change7d + ",change24h=" + crypto.Change24h + " WHERE symbol = " + crypto.Symbol + "";
            //MessageBox.Show(query);
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            connection.Close();
            return(true);
        }
Пример #8
0
        private void AddToWalletBtn_Click(object sender, EventArgs e)
        {
            Cryptocurrencies crypto    = new Cryptocurrencies();
            ConnectDB        connectDb = new ConnectDB();

            if (walletSymbolTextBox.Text != "" & walletNameTextBox.Text != "")
            {
                crypto = connectDb.Read(walletSymbolTextBox.Text); // to get crypto id from symbol Text Box
                WalletsC walletsC  = new WalletsC();
                WalletsC walletsC2 = new WalletsC();

                Users user = new Users();
                user            = connectDb.checkLoggedUser();
                walletsC.idUser = user.idUsers;

                walletsC.idWalletC      = 1;
                walletsC.idCrypto       = crypto.idCrypto;
                walletsC.priceWhenAdded = crypto.Price;
                walletsC.price          = crypto.Price;
                walletsC.quantity       = walletQuantityTextBox.Text;
                float tempSum = Convert.ToSingle(walletsC.price) * Convert.ToSingle(walletsC.quantity);
                walletsC.sum       = tempSum.ToString();
                walletsC.idAlert   = 1;
                walletsC.alertUp   = alertUpTextBox.Text;
                walletsC.alertDown = alertDownTextBox.Text;

                walletsC2 = connectDb.readWalletsC(walletsC.idUser, walletsC.idWalletC, walletsC.idCrypto);
                if (walletsC2.idCrypto != 0)
                {
                    connectDb.updateWalletsC(walletsC, user);
                }
                else
                {
                    connectDb.saveWalletsC(walletsC);
                }
                this.viewWalletTableAdapter1.Fill(this.finMarketsAppDBDataSet21.ViewWallet);
//                this.viewWalletTableAdapter.Fill(this.finMarketsAppDBDataSet1.ViewWallet);
                calculateWalletbalance();
                refreshWallet();
            }
        }
Пример #9
0
        public void cryptoGetData(int i, string response)
        {
            Cryptocurrencies crypto = new Cryptocurrencies();

            int    id      = i;
            string checkId = null;

            dynamic jsonObj = JObject.Parse(response);

            try
            {
//                checkId = jsonObj["data"]["" + id + ""].ToString();
                checkId = jsonObj.SelectToken("$.data[" + id + "].id").ToString();
//                MessageBox.Show(checkId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            if (checkId != null)
            {
                int startIndex  = 0;
                int length      = 4;
                int priceLength = 7;

                try
                {
                    string cryptoName       = jsonObj.SelectToken("$.data[" + id + "].name").ToString();
                    string cryptoSymbol     = jsonObj.SelectToken("$.data[" + id + "].symbol").ToString();
                    string cryptoPrice      = jsonObj.SelectToken("$.data[" + id + "].quote.USD.price").ToString().Substring(startIndex, priceLength);
                    string cryptoChange_24h = jsonObj.SelectToken("$.data[" + id + "].quote.USD.percent_change_24h").ToString().Substring(startIndex, length);
                    string cryptoChange_7d  = jsonObj.SelectToken("$.data[" + id + "].quote.USD.percent_change_7d").ToString().Substring(startIndex, length);
                    //     MessageBox.Show(cryptoName);
                    //     MessageBox.Show(cryptoSymbol);
                    //     MessageBox.Show(cryptoPrice);
                    //     MessageBox.Show(cryptoChange_24h);
                    //     MessageBox.Show(cryptoChange_7d);
                    ConnectDB connectDb = new ConnectDB();
                    crypto = connectDb.Read(cryptoSymbol);       // check if currency already exist in db
                    if (crypto.Symbol == null)
                    {
                        crypto.Symbol    = "'" + cryptoSymbol + "'";
                        crypto.Name      = "'" + cryptoName + "'";
                        crypto.Price     = "'" + cryptoPrice + "'";
                        crypto.Change24h = "'" + cryptoChange_24h + "'";
                        crypto.Change7d  = "'" + cryptoChange_7d + "'";

                        connectDb.Save(crypto);
                    }
                    else
                    {
                        crypto.Symbol    = "'" + cryptoSymbol + "'";
                        crypto.Name      = "'" + cryptoName + "'";
                        crypto.Price     = "'" + cryptoPrice + "'";
                        crypto.Change24h = "'" + cryptoChange_24h + "'";
                        crypto.Change7d  = "'" + cryptoChange_7d + "'";

                        connectDb.Update(crypto);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }