繁体   English   中英

c#WPF ATM应用程序

[英]c# WPF ATM Application

需要在以下代码中包含条件。

private void button1_Click(object sender, RoutedEventArgs e)
        {
            SqlConnection con = new SqlConnection(@"connectionstring");
            SqlCommand cmd = new SqlCommand("Command String", con);
            SqlDataReader readdata;

            try
            {
                con.Open();
                decimal balance = decimal.Parse(textBox1.Text);
                decimal Balance = 0.00M;
                cmd.CommandText = "SELECT Balance FROM Accounts";
                readdata = cmd.ExecuteReader();

                while (readdata.Read())
                {
                    Balance = decimal.Parse(readdata["Balance"].ToString());

                }
                con.Close();

                con = new SqlConnection(@"connectionstring");
                SqlCommand cmda = new SqlCommand("Command String", con);
                con.Open();

                if (Balance > balance)
                {

                    Balance -= balance;
                 cmda.CommandText = "UPDATE Accounts SET Balance = '" + Balance + "' ";

                    cmda.ExecuteNonQuery();
                    con.Close();
                    con.Dispose();
                    label2.Content = "Withdrawal Success";
                }
                else
                {
                    label2.Content = "Insufficient fund";

                    con.Close();
                    con.Dispose();
                }
            }

对于上面的代码,用户可以从余额中提取任何金额,但是我需要有条件仅提取100的金额(100,200,300等)

if (Balance > balance)更改为if (Balance > balance && balance % 100 == 0 )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM