예제 #1
0
        private void DisplayCapital()
        {
            //Displaying the user's capital
            Capital cap = new Capital();

            BGNCap.Text = Capital.BGN;
            USDCap.Text = Capital.USD;
            EURCap.Text = Capital.EUR;
            GBPCap.Text = Capital.GBP;
            CHFCap.Text = Capital.CHF;
            AUDCap.Text = Capital.AUD;
            CADCap.Text = Capital.CAD;
        }
예제 #2
0
        private void DisplayBalance()
        {
            Capital cap     = new Capital();
            string  balance = "";//variable that contains the old sum of the user
            //(before the new calulation with the up-to-date rates

            //making the connectiong with the database
            MySqlConnection  cnn;
            MySqlDataAdapter adapter = new MySqlDataAdapter();

            cnn = new MySqlConnection(LoginForm.connStr);
            cnn.Open();

            //getting the old sum
            string sql = "SELECT uc.usum FROM usercapital uc " +
                         "WHERE uc.uid = '" + LoginForm.uid + "';";

            //inserting the command
            MySqlCommand comd = new MySqlCommand(sql, cnn);

            adapter.InsertCommand = new MySqlCommand(sql, cnn);
            adapter.InsertCommand.ExecuteNonQuery();

            //reading the output
            MySqlDataReader dataReader = comd.ExecuteReader();

            while (dataReader.Read())
            {
                balance += dataReader.GetValue(0);
            }
            cnn.Close();

            //variable, containing the up-to-date sum
            float suma = Suma();

            suma                = (float)System.Math.Round(suma, 2);
            label3.Text         = suma.ToString().Trim();
            Capital.UserCapital = suma.ToString().Trim();

            float sum = suma - float.Parse(balance);//variable that contains the difference between

            //the old capital and the up-to-date one
            sum = (float)System.Math.Round(sum, 2);

            //displaying the differnence
            string label = "";

            //if the user lost money, it displays '-'
            if (sum < 0)
            {
                label += sum.ToString() + " .lv";
            }
            //if he won, it displays '+'
            else if (sum > 0)
            {
                label += "+";
                label += sum.ToString() + " .lv";
            }
            else
            {
                label += "+";
                label += "0 lv.";
            }
            label5.Text = label.Trim();
        }
예제 #3
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            //the errors in different scenarios
            if (ChooseCurr.Text == CurrToConvert.Text)
            {
                string            caption = "Error!";
                string            text    = "The currencies for the convertion are the same!";
                MessageBoxButtons buttons = MessageBoxButtons.OK;

                DialogResult result;
                result = MessageBox.Show(text, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (SumToConvert.Text == "")
            {
                string            caption = "Error!";
                string            text    = "Sum to convert is null!";
                MessageBoxButtons buttons = MessageBoxButtons.OK;

                DialogResult result;
                result = MessageBox.Show(text, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (Int32.Parse(SumToConvert.Text) == 0)
            {
                string            caption = "Error!";
                string            text    = "Sum to convert is 0!";
                MessageBoxButtons buttons = MessageBoxButtons.OK;

                DialogResult result;
                result = MessageBox.Show(text, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    this.Close();
                }
            }
            if (Int32.Parse(SumToConvert.Text) < 0)
            {
                string            caption = "Error!";
                string            text    = "Invalid sum!";
                MessageBoxButtons buttons = MessageBoxButtons.OK;

                DialogResult result;
                result = MessageBox.Show(text, caption, buttons);
                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    this.Close();
                }
            }
            //if everything is correct
            if (Int32.Parse(SumToConvert.Text) > 0)
            {
                Capital cap = new Capital();
                double  Cur1minus;//variable containing the capital in the currency, from which the user
                //subtracts money

                //Example: Convert.ToDouble(Capital.cap[usd])
                Cur1minus = Convert.ToDouble(Capital.cap[ChooseCurr.SelectedItem]);
                //subtracting the sum from the first currency
                Cur1minus -= Convert.ToDouble(SumToConvert.Text);
                //two symbols after decimal point
                Cur1minus = (double)System.Math.Round(Cur1minus, 2);
                //saving the result from subtracting capital from the first currency,
                //for it to be send to the other
                Capital.cap[ChooseCurr.SelectedItem] = Cur1minus.ToString();

                //variable containing the capital in the second currency where the user sends money
                //formula for finding the rate of the currency in which the user sends money
                //(example) EUR/USD = USD/BGN / EUR/BGN
                double Cur2plus = Convert.ToDouble(SumToConvert.Text) /
                                  (Convert.ToDouble(Kurs.kursP[CurrToConvert.SelectedItem]) /
                                   Convert.ToDouble(Kurs.kursP[ChooseCurr.SelectedItem]));
                //two symbols after the decimal point
                Cur2plus = (double)System.Math.Round(Cur2plus, 2);

                //saving the result from the transaction in the variable in the currency,
                //where money are send
                Capital.cap[CurrToConvert.Text] = Convert.ToDouble(Capital.cap[CurrToConvert.SelectedItem])
                                                  + Cur2plus;

                //Displaying the updated capitals in each of the currencies that took
                //part in the convertion
                FirstCurrCap.Text = Capital.cap[ChooseCurr.SelectedItem].ToString()
                                    + " " + ChooseCurr.SelectedItem;
                SecondCurrCap.Text = Capital.cap[CurrToConvert.SelectedItem].ToString()
                                     + " " + CurrToConvert.SelectedItem;

                //connecting with the database
                MySqlConnection  cnn;
                MySqlDataAdapter adapter = new MySqlDataAdapter();
                cnn = new MySqlConnection(LoginForm.connStr);
                cnn.Open();

                //making the command which updates the user capital in the database and sending it
                String sql = "UPDATE usercapital SET " + CurrToConvert.Text + " = '" + Capital.cap[CurrToConvert.Text].ToString().Replace(',', '.') + "', " + ChooseCurr.SelectedItem + " = '" + Capital.cap[ChooseCurr.SelectedItem].ToString().Replace(',', '.') +
                             "' WHERE uid = '" + LoginForm.uid + "';";
                MySqlCommand comd = new MySqlCommand(sql, cnn);
                adapter.InsertCommand = new MySqlCommand(sql, cnn);
                adapter.InsertCommand.ExecuteNonQuery();
                comd.Dispose();
                this.Refresh();
                this.Invalidate();
            }
        }