private void guardaPaciente(object sender, RoutedEventArgs e) { ArrayList valores = new ArrayList(); int Sexo = 1; if (this.radioButton2.IsChecked.Value) { Sexo = 2; } DatosCehavi datos1 = new DatosCehavi(); datos1.Connect(); string NombrePaciente = this.NombrePaciente.Text; if (NombrePaciente.Length < 5) { MessageBox.Show("El nombre es invalido!", "Advertencia:"); return; } if (this.FechaNac_DatePicker.SelectedDate == null) { MessageBox.Show("La Fecha de naciemiento es invalida!", "Advertencia:"); return; } valores.Add(new Registro("Nombre", NombrePaciente)); valores.Add(new Registro("FechaNac", this.FechaNac_DatePicker.SelectedDate)); valores.Add(new Registro("Sexo", Sexo)); valores.Add(new Registro("IdGradoEscuela", this.comboBox1.SelectedValue)); valores.Add(new Registro("IdEscuela", this.comboBox2.SelectedValue)); valores.Add(new Registro("terapias", 1)); valores.Add(new Registro("estatus", this.comboBox3.SelectedValue)); valores.Add(new Registro("calle", this.Calle.Text)); valores.Add(new Registro("cp", this.CodigoPostal.Text)); valores.Add(new Registro("idestado", this.comboBox4.SelectedValue)); valores.Add(new Registro("exterior", this.exterior.Text)); valores.Add(new Registro("interior", this.interior.Text)); valores.Add(new Registro("telefonocasa", this.telefonocasa.Text)); valores.Add(new Registro("telefonocel", this.telefonomovil.Text)); valores.Add(new Registro("telefonorecados", this.telefonorecados.Text)); valores.Add(new Registro("email", this.email.Text)); Int32 CurCiudad = datos1.BuscaNombreTabla(this.Ciudad.Text, "Ciudad", "Id", "Nombre"); if (CurCiudad == 0) { CurCiudad = datos1.InsertaNombreCampo(this.Ciudad.Text, "Ciudad", "Nombre"); } Int32 CurMunicipio = datos1.BuscaNombreTabla(this.Municipio.Text, "Municipio", "Id", "Nombre"); if (CurMunicipio == 0) { CurMunicipio = datos1.InsertaNombreCampo(this.Ciudad.Text, "Municipio", "Nombre"); } Int32 CurColonia = datos1.BuscaNombreTabla(this.Colonia.Text, "Colonia", "Id", "Nombre"); if (CurColonia == 0) { CurColonia = datos1.InsertaNombreCampo(this.Colonia.Text, "Colonia", "Nombre"); } valores.Add(new Registro("idciudad", CurCiudad)); valores.Add(new Registro("idmunicipio", CurMunicipio)); valores.Add(new Registro("idcolonia", CurColonia)); if (this.curPaciente != 0) { datos1.UpdateData(valores, this.curPaciente, "IdPaciente", "pacientes"); } else { this.curPaciente = datos1.InsertData(valores, "pacientes"); } if (this.newLoadedImage) { try { JpegBitmapEncoder encoder = new JpegBitmapEncoder(); String photolocation = "C:\\Datos\\images\\" + this.curPaciente.ToString() + ".jpg"; //file name //encoder.Frames.Add(BitmapFrame.Create(this.personPhoto)); encoder.Frames.Add(BitmapFrame.Create((BitmapImage)this.image.Source)); using (var filestream = new FileStream(photolocation, FileMode.Create)) encoder.Save(filestream); } catch (Exception ex) { MessageBox.Show("Unable to save now."); } } this.Close(); }