-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b7964e1
commit 484405e
Showing
2,181 changed files
with
960,181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
body { | ||
background-color: #F8F8F8; | ||
font-family: 'Open Sans', sans-serif; | ||
font-size: 14px; | ||
font-weight: normal; | ||
line-height: 1.2em; | ||
margin: 15px; | ||
padding: 20px; | ||
} | ||
|
||
form { | ||
background: #9cbc2c; | ||
-moz-border-radius: 5px; | ||
-webkit-border-radius: 5px; | ||
border-radius: 5px; | ||
padding: 20px; | ||
width: 400px; | ||
} | ||
|
||
h1, p { | ||
color: #333; | ||
} | ||
|
||
.auto-style1 { | ||
width: 25%; | ||
border: 1px solid #0000FF; | ||
} | ||
|
||
.auto-style2 { | ||
width: 107px; | ||
} | ||
|
||
.btns { | ||
width: 127px; | ||
} |
100 changes: 100 additions & 0 deletions
100
Chapter 1/bank_terminal/build/web/bank_terminal_s5.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import 'dart:html'; | ||
import 'package:bank_terminal_s5/bank_terminal.dart'; | ||
|
||
LabelElement owner, balance, error; | ||
InputElement number, amount; | ||
ButtonElement btn_other, btn_deposit, btn_withdrawal, btn_interest; | ||
BankAccount bac; | ||
|
||
void main() { | ||
bind_elements(); | ||
attach_event_handlers(); | ||
disable_transactions(true); | ||
} | ||
|
||
bind_elements() { | ||
owner = querySelector('#owner'); | ||
balance = querySelector('#balance'); | ||
number = querySelector('#number'); | ||
btn_other = querySelector('#btn_other'); | ||
amount = querySelector('#amount'); | ||
btn_deposit = querySelector('#btn_deposit'); | ||
btn_interest = querySelector('#btn_interest'); | ||
error = querySelector('#error'); | ||
} | ||
|
||
attach_event_handlers() { | ||
number.onInput.listen(readData); | ||
amount.onChange.listen(nonNegative); | ||
amount.onBlur.listen(nonNegative); | ||
btn_other.onClick.listen(clearData); | ||
btn_deposit.onClick.listen(changeBalance); | ||
btn_interest.onClick.listen(interest); | ||
} | ||
|
||
readData(Event e) { | ||
// show data: | ||
var key = 'Bankaccount:${number.value}'; | ||
if (!window.localStorage.containsKey(key)) { | ||
error.innerHtml = "Unknown bank account!"; | ||
number.focus(); | ||
return; | ||
} | ||
error.innerHtml = ""; | ||
// read data from local storage: | ||
String acc_json = window.localStorage[key]; | ||
bac = new BankAccount.fromJsonString(acc_json); | ||
// show owner and balance: | ||
owner.innerHtml = "<b>${bac.owner.name}</b>"; | ||
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>"; | ||
// enable transactions part: | ||
disable_transactions(false); | ||
} | ||
|
||
clearData(Event e) => clear(); | ||
|
||
clear() { | ||
number.value = ""; | ||
owner.innerHtml = "----------"; | ||
balance.innerHtml = "0.0"; | ||
number.focus(); | ||
disable_transactions(true); | ||
} | ||
|
||
disable_transactions(bool off) { | ||
amount.disabled = off; | ||
btn_deposit.disabled = off; | ||
btn_interest.disabled = off; | ||
} | ||
|
||
nonNegative(Event e) { | ||
num input; | ||
try { | ||
input = double.parse(amount.value); | ||
} on FormatException catch(e) { | ||
window.alert("This is not a valid amount!"); | ||
amount.focus(); | ||
} | ||
} | ||
|
||
changeBalance(Event e) { | ||
// read amount: | ||
double money_amount = double.parse(amount.value); | ||
// call deposit on BankAccount object: | ||
if (money_amount >= 0) bac.deposit(money_amount); | ||
else bac.withdraw(money_amount); | ||
window.localStorage["Bankaccount:${bac.number}"] = bac.toJson(); | ||
// show new amount: | ||
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>"; | ||
// disable refresh screen: | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} | ||
|
||
interest(Event e) { | ||
bac.interest(); | ||
window.localStorage["Bankaccount:${bac.number}"] = bac.toJson(); | ||
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>"; | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
} |
Oops, something went wrong.