Click here to Skip to main content
15,888,271 members
Home / Discussions / C#
   

C#

 
AnswerRe: showing form from bottom wth timer Pin
Midnight Ahri16-Sep-13 2:35
Midnight Ahri16-Sep-13 2:35 
GeneralRe: showing form from bottom wth timer Pin
eng.iris16-Sep-13 10:02
eng.iris16-Sep-13 10:02 
GeneralRe: showing form from bottom wth timer Pin
eng.iris17-Sep-13 7:54
eng.iris17-Sep-13 7:54 
AnswerRe: showing form from bottom wth timer Pin
Midnight Ahri17-Sep-13 17:26
Midnight Ahri17-Sep-13 17:26 
GeneralRe: showing form from bottom wth timer Pin
eng.iris18-Sep-13 7:13
eng.iris18-Sep-13 7:13 
Questionwpf backgroundworker, execution of processes one after another Pin
Member 974759714-Sep-13 19:55
Member 974759714-Sep-13 19:55 
AnswerRe: wpf backgroundworker, execution of processes one after another Pin
Abhinav S14-Sep-13 22:18
Abhinav S14-Sep-13 22:18 
QuestionSave Images in SQl Server Pin
sigridslima14-Sep-13 17:13
sigridslima14-Sep-13 17:13 
Hello, I have a doubt, how to save an image in the bank. I have a class to convert the image to byte and then save. I do not know the correct way, ask for help.

class:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Drawing.Imaging;
using ImagensTeste.Dados;
using System.Data.SqlClient;
using System.Windows.Forms;


namespace ImagensTeste.Negocio
{
class RegraNegocioFotos
{
private int id;

public int Id
{
get { return id; }
set { id = value; }
}
private string descricao;

public string Descricao
{
get { return descricao; }
set { descricao = value; }
}
private Image foto;

public Image Foto
{
get { return foto; }
set { foto = value; }
}
private Image foto1;

public Image Foto1
{
get { return foto1; }
set { foto1 = value; }
}

public byte[] ConvertImageToByteArray(Image image, ImageFormat imageFormat)
{
if (image == null)
return null;
MemoryStream ms = new MemoryStream();
image.Save(ms, imageFormat);
return ms.ToArray();
}

public Image ConvertByteArrayToImage(byte[] byteArray)
{
if (byteArray == null || byteArray.Length == 0)
{ return (null); }
return (Image.FromStream(new MemoryStream(byteArray)));
}

Banco dal = new Banco();

//Metodo inserir

public void InserirFoto()
{
try
{
dal.ComandoSQl("INSERT INTO tbFoto(descricao,foto, foto1) VALUES('" + Descricao + "','" + Foto + "','" + Foto1 + "')");
}
catch (Exception ex)
{
throw ex;
}
}
//Metodo atualizar

public void AtualizaFoto()
{
try
{
dal.ComandoSQl("UPDATE tbFoto set descricao='" + Descricao + "', foto='" + Foto + "', foto1='" + Foto1 + "'where id= " + Id + "");
}
catch (Exception ex)
{
throw ex;
}
}

//Metodo excluir

public void ExcluirFoto()
{
try
{
dal.ComandoSQl("DELETE FROM tbFoto where id= " + Id + "");
}
catch (Exception ex)
{
throw ex;
}
}

//Metodo preencher datagrid

public void PreencherDataGrid(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto");
}

//Metodo consultar codigo prefeitura

public void ConsultarId(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto WHERE id=" + Id + "");
}

//Metodo consultar razao social prefeitura

public void ConsultarNumero(DataGridView dgv)
{
dal.Consultar(dgv, "SELECT * FROM tbFoto WHERE descricao Like '%" + Descricao + "%'");
}
}
}

Form:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using ImagensTeste.Negocio;

namespace ImagensTeste
{
public partial class frmFoto : Form
{
public frmFoto()
{
InitializeComponent();

//Alterar do app.config

Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings["ImagensTeste.Properties.Settings.fotosConnectionString"].ConnectionString =
ConfigurationManager.ConnectionStrings["ImagensTeste.Properties.Settings.fotosConnectionString"].ConnectionString;
config.Save(ConfigurationSaveMode.Full);

// ler novamente a seção do HD
ConfigurationManager.RefreshSection("connectionStrings");
}

RegraNegocioFotos negocio = new RegraNegocioFotos();

private void habilitarControles()
{
txtDescricao.Enabled = true;
}

public void LimparCampo()
{
this.LimparCampo(this);
}

public void LimparCampo(Control parent)
{
foreach (Control cont in parent.Controls)
{
if (cont is TextBox)
(cont as TextBox).Text = "";
if (cont is PictureBox)
(cont as PictureBox).Text = "";
if (cont is ComboBox)
(cont as ComboBox).Text = "";
if (cont is MaskedTextBox)
(cont as MaskedTextBox).Text = "";
if (cont is RadioButton)
(cont as RadioButton).Checked = false;
if (cont is CheckBox)
(cont as CheckBox).Checked = false;
if (cont is RichTextBox)
(cont as RichTextBox).Text = "";
if (cont is CheckedListBox)
{
foreach (ListControl item in (cont as CheckedListBox).Items)
item.SelectedIndex = -1;
}
if (cont is ListView)
(cont as ListView).Items.Clear();

// varre os filhos...
this.LimparCampo(cont);
}
}

private void btnGravar_Click(object sender, EventArgs e)
{
try
{
// Campos obrigatorios
if ((txtDescricao.Text != "") && (txtDescricao.Text != ""))
{
{
RegraNegocioFotos cln = new RegraNegocioFotos();
cln.Descricao = this.txtDescricao.Text;

//???
cln.Foto = this.picBrasao.Image;


cln.InserirFoto();

{
txtDescricao.Focus();
}

LimparCampo();

MessageBox.Show("Documento cadastrada com sucesso", "Sucesso",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}

{
txtDescricao.Focus();

}
}
else
{
MessageBox.Show("Campos Obrigatórios: Numero e Descrição", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
}
catch (Exception ex)
{
//Caso haja uma exceção será tratada neste código
MessageBox.Show("Não foi possível salvar pelo seguinte motivo: " + ex.Message);
}
}

private void btnProcurarImagen1_Click(object sender, EventArgs e)
{
openBrasao.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
DialogResult res = openBrasao.ShowDialog();

if (res == DialogResult.OK)
{
txtCaminho1.Text = openBrasao.FileName;
picBrasao.Image = Image.FromFile(openBrasao.FileName);
}
}

private void btnProcurarImagen2_Click(object sender, EventArgs e)
{
openLogo.Filter = "jpeg|*.jpg|bmp|*.bmp|all files|*.*";
DialogResult res = openLogo.ShowDialog();

if (res == DialogResult.OK)
{
txtCaminho2.Text = openLogo.FileName;
picLogo.Image = Image.FromFile(openLogo.FileName);
}
}
}
}

thank you...
GeneralRe: Save Images in SQl Server Pin
PIEBALDconsult14-Sep-13 18:12
mvePIEBALDconsult14-Sep-13 18:12 
GeneralRe: Save Images in SQl Server Pin
sigridslima15-Sep-13 14:57
sigridslima15-Sep-13 14:57 
GeneralRe: Save Images in SQl Server Pin
PIEBALDconsult15-Sep-13 16:26
mvePIEBALDconsult15-Sep-13 16:26 
GeneralRe: Save Images in SQl Server Pin
sigridslima16-Sep-13 2:55
sigridslima16-Sep-13 2:55 
GeneralRe: Save Images in SQl Server Pin
PIEBALDconsult16-Sep-13 3:47
mvePIEBALDconsult16-Sep-13 3:47 
GeneralRe: Save Images in SQl Server Pin
sigridslima16-Sep-13 5:21
sigridslima16-Sep-13 5:21 
GeneralRe: Save Images in SQl Server Pin
PIEBALDconsult16-Sep-13 13:37
mvePIEBALDconsult16-Sep-13 13:37 
GeneralRe: Save Images in SQl Server Pin
sigridslima16-Sep-13 14:35
sigridslima16-Sep-13 14:35 
AnswerRe: Save Images in SQl Server Pin
OriginalGriff14-Sep-13 22:17
mveOriginalGriff14-Sep-13 22:17 
QuestionC# Application - SQL Syntax Problem Pin
Member 1026694314-Sep-13 16:34
Member 1026694314-Sep-13 16:34 
AnswerRe: C# Application - SQL Syntax Problem Pin
PIEBALDconsult14-Sep-13 17:17
mvePIEBALDconsult14-Sep-13 17:17 
GeneralRe: C# Application - SQL Syntax Problem Pin
Member 1026694315-Sep-13 11:03
Member 1026694315-Sep-13 11:03 
AnswerRe: C# Application - SQL Syntax Problem Pin
Dave Kreskowiak14-Sep-13 19:12
mveDave Kreskowiak14-Sep-13 19:12 
QuestionGet the value of RepositoryItemPictureEdit in GridControl Pin
nhanlaptrinh14-Sep-13 9:26
nhanlaptrinh14-Sep-13 9:26 
AnswerRe: Get the value of RepositoryItemPictureEdit in GridControl Pin
Richard MacCutchan14-Sep-13 21:45
mveRichard MacCutchan14-Sep-13 21:45 
QuestionDLLIMPORT - SENDMESSAGE Pin
M Riaz Bashir14-Sep-13 5:01
M Riaz Bashir14-Sep-13 5:01 
AnswerRe: DLLIMPORT - SENDMESSAGE Pin
Richard MacCutchan14-Sep-13 5:42
mveRichard MacCutchan14-Sep-13 5:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.