小区物业管理系统-照片存取

小区物业管理系统-照片存取

分别从文件获取,或者调用摄像头拍照
在这里插入图片描述

窗体代码

Public Class Pro_Photo
    Dim pro As Proprietor
    Public Sub New(u As Proprietor)
        InitializeComponent()
        pro = u
    End Sub
    Private Sub Pro_Photo_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Label2.Text = Format(Now, "yyyy-mm-dd")
        Label11.Text = Format(Now, "hh:mm:ss")
        Label1.Text = pro.pnameGet
        PhotoSHow()
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        'unilt 照片万能插入函数
        Photo_Insert(OpenFileDialog1, "Proprietor", "Pno", pro.pnoGet, "P_img")

        MsgBox("照片存储成功!", MsgBoxStyle.DefaultButton3, "提示")

        PhotoSHow()
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        Dim i As Integer
        i = MsgBox("是否删除?", MsgBoxStyle.YesNo, "提示")
        If i = 6 Then
            Photo_Delete("Proprietor", "Pno", pro.pnoGet, "P_img")

            MsgBox("照片删除成功!", MsgBoxStyle.DefaultButton3, "提示")

            PhotoSHow()
        End If
    End Sub


    Private Sub PhotoSHow()
        If IsDBNull(Photo_Select("Proprietor", "Pno", pro.pnoGet, "P_img")) = False Then
            Dim bb() As Byte = Photo_Select("Proprietor", "Pno", pro.pnoGet, "P_img")
            Dim ss As New System.IO.MemoryStream(bb)
            Me.PictureBox1.Image = System.Drawing.Image.FromStream(ss)
        Else
            Me.PictureBox1.Image = Image.FromFile("aaa.jpg")
        End If
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        'unilt 照片万能插入函数
        sfzx = 0
        Dim zx As New Pro_Photo_Camare("")
        zx.ShowDialog()
        Photo_Insert2("Proprietor", "Pno", pro.pnoGet, "P_img")
        'MsgBox("照片存储成功!", MsgBoxStyle.DefaultButton3, "提示")
        PhotoSHow()
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        Me.Close()
    End Sub
End Class

照片数据库交互

Imports System.Data.SqlClient
Imports System.IO
Imports AForge.Video.DirectShow
Imports System.Data.OleDb
Imports log4net

Module PhotoUnlit
    Dim conn2 As String = sqlconn2()
    Dim conn As String = sqlconn()
    Dim log As ILog = getLog()
    Public Sub Photo_Insert(OpenFileDialog1 As OpenFileDialog, Table As String, Type As String, name As String, lie As String)
        Try
            Dim apppath2 As String
            apppath2 = Application.StartupPath + "\照片"
            OpenFileDialog1.InitialDirectory = apppath2
            OpenFileDialog1.Filter = "pictures(*.jpg)|*.jpg"
            OpenFileDialog1.FileName = ""
            OpenFileDialog1.ShowDialog()

            Dim objconn As New SqlConnection(conn2)
            objconn.Open()
            Dim objfile As New FileStream(OpenFileDialog1.FileName, FileMode.Open, FileAccess.Read)


            Dim wj() As Byte
            ReDim wj(objfile.Length)
            objfile.Read(wj, 0, objfile.Length)
            objfile.Close()

            Dim zp As String = "update " & Table & " set " & lie & "=@img  where " & Type & "='" & name & "'"
            Dim objcmd1 As New SqlCommand(zp, objconn)
            objcmd1.Parameters.Add("@img", SqlDbType.Binary).Value = wj
            objcmd1.ExecuteNonQuery()
            objcmd1 = Nothing
            objconn.Close()
        Catch ex As Exception
            MsgBox("没有写入成功!")
            log.Warn(DateTime.Now.ToString() + ":Photo_Insert " + ex.Message)
        End Try
    End Sub
    '摄像头相关
    Public sfzx As Integer = 0  '判断是否照像了
    Public videoDevices As FilterInfoCollection  '数组
    Public videoDevice As VideoCaptureDevice
    Public VideoCapabilities() As VideoCapabilities

    '枚举所有摄像头
    Public Function getVideoDevices() As FilterInfoCollection
        Dim Devices As FilterInfoCollection = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        Return Devices
    End Function


    Public Sub Photo_Insert2(Table As String, Type As String, name As String, lie As String)
        If sfzx = 1 Then     '如果照像了就用新照片写入
            Try
                Dim objconn As New SqlConnection(conn2)
                Dim fjm As String = "pic.jpg"
                Dim objfile As New FileStream(fjm, FileMode.Open, FileAccess.Read)
                Dim wj() As Byte
                ReDim wj(objfile.Length)
                objfile.Read(wj, 0, objfile.Length)
                objfile.Close()
                objfile = Nothing
                objconn.Open()
                Dim zp As String = "update " & Table & " set " & lie & "=@img  where " & Type & "='" & name & "'"
                Dim objcmd1 As New SqlCommand(zp, objconn)
                objcmd1.Parameters.Add("@img", SqlDbType.Binary).Value = wj
                objcmd1.ExecuteNonQuery()
                objcmd1 = Nothing
                objconn.Close()
                ' MsgBox("写入成功!")

            Catch ex As Exception
                MsgBox("没有写入成功!")
                log.Warn(DateTime.Now.ToString() + ":Photo_Insert2 " + ex.Message)
            End Try
        End If
    End Sub

    Public Sub Photo_Delete(Table As String, Type As String, name As String, lie As String)
        Try
            Dim strsql As String = "update " & Table & " set " & lie & "=NULL  where " & Type & "='" & name & "'"
            Dim objconn As New SqlConnection(conn2)
            Dim objcmd As New SqlCommand(strsql, objconn)
            objconn.Open()
            objcmd.ExecuteNonQuery()
            ' MsgBox("修改成功!")
            objconn.Close()
        Catch ex As Exception
            MsgBox("Photo_Delete:" + ex.Message)
            log.Warn(DateTime.Now.ToString() + ":Photo_Delete " + ex.Message)
        End Try
    End Sub

    Public Function Photo_Select(Table As String, Type As String, name As String, lie As String)
        Dim objDataSet As New DataSet

        Try
            Dim objconn As New OleDbConnection(conn) '创建连接对象
            Dim objAdap As OleDbDataAdapter '创建适配对象
            '创建数据集对象
            Dim strsql As String = "select " & lie & " from " & Table & " where  " & Type & "='" & name & "'"

            objAdap = New OleDbDataAdapter(strsql, objconn)
            objDataSet.Reset() '清除数据集
            objAdap.Fill(objDataSet, "Photo") '第二个参数就是给这个虚拟表起个名字
        Catch ex As Exception
            MsgBox("PSelectforAll" + ex.Message)
            log.Warn(DateTime.Now.ToString() + ":Photo_Select " + ex.Message)
        End Try
        Return objDataSet.Tables("Photo").Rows(0).Item(0)
    End Function


End Module

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CaoPengCheng&

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值