private void BtnFoto_Click(object sender, EventArgs e) { if (Func.IdFunc > 0) { BuscaFoto.Filter = "jpeg|*.jpg|bmp|*.bmp|png|*.png|all files|*.*"; DialogResult res = BuscaFoto.ShowDialog(); if (res == DialogResult.OK) { PicFoto.Image = Image.FromFile(BuscaFoto.FileName); // Salvar Imagem MemoryStream ms = new MemoryStream(); PicFoto.Image.Save(ms, ImageFormat.Jpeg); byte[] photo_aray = new byte[ms.Length]; ms.Position = 0; ms.Read(photo_aray, 0, photo_aray.Length); SqlCommand CmdSql = new SqlCommand("Update Funcionarios set Foto=@Foto WHERE id_func=" + Func.IdFunc.ToString(), Controle.Conexao); CmdSql.Parameters.AddWithValue("@Foto", photo_aray); CmdSql.ExecuteNonQuery(); } } }
private void BtnFoto_Click(object sender, EventArgs e) { if (StaFormEdicao) { if (CadFiliais.IdFilial > 0) { BuscaFoto.Filter = "jpeg|*.jpg|bmp|*.bmp|png|*.png|all files|*.*"; DialogResult res = BuscaFoto.ShowDialog(); if (res == DialogResult.OK) { PicFoto.Image = Image.FromFile(BuscaFoto.FileName); // Salvar Imagem MemoryStream ms = new MemoryStream(); PicFoto.Image.Save(ms, ImageFormat.Jpeg); byte[] photo_aray = new byte[ms.Length]; ms.Position = 0; ms.Read(photo_aray, 0, photo_aray.Length); // SqlCommand CmdSql; SqlDataReader Tabela; Tabela = Controle.ConsultaSQL("SELECT * FROM TABIMAGENS WHERE TABELA='FILIAL' AND ID_CHAVE=" + CadFiliais.IdFilial.ToString()); if (Tabela.HasRows) { CmdSql = new SqlCommand("Update TABIMAGENS set Imagem=@Imagem WHERE TABELA='FILIAL' and Id_Chave=" + CadFiliais.IdFilial.ToString(), Controle.Conexao); CmdSql.Parameters.AddWithValue("@IMAGEM", photo_aray); } else { CmdSql = new SqlCommand("INSERT INTO TABIMAGENS (ID_CHAVE,TABELA,IMAGEM) VALUES (@CHAVE,@TABELA,@IMAGEM)", Controle.Conexao); CmdSql.Parameters.AddWithValue("@CHAVE", CadFiliais.IdFilial); CmdSql.Parameters.AddWithValue("@TABELA", "FILIAL"); CmdSql.Parameters.AddWithValue("@IMAGEM", photo_aray); } CmdSql.ExecuteNonQuery(); } } } }