public static AccountModel GetCurrentAccount(string cardId) { var acc = new AccountModel(); cnn = SqlConnectionData.getConnection(); try { string query = "Select * From Accounts Join " + "Cards On Accounts.ID = Cards.AccID "+ "And Cards.ID='"+ cardId + "' Join AccountType ON " + "Accounts.AccountTypeID = AccountType.ID"; //var command = new SqlCommand(query, cnn); var adapter = new SqlDataAdapter(query, cnn); var da = new DataTable(); adapter.Fill(da); if (da.Rows.Count > 0) { acc.ID = da.Rows[0]["ID"].ToString(); acc.CusID = da.Rows[0]["CusID"].ToString(); acc.Balance = float.Parse(da.Rows[0]["Balance"].ToString()); acc.OverDraft = float.Parse(da.Rows[0]["OverDraft"].ToString()); acc.AccountType = da.Rows[0]["Name"].ToString(); acc.ODLimit = float.Parse(da.Rows[0]["OverDraftLimit"].ToString()); acc.WithdrawLimit = float.Parse(da.Rows[0]["WithdrawLimit"].ToString()); } } catch(Exception e) { return null; } finally { SqlConnectionData.CloseConnection(); } return acc; }
/// <summary> /// /// </summary> /// <param name="money"></param> /// <returns> /// 0: Can Withdraw and navigate to WaitForMoneyView. /// 1: Can not withdraw and navigate to Thankyou. /// </returns> public static int Withdraw(float money, CardModel Card, AccountModel Acc) { if (CanWithdraw(money, Acc.Balance, Acc.OverDraft)) { UpdateAllData(Card.ID, money); return 0; } return 1; }
public static void UpdateCurrentAccount() { Acc = AccountData.GetCurrentAccount(Card.ID); }