/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/inv/itassetcheck.aspx.vb
142 строки
6 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports AjaxControlToolkit Imports System.IO Imports sharedClasses Imports sharedClasses.dbFunctions Imports System.Data.SqlClient Imports System.Data Imports System.Drawing Partial Class Inv_itassetcheck Inherits System.Web.UI.Page Dim sqlf As New SqlFunctions Private Sub Inv_itassetcheck_Load(sender As Object, e As EventArgs) Handles Me.Load End Sub Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs) Handles ASSETLIST.RowDataBound If e.Row.RowType = DataControlRowType.DataRow Then e.Row.Attributes("onclick") = Page.ClientScript.GetPostBackClientHyperlink(ASSETLIST, "Select$" & e.Row.RowIndex) e.Row.Attributes("class") = "action" e.Row.ToolTip = "Click to select this row." End If 'e.Row.Cells(10).Visible = False e.Row.Cells(11).Visible = False 'e.Row.Cells(e.Row.Cells.Count - 1).Visible = False End Sub Protected Sub OnSelectedIndexChanged(sender As Object, e As EventArgs) Handles ASSETLIST.SelectedIndexChanged For Each row As GridViewRow In ASSETLIST.Rows If row.RowIndex = ASSETLIST.SelectedIndex Then row.BackColor = ColorTranslator.FromHtml("#A1DCF2") row.ToolTip = String.Empty Else row.BackColor = ColorTranslator.FromHtml("#FFFFFF") row.ToolTip = "Click to select this row." End If Next Dim r As GridViewRow = ASSETLIST.Rows(ASSETLIST.SelectedIndex) assetid.Text = r.Cells(0).Text assetdescr.Text = r.Cells(1).Text & "/" & r.Cells(2).Text assetsn.Text = r.Cells(3).Text assetinvn.Text = r.Cells(4).Text remark.Text = r.Cells(7).Text.Replace("nbsp;", " ").Replace("&", "") inspector.Text = r.Cells(8).Text.Replace("nbsp;", " ").Replace("&", "") Image1.ImageUrl = "~/handlers/getimage.ashx?mode=thumb&id=" & r.Cells(10).Text & "&storage=UserModulesAttachments.[user].[IT_ASSET_INVENTORY]" 'r.Cells(10).Text rowid.value = r.Cells(11).Text Session("UploadedFile") = Nothing End Sub Protected Sub UploadComplete(sender As Object, e As AsyncFileUploadEventArgs) Handles FileUpload1.UploadedComplete Dim afu As AsyncFileUpload = DirectCast(sender, AsyncFileUpload) Dim path As String = Server.MapPath("") & "\" & e.FileName afu.SaveAs(path) Session.Add("UploadedFile", e.FileName) 'afu.ClearAllFilesFromPersistedStore() ClearContents(CType(sender, Control)) End Sub Private Sub ClearContents(ByVal Control As Control) For i As Integer = 0 To Session.Keys.Count - 1 If Session.Keys(i).Contains(Control.ClientID) Then Session.Remove(Session.Keys(i)) Exit For End If Next End Sub Private Sub binddata() ASSETLIST.DataBind() End Sub Private Sub Inv_itassetcheck_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender End Sub Protected Sub save_Click(sender As Object, e As EventArgs) Handles save.Click Dim sql As New StringBuilder sql.AppendLine("UPDATE UserModules.[User].[IT_ASSET_INVENTORY] SET ") sql.AppendLine("result = @RESULT ") sql.AppendLine(", REMARK = @REMARK") sql.AppendLine(", PHOTO = @PHOTO") sql.AppendLine(", inventory_date = '" & Date.Today.ToString("yyyy-MM-dd") & "'") sql.AppendLine(", PIC_GEN = @GEN") sql.AppendLine(", pic_singleid = @SINGLEID") sql.AppendLine(" WHERE asset_id = @ID") Dim COM As New SqlCommand COM.CommandText = sql.ToString With COM.Parameters .AddWithValue("RESULT", checkresult.Items(checkresult.SelectedIndex).Value) .AddWithValue("REMARK", remark.Text) If IsNothing(Session("UploadedFile")) Then .AddWithValue("PHOTO", "") Else .AddWithValue("PHOTO", Session("UploadedFile")) Dim f() As Byte Dim fs As FileStream Dim reader As BinaryReader fs = New FileStream(Server.MapPath("") & "\" & Session("UploadedFile"), FileMode.Open, FileAccess.Read) reader = New BinaryReader(fs) f = reader.ReadBytes(fs.Length) reader.Close() fs.Close() SaveFileToDb("IT_Asset_Inventory", rowid.Value, "PHOTO", Session("UploadedFile"), f) End If .AddWithValue("SINGLEID", inspector.Text) .AddWithValue("GEN", "") .AddWithValue("ID", assetid.Text) End With sqlf.NonQuery(COM) binddata() Session("UploadedFile") = Nothing End Sub Protected Sub department_SelectedIndexChanged(sender As Object, e As EventArgs) Handles department.SelectedIndexChanged binddata() End Sub Protected Sub PIC_DataBound(sender As Object, e As EventArgs) Handles PIC.DataBound binddata() End Sub Private Function SaveFileToDb(tablename As String, ByVal parentId As Integer, field As String, filename As String, ByVal file() As Byte) As String 'Saving files to DB Dim sqlf As New sharedClasses.dbFunctions.SqlFunctions Dim com As New SqlCommand com.CommandText = "INSERT INTO UserModulesAttachments.[user].[" & tablename & "] " & "([type], [parentId], [name], [doc]) VALUES " & "(@type, @parentid, @name, @doc)" com.Parameters.Clear() With com.Parameters .AddWithValue("type", field) .AddWithValue("parentId", parentId) .AddWithValue("name", filename) .AddWithValue("doc", file) End With Try Dim res As Integer = sqlf.Insert(com) If res > 0 Then sqlf.NonQuery("UPDATE UserModules.[user].[" & tablename & "] SET [" & field & "]='Y' WHERE id=" & parentId) End If Return res Catch ex As Exception Return -1 End Try End Function End Class