(Code of OpenFile Dailog)
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fd = new OpenFileDialog();
fd.InitialDirectory = "c:\\";
if (fd.ShowDialog() == DialogResult.OK)
{
textBox.Text = fd.FileName.ToString();
pictureBox.ImageLocation = textBox.Text;
}
Console.ReadLine();
}
----------------------------------------------------------------------
(Code For Insert Image)
private void btnSubmit_Click(object sender, EventArgs e)
{
byte[] picbyte = System.IO.File.ReadAllBytes(textBox.Text);
try
{
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
Com.CommandText = "INSERT INTO PatientImages (Patient_Id,ImageDate,Photo,ImageName)VALUES('" + txtPatientId.Text + "','" + txtImageDate.Value.ToString("yyyy/MM/dd HH:mm:ss") + "', @Photo ,'" + txtImageName.Text + "')";
OleDbParameter picParam = Com.Parameters.Add("@Photo", SqlDbType.Binary);
picParam.Value = picbyte.ToArray();
picParam.Size = picbyte.ToArray().Length;
Com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Con.Close();
MessageBox.Show("Image Uploaded Successfully", "PIS System");
}
}
------------------------------------------------------------------
CODE FOR FETCHING IMAGES FROM DATABASE:-
private void Images_Load(object sender, EventArgs e)
{
FetchedImage();
}
------------------------------
private void FetchedImage()
{
lblIdImage.Text = val.ToString();
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
OleDbDataAdapter da = new OleDbDataAdapter("SELECT Photo,ImageDate,ImageName FROM PatientImages WHERE Patient_Id = " + val + " ", Con);
//Initialize dataset
ds = new DataSet();
//Fill DataSet using query defined for DataAdapter
da.Fill(ds);
//da.Fill(ds, "PatientVisitation ");
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
-------------------------------------------------------------------------
CODE FOR NEXT & PREVIOUS IMAGE BUTTON:-
private void btnNextImage_Click(object sender, EventArgs e)
{
if (i < ds.Tables[0].Rows.Count - 1)
{
i++;
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
else
{
MessageBox.Show("Next Image not available");
}
}
private void btnPreviewImage_Click(object sender, EventArgs e)
{
if (i == ds.Tables[0].Rows.Count - 1 || i != 0)
{
i--;
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
else
{
MessageBox.Show("Previous Image not available");
}
}
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog fd = new OpenFileDialog();
fd.InitialDirectory = "c:\\";
if (fd.ShowDialog() == DialogResult.OK)
{
textBox.Text = fd.FileName.ToString();
pictureBox.ImageLocation = textBox.Text;
}
Console.ReadLine();
}
----------------------------------------------------------------------
(Code For Insert Image)
private void btnSubmit_Click(object sender, EventArgs e)
{
byte[] picbyte = System.IO.File.ReadAllBytes(textBox.Text);
try
{
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
Com.CommandText = "INSERT INTO PatientImages (Patient_Id,ImageDate,Photo,ImageName)VALUES('" + txtPatientId.Text + "','" + txtImageDate.Value.ToString("yyyy/MM/dd HH:mm:ss") + "', @Photo ,'" + txtImageName.Text + "')";
OleDbParameter picParam = Com.Parameters.Add("@Photo", SqlDbType.Binary);
picParam.Value = picbyte.ToArray();
picParam.Size = picbyte.ToArray().Length;
Com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
Con.Close();
MessageBox.Show("Image Uploaded Successfully", "PIS System");
}
}
------------------------------------------------------------------
CODE FOR FETCHING IMAGES FROM DATABASE:-
private void Images_Load(object sender, EventArgs e)
{
FetchedImage();
}
------------------------------
private void FetchedImage()
{
lblIdImage.Text = val.ToString();
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;";
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
OleDbDataAdapter da = new OleDbDataAdapter("SELECT Photo,ImageDate,ImageName FROM PatientImages WHERE Patient_Id = " + val + " ", Con);
//Initialize dataset
ds = new DataSet();
//Fill DataSet using query defined for DataAdapter
da.Fill(ds);
//da.Fill(ds, "PatientVisitation ");
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
-------------------------------------------------------------------------
CODE FOR NEXT & PREVIOUS IMAGE BUTTON:-
private void btnNextImage_Click(object sender, EventArgs e)
{
if (i < ds.Tables[0].Rows.Count - 1)
{
i++;
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
else
{
MessageBox.Show("Next Image not available");
}
}
private void btnPreviewImage_Click(object sender, EventArgs e)
{
if (i == ds.Tables[0].Rows.Count - 1 || i != 0)
{
i--;
byte[] picbyte = ds.Tables[0].Rows[i]["Photo"] as byte[] ?? null;
if (picbyte != null)
{
MemoryStream mstream = new MemoryStream(picbyte);
pictureBoxForImage.Image = System.Drawing.Image.FromStream(mstream);
pictureBoxForImage.SizeMode = PictureBoxSizeMode.StretchImage;
{
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(mstream);
}
}
lblImageName.Text = ds.Tables[0].Rows[i]["ImageName"].ToString();
lblImageDate.Text = ds.Tables[0].Rows[i]["ImageDate"].ToString();
}
else
{
MessageBox.Show("Previous Image not available");
}
}
No comments:
Post a Comment