how can i store datetime value in database ???
how can show screenshot picture in picture box window application ???
private void Form2_Load(object sender, EventArgs e)
{
con1.Open();
Form1 home = new Form1();
home.MdiParent = this.MdiParent ;
System.Timers.Timer timer1 = new System.Timers.Timer();
Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"\\server1\KamalSingh\ScreenCaptures");
t.Interval = 100;
t.Tick += new EventHandler(StartThread);
t.Start();
}
System.Windows.Forms.Timer t = new System.Windows.Forms.Timer();
//Thread tt;
string i;
private static Bitmap bmpscreenshot;
private static Graphics gfxscreenshot;
void TakeScreenShot()
{
using (Bitmap bmpscreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb))
{
using (Graphics gfxscreenshot = Graphics.FromImage(bmpscreenshot))
{
gfxscreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
bmpscreenshot.Save(Environment.GetFolderPath(Environment.SpecialFolder.MyComputer) + @"\\server1\KamalSingh\ScreenCaptures\" + i + ".jpeg", ImageFormat.Jpeg );
}
}
//tt.Abort();
}
protected void StartThread(object sender, EventArgs e)
{
Thread th = new Thread(new ThreadStart(TakeScreenShot));
th.SetApartmentState(ApartmentState.STA );
th.Start();
Thread.Sleep(100);
th.Join();
}
MemoryStream ms;
FileStream st;
// storing datetime value in database
private int SaveToDB (string st ,string brt,string brot, string spt)
{
con1.Open();
SqlCommand cmd = new SqlCommand("dattime", con1);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con1 ;
cmd.Parameters.Add("@st", SqlDbType.DateTime ).Value = label2_time1.Text ;
cmd.Parameters.Add("@brt", SqlDbType.DateTime ).Value = label2_brkintime.Text ;
cmd.Parameters.Add("@brot", SqlDbType.DateTime ).Value = label3_brkofftm.Text ;
cmd.Parameters.Add("@spt", SqlDbType.DateTime ).Value = label2_time2.Text ;
cmd.ExecuteReader();
con1.Open();
int tm = cmd.ExecuteNonQuery();
con1.Close();
return tm;
}
// showing image on picture box
private void pictureBox2_Click(object sender, EventArgs e)
{
byte[] image = File.ReadAllBytes(@"\\server1\KamalSingh\ScreenCaptures\.jpeg");
SqlCommand cmd = new SqlCommand("INSERT INTO imagelog(imgid,imgpath,imgimage) VALUES(1,@\\server1\\kamalsingh\\screencaptures\\.jpeg,@imgimage) , con1");
cmd.Parameters.AddWithValue("@imgimage", image);
cmd.ExecuteNonQuery();
SqlDataAdapter da = new SqlDataAdapter(new SqlCommand("SELECT imgimage FROM imagelog WHERE imgid=1", con1));
DataSet dst = new DataSet();
da.Fill(dst);
if (dst.Tables[0].Rows.Count == 1)
{
byte[] data = new Byte[0];
data = (Byte[])(dst.Tables[0].Rows[0]["imgimage"]);
MemoryStream mem = new MemoryStream(data);
pictureBox2.Image = Image.FromStream(mem);
}
}
2 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
praveen mishraPosted Sep 27, 2012, 6:09 AM
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Filter = "Ping Files(*.png)|*.png|JPEG File(*.JPEG)|*.JPEG|GIF File(*.GIF)|*.GIF|All Files(*.*)|*.*";
// show the openFile dialog box
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
fname = openFileDialog1.FileName;
pictureBox1.Image = Image.FromFile(fname);
pictureBox1.Visible = true;
}
Save The Picture in Folder-------------------
string save = "";
SaveFileDialog sav = new SaveFileDialog();
file = System.IO.Path.GetFileName(fname);
save = System.IO.Path.GetExtension(fname);
sav.InitialDirectory = "E:\\HMS\\Inpateint";
sav.Filter = "Ping Files(*.png)|*.png|JPEG File(*.JPEG)|*.JPEG|GIF File(*.GIF)|*.GIF|All Files(*.*)|*.*";
file = txtpid.Text + save;
string destFile = System.IO.Path.Combine(sav.InitialDirectory, file);
if (!System.IO.Directory.Exists(sav.InitialDirectory))
{
System.IO.Directory.CreateDirectory(sav.InitialDirectory);
}
else
{
System.IO.File.Delete(destFile);
System.IO.File.Copy(fname, destFile, true);
pictureBox1.Visible = true;
}
string path = System.IO.Path.GetFullPath("E:\\HMS\\Inpateint\\" + txtpid.Text + "");
string[] ext = new string[] { ".png", ".jpg", ".gif", ".jpeg" };
foreach (string i in ext)
{
if (System.IO.File.Exists(path + i))
{
file = txtpid.Text + i;
}
}
if (System.IO.Directory.Exists(fname))
{
string[] files = System.IO.Directory.GetFiles(fname);
foreach (string s in files)
{
file = System.IO.Path.GetFileName(s);
System.IO.File.Copy(s, destFile, true);
if (i == 0)
{
}
i++;
}
}
praveen mishraPosted Sep 27, 2012, 6:02 AM
OleDbConnection con1 = new OleDbConnection(conn);
con1.Open();
OleDbCommand cmd = new OleDbCommand("insert into tbl(Dates,Times) values(#" + dtstart.Value.ToString("dd-MMM-yyyy") + "#,'" + lbltime.text + "')", con1);
cmd.ExecuteNonQuery();
con1.close();