Exemplo n.º 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            ForeignExchange foreignExchange = new ForeignExchange();

            foreignExchange.Show();

            this.Hide();
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (excToRmbBtn.Checked)
            {
                double excToRmb;
                try
                {
                    excToRmb = double.Parse(excNum.Text);
                    double sellprice3 = double.Parse(sellPrice.Text);
                    //double exc_excToRmb = (excToRmb / sellprice3) * 100;
                    //因为用户输入的是人民币,这里把人民币换成对应货币在比较是否会发生"您拥有的货币量不足"

                    string excKey = currencyChoose.Text;
                    //int nowexc = 0;         //需要数据库提供数据(当前币种拥有的货币量)(币种:excKey)

                    double           nowrmb;
                    string           sql  = "Select * from foreignexchange where 手机号='" + phonenumber + "'AND 货币种类='" + excKey + "'";
                    string           sql2 = "Select * from debitcardinfo where 手机号='" + phonenumber + "'";
                    DB.MySqlDataBase mdb  = new DB.MySqlDataBase();
                    MySqlDataReader  rd   = mdb.read(sql);
                    MySqlDataReader  rd2  = mdb.read(sql2);

                    rd.Read();

                    string a;
                    a      = rd["货币持有量"].ToString();
                    nowExc = double.Parse(a);

                    rd2.Read();

                    string b;
                    b      = rd2["活期存款余额"].ToString();  //读出此时储蓄卡的余额到string型变量b
                    nowrmb = double.Parse(b);

                    rd.Close();                             //关闭连接
                    rd2.Close();

                    if (excToRmb > nowExc)
                    {
                        MessageBox.Show("您拥有的货币量不足");
                    }

                    else if (excToRmb <= 0)
                    {
                        MessageBox.Show("兑换数量应大于0!");
                        excNum.Text = "";
                    }

                    else
                    {
                        //更新数据库(减少该种货币量以及增加人民币储蓄)
                        //返回上一界面

                        double newexc, newrmb;   //兑换后的外币和人民币
                        //double sellprice3 = double.Parse(sellPrice.Text);
                        //计算公式
                        newexc = nowExc - excToRmb;
                        newrmb = nowrmb + double.Parse(textBox1.Text);
                        string           sql3 = "UPDATE debitcardinfo SET 活期存款余额 = '" + newrmb + "' where 手机号='" + phonenumber + "'";
                        string           sql4 = "UPDATE foreignexchange SET 货币持有量 = '" + newexc + "' where 手机号='" + phonenumber + "'AND 货币种类='" + excKey + "'";
                        DB.MySqlDataBase db3  = new DB.MySqlDataBase();
                        int ext3 = mdb.Excute(sql3);
                        int ext4 = mdb.Excute(sql4);
                        if (ext4 > 0)
                        {
                            MessageBox.Show("兑换成功!");
                            ForeignExchange insert = new ForeignExchange();
                            insert.Show();
                            this.Close();
                            //更新界面
                        }

                        //更新数据库(减少该种货币量以及增加人民币储蓄)
                    }
                }
                catch
                {
                    if (currencyChoose.Text == "")
                    {
                        MessageBox.Show("未选择交易币种");
                    }
                    else
                    {
                        MessageBox.Show("请输入兑换金额");
                    }
                }
            }

            else if (rmbToExcBtn.Checked)
            {
                double rmbToExc;
                try
                {
                    rmbToExc = double.Parse(textBox1.Text);

                    //int rmbToExc = int.Parse(excNum.Text);
                    string excKey = currencyChoose.Text;
                    //int nowrmb = 0;     //需要数据库提供数据(人民币储蓄)(币种:excKey)

                    double           nowrmb;
                    string           sql  = "Select * from foreignexchange where 手机号='" + phonenumber + "'AND 货币种类='" + excKey + "'";
                    string           sql2 = "Select * from debitcardinfo where 手机号='" + phonenumber + "'";
                    DB.MySqlDataBase mdb  = new DB.MySqlDataBase();
                    MySqlDataReader  rd   = mdb.read(sql);
                    MySqlDataReader  rd2  = mdb.read(sql2);

                    rd.Read();
                    string a;
                    a      = rd["货币持有量"].ToString();
                    nowExc = double.Parse(a);

                    rd2.Read();
                    string b;
                    b      = rd2["活期存款余额"].ToString();  //读出此时储蓄卡的余额到string型变量b
                    nowrmb = double.Parse(b);

                    rd.Close();                             //关闭连接


                    if (rmbToExc > nowrmb)
                    {
                        MessageBox.Show("您的人民币储蓄不足");
                    }

                    else if (rmbToExc <= 0)
                    {
                        MessageBox.Show("兑换数量应大于0!");
                        excNum.Text = "";
                    }

                    else
                    {
                        //更新数据库(减少人民币储蓄以及增加该种货币量)(币种:excKey)
                        //返回上一界面

                        double newexc, newrmb;   //兑换后的外币和人民币
                        double buyprice4 = double.Parse(buyPrice.Text);
                        //计算公式
                        newexc = nowExc + double.Parse(excNum.Text);
                        newrmb = nowrmb - double.Parse(textBox1.Text);
                        string sql3 = "UPDATE debitcardinfo SET 活期存款余额 = '" + newrmb + "' where 手机号='" + phonenumber + "'";
                        string sql4 = "UPDATE foreignexchange SET 货币持有量 = '" + newexc + "' where 手机号='" + phonenumber + "'AND 货币种类='" + excKey + "'";
                        //更新数据库(减少人民币储蓄以及增加该种货币量)(币种:excKey)

                        DB.MySqlDataBase db3 = new DB.MySqlDataBase();
                        int ext3             = mdb.Excute(sql3);
                        int ext4             = mdb.Excute(sql4);
                        if (ext4 > 0)
                        {
                            MessageBox.Show("兑换成功!");
                            ForeignExchange insert = new ForeignExchange();
                            insert.Show();
                            this.Close();
                            //更新此界面
                        }
                    }
                }
                catch
                {
                    if (currencyChoose.Text == "")
                    {
                        MessageBox.Show("未选择交易币种");
                    }
                    else
                    {
                        MessageBox.Show("请输入兑换金额");
                    }
                }
            }

            else
            {
                MessageBox.Show("请选择交易类型");
            }
        }