У меня есть применение зубных записей, где я охраняю консультацию клиента и фотографию dentagrama используя Entity Framework
следующей формы:
byte[] file = null;
Stream mystream = opdImagen.OpenFile();
using (MemoryStream ms = new MemoryStream())
{
mystream.CopyTo(ms);
file = ms.ToArray();
}
using (Model.GRUDENTEntities db = new Model.GRUDENTEntities())
{
Model.Paciente oImage = new Model.Paciente();
oImage.Documento = txtcedula.Text.Trim();
oImage.Nombres = txtnombre.Text.Trim();
oImage.PrimerApellido = txtpapellido.Text.Trim();
oImage.SegundoApellido = txtsapellido.Text.Trim();
oImage.Sexo = cmbsexo.Text.Trim();
oImage.FechaDeNacimiento = Convert.ToDateTime(dtpfechanacimiento.Value);
oImage.EstadoCivil = cmbestadocivil.Text.Trim();
oImage.GrupoSanguineo = cmbgruposanguineo.Text.Trim();
oImage.ARS = cmbars.Text.Trim();
oImage.NSS = txtnss.Text.Trim();
oImage.CorreoElectronico = txtcorreoelectronico.Text.Trim();
oImage.Telefono = txttelefono.Text.Trim();
oImage.Celular = txtcelular.Text.Trim();
oImage.Direccion = txtdireccion.Text.Trim();
oImage.Foto = file;
db.Paciente.Add(oImage);
db.SaveChanges();
LimpiarCampos();
MessageBox.Show("Paciente registrado correctamente", "Operacion Exitosa", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtnombre.Focus();
}
в datagridview консультации я могу делать видимой фотографию следующего способа:
DetalleConsulta fco = new DetalleConsulta();
fco.lblnombre.Text = dgvPacienteConsulta.CurrentRow.Cells["NombrePaciente"].Value.ToString();
fco.lbledad.Text = dgvPacienteConsulta.CurrentRow.Cells["Edad"].Value.ToString();
fco.lblsexo.Text = dgvPacienteConsulta.CurrentRow.Cells["Sexo"].Value.ToString();
fco.lblfecha.Text = Convert.ToDateTime(dgvPacienteConsulta.CurrentRow.Cells["Fecha"].Value.ToString()).ToString("dd-MM-yyyy");
fco.lbldoctor.Text = dgvPacienteConsulta.CurrentRow.Cells["NombreDoctor"].Value.ToString();
fco.lblmotivo.Text = dgvPacienteConsulta.CurrentRow.Cells["Motivo"].Value.ToString();
fco.lblobservacion.Text = dgvPacienteConsulta.CurrentRow.Cells["Observaciones"].Value.ToString();
fco.lbldiagnostico.Text = dgvPacienteConsulta.CurrentRow.Cells["Diagnostico"].Value.ToString();
fco.lblprocedimiento.Text = dgvPacienteConsulta.CurrentRow.Cells["Procedimiento"].Value.ToString();
fco.lblindicacion.Text = dgvPacienteConsulta.CurrentRow.Cells["Indicaciones"].Value.ToString();
if (dgvPacienteConsulta.Rows[e.RowIndex].Cells["Ficha"].Selected)
{
int id = Convert.ToInt16(dgvPacienteConsulta.CurrentRow.Cells["ID"].Value.ToString());
using (GRUDENTEntities db = new GRUDENTEntities())
{
var oImage = db.Consulta.Find(id);
MemoryStream ms = new MemoryStream(oImage.Foto);
Bitmap bmp = new Bitmap(ms);
fco.pbDentagrama.Image = bmp;
fco.Show();
}
То, что я желаю, состоит в том, чтобы я бросился образ в picturebox последней консультации клиента на основании id клиента, что у меня это есть в переменной так называемый idd, но мне не ясно как. Какая-то идея?
Чтобы получать организацию из-за id ты использовал бы фильтр в entity framework
Что-то как это
int id = Convert.ToInt16(dgvPacienteConsulta.CurrentRow.Cells["ID"].Value.ToString());
using (Model.GRUDENTEntities db = new Model.GRUDENTEntities())
{
var paciente = db.Pacientes.FirstOrDefault(x=> x.Id == id);
if(paciente == null)
return;
fco.lblnombre.Text = paciente.Nombres;
//resto propiedades
using (MemoryStream ms= new MemoryStream(paciente.Foto))
{
fco.pbDentagrama.Image = Image.FromStream(ms);
}
}
так может конвертировать byte[]
изображения, чтобы распределять picturebox