?? form1.cs
字號(hào):
public void RegisterChangeListener(IMoneyDbChangeListener listener)
{
this.ChangeListners.Add(listener);
}
public void RemoveChangeListener(IMoneyDbChangeListener listener)
{
this.ChangeListners.Remove(listener);
}
private void FireAccountChangeEvent()
{
for(int i=0;i<this.ChangeListners.Count;i++)
{
IMoneyDbChangeListener listener=this.ChangeListners[i] as IMoneyDbChangeListener;
if(listener!=null)
{
listener.OnAccountChanged();
}
}
}
private void FireBalanceChangeEvent()
{
for(int i=0;i<this.ChangeListners.Count;i++)
{
IMoneyDbChangeListener listener=this.ChangeListners[i] as IMoneyDbChangeListener;
if(listener!=null)
{
listener.OnBalanceChanged();
}
}
}
private void FireTransactionChangeEvent()
{
for(int i=0;i<this.ChangeListners.Count;i++)
{
IMoneyDbChangeListener listener=this.ChangeListners[i] as IMoneyDbChangeListener;
if(listener!=null)
{
listener.OnTransactionChanged();
}
}
}
public void CommitToFile(string filename)
{
if(this.GetChangedFlag()!=true)
{
return;
}
lock(this)
{
ds.WriteXml(filename);
}
this.ResetChangedFlag();
}
public void CommitToFile()
{
this.CommitToFile(this.sourcefile);
}
public void FillTransactionTypes()
{
lock(this)
{
ds.Tables["TransactionType"].Rows.Add(new object[]{"Dining Out"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Food"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Newspapger & Mag"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Clothing"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Movie/Video"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Sports"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Book"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Automobile"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Night Life"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Inventory Purchase"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Job Expense"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Cell Phone"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Cable TV"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Electricity"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Mortege"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Gas"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Telephone"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"House Rent"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Insuarance"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Water"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Computer"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Education"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Gift"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"House Cleaning"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Healthcare"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Pet"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Vacation"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Withdrawal"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Unknown Expense"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Investment Income"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Salary"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Reimbursement"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Deposit"});
ds.Tables["TransactionType"].Rows.Add(new object[]{"Unknown Income"});
this.SetChangedFlag();
}
}
public void FillSampleData()
{
this.FillTransactionTypes();
ds.Tables["Accounts"].Rows.Add(new object[]{0,"Cash",150.5});
ds.Tables["Accounts"].Rows.Add(new object[]{1,"CMB Credit Card",-3200});
ds.Tables["Transaction"].Rows.Add(new object[]{0,"Food",0,-22,System.DateTime.Now,"for lunch"});
ds.Tables["Transaction"].Rows.Add(new object[]{1,"Book",0,-10.5,System.DateTime.Now,"magazine"});
ds.Tables["Transaction"].Rows.Add(new object[]{2,"Unknown Expense",1,-698,System.DateTime.Now,"jean"});
ds.Tables["Transaction"].Rows.Add(new object[]{3,"Food",1,-38,System.DateTime.Now,"dinner"});
ds.Tables["Transaction"].Rows.Add(new object[]{4,"Salary",0,10200,System.DateTime.Now,"Salary"});
}
private int GetLatestTransactionID()
{
int rowcount=ds.Tables["Transaction"].Rows.Count;
if(rowcount==0)
{
return -1;
}
else
{
return System.Int32.Parse(ds.Tables["Transaction"].Rows[rowcount-1]["ID"].ToString());
}
}
private int GetLatestAccountID()
{
int rowcount=ds.Tables["Accounts"].Rows.Count;
if(rowcount==0)
{
return -1;
}
else
{
return System.Int32.Parse(ds.Tables["Accounts"].Rows[rowcount-1]["AccountID"].ToString());
}
}
public void NewTransaction(string Type,int Account,double Amount,System.DateTime Date,string Note)
{
lock(this)
{
ds.Tables["Transaction"].Rows.Add(new object[]{this.GetLatestTransactionID()+1,Type,Account,Amount,Date,Note});
this.SetBalance(Account,this.GetBalance(Account)+Amount);
this.FireTransactionChangeEvent();
this.SetChangedFlag();
}
}
public double GetBalance(int AccountID)
{
DataRow[] drs=ds.Tables["Accounts"].Select("AccountID="+AccountID);
if(drs.Length>0)
{
return System.Double.Parse(drs[0]["Balance"].ToString());
}
else
return 0;
}
public void SetBalance(int AccountID,double newvalue)
{
DataRow[] drs=ds.Tables["Accounts"].Select("AccountID="+AccountID);
if(drs.Length>0)
{
drs[0]["Balance"]=newvalue;
}
this.FireBalanceChangeEvent();
}
public void DeleteTransaction(int TransactionID)
{
lock(this)
{
DataRow[] drs=ds.Tables["Transaction"].Select("ID="+TransactionID);
foreach(DataRow dr in drs)
{
double amount=System.Double.Parse(dr["Amount"].ToString());
int accountid=System.Int32.Parse(dr["Account"].ToString());
this.SetBalance(accountid,this.GetBalance(accountid)-amount);
ds.Tables["Transaction"].Rows.Remove(dr);
}
this.FireTransactionChangeEvent();
this.SetChangedFlag();
}
}
public void ClearTransactions(int AccountID)
{
lock(this)
{
DataRow[] drs=ds.Tables["Transaction"].Select("Account="+AccountID);
foreach(DataRow dr in drs)
{
ds.Tables["Transaction"].Rows.Remove(dr);
}
this.FireTransactionChangeEvent();
this.SetChangedFlag();
}
}
public int GetAccountId(string AccountName)
{
DataRow[] drs=ds.Tables["Accounts"].Select("Name='"+AccountName+"'");
foreach(DataRow dr in drs)
{
return System.Int32.Parse(dr["AccountID"].ToString());
}
return -1;
}
public void NewAccount(string Name,double initBalance)
{
lock(this)
{
ds.Tables["Accounts"].Rows.Add(new object[]{this.GetLatestAccountID()+1,Name,initBalance});
this.FireAccountChangeEvent();
this.SetChangedFlag();
}
}
public void DeleteAccount(string Name)
{
int id=this.GetAccountId(Name);
if(id!=-1)
{
this.DeleteAccount(id);
}
}
public void DeleteAccount(int AccountID)
{
lock(this)
{
DataRow[] drs=ds.Tables["Accounts"].Select("AccountID="+AccountID+"");
foreach(DataRow dr in drs)
{
DataRow[] trans=ds.Tables["Transaction"].Select("Account="+dr["AccountID"].ToString());
foreach(DataRow transactionRow in trans)
{
ds.Tables["Transaction"].Rows.Remove(transactionRow);
}
}
ds.Tables["Accounts"].Rows.Remove(ds.Tables["Accounts"].Rows.Find(AccountID));
this.FireAccountChangeEvent();
this.SetChangedFlag();
}
}
public DataTable GetAccounts()
{
return ds.Tables["Accounts"];
}
public DataRow[] GetTransactions(int AccountID)
{
return ds.Tables["Transaction"].Select("Account="+AccountID);
}
public DataRow GetTransactionInfo(int TransactionID)
{
DataRow[] rows=ds.Tables["Transaction"].Select("ID="+TransactionID);
if(rows.Length>0)
{
return rows[0];
}
else
{
return null;
}
}
public string[] GetTypes()
{
string[] types=new string[ds.Tables["TransactionType"].Rows.Count];
for(int i=0;i<ds.Tables["TransactionType"].Rows.Count;i++)
{
types[i]=ds.Tables["TransactionType"].Rows[i]["TypeName"].ToString();
}
return types;
}
public void Transfer(int FromAccount,int ToAccount,double Amount)
{
this.NewTransaction("Withdrawal",FromAccount,0-Amount,System.DateTime.Now,"transfer "+FromAccount+"->"+ToAccount);
this.NewTransaction("Deposit",ToAccount,Amount,System.DateTime.Now,"transfer "+FromAccount+"->"+ToAccount);
}
public bool SetAccountName(string originalName,string newName)
{
lock(this)
{
DataRow[] rows=ds.Tables["Accounts"].Select("Name='"+newName+"'");
if(rows.Length>0)
{
return false;
}
DataRow[] drs=ds.Tables["Accounts"].Select("Name='"+originalName+"'");
foreach(DataRow row in drs)
{
row["Name"]=newName;
}
this.FireAccountChangeEvent();
this.SetChangedFlag();
return true;
}
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -