217 lines
7.8 KiB
VB.net
217 lines
7.8 KiB
VB.net
Imports System
|
|
Imports System.Data
|
|
Imports System.Data.SqlTypes
|
|
Imports System.Data.SqlClient
|
|
Imports System.IO
|
|
|
|
Public Class ctlPictures
|
|
Dim m_Connectionstring As String
|
|
Property Connectionstring As String
|
|
Get
|
|
Return m_Connectionstring
|
|
End Get
|
|
Set(value As String)
|
|
m_Connectionstring = value
|
|
End Set
|
|
End Property
|
|
|
|
Dim m_Produktnr As Integer
|
|
Property Produktnr As Integer
|
|
Get
|
|
Return m_Produktnr
|
|
End Get
|
|
Set(value As Integer)
|
|
m_Produktnr = value
|
|
End Set
|
|
End Property
|
|
|
|
Dim m_mitarbeiternr As Integer
|
|
Property Mitarbeiternr As Integer
|
|
Get
|
|
Return m_mitarbeiternr
|
|
End Get
|
|
Set(value As Integer)
|
|
m_mitarbeiternr = value
|
|
End Set
|
|
End Property
|
|
|
|
Dim m_tempfilepath As String
|
|
Property TempfilePath As String
|
|
Get
|
|
Return m_tempfilepath
|
|
End Get
|
|
Set(value As String)
|
|
m_tempfilepath = value
|
|
End Set
|
|
End Property
|
|
Dim images As New DataSet
|
|
Dim CurrentImage As Integer = 1
|
|
Dim Maximages As Integer = 0
|
|
Dim ProduktImages As New TKB.VV.Lifecycle.clsProduktImage
|
|
|
|
Public Function Refresh()
|
|
Me.GetImages()
|
|
Maximages = images.Tables(0).Rows.Count
|
|
CurrentImage = 1
|
|
ShowImage()
|
|
End Function
|
|
|
|
Private Sub ShowImage()
|
|
If images.Tables(0).Rows.Count > 1 Then
|
|
ToolStipImages.Visible = True
|
|
Else
|
|
ToolStipImages.Visible = False
|
|
End If
|
|
Dim i As Integer = 0
|
|
For Each r As DataRow In images.Tables(0).Rows
|
|
i = i + 1
|
|
If i = CurrentImage Then
|
|
Dim arrayImage() As Byte = CType(r.Item("Image"), Byte())
|
|
Dim ms As New MemoryStream(arrayImage)
|
|
With Me.PictureBox1
|
|
.Image = Image.FromStream(ms)
|
|
.SizeMode = PictureBoxSizeMode.Zoom
|
|
End With
|
|
End If
|
|
Next
|
|
Me.tslblPicture.Text = CurrentImage.ToString + " / " + Maximages.ToString
|
|
End Sub
|
|
|
|
|
|
Private Function GetImages()
|
|
images.Tables.Clear()
|
|
Dim selectcommand As New SqlCommand
|
|
Dim connection As New SqlConnection()
|
|
Dim da As New SqlDataAdapter("Select * from dbo.lc_produktimage where aktiv=1 and lc_produktnr = " + Produktnr.ToString + " order by lc_produktimagenr", connection)
|
|
selectcommand.CommandType = CommandType.Text
|
|
selectcommand.Connection = connection
|
|
Try
|
|
connection.ConnectionString = Globals.sConnectionString
|
|
connection.Open()
|
|
da.Fill(images, "ProductImages")
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
Finally
|
|
connection.Close()
|
|
da.Dispose()
|
|
selectcommand.Dispose()
|
|
End Try
|
|
End Function
|
|
|
|
Public Function Save_Image(ByVal Produktnr As Integer, ByRef PicBox As PictureBox)
|
|
Dim ms As New MemoryStream
|
|
PicBox.Image.Save(ms, PicBox.Image.RawFormat)
|
|
Dim connection As New SqlConnection(Globals.sConnectionString)
|
|
|
|
Dim arrayImage() As Byte = ms.GetBuffer
|
|
ms.Close() ' Closes the Memory Stream
|
|
|
|
Dim strQuery As String = "INSERT INTO dbo.lc_produktImage (lc_produktnr, image, erstellt_am, mutiert_am, mutierer, aktiv) " + _
|
|
" VALUES(@Produktnr, @image, @erstellt_am, @mutiert_am, @mutierer, @aktiv)"
|
|
|
|
Dim objcommand As New SqlCommand(strQuery, connection)
|
|
|
|
With objcommand
|
|
.Parameters.Add(New SqlParameter("@Produktnr", SqlDbType.Int, 4)).Value = Me.Produktnr
|
|
.Parameters.Add(New SqlParameter("@Image", SqlDbType.Image)).Value = arrayImage
|
|
.Parameters.Add(New SqlParameter("@Erstellt_am", SqlDbType.DateTime)).Value = Now
|
|
.Parameters.Add(New SqlParameter("@Mutiert_am", SqlDbType.DateTime)).Value = Now
|
|
.Parameters.Add(New SqlParameter("@Mutierer", SqlDbType.Int)).Value = Me.Mitarbeiternr
|
|
.Parameters.Add(New SqlParameter("@aktiv", SqlDbType.Bit)).Value = 1
|
|
End With
|
|
|
|
connection.Open()
|
|
objcommand.ExecuteNonQuery()
|
|
connection.Close()
|
|
End Function
|
|
|
|
Public Function Delete_Image(Imagenr As String, produktnr As Integer)
|
|
Me.GetImages()
|
|
Dim i As Integer = 0
|
|
For Each r As DataRow In images.Tables(0).Rows
|
|
i = i + 1
|
|
If "P" + i.ToString = Imagenr Then
|
|
Dim connection As New SqlConnection(Globals.sConnectionString)
|
|
Dim objcommand As New SqlCommand("Update lc_produktimage set aktiv=0,mutierer=" + Globals.clsmitarbeiter.iMitarbeiternr.Value.ToString + " where lc_produktimageNr=" + r.Item("LC_ProduktimageNr").ToString, connection)
|
|
connection.Open()
|
|
objcommand.ExecuteNonQuery()
|
|
connection.Close()
|
|
End If
|
|
Next
|
|
End Function
|
|
|
|
|
|
Private Sub TSBtnNextImage_Click(sender As Object, e As EventArgs) Handles TSBtnNextImage.Click
|
|
Dim i As Integer
|
|
i = Me.CurrentImage + 1
|
|
If i > Maximages Then i = 1
|
|
CurrentImage = i
|
|
ShowImage()
|
|
|
|
End Sub
|
|
|
|
Private Sub TSBtnPreviousImage_Click(sender As Object, e As EventArgs) Handles TSBtnPreviousImage.Click
|
|
Dim i As Integer
|
|
i = CurrentImage - 1
|
|
If i < 1 Then i = Maximages
|
|
CurrentImage = i
|
|
ShowImage()
|
|
End Sub
|
|
|
|
Private Sub ToolStripMenuItem3_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem3.Click
|
|
Me.OpenFileDialog1.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
|
|
Me.OpenFileDialog1.ShowDialog()
|
|
Dim pbox As New PictureBox
|
|
If Me.OpenFileDialog1.FileName <> "" Then
|
|
pbox.Image = Image.FromFile(Me.OpenFileDialog1.FileName)
|
|
End If
|
|
Me.ProduktImages.Save_Image(Me.Produktnr, pbox)
|
|
Refresh()
|
|
CurrentImage = Maximages
|
|
ShowImage()
|
|
End Sub
|
|
|
|
Private Sub ToolStripMenuItem4_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem4.Click
|
|
If MsgBox("Aktuelle Bild inaktivieren?", vbYesNo + vbQuestion) = vbYes Then
|
|
Dim i As Integer
|
|
For Each r As DataRow In images.Tables(0).Rows
|
|
i = i + 1
|
|
If i = CurrentImage Then ProduktImages.Delete_Image(r.Item("lc_produktimagenr"))
|
|
Next
|
|
End If
|
|
Refresh()
|
|
End Sub
|
|
|
|
Private Sub BildInDieZwischenablageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BildInDieZwischenablageToolStripMenuItem.Click
|
|
Clipboard.SetDataObject(Me.PictureBox1.Image)
|
|
End Sub
|
|
|
|
Private Sub NeuesBildAusZwischenablageToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NeuesBildAusZwischenablageToolStripMenuItem.Click
|
|
Try
|
|
|
|
If Not System.Windows.Forms.Clipboard.GetDataObject() Is Nothing Then
|
|
Dim oDataObj As IDataObject = System.Windows.Forms.Clipboard.GetDataObject()
|
|
If oDataObj.GetDataPresent(System.Windows.Forms.DataFormats.Bitmap) Then
|
|
Dim oImgObj As System.Drawing.Image = oDataObj.GetData(DataFormats.Bitmap, True)
|
|
' oImgObj.Save("c:\Test.bmp", System.Drawing.Imaging.ImageFormat.Bmp)
|
|
oImgObj.Save(Me.TempfilePath + "\tmppic.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
|
|
' oImgObj.Save("c:\Test.gif", System.Drawing.Imaging.ImageFormat.Gif)
|
|
End If
|
|
End If
|
|
|
|
Dim pbox As New PictureBox
|
|
pbox.Image = Image.FromFile(Me.TempfilePath + "\tmppic.jpg")
|
|
Me.ProduktImages.Save_Image(Me.Produktnr, pbox)
|
|
|
|
Refresh()
|
|
CurrentImage = Maximages
|
|
ShowImage()
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
End Class
|