async void RegistrarItem(object sender, System.EventArgs e) { if (await validarFormulario()) { var dbpath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db"); var db = new SQLiteConnection(dbpath); db.CreateTable <ItemViewTable>(); db.CreateTable <Campo_custom_item>(); string nuevoId = DateTime.Now.ToString(); var item = new ItemViewTable() { Id = nuevoId, nombre = EntryName.Text, imagen = labelpath.Text, fecha_creacion = DateTime.Now.ToString(), IdColeccion = this.idcolle }; foreach (Entry entry in camposCustom.Children) { var valorCustoms = new Campo_custom_item() { valor = entry.Text, IdCampoCustom = Int32.Parse(entry.StyleId), IdItem = nuevoId }; db.Insert(valorCustoms); } db.Insert(item); Device.BeginInvokeOnMainThread(async() => { var result = await this.DisplayAlert("Agregado!", "Objeto agregado", "OK", "Cancelar"); if (result) { /* await Navigation.PushAsync(new CollectionPage(this.idcolle ,this.idusu)); */ await Navigation.PopAsync(); } }); } }
void GuardarCustom(object sender, System.EventArgs e) { var dbpath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "UserDatabase.db"); var db = new SQLiteConnection(dbpath); db.CreateTable <Campo_custom_item>(); string propiedad = db.Table <Campo_custom>().Where(u => u.Id.Equals(this.idCus)).FirstOrDefault().nombre_campo; var valorCustom = new Campo_custom_item() { valor = propiedad + ": " + EntryValor.Text, //IdCampoCustom = this.idCus, //IdItem = this.idItem }; int Count = db.Table <Campo_custom_item>().Where(u => u.IdCampoCustom.Equals(this.idCus) && u.IdItem.Equals(this.idItem)).Count(); if (Count >= 1) { db.Update(db.Table <Campo_custom_item>().Where(u => u.IdCampoCustom.Equals(this.idCus) && u.IdItem.Equals(this.idItem)).FirstOrDefault()); } else { db.Insert(valorCustom); } Device.BeginInvokeOnMainThread(async() => { var result = await this.DisplayAlert("Agregada!", "custom agregado", "OK", "Cancelar"); if (result) { /* await Navigation.PushAsync(new CollectionPage(this.idcolle ,this.idusu)); */ await Navigation.PopAsync(); } }); }