Beispiel #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.activity_main);
            //Create Database
            db = new Database();
            db.createDatabase();
            lstViewData = FindViewById <ListView>(Resource.Id.listView);
            var edtName = FindViewById <EditText>(Resource.Id.edtName);

            var btnAdd    = FindViewById <Button>(Resource.Id.btnAdd);
            var btnEdit   = FindViewById <Button>(Resource.Id.btnEdit);
            var btnRemove = FindViewById <Button>(Resource.Id.btnRemove);

            //Load Data
            LoadData();
            //Event
            btnAdd.Click += delegate
            {
                Shopping shopping = new Shopping()
                {
                    Name = edtName.Text,
                };
                db.insertIntoTable(shopping);
                LoadData();
            };
            btnEdit.Click += delegate
            {
                Shopping shopping = new Shopping()
                {
                    Id   = int.Parse(edtName.Tag.ToString()),
                    Name = edtName.Text,
                };
                db.updateTable(shopping);
                LoadData();
            };
            btnRemove.Click += delegate
            {
                Shopping shopping = new Shopping()
                {
                    Id   = int.Parse(edtName.Tag.ToString()),
                    Name = edtName.Text,
                };
                db.removeTable(shopping);
                LoadData();
            };
        }
Beispiel #2
0
        //Delete Data Operation

        public bool removeTable(Shopping shopping)
        {
            try
            {
                using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Shopping.db")))
                {
                    connection.Delete(shopping);
                    return(true);
                }
            }
            catch (SQLiteException ex)
            {
                Log.Info("SQLiteEx", ex.Message);
                return(false);
            }
        }
Beispiel #3
0
        //Edit Operation

        public bool updateTable(Shopping shopping)
        {
            try
            {
                using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Shopping.db")))
                {
                    connection.Query <Shopping>("UPDATE Shopping set Name=? Where Id=?", shopping.Name, shopping.Id);
                    return(true);
                }
            }
            catch (SQLiteException ex)
            {
                Log.Info("SQLiteEx", ex.Message);
                return(false);
            }
        }