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);
}
}