خارطة الموقع برنامج مبيعات ونقاط البيع وجرد المستودعات ومحاسبة الرئيسية من نحن اتصل بنا English
Yazsys.com
منذ عام 2012 - 2018
Skip Navigation Links
نظام إدارة المبيعات
|
تعليم & شروحاتExpand تعليم & شروحات
 
كود تشغيل الكاميرا والتقاط الصورة وحفظها في قاعدة البيانات
بواسطة احمد عادل موسى
2015-03-25

From1

Imports System.Data.SqlClient
Imports System.IO
Imports Emgu.CV
Imports Emgu.CV.UI
Imports Emgu.Util
Imports System.Drawing.Imaging
 
Public Class Form1
    Private _capture As Emgu.CV.Capture
    Private _captureInProgress As Boolean
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Load_GridView()
    End Sub
 
    Private Sub btnAddNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
        Me.captureImageBox.ImageLocation = ""
        Me.txtDescription.Text = ""
        Me.txtDescription.Tag = 0
 
    End Sub
    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub
    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Save_Image()
        Form1_Load(sender, e)
        Me.captureImageBox.ImageLocation = Me.lblPath.Text
    End Sub
    Private Sub Save_Image()
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim sSQL As String = String.Empty
        Dim arrImage() As Byte
        Dim myMs As New IO.MemoryStream
        Dim bSaveImage As Boolean = False
        Dim strImg As String = String.Empty
 
        Try
            If Not IsNothing(Me.captureImageBox.Image) Then
                Me.captureImageBox.ImageLocation = Me.lblPath.Text
                Me.captureImageBox.Image.Save(myMs, Me.captureImageBox.Image.RawFormat)
                arrImage = myMs.GetBuffer
                bSaveImage = True
            Else
                arrImage = Nothing
                bSaveImage = False
            End If
            If bSaveImage = True Then
                conn = New SqlConnection(sConnString)
                conn.Open()
                cmd.Connection = conn
                cmd.CommandType = CommandType.Text
                If Me.txtDescription.Tag = 0 Then
                    cmd.CommandText = "INSERT INTO tbl_image ( image_description, [image] ) VALUES(@img_desc, @img)"
                Else
                    cmd.CommandText = "UPDATE tbl_image set image_description = @img_desc, [image] = @img where id=@id"
                End If
                cmd.Parameters.Add("@img_desc", SqlDbType.VarChar).Value = Me.txtDescription.Text
                cmd.Parameters.Add("@img", SqlDbType.Image).Value = arrImage
                If Me.txtDescription.Tag <> 0 Then
                    cmd.Parameters.Add("@id", SqlDbType.BigInt).Value = Me.txtDescription.Tag
                End If
                cmd.ExecuteNonQuery()
                If Me.txtDescription.Tag = 0 Then
                    cmd.CommandText = "Select @@Identity"
                    Me.txtDescription.Tag = cmd.ExecuteScalar()
                End If
                MsgBox("Image has been save.")
            Else
                MsgBox("Please add an image")
            End If
        Catch ex As Exception
            MsgBox(ErrorToString)
        Finally
            conn.Close()
        End Try
 
    End Sub
    Private Sub Load_Image(ByVal iIMageID As Long)
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim dr As SqlDataReader
        Dim arrImage() As Byte
        Dim myMS As New IO.MemoryStream
 
        Try
 
            conn = New SqlConnection(sConnString)
            conn.Open()
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "select id, image_description  as description, [image] from tbl_image where id= " & iIMageID
 
            dr = cmd.ExecuteReader
            If dr.HasRows Then
                While dr.Read
                    Me.txtDescription.Tag = dr("id")
                    Me.txtDescription.Text = dr("description")
                    arrImage = dr("image")
                    For Each ar As Byte In arrImage
                        myMS.WriteByte(ar)
                    Next
                    '
                    Me.captureImageBox.Image = System.Drawing.Image.FromStream(myMS)
                End While
            End If
 
        Catch ex As Exception
            MsgBox(ErrorToString)
        Finally
            conn.Close()
        End Try
    End Sub
    Private Sub Load_GridView()
        Dim conn As New SqlConnection
        Dim cmd As New SqlCommand
        Dim da As New SqlDataAdapter
        Dim dt As New DataTable
 
        Try
            conn = New SqlConnection(sConnString)
            conn.Open()
            cmd.Connection = conn
            cmd.CommandType = CommandType.Text
            cmd.CommandText = "select id, image_description as description from tbl_image"
            da.SelectCommand = cmd
            da.Fill(dt)
            Me.DataGridView1.DataSource = dt
        Catch ex As Exception
            MsgBox(ErrorToString)
        Finally
            conn.Close()
        End Try
    End Sub
 
 
    Private Sub DataGridView1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        Load_Image(Me.DataGridView1.Item(0, Me.DataGridView1.CurrentRow.Index).Value)
    End Sub
 
    Private Sub captureButton_Click(sender As System.Object, e As System.EventArgs) Handles captureButton.Click
        If Len(Trim(Me.lblPath.Text)) > 0 Then
            If (_capture Is Nothing) Then
                Try
                    _capture = New Emgu.CV.Capture
                Catch excpt As NullReferenceException
                    MessageBox.Show(excpt.Message)
                End Try
            End If
            If (Not _capture Is Nothing) Then
                If _captureInProgress Then
                    Me.captureButton.Text = "Start Capture"
                    RemoveHandler Application.Idle, New EventHandler(AddressOf Me.ProcessFrame)
                    Me.captureImageBox.Image.Save(Me.lblPath.Text, ImageFormat.Jpeg)
                    Me.captureImageBox.ImageLocation = Me.lblPath.Text
 
                Else
                    captureButton.Text = "Capture"
                    AddHandler Application.Idle, New EventHandler(AddressOf Me.ProcessFrame)
                End If
                _captureInProgress = Not _captureInProgress
            End If
        Else
            MsgBox("Please set directory path for saving the image.")
        End If
    End Sub
    Private Sub ProcessFrame(ByVal sender As Object, ByVal arg As EventArgs)
 
        Dim frame As Emgu.CV.Image(Of Emgu.CV.Structure.Bgr, Byte) = Me._capture.QueryFrame
        Dim grayFrame As Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) = frame.Convert(Of Emgu.CV.Structure.Gray, Byte)()
        Dim smoothedGrayFrame As Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) = grayFrame.PyrDown.PyrUp
        'Dim cannyFrame As Emgu.CV.Image(Of Emgu.CV.Structure.Gray, Byte) = smoothedGrayFrame.Canny(New Emgu.CV.Structure.Gray(100), New Emgu.CV.Structure.Gray(60))
 
        captureImageBox.Image = frame.Bitmap
        'grayscaleImageBox.Image = grayFrame
        'smoothedGrayscaleImageBox.Image = smoothedGrayFrame
        'cannyImageBox.Image = cannyFrame
    End Sub
 
    Private Sub ReleaseData()
        If (Not _capture Is Nothing) Then
            _capture.Dispose()
        End If
    End Sub
 
    Private Sub btnSaveLoc_Click(sender As System.Object, e As System.EventArgs) Handles btnSaveLoc.Click
        Dim FolderBrowser As New FolderBrowserDialog
        If FolderBrowser.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.lblPath.Text = FolderBrowser.SelectedPath & "\image1.jpg"
        End If
    End Sub
End Class
 
Module1
Module Module1
    Public sConnString As String = "Server=CHRIS-PC\TIDUS;Database=sattsoftdb;User Id=sa;Password=cet12345;"
End Modul
 
 
 

 

 
 
إعلان ... لأصحاب المتجار فقط - برنامج تنفيذي وليس سورس كود
تحميل برنامج مبيعات وجرد المستودعات

 
 
الصفحة الرئيسية
اتصل بنا
نبذة عن هذا الموقع
خارطة الموقع
مشاريع برمجة متنوعة مفتوحة المصدر
مواضيع ودروس تعليمية
 
 
نظام YAZSYS لإدارة المبيعات