Exemplo n.º 1
0
        public WalletsC readWalletsC(int idUser, int idWalletC, int idCrypto)
        {
            WalletsC walletsC2 = new WalletsC();

            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 WalletsC WHERE idUser = "******" AND idWalletC = " + idWalletC + "AND idCrypto =" + idCrypto + "";
            SqlCommand command = new SqlCommand(query, connection);

            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                walletsC2.idUser    = Convert.ToInt32(reader["idUser"]);
                walletsC2.idWalletC = Convert.ToInt32(reader["idWalletC"]);
                walletsC2.idCrypto  = Convert.ToInt32(reader["idCrypto"]);
                walletsC2.quantity  = reader["quantity"].ToString();
                walletsC2.sum       = reader["sum"].ToString();
                walletsC2.idAlert   = Convert.ToInt32(reader["idAlert"]);
            }

            connection.Close();
            return(walletsC2);
        }
Exemplo n.º 2
0
        public bool updateWalletsC(WalletsC walletsC, Users user)
        {
            float price          = 0;
            float priceWhenAdded = 0;

            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 query2 = @"SELECT price, priceWhenAdded FROM WalletsC,Cryptocurrencies WHERE Cryptocurrencies.idCrypto = WalletsC.idCrypto AND WalletsC.idUser = "******"AND WalletsC.idCrypto =" + walletsC.idCrypto + "";
            //   String query = @"SELECT sum FROM dbo.ViewWallet";
            SqlCommand    command2 = new SqlCommand(query2, connection);
            SqlDataReader reader   = command2.ExecuteReader();

            while (reader.Read())
            {
                price          = Convert.ToSingle(reader["price"].ToString());
                priceWhenAdded = Convert.ToSingle(reader["priceWhenAdded"].ToString());
            }
            connection.Close();

            connection.Open();
            if (price != priceWhenAdded)
            {
//            string query = @"UPDATE WalletsC SET idUser = "******",idWalletC=" + walletsC.idWalletC + ",idCrypto=" + walletsC.idCrypto + ",quantity=" + "'"+walletsC.quantity+"'" + ",sum=" + "'"+walletsC.sum+"'" + ",idAlert=" + walletsC.idAlert + "," + "priceWhenAdded=" + "'"+walletsC.priceWhenAdded + "'" + "," + "alertUp=" + "'"+walletsC.alertUp+"'" + "," + "alertDown=" + "'"+walletsC.alertDown+"'" + " WHERE idCrypto = " + walletsC.idCrypto + "";
                string query = @"UPDATE WalletsC SET idUser = "******",idWalletC=" + walletsC.idWalletC + ",idCrypto=" + walletsC.idCrypto + ",quantity=" + "'" + walletsC.quantity + "'" + ",sum=" + "'" + walletsC.sum + "'" + ",idAlert=" + walletsC.idAlert + "," + "priceWhenAdded=" + "'" + priceWhenAdded + "'" + "," + "alertUp=" + "'" + walletsC.alertUp + "'" + "," + "alertDown=" + "'" + walletsC.alertDown + "'" + " WHERE idCrypto = " + walletsC.idCrypto + "";
                //MessageBox.Show(query);
                SqlCommand command = new SqlCommand(query, connection);
                command.ExecuteNonQuery();
            }
            connection.Close();
            return(true);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
        public bool deleteWalletsC(WalletsC walletsC)
        {
            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 WalletsC WHERE idCrypto = " + walletsC.idCrypto + "";
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            connection.Close();
            return(true);
        }
Exemplo n.º 5
0
        public bool saveWalletsC(WalletsC walletsC)
        {
            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 WalletsC VALUES (" + walletsC.idUser + "," + walletsC.idWalletC + "," + walletsC.idCrypto + "," + "'" + walletsC.quantity + "'" + "," + "'" + walletsC.sum + "'" + "," + walletsC.idAlert + "," + "'" + walletsC.priceWhenAdded + "'" + ", 0," + "'" + walletsC.alertUp + "'" + "," + "'" + walletsC.alertDown + "'" + ")";
            SqlCommand command = new SqlCommand(query, connection);

            command.ExecuteNonQuery();

            connection.Close();
            return(true);
        }
Exemplo n.º 6
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();
            }
        }