Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Firebird 2 and Images

, 9 Jun 2007 CPOL
Firebird 2 using stored procedure, manage Image ‘BLOB’ and easy to save and get back your images
/*
 * Created by SharpDevelop. [anish mm]
 * User: anish m m
 * Date: 18/Jan/2007
 * Time: 1:07 AM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace FireB
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm
	{
		[STAThread]
		public static void Main(string[] args)
		{
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new MainForm());
		}
		
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			this.dataGridView1.Click += new EventHandler(this.GridChange);
            this.dataGridView1.KeyDown += new KeyEventHandler(dataGridView1_KeyDown);
            this.KeyDown +=new KeyEventHandler(Form1_KeyDown);
            dataGridView1.ReadOnly = true;
            this.dataGridView1.RowEnter +=new DataGridViewCellEventHandler(dataGridView1_RowEnter);

			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		       private void Form1_Load(object sender, EventArgs e)
        {
            LoadGrid();
            //ShowAgent();
            //this.speaker.Play("Explain");
            label2.Text = iU1_Table.Connection();
            clarText();
            notifyIcon1.BalloonTipTitle="FB";
            notifyIcon1.BalloonTipText="dsafdf";
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
                Application.Exit();
            else if(e.KeyCode ==Keys.F5)
                LoadGrid();
        }
        private void GridChange(object sender, EventArgs e)
        {
            int uid;
            try
            {
            	
                uid = (int)dataGridView1.CurrentRow.Cells[0].Value;

                iU1_Table m = new iU1_Table(uid.ToString());
                textBox2.Text = m.FName;
                textBox3.Text = m.SNAME;
                textBox7.Text = m.LNAME;
                textBox8.Text = m.PHONE;
                textBox9.Text = m.MOB;
                textBox10.Text = m.EMAIL;
                textBox4.Text = m.AutoNo.ToString();
                //this.speaker.Play("");
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            //if((e.KeyCode==Keys.Up)||(e.KeyCode ==Keys.Down))
            //{
            //    int uid;
            //    uid = (int)dataGridView1.CurrentRow.Cells[0].Value;
            //    iU1_Table m = new iU1_Table(uid.ToString());
            //    textBox2.Text = m.FName;
            //    textBox3.Text = m.SNAME;
            //    textBox7.Text = m.LNAME;
            //    textBox8.Text = m.PHONE;
            //    textBox9.Text = m.MOB;
            //    textBox10.Text = m.EMAIL;
            //    textBox4.Text = m.AutoNo.ToString();

            //}
        }
        private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            int r = e.RowIndex;
            int uid;
            if (r >= 0)
            {
                uid = (int)dataGridView1[0, r].Value;
                iU1_Table m = new iU1_Table(uid.ToString());
                textBox2.Text = m.FName;
                textBox3.Text = m.SNAME;
                textBox7.Text = m.LNAME;
                textBox8.Text = m.PHONE;
                textBox9.Text = m.MOB;
                textBox10.Text = m.EMAIL;
                textBox4.Text = m.AutoNo.ToString();
                if (m.Image != null)
                {
                    Bitmap image = new Bitmap(m.Image);
                    pictureBox1.Image = image;
                }
                else
                    pictureBox1.Image = null;


            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                string str = "ALTER TABLE TAB ADD "+ textBox5.Text.ToUpper().Trim()+" "+ label1.Text +";";


                iU1_Table.AddField(str);
                LoadGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }


        }
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {

                if (textBox2.Text.Length <= 0)
                {
                    errorProvider1.SetError(textBox2, "Please fill Fist Name");
                }
                else if (textBox4.Text.Length > 0)
                {
                    iU1_Table m = new iU1_Table();
                    m.FName = textBox2.Text;
                    m.SNAME = textBox3.Text;
                    m.LNAME = textBox7.Text;
                    m.PHONE = textBox8.Text;
                    m.MOB = textBox9.Text;
                    m.EMAIL = textBox10.Text;
                    m.AutoNo = Convert.ToInt32(textBox4.Text);

                    if (pictureBox1.Image != null)
                    {
                        Bitmap IMG = new Bitmap(pictureBox1.Image);
                        MemoryStream stream = new MemoryStream();
                        IMG.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        m.Image = stream;
                    }

                    m.Update();
                    LoadGrid();
                    clarText();
                    errorProvider1.Clear();
                }
                else
                {
                    errorProvider1.Clear();
                    iU1_Table m = new iU1_Table();
                    m.FName = textBox2.Text;
                    m.FNAME = "";
                    m.SNAME = textBox3.Text;
                    m.LNAME = textBox7.Text;
                    m.PHONE = textBox8.Text;
                    m.MOB = textBox9.Text;
                    m.EMAIL = textBox10.Text;

                    if (pictureBox1.Image != null)
                    {

                        Bitmap IMG = new Bitmap(pictureBox1.Image);
                        MemoryStream stream = new MemoryStream();
                        IMG.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
                        m.Image = stream;
                    }
                    m.Save();
                    LoadGrid();
                    clarText();


                    errorProvider1.Clear();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {

            clarText();
            textBox2.Focus();
            //iU1_Table.CreateData();
        }
        private void LoadGrid()
        {
            dataGridView1.DataSource = iU1_Table.iU1_TableD();
            dataGridView1.Columns[0].Visible = false;
        }
        private void textBox6_TextChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text.Trim() == "VARCHAR")
            {
                if ((textBox6.Text == "")||(Convert.ToInt32(textBox6.Text) < 1))
                    textBox6.Text = "1";
            }

            if (textBox6.Text.Trim().Length > 0)
                label1.Text = comboBox1.Text.ToUpper().Trim() + "(" + textBox6.Text.Trim() + ")";
            else
                label1.Text = comboBox1.Text.ToUpper().Trim();

        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox1.Text == "VARCHAR")
                textBox6.Text = "20";
            else
                textBox6.Text = "";

            if (textBox6.Text.Trim().Length > 0)
                label1.Text = comboBox1.Text.ToUpper().Trim() + "(" + textBox6.Text.Trim() + ")";
            else
                label1.Text = comboBox1.Text.ToUpper().Trim();

        }
        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                string str = "ALTER TABLE TAB  DROP " + textBox5.Text.Trim().ToUpper() + ";";
                iU1_Table.DropField(str);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox4.Text.Length > 0)
                {
                    iU1_Table.Delete(textBox4.Text.Trim());
                    LoadGrid();
                    clarText();
                    errorProvider1.Clear();
                }
                else
                {
                    errorProvider1.SetError(button5, "Please Select details before delete");
                }
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
        }
        private void button6_Click(object sender, EventArgs e)
        {
        }
        private void clarText()
        {
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Clear();
            textBox5.Clear();
            textBox6.Clear();
            textBox7.Clear();
            textBox8.Clear();
            textBox9.Clear();
            textBox10.Clear();
            pictureBox1.Image = null;
        }
        private void button6_Click_1(object sender, EventArgs e)
        {
            SaveFileDialog sav = new SaveFileDialog();
            sav.Filter = "Backup|*.FBK";
            sav.DefaultExt = "FBK";
            sav.FileName = "BackUp";
            sav.ShowDialog();

            string str = sav.FileName.ToUpper();
            iU1_Table.BackUp(str);
        }
        private void button7_Click(object sender, EventArgs e)
        {
            //iU1_Table.CreateData();
            OpenFileDialog opn = new OpenFileDialog();
            opn.Filter = "Backup|*.FBK";
            opn.ShowDialog();

            string str = opn.FileName.ToUpper();
            iU1_Table.ReStore(str);

            
        }
        private void button8_Click(object sender, EventArgs e)
        {
            iU1_Table.CreateUser();
        }
        private void addImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog opn = new OpenFileDialog();
            opn.Filter = "JPEG|*.jpg|GIF|*.gif";
            opn.ShowDialog();
            if (opn.FileName.Length > 0)
            {
                Bitmap IMG = new Bitmap(opn.FileName);


                pictureBox1.Image = IMG;
            }

        }
        private void clearImageToolStripMenuItem_Click(object sender, EventArgs e)
        {
            pictureBox1.Image = null;
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
        }
		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

anishmm
Software Developer (Senior)
India India
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.1411023.1 | Last Updated 9 Jun 2007
Article Copyright 2007 by anishmm
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid