📄 pic.vb
字号:
Imports System
Imports System.Configuration
Imports System.Data
Imports System.Data.OleDb
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports Microsoft.VisualBasic.Strings
Namespace Packaging
Public Class Pic
Public PicId As Integer
Public PicDesc As String
Public PicTitle As String
Public PicOwner As String
Public PicClicks As Integer
Public PicUrl As String
Public PicTime As DateTime
End Class
Public Class PicDB
Public Function GetPicInfo(ByVal id As Integer) As DataView
Dim MySQL As String
MySQL="SELECT * FROM [Pic] WHERE PicID="
MySQL &=ID &""
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim MyDS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=MyDS.Tables("My").DefaultView
DV.Table.Rows(0)("PicClicks")+=1
Dim MyFilter As StringFilter=New StringFilter()
MyFilter.FilterDegree=2
DV.Table.Rows(0)("PicDesc")=MyFilter.Change4Showing(DV.Table.Rows(0)("PicDesc"))
ReadOnce(id)
Return DV
End Function
Public Function Getlast() As Integer
Dim MySQL As String="SELECT PicId FROM [Pic] ORDER BY PicId"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim DS As DataSet=MyDB.SelectFromDB()
Dim DV As DataView=DS.Tables("My").DefaultView
Dim id As Integer=DV.Table.Rows.Count
If id>0 Then
id=DV.Table.Rows(id-1)("PicId")+1
Else
id=1
End If
Return id
End Function
Public PageSize As Integer
Public Function GetPicList(ByVal CurPage As Integer, ByRef TotalPage As Integer) As DataView
Dim MySQL As String
MySQL="SELECT * FROM [Pic] ORDER BY PicTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim DataSource As DataSet=MyDB.SelectFromDB()
Dim TotalItem As Integer=DataSource.Tables("My").Rows.Count
TotalPage=TotalItem\PageSize+1
If TotalItem Mod PageSize=0 Then
TotalPage=TotalPage-1
End If
Dim i,j As Integer
Dim StartItem As Integer= (CurPage-1) * PageSize + 1
Dim EndItem As Integer= CurPage * PageSize
If EndItem>TotalItem Then
EndItem=TotalItem
End If
Dim DV As DataView=New DataView()
Dim DT As DataTable=New DataTable("My")
Dim keyDC As DataColumn
Dim DR As DataRow
For Each keyDC In DataSource.Tables("My").Columns
DT.Columns.Add(keyDC.ColumnName, keyDC.DataType)
Next
DT.Columns.Add("thumbUrl", Type.GetType("System.String"))
For i=StartItem To EndItem
DR=DT.NewRow()
For j=0 To DT.Columns.Count-2
DR(j)=DataSource.Tables("My").Rows(i-1)(j)
Next
DR(DT.Columns.Count-1)=GetThumb(DataSource.Tables("My").Rows(i-1)("PicId"))
DT.Rows.Add(DR)
Next
DV.Table=DT
Return DV
End Function
Public Function GetMyPicList(ByVal CurPage As Integer, ByRef TotalPage As Integer, ByVal account As String) As DataView
Dim MyFilter As StringFilter=New StringFilter()
MyFilter.FilterDegree=0
account=MyFilter.Change4Saving(account)
Dim MySQL As String
MySQL="SELECT * FROM [Pic] WHERE PicOwner='"
MySQL &= account & "' ORDER BY PicTime DESC"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
Dim DataSource As DataSet=MyDB.SelectFromDB()
Dim TotalItem As Integer=DataSource.Tables("My").Rows.Count
TotalPage=TotalItem\PageSize+1
If TotalItem Mod PageSize=0 Then
TotalPage=TotalPage-1
End If
Dim i,j As Integer
Dim StartItem As Integer= (CurPage-1) * PageSize + 1
Dim EndItem As Integer= CurPage * PageSize
If EndItem>TotalItem Then
EndItem=TotalItem
End If
Dim DV As DataView=New DataView()
Dim DT As DataTable=New DataTable("My")
Dim keyDC As DataColumn
Dim DR As DataRow
For Each keyDC In DataSource.Tables("My").Columns
DT.Columns.Add(keyDC.ColumnName, keyDC.DataType)
Next
DT.Columns.Add("thumbUrl", Type.GetType("System.String"))
For i=StartItem To EndItem
DR=DT.NewRow()
For j=0 To DT.Columns.Count-2
DR(j)=DataSource.Tables("My").Rows(i-1)(j)
Next
DR(DT.Columns.Count-1)=GetThumb(DataSource.Tables("My").Rows(i-1)("PicId"))
DT.Rows.Add(DR)
Next
DV.Table=DT
Return DV
End Function
Private Function ReadOnce(ByVal id As Integer)
Dim MySQL As String
MySQL="UPDATE [Pic] SET PicClicks=PicClicks+1 WHERE PicID="
MySQL &=id
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Function
Private Sub Change4SQL(ByRef MyPic As Pic)
Dim MyFilter As StringFilter=New StringFilter()
MyFilter.FilterDegree=5
MyPic.PicTitle=MyFilter.Change4Saving(MyPic.PicTitle)
MyPic.PicDesc=MyFilter.Change4Saving(MyPic.PicDesc)
MyPic.PicOwner=MyFilter.Change4Saving(MyPic.PicOwner)
MyPic.PicUrl=MyFilter.Change4Saving(MyPic.PicUrl)
End Sub
Public Sub AddPic(ByVal MyPic As Pic)
Change4SQL(MyPic)
Dim MySQL As String="INSERT INTO [Pic] "
MySQL &= "(PicTitle, PicUrl, PicDesc, "
MySQL &= "PicOwner, PicTime) VALUES ('"
MySQL &= MyPic.PicTitle & "', '"
MySQL &= MyPic.PicUrl & "', '"
MySQL &= MyPic.PicDesc & "', '"
MySQL &= MyPic.PicOwner & "', #"
MySQL &= MyPic.PicTime & "#)"
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub ChangePic(ByVal MyPic As Pic)
Change4SQL(MyPic)
Dim MySQL As String="UPDATE [Pic] SET "
MySQL &= "PicTitle='" & MyPic.PicTitle & "', "
MySQL &= "PicUrl='" & MyPic.PicUrl & "', "
MySQL &= "PicDesc='" & MyPic.PicDesc & "', "
MySQL &= "PicOwner='" & MyPic.PicOwner & "'"
MySQL &= " WHERE NewsId=" & MyPic.PicId
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Sub DeletePic(ByVal Id As Integer)
Dim appPath As String=ConfigurationSettings.AppSettings("appPathString")
Dim DV As DataView=GetPicInfo(id)
buchang(id)
Dim cdir As String=DV.Table.Rows(0)("PicUrl")
cdir=replace(cdir,"/","\")
cdir=appPath + cdir
Try
If file.Exists(cdir) Then
File.Delete(cdir)
End If
Catch
End Try
Dim MySQL As String="DELETE FROM [Pic] WHERE PicId="
MySQL &= Id
MySQL &= " "
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Private Sub buchang(ByVal id As Integer)
Dim MySQL As String
MySQL="UPDATE [Pic] SET PicClicks=PicClicks-1 WHERE PicID="
MySQL &=id
Dim MyDB As SQLDB=New SQLDB()
MyDB.strSQL=MySQL
MyDB.ExecuteSQL()
End Sub
Public Function GetThumb(ByVal id As Integer) As String
Dim appPath As String=ConfigurationSettings.AppSettings("appPathString")
Dim DV As DataView=GetPicInfo(id)
buchang(id)
Dim MyImageName As String=DV.Table.Rows(0)("PicUrl")
MyImageName=replace(MyImageName,"/","\")
MyImageName=appPath + MyImageName
Dim MyImage As Image=Image.FromFile(MyImageName)
Dim w1 As Integer=MyImage.Width
Dim h1 As Integer=MyImage.Height
Dim w As Integer
Dim h As Integer
If (100*h1/w1<=100) Then
w=100
h=100*h1/w1
Else
w=100*w1/h1
h=100
End If
Dim MyThumb As Image=MyImage.GetThumbnailImage(w,h,Nothing,IntPtr.Zero)
Dim MyThumbName As String
Dim nRandom As Random = New Random(DateTime.Now.Millisecond)
MyThumbName="upload/temp/"+nRandom.Next().ToString()+".jpg"
MyThumb.Save(appPath+MyThumbName, ImageFormat.Jpeg)
Return MyThumbName
End Function
End Class
End Namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -