Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Data.SqlServerCe
Module Module1
'By https://www.thaicreate.com (mr.win) '
<STAThread()> _
Sub Main(ByVal args As String())
Dim t As New System.Threading.Thread(AddressOf ThreadStart)
t.SetApartmentState(System.Threading.ApartmentState.STA)
t.Start()
End Sub
Private Sub ThreadStart()
'*** Capture Web Page ***//
Dim web As New WebBrowser()
web.ScrollBarsEnabled = False
web.ScriptErrorsSuppressed = True
Dim CmdLine As String() = System.Environment.GetCommandLineArgs()
Dim strURL As String = CmdLine(1).ToString()
Dim fileName As String = DateTime.Now.ToString("ddMMyyyyHHmmss") & ".jpg"
web.Navigate(strURL)
While web.ReadyState <> System.Windows.Forms.WebBrowserReadyState.Complete
System.Windows.Forms.Application.DoEvents()
End While
System.Threading.Thread.Sleep(1500)
Dim width As Integer = web.Document.Body.ScrollRectangle.Width
Dim height As Integer = web.Document.Body.ScrollRectangle.Height
web.Width = width
web.Height = height
Dim bmp As New System.Drawing.Bitmap(width, height)
web.DrawToBitmap(bmp, New System.Drawing.Rectangle(0, 0, width, height))
bmp.Save(Directory.GetCurrentDirectory() & "\Img\" & fileName, ImageFormat.Jpeg)
bmp.Dispose()
'*** Insert to Table ***//
Dim myConnection As SqlCeConnection = Nothing
'*** Current Application Path ***'
'myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase ) + "\\Database1.sdf;"));
myConnection = New SqlCeConnection("Data Source =" & ("C:\ConsoleApplication\ConsoleApplication\Database1.sdf;"))
myConnection.Open()
Dim myCommand As SqlCeCommand = myConnection.CreateCommand()
myCommand.CommandText = "INSERT INTO [mytable] ([sitename], [picture]) VALUES " & " ('" & strURL & "','" & fileName & "' ) "
myCommand.CommandType = CommandType.Text
myCommand.ExecuteNonQuery()
myConnection.Close()
Console.WriteLine("Capture Finish.")
End Sub
End Module
การเพิ่ม Database ให้เลือกใช้ Local ของ Database ได้เลยครับ เพื่อความสะดวก
โดยคลิกขวาที่ Project -> Add -> New Item...
เลือก Local Database พร้อมกับกำหนดชื่อไฟล์ของ Database ด้วย