private void crearPeso() { int idpersona = ApplicationState.GetValue<int>("persona"); using (IObjectContainer container = Db4oEmbedded.OpenFile("BikeTrain.db4o")) { int tmpIdPeso; try { tmpIdPeso = (from DPeso ps in container group ps by 1 into g select g.Max(q => q.ID)).First(); } catch (Exception) { tmpIdPeso = -1; } DPeso pes = new DPeso() { Fecha = dpFecha.SelectedDate.Value, ID = tmpIdPeso + 1, idPersona = idpersona, Peso = Convert.ToDouble(udPeso.Value.ToString().Replace('.', ',')) }; container.Store(pes); } }
private void btnCrearPrsona_Click(object sender, RoutedEventArgs e) { Persona prs; if (udAltura.Value != null && udEdad.Value != null && udPeso.Value != null && txtNombrPersona.Text != "") { using (IObjectContainer container = Db4oEmbedded.OpenFile("BikeTrain.db4o")) { int tmpId; int tmpIdPeso; try { tmpId = (from Persona p in container group p by 1 into g select g.Max(q => q.ID)).First(); } catch (Exception) { tmpId = -1; } try { tmpIdPeso = (from DPeso ps in container group ps by 1 into g select g.Max(q => q.ID)).First(); } catch (Exception) { tmpIdPeso = -1; } prs = new Persona() { ID = tmpId + 1, Altura = System.Convert.ToDouble(udAltura.Value), Edad = System.Convert.ToInt16(udEdad.Value), Nombre = txtNombrPersona.Text }; DPeso dppes = new DPeso() { ID = tmpIdPeso, idPersona = prs.ID, Fecha = DateTime.Now, Peso = System.Convert.ToDouble(udPeso.Value), }; container.Store(prs); container.Store(dppes); } disableAll(); loadComboPersonas(); cmbPersona.SelectedIndex = cmbPersona.Items.Count - 1; } else { Xceed.Wpf.Toolkit.MessageBox.Show("Faltan Datos!", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }