Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Android.App;
- using Android.Widget;
- using Android.OS;
- using SQLite;
- using Android;
- using System;
- using System.Collections;
- namespace whatever
- {
- [Activity(Label = "whatever", MainLauncher = true)]
- public class MainActivity : Activity
- {
- TextView textView;
- EditText ime;
- EditText cena;
- protected override void OnCreate(Bundle savedInstanceState)
- {
- base.OnCreate(savedInstanceState);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.Main);
- Button button_create_db = FindViewById<Button>(Resource.Id.button1);
- button_create_db.Click += Button_create_db_Click1;
- textView = FindViewById<TextView>(Resource.Id.textView1);
- Button button_fill_spinner = FindViewById<Button>(Resource.Id.button2);
- button_fill_spinner.Click += Button_fill_spinner_Click;
- Button button_delete = FindViewById<Button>(Resource.Id.button3);
- button_delete.Click += Button_delete_Click;
- }
- private void Button_delete_Click(object sender, EventArgs e)
- {
- string dbPath = System.IO.Path.Combine(
- System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
- "sales.db3");
- var db = new SQLiteConnection(dbPath);
- db.DropTable<Products>();
- //throw new NotImplementedException();
- }
- private void Button_fill_spinner_Click(object sender, EventArgs e)
- {
- Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);
- string dbPath = System.IO.Path.Combine(
- System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
- "sales.db3");
- var sales = new SQLiteConnection(dbPath);
- ArrayList result = new ArrayList();
- var table = sales.Table<Products>();
- foreach (var s in table)
- {
- result.Add(s.Name);
- }
- string[] result_string = (string[])result.ToArray(typeof(string));
- var spiner_adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem, result_string);
- spiner_adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
- spinner.Adapter = spiner_adapter;
- }
- private void Button_create_db_Click1(object sender, EventArgs e)
- {
- string dbPath = System.IO.Path.Combine(
- System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
- "sales.db3");
- var sales = new SQLiteConnection(dbPath);
- sales.CreateTable<Products>();
- var newProduct = new Products();
- newProduct.Name = "Keyboard";
- newProduct.Price = 10;
- sales.Insert(newProduct);
- newProduct.Name = "Mouse";
- newProduct.Price = 15;
- sales.Insert(newProduct);
- newProduct.Name = "Printer";
- newProduct.Price = 20;
- sales.Insert(newProduct);
- ime = FindViewById<EditText>(Resource.Id.editText1);
- cena = FindViewById<EditText>(Resource.Id.editText2);
- newProduct.Name = ime.Text;
- newProduct.Price = float.Parse(cena.Text);
- sales.Insert(newProduct);
- }
- [Table("products")]
- public class Products
- {
- [PrimaryKey, AutoIncrement, Column("_id")]
- public int Id { get; set; }
- [MaxLength(8)]
- public string Name { get; set; }
- public float Price { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement