Beispiel #1
0
        private void OK_Click(object sender, EventArgs e)
        {
            if (PIB.Text.Length == 0 || Passport.Text.Length == 0 || Summ.Text.Length == 0)
            {
                MessageBox.Show("Всі поля мають бути заповнені!");
            }
            else
            {
                string pib       = PIB.Text;
                int    passport  = int.Parse(Passport.Text);
                string operation = Operation.SelectedItem.ToString();
                string valuta    = Currency.SelectedItem.ToString();
                float  summ      = float.Parse(Summ.Text);

                DB db = new DB();

                DataTable table  = new DataTable();
                DataTable table2 = new DataTable();

                MySqlDataAdapter adapter = new MySqlDataAdapter();

                MySqlCommand query  = new MySqlCommand("INSERT INTO `clients`(`id`, `PIB`, `passport`, `operation`, `valuta`, `summ`) VALUES ('','" + pib + "','" + passport + "','" + operation + "','" + valuta + "','" + summ + "')", db.GetConnection());
                MySqlCommand query2 = new MySqlCommand("SELECT `Buy`,`Sell` FROM `exchangerate` WHERE `title` = '" + valuta + "'", db.GetConnection());

                adapter.SelectCommand = query;
                adapter.Fill(table);
                adapter.SelectCommand = query2;
                adapter.Fill(table2);

                SummUAH.Visible = true;
                label3.Visible  = true;

                float[,] values = new float[table2.Rows.Count, table2.Columns.Count];
                for (int i = 0; i < table2.Rows.Count; i++)
                {
                    DataRow row = table2.Rows[i];
                    for (int j = 0; j < table2.Columns.Count; j++)
                    {
                        values[i, j] = (float)row[j];
                    }
                }

                float result = values[0, 0] * summ;

                SummUAH.Text = result.ToString();

                PIB.Clear();
                Passport.Clear();
                Summ.Clear();
                Operation.SelectedItem = "Купівля";
                Currency.SelectedItem  = 0;
            }
        }