You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
9.8 KiB
273 lines
9.8 KiB
Imports System
|
|
Imports System.Data
|
|
Imports System.Data.SqlTypes
|
|
Imports System.Data.SqlClient
|
|
Imports System.IO
|
|
Imports System.ComponentModel
|
|
|
|
Public Class ctlPictures
|
|
Dim m_Connectionstring As String
|
|
<DefaultValue("data source=shu00;initial catalog=Vertragsverwaltung;persist security info=False;workstation id=SHU;packet size=4096;user id=sa;password=*shu29"), Description("ConnectionString"), Category("Options")> _
|
|
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 m_formreadonly As Boolean
|
|
Property FormReadOnly As Boolean
|
|
Get
|
|
Return m_formreadonly
|
|
End Get
|
|
Set(value As Boolean)
|
|
m_formreadonly = value
|
|
If value = True Then
|
|
Me.ImageMenuStrip.Enabled = False
|
|
Else
|
|
Me.ImageMenuStrip.Enabled = True
|
|
End If
|
|
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
|
|
Dim lvimagelist As New ImageList
|
|
|
|
Public Function Refresh()
|
|
Me.GetImages()
|
|
Maximages = images.Tables(0).Rows.Count
|
|
CurrentImage = 1
|
|
ShowImage()
|
|
End Function
|
|
|
|
Private Sub ShowImage()
|
|
Me.Picturelist.BeginUpdate()
|
|
If images.Tables(0).Rows.Count > 1 Then
|
|
ToolStipImages.Visible = True
|
|
Picturelist.Visible = True
|
|
Else
|
|
ToolStipImages.Visible = False
|
|
Picturelist.Visible = False
|
|
End If
|
|
' If images.Tables(0).Rows.Count = 0 Then
|
|
Me.PictureBox1.Image = Nothing
|
|
lvimagelist.Images.Clear()
|
|
Me.Picturelist.Items.Clear()
|
|
'End If
|
|
Dim i As Integer = 0
|
|
For Each r As DataRow In images.Tables(0).Rows
|
|
|
|
i = i + 1
|
|
|
|
|
|
If Me.Picturelist.Visible = True Then
|
|
Picturelist.View = View.LargeIcon
|
|
|
|
|
|
Dim arrayImage() As Byte = CType(r.Item("Image"), Byte())
|
|
Dim ms As New MemoryStream(arrayImage)
|
|
lvimagelist.Images.Add(Image.FromStream(ms))
|
|
Picturelist.Items.Add((i).ToString, i - 1)
|
|
End If
|
|
Me.Picturelist.LargeImageList = lvimagelist
|
|
Me.lvimagelist.ImageSize = New Size(50, 34)
|
|
Me.Picturelist.SmallImageList = lvimagelist
|
|
Me.Picturelist.StateImageList = lvimagelist
|
|
|
|
|
|
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.Picturelist.Refresh()
|
|
|
|
Me.tslblPicture.Text = CurrentImage.ToString + " / " + Maximages.ToString
|
|
Me.Picturelist.EndUpdate()
|
|
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("Aktuelles Bild löschen?", 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_Physisch(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
|
|
|
|
Private Sub ToolStipImages_ItemClicked(sender As Object, e As ToolStripItemClickedEventArgs) Handles ToolStipImages.ItemClicked
|
|
|
|
End Sub
|
|
|
|
Private Sub Picturelist_Click(sender As Object, e As EventArgs) Handles Picturelist.Click
|
|
CurrentImage = Me.Picturelist.FocusedItem.Text
|
|
ShowImage()
|
|
End Sub
|
|
|
|
End Class
|