/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/handlers/graphdata.ashx
139 строк
5 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
<%@ WebHandler Language="VB" Class="GraphData" %> Imports System Imports System.Web Imports OpenFlashChartLib Imports OpenFlashChartLib.Charts Imports sharedClasses.dbFunctions Public Class GraphData : Implements IHttpHandler Private Property tableName As String Private Property weeks As String Private Property kpiColumn As String Private Property kpiName As String Private Property targetColumn As String Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest Dim params As String = context.Request.QueryString("params") Try Dim paramsList() As String = params.Split("|") tableName = paramsList(0) weeks = paramsList(1) kpiColumn = paramsList(2) kpiName = paramsList(3) targetColumn = paramsList(4) Dim Chart As New Graph Chart.Title = New Title(kpiName) Dim LineHollow As New OpenFlashChartLib.Charts.LineHollow LineHollow.Colour = "#00FF00" LineHollow.Text = "Result" LineHollow.Fontsize = 12 LineHollow.Width = 2 LineHollow.DotSize = 4 Dim Line As New OpenFlashChartLib.Charts.Line Line.Colour = "#0000FF" Line.Width = 2 Line.Text = "Target" Line.Fontsize = 12 Dim ds As Data.DataTable = BuildGraphData() Dim maxY As Integer = Integer.MinValue Dim minY As Integer = Integer.MaxValue If Not IsNothing(ds) Then Dim dt As Data.DataTable = ds For Each dr As Data.DataRow In dt.Rows Chart.X_Axis.Labels.Labels.Add(dr("weeks").ToString.ToLower.Replace("_result", "").Replace("_", "")) Try Dim v As Single = Convert.ToSingle(dr("vals").ToString.Replace(" ", "")) + 0.001 '.Replace(".", ",")) Dim vVal As ILabelValue = LineHollow.NewValue(v.ToString, v) LineHollow.Values.Add(vVal) If minY > v Then minY = v End If If maxY < v Then maxY = v End If If targetColumn <> "" Then Dim t As Single = Convert.ToSingle(dr(targetColumn).ToString) If v > t Then LineHollow.Colour = "#FF0000" End If Dim tVal As ILabelValue = Line.NewValue(t.ToString, t) Line.Values.Add(tVal) If minY > t Then minY = t End If If maxY < t Then maxY = t End If End If Catch ex As Exception End Try Next End If Chart.Y_Axis.Max = maxY + 1 Chart.Y_Axis.Min = minY - 1 Dim steps As Integer = Math.Truncate((maxY - minY) / 10) If steps < 1 Then steps = 1 Chart.Y_Axis.Steps = steps Chart.AddElement(LineHollow) If targetColumn <> "" Then Chart.AddElement(Line) End If context.Response.CacheControl = "no-cache" context.Response.ContentType = "text/plain" context.Response.Write(Chart.ToString) Catch ex As Exception context.Response.CacheControl = "no-cache" context.Response.ContentType = "text/plain" context.Response.Write("Error") End Try End Sub Private Function BuildGraphData() As Data.DataTable Dim sql As New StringBuilder sql.Append("select * from ") sql.Append("( ") sql.Append("select " & kpiColumn & ", ") If targetColumn <> "" Then sql.Append(targetColumn & ", ") End If sql.Append(weeks & " ") sql.Append("from usermodules.[user]." & tableName & ") p ") sql.Append("UNPIVOT ") sql.Append("( ") sql.Append("vals for weeks in (" & weeks & ") ") sql.Append(") as unpvt ") sql.Append("where " & kpiColumn & " = '" & kpiName & "'") Return (New SqlFunctions).GetData(sql.ToString) End Function Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable Get Return False End Get End Property End Class