private void PopulateTable() { //Connect to db CreateDB(DbPath); var conn = new SQLite.SQLiteConnection(DbPath); var cmd = new SQLite.SQLiteCommand(conn); var results = conn.Table <Balance>().Where(x => true).OrderByDescending(x => x.Id); var DataSource = new BalanceTableDataSource(); double totalBalance = 0; foreach (var r in results) { DataSource.Balances.Add(new Balance(r.Id, r.Date, r.Desc, r.Amount)); totalBalance += r.Amount; } //populate table BalanceTable.DataSource = DataSource; BalanceTable.Delegate = new BalanceTableDelegate(this, DataSource); // populate initial double initialValue = 1000; try { initialValue = conn.Table <InitialValue>().OrderByDescending(x => x.id).First().Value; } catch (Exception e) { conn.Insert(new InitialValue(initialValue)); } InitialLabel.StringValue = string.Format("(Init. amt: {0})", initialValue); //Populate total TotalLabel.StringValue = string.Format("结余: {0}", initialValue + totalBalance); }
//constructor public BalanceTableDelegate(ViewController controller, BalanceTableDataSource dataSource) { this.Controller = controller; this.DataSource = dataSource; }