Beispiel #1
0
        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();
        }
Beispiel #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Edit);
            // Create your application here


            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);

            addButton.Text = "Add New Event";


            string[] datepart;
            string   displaydate;

            string displaytime;

            string[] timepart;

            string meridian = "am";
            int    timehr;


            if (Intent.HasExtra("name"))
            {
                nameText.Text = Intent.GetStringExtra("name");
            }


            if (Intent.HasExtra("where"))
            {
                whereText.Text = Intent.GetStringExtra("where");
            }


            if (Intent.HasExtra("with"))
            {
                withText.Text = Intent.GetStringExtra("with");
            }


            if (Intent.HasExtra("extra"))
            {
                extraText.Text = Intent.GetStringExtra("extra");
            }


            if (Intent.HasExtra("date"))
            {
                displaydate = Intent.GetStringExtra("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");


                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
            {
                Event e = new Event();


                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);


                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.Create(e);
                base.OnBackPressed();
                Android.Widget.Toast.MakeText(this, "Added!", Android.Widget.ToastLength.Short).Show();
            };
        }