Exemplo n.º 1
0
        private void btn_salvar_Click(object sender, EventArgs e)
        {
            //byte[] img = null;
            FileStream   stream = new FileStream(this.txt_caminho.Text, FileMode.Open, FileAccess.Read);
            BinaryReader binary = new BinaryReader(stream);

            byte[]  img     = binary.ReadBytes((int)stream.Length);
            Posicao posicao = new Posicao();

            posicao.Position = txt_posicao.Text;
            //posicao.Imagem = img;
            try
            {
                posicao.Inserir();
                if (posicao.Cod > 0)
                {
                    var gravou = MessageBox.Show("Nova posição gravada com sucesso! Porém, não foi possível gravar a imagem!",
                                                 "PosiChange | Cadastro de Posicao",
                                                 MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (gravou == DialogResult.OK)
                    {
                        pic_posicao.Image = null;
                        txt_posicao.Clear();
                        txt_caminho.Clear();
                    }
                }
            }
            catch (Exception Ex)
            {
                //throw Ex;

                MessageBox.Show("Sinto muito, mas não cosegui gravar as informações",
                                "PosiChange", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }