コードに引き出し画面があり、お金を引き出すときにアクセスデータベースを更新したいのですが、コードはプログラム内からデータベースから金額を削除するだけです。プログラムを閉じると、データベースは以前の状態にリセットされます。
この画面の私のコード
int moneyselected = 0;
Decimal balance = frmaccount.Balance;
public FrmTransaction()
{
InitializeComponent();
}
private void btnWithdraw_Click(object sender, EventArgs e)
{
if (moneyselected == 0)
{
MessageBox.Show("Select Amount");
}
else
{
if (moneyselected > balance)
{
MessageBox.Show("Not enough funds");
}
else
{
balance = balance - moneyselected;
OleDbCommandBuilder cb = new OleDbCommandBuilder(FrmLogin.da);
FrmLogin.da.Update(FrmLogin.ds1, "tblCustomers");
MessageBox.Show("Amount Withdrawn = " + moneyselected.ToString() + "\r\nBalance = " + balance.ToString());
}
}
}
private void btnWithdrawreceipt_Click(object sender, EventArgs e)
{
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
Form FrmLogin = new FrmLogin();
this.Hide();
FrmLogin.Show();
}
private void FrmTransaction_Load(object sender, EventArgs e)
{
}
private void rb10_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 10;
}
private void rb20_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 20;
}
private void rb30_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 30;
}
private void rb40_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 40;
}
private void rb50_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 50;
}
private void rb60_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 60;
}
private void rb70_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 70;
}
private void rb80_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 80;
}
private void rb90_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 90;
}
private void Cashamountbox_Enter(object sender, EventArgs e)
{
}
private void rb100_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 100;
}
private void rb150_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 150;
}
private void rb250_CheckedChanged(object sender, EventArgs e)
{
moneyselected = 250;
}
}>>LOGIN PAGE<<
}
namespace BANK_ATM_PROJECT
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
int failedAttempts = 0;
public static OleDbConnection con = new OleDbConnection();
string dbProvider;
string dbSource;
public static OleDbDataAdapter da;
public static DataSet ds1 = new DataSet();
string sql;
string pin;
int rownum = 0;
bool valid = false;
public static decimal balance = 0;
private void FrmLogin_Load(object sender, EventArgs e)
{
{
dbProvider = "PROVIDER=Microsoft.ACE.OLEDB.12.0;";
dbSource = "Data Source = 'D:\\bank11.accdb'";
con.ConnectionString = dbProvider + dbSource;
ds1 = new DataSet();
con.Open();
sql = " SELECT tblCustomers.* FROM tblCustomers";
da = new OleDbDataAdapter(sql, con);
rownum = da.Fill(ds1, "tblCustomers");
con.Close();
{
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
System.Environment.Exit(0);
this.Close();
}
private bool validate()
{
ds1 = new DataSet();
con.Open();
sql = "SELECT tblCustomers.* FROM tblCustomers WHERE ((tblCustomers.AccountNo) = '" + txtAccount.Text + "')";
da = new OleDbDataAdapter(sql, con);
rownum = da.Fill(ds1, "tblCustomers");
con.Close();
if (rownum != 1)
{
return false;
}
else
{
pin = ds1.Tables["tblCustomers"].Rows[0][4].ToString();
if (pin == txtPin.Text)
{
return true;
}
else
{
MessageBox.Show("INVALID PIN");
return false;
}
}
}
private void btnLogin_Click(object sender, EventArgs e)
{
valid = validate();
if (!valid)
{
//Increment the number of failed attempts
failedAttempts += 1;
if (failedAttempts == 1)
MessageBox.Show("You Have 2 Attempts Left");
if (failedAttempts == 2)
MessageBox.Show("You Have 1 Attempt Left");
//If equal to 3
if (failedAttempts == 3)
MessageBox.Show("Card Retained");
{
}
}
else
{
valid = validate();
if (valid == true)
{
if (txtAccount.Text == "11111111" && txtPin.Text == "9999")
{
Frmmanager Manager = new Frmmanager();
this.Close();
Manager.Show();
}
else
{
frmaccount account = new frmaccount();
this.Close();
account.Show();
{
txtAccount.Clear();
txtPin.Clear();
valid = validate();
if (valid == true)
{
if (txtAccount.Text == "11111111" && txtPin.Text == "9999")
{
Frmmanager Manager = new Frmmanager();
this.Close();
Manager.Show();
}
else
{
frmaccount Account = new frmaccount();
this.Close();
account.Show();
{
txtAccount.Clear();
txtPin.Clear();
}
}
}
}
}
}
}
}
}
}
私は
ds.update
それを更新しただろうと思っていましたが、これはプログラム内でのみ機能するようです
ヘルプやアドバイスをいただければ幸いです