protected override void OnResume() { base.OnResume(); int Id = Intent.GetIntExtra("Id", 0); string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "EventDB.db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("EventDB.db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } EventDbAccess eventDb = new EventDbAccess(dbPath); Event e = eventDb.RetrieveId(Id); var itemName = FindViewById <TextView>(Resource.Id.itemName); var itemDate = FindViewById <TextView>(Resource.Id.itemDate); var itemWith = FindViewById <TextView>(Resource.Id.itemWith); var itemWhere = FindViewById <TextView>(Resource.Id.itemWhere); var itemExtra = FindViewById <TextView>(Resource.Id.itemExtra); var doneButton = FindViewById <Button>(Resource.Id.DoneButton); itemName.Text = e.name; itemDate.Text = "Due by " + e.time + " on " + e.date; itemWith.Text = "With " + e.with; itemWhere.Text = "At " + e.where; itemExtra.Text = e.extra; if (e.state == 1) { doneButton.Visibility = ViewStates.Gone; } }
static void Main(string[] args) { string dbPath = System.AppDomain.CurrentDomain.BaseDirectory + "/Files/EventDB.db"; //using (var conn = new SQLite.SQLiteConnection(dbPath)) //{ // conn.CreateTable<Event>(); //} EventDbAccess eventDb = new EventDbAccess(dbPath); string meridian; int month; int hour; int day; int minute; string date; string time; Random rnd = new Random(); Event e = new Event(); for (int i = 0; i < 100; i++) { month = rnd.Next(6, 13); day = rnd.Next(1, 31); hour = rnd.Next(1, 13); minute = rnd.Next(1, 60); if (rnd.Next(1, 3) == 1) { meridian = "am"; } else { meridian = "pm"; } date = "2017/" + month.ToString("00") + "/" + day.ToString("00"); time = hour.ToString("00") + ":" + minute.ToString("00") + " " + meridian; e.name = "Random Event " + i.ToString(); e.date = date; e.time = time; e.with = "Bob, Joe, Sue"; e.where = "Lane Community College"; e.extra = "This is a randomly generated event for demonstration purposes."; e.state = 0; eventDb.Create(e); } List <Event> d = eventDb.RetrieveId(1); Console.WriteLine(d[0].with); e = d[0]; e.with = "Joe, Fred, Bob"; eventDb.Update(e); List <Event> d2 = eventDb.RetrieveId(1); Console.WriteLine(d2[0].with); Console.WriteLine(); Console.ReadLine(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Details); if (!Intent.HasExtra("Id")) { var go = new Android.Content.Intent(this, typeof(MainActivity)); StartActivity(go); } else { var itemName = FindViewById <TextView>(Resource.Id.itemName); var itemDate = FindViewById <TextView>(Resource.Id.itemDate); var itemWith = FindViewById <TextView>(Resource.Id.itemWith); var itemWhere = FindViewById <TextView>(Resource.Id.itemWhere); var itemExtra = FindViewById <TextView>(Resource.Id.itemExtra); var doneButton = FindViewById <Button>(Resource.Id.DoneButton); var deleteButton = FindViewById <Button>(Resource.Id.DeleteButton); var editButton = FindViewById <Button>(Resource.Id.EditButton); int Id = Intent.GetIntExtra("Id", 0); string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "EventDB.db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("EventDB.db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } EventDbAccess eventDb = new EventDbAccess(dbPath); Event e = eventDb.RetrieveId(Id); itemName.Text = e.name; itemDate.Text = "Due by " + e.time + " on " + e.date; itemWith.Text = "With " + e.with; itemWhere.Text = "At " + e.where; itemExtra.Text = e.extra; if (e.state == 1) { doneButton.Visibility = ViewStates.Gone; } deleteButton.Click += delegate { eventDb.Delete(e); base.OnBackPressed(); Android.Widget.Toast.MakeText(this, "Event Deleted", Android.Widget.ToastLength.Short).Show(); }; editButton.Click += delegate { var go = new Android.Content.Intent(this, typeof(EditEvent)); go.PutExtra("Id", e.ID); StartActivity(go); }; doneButton.Click += delegate { e.state = 1; eventDb.Update(e); base.OnBackPressed(); Android.Widget.Toast.MakeText(this, "Completed!", Android.Widget.ToastLength.Short).Show(); }; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Edit); if (!Intent.HasExtra("Id")) { var go = new Android.Content.Intent(this, typeof(MainActivity)); StartActivity(go); } else { int Id = Intent.GetIntExtra("Id", 0); string dbPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "EventDB.db"); if (!File.Exists(dbPath)) { using (Stream inStream = Assets.Open("EventDB.db")) using (Stream outStream = File.Create(dbPath)) inStream.CopyTo(outStream); } EventDbAccess eventDb = new EventDbAccess(dbPath); Event e = eventDb.RetrieveId(Id); var nameText = FindViewById <EditText>(Resource.Id.NameText); var whereText = FindViewById <EditText>(Resource.Id.WhereText); var withText = FindViewById <EditText>(Resource.Id.WithText); var extraText = FindViewById <EditText>(Resource.Id.ExtraText); var date = FindViewById <DatePicker>(Resource.Id.DatePicker); var time = (TimePicker)FindViewById <TimePicker>(Resource.Id.TimePicker); var addButton = FindViewById <Button>(Resource.Id.AddButton); string[] datepart; string displaydate; string displaytime; string[] timepart; string meridian = "am"; int timehr; if (Intent.HasExtra("name")) { nameText.Text = Intent.GetStringExtra("name"); } else { nameText.Text = e.name; } if (Intent.HasExtra("where")) { whereText.Text = Intent.GetStringExtra("where"); } else { whereText.Text = e.where; } if (Intent.HasExtra("with")) { withText.Text = Intent.GetStringExtra("with"); } else { withText.Text = e.with; } if (Intent.HasExtra("extra")) { extraText.Text = Intent.GetStringExtra("extra"); } else { extraText.Text = e.extra; } if (Intent.HasExtra("date")) { displaydate = Intent.GetStringExtra("date"); } else { displaydate = e.date; } datepart = displaydate.Split('/'); date.UpdateDate(int.Parse(datepart[0]), (int.Parse(datepart[1]) - 1), int.Parse(datepart[2])); if (Intent.HasExtra("time")) { displaytime = Intent.GetStringExtra("time"); } else { displaytime = e.time; } timepart = displaytime.Split(new char[2] { ':', ' ' }); if (timepart[2] == "pm") { timepart[0] += 12; } time.Hour = int.Parse(timepart[0]); time.Minute = int.Parse(timepart[1]); addButton.Click += delegate { e.name = nameText.Text; e.date = date.Year + "/" + (date.Month + 1).ToString("00") + "/" + date.DayOfMonth.ToString("00"); e.where = whereText.Text; e.with = withText.Text; e.extra = extraText.Text; if (time.Hour > 12) { timehr = time.Hour - 12; meridian = "pm"; } else { timehr = time.Hour; } e.time = timehr.ToString() + ":" + time.Minute + " " + meridian; eventDb.Update(e); base.OnBackPressed(); Android.Widget.Toast.MakeText(this, "Updated!", Android.Widget.ToastLength.Short).Show(); }; } }