/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/test.aspx.vb
678 строк
24 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.IO Imports Newtonsoft.Json Imports sharedClasses Imports System.Math Imports System Imports System.Web Imports System.Data Imports System.Net Imports sharedClasses.dbFunctions Imports System.Text Imports System.Threading Imports Microsoft.VisualBasic Imports System.Drawing Imports System.Drawing.Drawing2D Partial Class test Inherits System.Web.UI.Page Private sqlf As New sharedClasses.dbFunctions.SqlFunctions 'Private Sub test_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad 'End Sub 'Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load ' Label1.Text = Propis(Convert.ToDecimal(TextBox1.Text)) ' 'lbl.Text = "" ' 'For i As Integer = 0 To TextBox1.Text ' ' 'lbl.Text &= i & ": " & f(i, 0, 0) & "<br />" ' ' Dim start As DateTime = DateTime.Now ' ' lbl.Text &= "<br />" & i & ": " & ff(i, 4, 17 / 3.99999996D).ToString ' ' Dim send As DateTime = DateTime.Now ' ' msg.Text = (send.Subtract(start).TotalMilliseconds) ' 'Next ' 'Dim a As Decimal = 1 ' 'Dim b As Decimal = 0 ' 'Dim c As Decimal = a / b ' If Not IsPostBack Then ' Dim sqlf As New sharedClasses.dbFunctions.SqlFunctions ' Dim db As Data.DataTable = sqlf.GetData("SELECT DISTINCT MACH_CATEGORY FROM UserModules.[user].[VI_SONIC_STATISTICS_01]") ' multiselect1.DataSource = db ' multiselect1.TextField = "MACH_CATEGORY" ' multiselect1.ValueField = "MACH_CATEGORY" ' multiselect1.DataBind() ' multiselect2.DataSource = db ' multiselect2.TextField = "MACH_CATEGORY" ' multiselect2.ValueField = "MACH_CATEGORY" ' multiselect2.DataBind() ' End If ' Dim ms As UserControls_multiselect = LoadControl("~/UserControls/multiselect.ascx") ' ms.DataSource = sqlf.GetData("SELECT DISTINCT MACH_CATEGORY FROM UserModules.[user].[VI_SONIC_STATISTICS_01]") ' ms.TextField = "MACH_CATEGORY" ' ms.ValueField = "MACH_CATEGORY" ' ms.DataBind() ' PlaceHolder1.Controls.Add(ms) ' 'For i As Integer = 3 To 15 ' ' PlaceHolder1.Controls.Add(New TextBox With {.ID = "txt" & i, .Text = i, .TextMode = i}) ' 'Next 'End Sub 'Public Function Propis(Summa As Double) As String ' Propis = "NA" ' Dim t As String ' Dim s() As String ' Dim n(0 To 2) As Integer ' Dim i As Integer ' t = "один два три четыре пять шесть семь восемь девять десять одиннадцать двенадцать тринадцать четырнадцать пятнадцать шестнадцать семнадцать восемнадцать девятнадцать двадцать тридцать сорок пятьдесят шестьдесят семьдесят восемьдесят девяносто сто двести триста четыреста пятьсот шестьсот семьсот восемьсот девятьсот одна две тысяча тысячи тысяч рубль рубля рублей копеек копеек копеек ноль" ' s = Split(t, " ") ' If Summa > 999999.99 Or Summa < 0 Then Exit Function ' t = Trim(Format(Summa, "# ##0.00")) ' n(0) = CInt(Right$(t, 2)) ' t = Left$(t, InStr(1, t, ".") - 1) ' If InStr(1, t, " ") = 0 Then ' n(1) = CInt(t) ' n(2) = 0 ' Else ' n(1) = CInt(Mid$(t, InStr(1, t, " ") + 1)) ' n(2) = CInt(Left$(t, InStr(1, t, " ") - 1)) ' End If ' t = "" ' If n(2) > 0 Then ' i = n(2) \ 100 ' If i > 0 Then ' t = s(i + 26) ' End If ' i = n(2) - i * 100 ' If i > 0 Then ' Select Case i ' Case Is = 1 ' t = t & " " & s(36) & " " & s(38) ' Case Is = 2 ' t = t & " " & s(37) & " " & s(39) ' Case 3 To 4 ' t = t & " " & s(i - 1) & " " & s(39) ' Case 5 To 19 ' t = t & " " & s(i - 1) & " " & s(40) ' Case 20 To 99 ' t = t & " " & s(i \ 10 + 17) ' i = i Mod 10 ' Select Case i ' Case Is = 0 ' t = t & " " & s(40) ' Case Is = 1 ' t = t & " " & s(36) & " " & s(38) ' Case Is = 2 ' t = t & " " & s(37) & " " & s(39) ' Case 3 To 4 ' t = t & " " & s(i - 1) & " " & s(39) ' Case 5 To 9 ' t = t & " " & s(i - 1) & " " & s(40) ' End Select ' End Select ' Else ' t = t & " " & s(40) ' End If ' End If ' If n(1) > 0 Then ' i = n(1) \ 100 ' If i > 0 Then ' t = t & " " & s(i + 26) ' End If ' i = n(1) - i * 100 ' If i > 0 Then ' Select Case i ' Case 1 To 19 ' t = t & " " & s(i - 1) ' Case 20 To 99 ' t = t & " " & s(i \ 10 + 17) ' i = i Mod 10 ' If i > 0 Then ' t = t & " " & s(i - 1) ' End If ' End Select ' End If ' End If ' Select Case i ' Case 0 ' t = t & " " & s(43) & " " & Format$(n(0), "00") ' Case 1 ' t = t & " " & s(41) & " " & Format$(n(0), "00") ' Case 2 To 4 ' t = t & " " & s(42) & " " & Format$(n(0), "00") ' Case 5 To 9 ' t = t & " " & s(43) & " " & Format$(n(0), "00") ' End Select ' 't = t & " " & s(41) & " " & Format$(n(0), "00") ' Select Case n(0) ' Case Is = 0 ' t = t & " " & s(44) ' Case Is = 1 ' t = t & " " & s(42) ' Case 2 To 4 ' t = t & " " & s(43) ' Case 5 To 19 ' t = t & " " & s(44) ' Case 20 To 99 ' i = n(0) Mod 10 ' Select Case i ' Case Is = 0 ' t = t & " " & s(44) ' Case Is = 1 ' t = t & " " & s(42) ' Case 2 To 4 ' t = t & " " & s(43) ' Case 5 To 9 ' t = t & " " & s(44) ' End Select ' End Select ' t = Trim(t) ' If n(2) = 0 And n(1) = 0 Then t = s(45) & " " & t ' t = UCase(Left(t, 1)) & Mid(t, 2) ' Propis = t 'End Function ''Class Money '' Dim NumEd As String '' Dim NumEd1 As String '' Dim NumDec As String '' Dim NumSot As String '' Dim Xlion0 As String '' Dim Xlion1 As String '' Dim Xlion2 As String '' Public Function MoneyToWord(Money As Double, valut As String, includekops As Boolean) As String '' Select Case valut '' Case "RUR" '' NumArrayInitRUR() '' Case Else '' valut = "RUR" '' NumArrayInitRUR() '' End Select '' Dim Money3 As Integer, MoneyI As Integer, MoneyK As Integer, Digit As Integer, LastDigit As Integer, T As Integer '' Dim Sto As String, Kop As String, Result As String '' MoneyI = Money '' MoneyK = Round((Money - MoneyI) * 100, 0) '' T = 0 '' While MoneyI > 0 '' Money3 = MoneyI Mod 1000 '' MoneyI = Int(MoneyI / 1000) '' Sto = "" '' If (Money3 Mod 100) < 20 Then '' LastDigit = (Money3 Mod 20) '' If LastDigit > 0 Then '' If (T = 1) And (LastDigit = 1 Or LastDigit = 2) Then '' Sto = NumEd1(LastDigit) '' Else '' Sto = NumEd(LastDigit) '' End If '' End If '' Money3 = Int(Money3 / 100) '' Else '' LastDigit = Money3 Mod 10 '' If LastDigit > 0 Then '' If (T = 1) And (LastDigit = 1 Or LastDigit = 2) Then '' Sto = NumEd1(LastDigit) '' Else '' Sto = NumEd(LastDigit) '' End If '' End If '' Money3 = Int(Money3 / 10) '' Digit = Money3 Mod 10 '' If Digit > 0 Then '' Sto = NumDec(Digit) + Sto '' End If '' Money3 = Int(Money3 / 10) '' End If '' If Money3 > 0 Then '' Sto = NumSot(Money3) + Sto '' End If '' If T > 0 Then '' If LastDigit = 1 Then '' Sto = Sto + Xlion1(T) '' Else '' If (LastDigit >= 2 And LastDigit <= 4) Then '' Sto = Sto + Xlion2(T) '' Else '' Sto = Sto + Xlion0(T) '' End If '' End If '' End If '' T = T + 1 '' Result = Sto + Result '' End While '' Kop = CStr(MoneyK Mod 10) '' MoneyK = MoneyK / 10 '' Kop = CStr(MoneyK) + Kop '' Select Case valut '' Case "RUR" '' If includekops Then '' Result = Result + "руб. " + Kop + " коп." '' Else '' Result = Result + "руб. " '' End If '' End Select '' MoneyToWord = Result '' End Function '' Private Sub NumArrayInitRUR() '' NumEd(1) = "один " '' NumEd(2) = "два " '' NumEd(3) = "три " '' NumEd(4) = "четыре " '' NumEd(5) = "пять " '' NumEd(6) = "шесть " '' NumEd(7) = "семь " '' NumEd(8) = "восемь " '' NumEd(9) = "девять " '' NumEd(10) = "десять " '' NumEd(11) = "одиннадцать " '' NumEd(12) = "двенадцать " '' NumEd(13) = "тринадцать " '' NumEd(14) = "четырнадцать " '' NumEd(15) = "пятнадцать " '' NumEd(16) = "шестадцать " '' NumEd(17) = "семнадцать " '' NumEd(18) = "восемнадцать " '' NumEd(19) = "девятнадцать " '' NumEd1(1) = "одна " '' NumEd1(2) = "две " '' NumDec(2) = "двадцать " '' NumDec(3) = "тридцать " '' NumDec(4) = "сорок " '' NumDec(5) = "пятьдесят " '' NumDec(6) = "шестьдесят " '' NumDec(7) = "семьдесят " '' NumDec(8) = "восемьдесят " '' NumDec(9) = "девяносто " '' NumSot(1) = "сто " '' NumSot(2) = "двести " '' NumSot(3) = "триста " '' NumSot(4) = "четыреста " '' NumSot(5) = "пятьсот " '' NumSot(6) = "шестьсот " '' NumSot(7) = "семьсот " '' NumSot(8) = "восемьсот " '' NumSot(9) = "девятьсот " '' Xlion0(1) = "тысяч " '' Xlion0(2) = "миллионов " '' Xlion0(3) = "миллиардов " '' Xlion1(1) = "тысяча " '' Xlion1(2) = "миллион " '' Xlion1(3) = "миллиард " '' Xlion2(1) = "тысячи " '' Xlion2(2) = "миллиона " '' Xlion2(3) = "миллиарда" '' End Sub ''End Class ''Function f(n As Integer, x As Decimal, y As Decimal) As Decimal '' Return (3 ^ (n + 1) + 5 ^ (n + 1)) / (3 ^ (n) + 5 ^ (n)) ''End Function ''Function ff(n As Decimal, x As Decimal, y As Decimal) As Decimal '' 'If n = 0 Then '' ' Return x '' 'ElseIf n = 1 Then '' ' Return y '' 'Else '' ' Return (108 - (815 - 1500 / ff(n - 2, x, y)) / ff(n - 1, x, y)) '' 'End If '' Dim x1 As Decimal '' Dim x2 As Decimal '' Dim xn As Decimal = 0 '' If n = 0 Then '' Return x '' ElseIf n = 1 Then '' Return y '' Else '' x1 = y '' x2 = x '' For i As Integer = 2 To n '' xn = (108 - (815 - 1500 / x2) / x1) '' x2 = x1 '' x1 = xn '' Next '' End If '' Return xn ''End Function 'Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click ' 'Label1.Text = "" ' 'For Each i As DictionaryEntry In multiselect1.CheckedItems ' ' Label1.Text &= i.Key & ":" & i.Value & "/" ' 'Next ' Dim i As Integer = 1 ' For Each c As Newtonsoft.Json.Linq.JToken In GetStBinStatus().First.Children ' For Each cc As Newtonsoft.Json.Linq.JToken In c.Children ' Response.Write(i & "--->" & c.ToString) ' i += 1 ' Next ' Next 'End Sub 'Private Class Coordinates ' Public x As Decimal ' Public y As Decimal ' Public z As Decimal 'End Class 'Private Class Loc ' Public coord As Coordinates 'End Class 'Private Class CoordSet ' Public geoLoc As New Loc ' Public xyzLoc As New Loc 'End Class 'Private Class MotionType ' Public type() As String 'End Class 'Private Class Rtls ' Public mac As String ' Public ts As Integer ' Public coord As CoordSet ' Public motion As MotionType 'End Class 'Private Class RtlsResponse ' Public rtlsPoints() As Rtls 'End Class 'Private Function GetStBinStatus(Optional lastChangeDate As String = "") As Object ' Dim wb As WebRequest ' Dim url As String = "" ' 'If lastChangeDate <> "" Then ' ' url = "http://serkweb.serk.lan:8080/tools/Handlers/getwmsdata.ashx?fname=Z_RFC_STBIN_STATUS&format=json&mode=param&LAST_CHANGE_DATETIME=" & lastChangeDate ' 'Else ' url = "http://106.109.79.145:9003/rtlscp/location/get/" ' 'End If ' wb = WebRequest.Create(url) ' Dim res As WebResponse = wb.GetResponse ' Dim sr As New StreamReader(res.GetResponseStream) ' Dim json As String = sr.ReadToEnd() ' Dim dt As Newtonsoft.Json.Linq.JObject ' Try ' dt = Newtonsoft.Json.Linq.JObject.Parse(json) ' Return dt ' Catch ex As Exception ' Return Nothing ' End Try 'End Function 'Dim runningRequestCount As Integer = 0 Dim maxRequestCount As Integer = 4 Private threadsToStart As Integer = maxRequestCount Dim maxitemstoprocess As Integer = 10000 Private idToProcess As New Collection Dim waitCounter As Integer = 0 'Public Shared allDone As New ManualResetEvent(False) Protected Sub goresize_Click(sender As Object, e As EventArgs) Handles goresize.Click If IsNumeric(threadsnumber.Text) Then maxRequestCount = threadsnumber.Text threadsToStart = threadsnumber.Text End If If IsNumeric(itemstoprocess.Text) Then maxitemstoprocess = itemstoprocess.Text End If resizelog.Text = "" Dim sqlf As New SqlFunctions sqlf.NonQuery("DELETE FROM UserModulesAttachments.[user]." & tablename.Text & " WHERE DELETED = 'Y' ") Dim sql As New StringBuilder sql.AppendLine("SELECT TOP " & maxitemstoprocess & " id FROM UserModulesAttachments.[user]." & tablename.Text) sql.AppendLine(" WHERE DELETED = 'N'") If chkOnlyNotResized.Checked Then sql.AppendLine("AND RESIZED = 'N' ") End If sql.AppendLine("AND NAME LIKE '%.jpg' ORDER BY ID DESC ") Dim imagelist As DataTable = sqlf.GetData(sql.ToString) For Each dr As DataRow In imagelist.Rows idToProcess.Add(dr("id"), dr("id")) resizelog.Text &= vbNewLine & dr("id") Next processId() End Sub Protected Class imgProp Public tableName As String Public rowId As Integer Public Sub New(tb As String, id As Integer) tableName = tb rowId = id End Sub End Class Private Sub processId() Dim itemscounter As Integer = 0 While (idToProcess.Count > 0) And (itemscounter < maxitemstoprocess) If threadsToStart > 0 Then Dim id As Integer = idToProcess.Item(1) idToProcess.Remove(id.ToString) threadsToStart -= 1 Dim st As New imgProp(tablename.Text, id) ThreadPool.QueueUserWorkItem(New System.Threading.WaitCallback(AddressOf startThread), st) itemscounter += 1 End If End While 'While threadsToStart < maxRequestCount 'End While End Sub 'Private Sub startThread(id As Integer) ' Dim wb As WebRequest ' Dim url As String = HttpContext. ' Current. ' Request. ' Url. ' AbsoluteUri. ' ToString. ' Replace("test.aspx", ' "/handlers/getimage.ashx?mode=resize&id=" & id & "&storage=UserModulesAttachments.[user]." & tablename.Text) ' wb = WebRequest.Create(url) ' Dim myRequestState As New Object ' Dim asyncResult As IAsyncResult = CType(wb.BeginGetResponse(AddressOf endRequest, myRequestState), IAsyncResult) ' allDone.WaitOne() 'End Sub 'Private Sub endRequest(result As IAsyncResult) ' threadsToStart += 1 ' allDone.Set() 'End Sub Dim lasterror As String = "" Private Event allDone(imgid As Integer) Private Sub threadEnds(imgid As Integer) Handles Me.allDone threadsToStart += 1 End Sub Private Sub startThread(state As Object) Dim storagename As String = CType(state, imgProp).tableName Dim imageId As Integer = CType(state, imgProp).rowId readResizeSave(storagename, imageId) RaiseEvent allDone(imageId) End Sub Private Sub readResizeSave(storagename As String, imageId As Integer) Dim con As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("SERKIntranetConnectionString").ConnectionString) Dim com As New SqlClient.SqlCommand("", con) storagename = "UserModulesAttachments.[user]." & storagename com.CommandText = "SELECT [doc], [name] FROM " & storagename & " WHERE [id]=" & imageId Dim img() As Byte = Nothing Dim fName As String = "" Dim fExtension As String = "" Try con.Open() Dim r As SqlClient.SqlDataReader = com.ExecuteReader While r.Read img = r.Item("doc") fName = r.Item("name") End While Catch ex As Exception lasterror = ex.Message Finally If con.State <> Data.ConnectionState.Closed Then con.Close() End If End Try Dim c As New sharedClasses.Common.common Try Using imgMemoryStream As New IO.MemoryStream(img) Dim originalImage As Image = Image.FromStream(imgMemoryStream) Dim owidth As Integer = originalImage.Width Dim oheight As Integer = originalImage.Height If originalImage.Width > 1920 Or originalImage.Height > 1080 Then originalImage = ResizeImage(originalImage, New Size With {.Width = 1920, .Height = 1080}) Using stream As New System.IO.MemoryStream originalImage.Save(stream, Imaging.ImageFormat.Jpeg) img = stream.ToArray End Using SaveThumbToDb(storagename, imageId, img, "resize") c.Log(storagename & "/thr:" & maxRequestCount, "resize", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "success: id - " & imageId & " osize - " & owidth & "x" & oheight) Else c.Log(storagename & "/thr:" & maxRequestCount, "resize", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "skip: id - " & imageId & " osize - " & owidth & "x" & oheight) End If End Using Catch ex As Exception c.Log(storagename & "/thr:" & maxRequestCount, "resize", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "fail: id - " & imageId & " ex - " & ex.Message) End Try End Sub Public Shared Function ResizeImage(ByVal image As Image, ByVal size As Size, Optional ByVal preserveAspectRatio As Boolean = True) As Image Dim newWidth As Integer Dim newHeight As Integer If preserveAspectRatio Then Dim originalWidth As Integer = image.Width Dim originalHeight As Integer = image.Height Dim percentWidth As Single = CSng(size.Width) / CSng(originalWidth) Dim percentHeight As Single = CSng(size.Height) / CSng(originalHeight) Dim percent As Single = If(percentHeight < percentWidth, percentHeight, percentWidth) newWidth = CInt(originalWidth * percent) newHeight = CInt(originalHeight * percent) Else newWidth = size.Width newHeight = size.Height End If Dim newImage As Image = New Bitmap(newWidth, newHeight) Using graphicsHandle As Graphics = Graphics.FromImage(newImage) graphicsHandle.InterpolationMode = InterpolationMode.HighQualityBicubic graphicsHandle.DrawImage(image, 0, 0, newWidth, newHeight) End Using Return newImage End Function Private Sub SaveThumbToDb(tablename As String, rowid As String, ByVal thumb() As Byte, Optional mode As String = "thumb") 'Saving files to DB Dim sqlf As New sharedClasses.dbFunctions.SqlFunctions Dim com As New Data.SqlClient.SqlCommand If mode = "resize" Then com.CommandText = "UPDATE " & tablename & " SET doc = @thumb, resized = 'Y' where id = @rowid " Else com.CommandText = "UPDATE " & tablename & " SET thumb = @thumb where id = @rowid " End If com.Parameters.Clear() With com.Parameters .AddWithValue("thumb", thumb) .AddWithValue("rowid", rowid) End With sqlf.NonQuery(com) lastError = sqlf.lastException End Sub Protected Sub itemstoprocess_TextChanged(sender As Object, e As EventArgs) Handles itemstoprocess.TextChanged End Sub Private Sub test_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad End Sub Private Sub test_Load(sender As Object, e As EventArgs) Handles Me.Load Dim sqlf As New SqlFunctions Dim com As New Data.SqlClient.SqlCommand Dim cardNo As String = "6469237000010100" Dim dt As Data.DataTable = sqlf.GetData("SELECT top 1 [EventLogSeq], isnull([EmployeeNO],'') as EmployeeNO, [EmployeeName], [CardNO], [FactoryName], isnull([DeptCode],'') as DeptCode, [DepartmentName] FROM [hr].[dbo].[CHECK_CARD_LOG] where CardNO = '" & cardNo & "' order by work_date desc ") Randomize() Dim gen As System.Random = New System.Random() Dim i As Integer = gen.Next(1, 4) Select Case i Case 1 Response.Write("One") Case 2 Response.Write("One") Case 3 Response.Write("One") End Select End Sub End Class