Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

//EN LA CLASE CLASSABCMEDICAMENTOS

public void AgregarRegistros(String CodMed, String NomMed,


String Prov, String Cat, Int32 Cant, double Precio, PictureBox
pctFoto, Int32 Stock)
{
cn = bd.ConectarBD();

CadenaSql = "INSERT into tb_Medicamentos (idMedicamento,


NombreMedicamento, idProveedor, idCategoria, CantidadPorUnidad, PrecioPorUnidad,
stock,representacion) VALUES ('" + CodMed + "','" + NomMed + "','" + Prov + "','" +
Cat + "', " + Cant + "," + Precio + " , " + Stock + ", @presentacion ) ";

comand = new SqlCommand(CadenaSql, cn);


comand.Parameters.Add("@presentacion", SqlDbType.Image);
MemoryStream ms = new MemoryStream();
pctFoto.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
comand.Parameters["@presentacion"].Value = ms.GetBuffer();

comand.ExecuteNonQuery();
bd.cerrarBD();
}

//EN EL FORMULARIO
//deben de poner un boton foto
private void btnfoto_Click(object sender, EventArgs e)
{
try
{
openFileDialog1.ShowDialog();
if (openFileDialog1.FileName.Equals("") == false)
{
pctFoto.Load(this.openFileDialog1.FileName);
}
}
catch (Exception ex)
{
MessageBox.Show("No se pudo cargar la imagen: " +
ex.ToString());
}
//en el boton agregar
private void btnAgregar_Click(object sender, EventArgs e)
{
metodosABC.AgregarRegistros(txtCodMed.Text, txtNomMed.Text,
cboProv.SelectedValue.ToString(), cboCat.Text,
Int32.Parse(txtCant.Text),
float.Parse(txtPrecio.Text),pctFoto, Int32.Parse(txtStock.Text));
MessageBox.Show("Datos guardados");
txtCant.Text = "0";
txtCodMed.Text = "";
txtNomMed.Text = "";
txtPrecio.Text = "0";
txtStock.Text = "0";
txtCodMed.Focus();
}

private void btnBuscar_Click(object sender, EventArgs e)


{
metodosABC.verImagen(pctFoto, txtCodMed.Text);
metodosABC.LlenarCampos(txtCodMed, txtNomMed, cboProv, cboCat,
txtCant, txtPrecio, txtStock);
}

You might also like