/// <returns> /// Output of test query /// </returns> public static string DoSomeDataAccess () { var output = ""; output += "\nCreating database, if it doesn't already exist"; string dbPath = Path.Combine ( Environment.GetFolderPath (Environment.SpecialFolder.Personal), "ormdemo.db3"); var db = new SQLiteConnection (dbPath); db.CreateTable<Stock> (); if (db.Table<Stock> ().Count() == 0) { // only insert the data if it doesn't already exist var newStock = new Stock (); newStock.Symbol = "AAPL"; db.Insert (newStock); newStock = new Stock (); newStock.Symbol = "GOOG"; db.Insert (newStock); newStock = new Stock (); newStock.Symbol = "MSFT"; db.Insert (newStock); } output += "\nReading data using Orm"; var table = db.Table<Stock> (); foreach (var s in table) { output += "\n" + s.Id + " " + s.Symbol; } return output; }
// when displaying, set-up the properties public override void ViewWillAppear(bool animated) { base.ViewWillAppear (animated); if (currentStock == null) currentStock = new Stock();; Name.Text = currentStock.Name; Code.Text = currentStock.Symbol; }
public int SaveStock (Stock item) { lock (locker) { if (item.Id != 0) { Update (item); return item.Id; } else { return Insert (item); } } }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); View titleView = Window.FindViewById(Android.Resource.Id.Title); if (titleView != null) { IViewParent parent = titleView.Parent; if (parent != null && (parent is View)) { View parentView = (View)parent; parentView.SetBackgroundColor(Color.Rgb(0x26, 0x75 ,0xFF)); //38, 117 ,255 } } int stockId = Intent.GetIntExtra("StockId", 0); if (stockId > 0) { task = StockRepository.GetStock(stockId); } // set our layout to be the home screen SetContentView(Resource.Layout.TaskDetails); nameTextEdit = FindViewById<EditText>(Resource.Id.txtName); notesTextEdit = FindViewById<EditText>(Resource.Id.txtNotes); saveButton = FindViewById<Button>(Resource.Id.btnSave); // find all our controls cancelDeleteButton = FindViewById<Button>(Resource.Id.btnCancelDelete); // set the cancel delete based on whether or not it's an existing task if(cancelDeleteButton != null) { cancelDeleteButton.Text = (task.Id == 0 ? "Cancel" : "Delete"); } // name if(nameTextEdit != null) { nameTextEdit.Text = task.Name; } // notes if(notesTextEdit != null) { notesTextEdit.Text = task.Symbol; } // button clicks cancelDeleteButton.Click += (sender, e) => { CancelDelete(); }; saveButton.Click += (sender, e) => { Save(); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); View titleView = Window.FindViewById(Android.Resource.Id.Title); if (titleView != null) { IViewParent parent = titleView.Parent; if (parent != null && (parent is View)) { View parentView = (View)parent; parentView.SetBackgroundColor(Color.Rgb(0x26, 0x75 ,0xFF)); //38, 117 ,255 } } int stockId = Intent.GetIntExtra("StockId", 0); if (stockId > 0) { task = StockRepository.GetStock(stockId); } // seta o layout como paginas iniciais SetContentView(Resource.Layout.Edit); nameTextEdit = FindViewById<EditText>(Resource.Id.txtName); notesTextEdit = FindViewById<EditText>(Resource.Id.txtNotes); saveButton = FindViewById<Button>(Resource.Id.btnSave); // pega os controles cancelDeleteButton = FindViewById<Button>(Resource.Id.btnCancelDelete); if(cancelDeleteButton != null) { cancelDeleteButton.Text = (task.Id == 0 ? "Cancel" : "Delete"); } // Email if(nameTextEdit != null) { nameTextEdit.Text = task.Email; } // nome if(notesTextEdit != null) { notesTextEdit.Text = task.Nome; } // botoes cancelDeleteButton.Click += (sender, e) => { CancelDelete(); }; saveButton.Click += (sender, e) => { Save(); }; }
// public int DeleteStock(int id) // { // lock (locker) { // return Delete<Stock> (new Stock () { Id = id }); // } // } public int DeleteStock(Stock stock) { lock (locker) { return Delete<Stock> (stock.Id); } }
public void DeleteStock (Stock stock) { Console.WriteLine("Delete "+stock.Name); AppDelegate.Database.DeleteStock (stock); NavigationController.PopViewController(true); }
public static int DeleteStock(Stock item) { return me.db.DeleteStock(item); }
public static int SaveStock (Stock item) { return me.db.SaveStock(item); }
// this will be called before the view is displayed public void SetStock(RootViewController d, Stock Stock) { Delegate = d; currentStock = Stock; }
public void SaveStock(Stock stock) { Console.WriteLine("Save "+stock.Name); AppDelegate.Database.SaveStock (stock); NavigationController.PopViewControllerAnimated(true); }