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

Posted CaoPengCheng&

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了小区物业管理系统-照片存取相关的知识,希望对你有一定的参考价值。

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

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

窗体代码

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

以上是关于小区物业管理系统-照片存取的主要内容,如果未能解决你的问题,请参考以下文章

计算机毕业设计-社区疫情防控管理系统springboot-小区疫情管理系统java代码

小区物业管理系统的设计与实现 文献收集

小区物业管理系统-总结-需求分析

基于java的小区物业管理系统

小区物业管理系统-系统管理员页面

小区物业管理系统-通知发布