예제 #1
0
        private void button_Click_1(object sender, RoutedEventArgs e)
        {
            double aux = -1;

            try
            {
                if (double.TryParse(textBoxc.Text, out aux))
                {
                    if (comboBox.Text == "Ordem")
                    {
                        atype = 0;
                    }

                    else if (comboBox.Text == "Prazo 6M")
                    {
                        atype = 1;
                    }
                    else if (comboBox.Text == "Prazo 1A")
                    {
                        atype = 2;
                    }
                    else if (comboBox.Text == "Prazo 3A")
                    {
                        atype = 3;
                    }


                    if (!refresh())
                    {
                        return;
                    }

                    SqlCommand cmd = new SqlCommand("SELECT interest from account_type where atype=" + atype);
                    cmd.Connection = cn;
                    double baseInterest = (double)(decimal)cmd.ExecuteScalar() * 100;

                    double interest = 0;

                    if (atype == 1)
                    {
                        double capital   = Convert.ToDouble(textBoxc.Text);
                        double jurofinal = ((capital * baseInterest) / 180) / 365;
                        double pormes    = capital * jurofinal;
                        interest = pormes / 6;
                    }
                    else if (atype == 2)
                    {
                        double capital   = Convert.ToDouble(textBoxc.Text);
                        double jurofinal = ((capital * baseInterest) / 365) / 365;
                        double pormes    = capital * jurofinal;
                        interest = pormes / (1 * 12);
                    }
                    else if (atype == 3)
                    {
                        double capital   = Convert.ToDouble(textBoxc.Text);
                        double jurofinal = ((capital * baseInterest) / 1095) / 365;
                        double pormes    = capital * jurofinal;
                        interest = pormes / (3 * 12);
                    }

                    //make sure unique IDs are used when creating things


                    cmd            = new SqlCommand("SELECT max(id) FROM ACCOUNTS");
                    cmd.Connection = cn;
                    int newID = (int)cmd.ExecuteScalar() + 1;

                    string b = aux.ToString().Replace(",", ".");
                    string i = interest.ToString().Replace(",", ".");

                    try
                    {
                        cmd            = new SqlCommand("EXEC InsertAccount " + newID + ", " + b + ", " + atype + ", " + i);
                        cmd.Connection = cn;
                        cmd.ExecuteNonQuery();

                        if (goback == "client" && autolinkid != -1)
                        {
                            cmd            = new SqlCommand("INSERT INTO CLIENT_ACCOUNTS (aid, cid) VALUES (" + newID + ", " + autolinkid + ")");
                            cmd.Connection = cn;
                            cmd.ExecuteNonQuery();

                            ClientDetails window = new ClientDetails();
                            window.Show();
                            this.Hide();
                        }
                        else
                        {
                            Accounts window = new Accounts();
                            window.Show();
                            this.Hide();
                        }
                    }
                    catch (SqlException) { MessageBox.Show("Error updating database: the balance might be too high."); }
                }
                else
                {
                    MessageBox.Show("Invalid amount.");
                }
            }
            catch (OverflowException) { MessageBox.Show("The number is too big."); }
        }