Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                amd = Convert.ToInt32(textBox1.Text);
            }
            catch (Exception e1)
            {
                MessageBox.Show("invalid input");
            }
            if (amd > 0)
            {
                if (amd % 100 == 0)
                {
                    if (amd <= 40000)
                    {
                        con.Open();
                        var        date = DateTime.Now;
                        string     dat  = date.ToString("dd/MM/yyyy:::hh:mm:ss");
                        SqlCommand cmd1 = new SqlCommand("insert into [transaction] (date,amount,cust_id) values('" + dat + "','" + amd + "','" + cust_id + "')", con);
                        cmd1.ExecuteNonQuery();
                        SqlCommand cmd = new SqlCommand("update account set balance=balance+'" + amd + "' where cust_id='" + cust_id + "'", con);
                        cmd.ExecuteNonQuery();
                        SqlCommand cmd2 = new SqlCommand("select cust_name from customer where cust_id='" + cust_id + "'", con);
                        using (SqlDataReader red = cmd2.ExecuteReader())
                        {
                            if (red.Read())
                            {
                                name = Convert.ToString(red["cust_name"]);
                            }
                        }

                        con.Close();
                        this.Hide();
                        transactionbill tr = new transactionbill(amd, cust_id, name);

                        tr.ShowDialog();
                    }
                    else
                    {
                        MessageBox.Show("enter amount below 40000");
                        textBox1.Clear();
                    }
                }
                else
                {
                    MessageBox.Show("ATM can accept notes of 100 500 2000 only");
                    textBox1.Clear();
                }
            }
            else
            {
                MessageBox.Show("enter valid amount");
                textBox1.Clear();
            }
        }
Пример #2
0
        public void withdrawamt(int s)
        {
            int    balance = 0;
            string name    = null;
            var    time    = DateTime.Now;

            con.Open();
            SqlCommand cmd1 = con.CreateCommand();

            cmd1.CommandType = CommandType.Text;
            string dt = time.ToString("dd/MM/yyyy:::hh:mm:ss");

            cmd1.CommandText = "insert into [transaction] (date,amount,cust_id) values('" + dt + "','" + s + "','" + cust_id + "')";
            cmd1.ExecuteNonQuery();
            SqlCommand cmd = con.CreateCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from account,customer where customer.cust_id=account.cust_id and customer.cust_id='" + cust_id + "' ";
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    balance = Convert.ToInt32(reader["balance"]);
                    name    = Convert.ToString(reader["cust_name"]);
                }
            }
            con.Close();
            if (balance < s)
            {
                label2.Hide();
                MessageBox.Show("Insufficient balance");
                textBox1.Clear();
            }
            else
            {
                con.Open();
                SqlCommand cmd3 = con.CreateCommand();
                cmd3.CommandType = CommandType.Text;
                int newb = balance - s;
                cmd3.CommandText = "update account set balance='" + newb + "' where cust_id='" + cust_id + "'";
                cmd3.ExecuteNonQuery();
                con.Close();
                transactionbill tr = new transactionbill(s, cust_id, name);
                this.Hide();
                tr.ShowDialog();
            }
        }