/
ivan
/
ModMas
Обзор
Документация
Войти
/
ivan
/
ModMas
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
ModuleMaster/usercontrols/graphaspnet.ascx.vb
221 строка
8 KB
i.krivokon
Initial commit
13 мар 2026, 13:49
13 мар 2026, 13:49
00d9fb6
Код
Авторство
О чём код?
Imports System.Web.UI.DataVisualization.Charting Imports sharedClasses.dbFunctions Partial Class UserControls_graphaspnet Inherits System.Web.UI.UserControl Public targetColumn As String Public kpiColumn As String Public weeks As String Public targets As String Public _tableName As String Public _tableId As Integer Public Property tableName As String Set(value As String) _tableName = value _tableId = (New SqlFunctions).GetScalar("SELECT ID from UserModules.dbo.ModuleTables WHERE DBTABLENAME = '" & value.Replace("[", "").Replace("]", "") & "'") End Set Get Return _tableName End Get End Property Public kpiName As String Public highlight As Boolean = False Public querystringparams As String = "" Public Property Palette As ChartColorPalette Set(value As ChartColorPalette) Chart1.Palette = value End Set Get Return Chart1.Palette End Get End Property Public Property MapAreaAttributes As String Get Return Chart1.MapAreas(0).MapAreaAttributes End Get Set(value As String) Chart1.MapAreas(0).MapAreaAttributes = value End Set End Property Public Property width As Integer Set(value As Integer) Chart1.Width = Unit.Pixel(value) End Set Get Return Chart1.Width.Value End Get End Property Public Property height As Integer Set(value As Integer) Chart1.Height = Unit.Pixel(value) End Set Get Return Chart1.Height.Value End Get End Property Public Property MapAreaUrl As String Get Return Chart1.MapAreas(0).Url End Get Set(value As String) Chart1.MapAreas(0).Url = value End Set End Property Public ReadOnly Property Title As Title Get Return Chart1.Titles(0) End Get End Property Public ReadOnly Property Series As SeriesCollection Get Return Chart1.Series End Get End Property Private Function BuildGraphData() As Data.DataTable Dim sql As New StringBuilder If targets <> "" Then sql.Append(" SELECT * FROM ( ") End If sql.Append("select row_number () OVER (ORDER BY tf.position) AS rn, unpvt.*, tf.position from ") sql.Append("( select [" & kpiColumn & "], ") If targetColumn <> "" And Not targetColumn.Contains("%") And targets = "" Then sql.Append("[" & targetColumn & "], ") End If sql.Append(weeks & " ") sql.Append("from usermodules.[user]." & tableName & ") p ") sql.Append("UNPIVOT ") sql.Append("( vals for weeks in (" & weeks & ") ") sql.Append(") as unpvt left join UserModules.dbo.TableFields tf on unpvt.weeks = tf.DbFieldName ") sql.Append("where tf.tableid = " & _tableId & " and " & kpiColumn & " = '" & kpiName & "'") If targets <> "" Then sql.Append(") T1 LEFT JOIN (") sql.Append("select row_number () OVER (ORDER BY tf.position) AS rn, unpvt.*, tf.position from ") sql.Append("( select [" & kpiColumn & "], ") sql.Append(targets & " ") sql.Append("from usermodules.[user]." & tableName & ") p ") sql.Append("UNPIVOT ") sql.Append("( vals_t for targets in (" & targets & ") ") sql.Append(") as unpvt left join UserModules.dbo.TableFields tf on unpvt.targets = tf.DbFieldName ") sql.Append("where tf.tableid = " & _tableId & " and " & kpiColumn & " = '" & kpiName & "'") sql.Append(")T2 on t1.rn = t2.rn") End If Return (New SqlFunctions).GetData(sql.ToString) End Function Protected Sub UserControls_graphaspnet_DataBinding(sender As Object, e As EventArgs) Handles Me.DataBinding Try Dim ds As Data.DataTable = BuildGraphData() Dim maxY As Decimal = Decimal.MinValue Dim minY As Decimal = Decimal.MaxValue Dim prevTarget As String = "" If Not IsNothing(ds) Then For Each dr As Data.DataRow In ds.Rows dr("weeks") = dr("weeks").ToString.Replace("_RESULT", "").Replace("_", " ").Trim If dr("vals").ToString.Trim = "" Then dr("vals") = 0 dr("vals") = dr("vals").ToString.Replace(":", ".").Replace(" ", "") Dim curvaluemax As String = "0" Dim curvaluemin As String = "0" If targets <> "" Then dr("targets") = dr("weeks") If prevTarget = "" Then If dr("vals_t").ToString.Trim = "" Then dr("vals_t") = 0 prevTarget = dr("vals_t") Else If dr("vals_t").ToString.Trim = "" Then dr("vals_t") = prevTarget End If End If dr("vals_t") = dr("vals_t").ToString.Replace(":", ".").Replace(" ", "") curvaluemax = Math.Max(Convert.ToDecimal(dr("vals")), Convert.ToDecimal(dr("vals_t"))) curvaluemin = Math.Min(Convert.ToDecimal(dr("vals")), Convert.ToDecimal(dr("vals_t"))) Else curvaluemax = dr("vals") curvaluemin = dr("vals") End If If maxY < curvaluemax Then maxY = curvaluemax End If If minY > curvaluemin Then minY = curvaluemin End If If targetColumn <> "" And Not targetColumn.Contains("%") And targets = "" Then If maxY < dr(targetColumn).ToString.Replace(" ", "") Then maxY = dr(targetColumn).ToString.Replace(" ", "") End If If minY > dr(targetColumn).ToString.Replace(" ", "") Then minY = dr(targetColumn).ToString.Replace(" ", "") End If End If Next Chart1.Titles("Title1").Text = kpiName 'Chart1.Titles("Title1").Font = New System.Drawing.Font("Tahoma", 10, Drawing.FontStyle.Bold) Chart1.Titles("Title1").ForeColor = Drawing.Color.Navy Chart1.DataSource = ds Chart1.Series(1).XValueMember = "weeks" Chart1.Series(1).YValueMembers = "vals" If targetColumn <> "" And Not targetColumn.Contains("%") And targets = "" Then Chart1.Series(0).XValueMember = "weeks" Chart1.Series(0).YValueMembers = targetColumn ElseIf targets <> "" Then Chart1.Series(0).XValueMember = "targets" Chart1.Series(0).YValueMembers = "vals_t" End If Try Chart1.DataBind() Dim gap As Decimal = maxY - minY Chart1.ChartAreas(0).AxisY.Maximum = maxY + gap * 0.1 Chart1.ChartAreas(0).AxisY.Minimum = IIf(minY - gap * 0.1 < 0, 0, minY - gap * 0.1) If Chart1.ChartAreas(0).AxisY.Maximum = Chart1.ChartAreas(0).AxisY.Minimum Then Chart1.ChartAreas(0).AxisY.Maximum += 10 End If If highlight Then Chart1.BackColor = Drawing.Color.Red End If Catch ex As Exception End Try End If Chart1.MapAreas(0).Url = Request.Url.GetLeftPart(UriPartial.Authority) & _ Request.ApplicationPath & "/viewSingleGraph.aspx?params=" & Server.UrlEncode(targetColumn & "|" & kpiColumn & "|" & weeks & "|" & tableName & "|" & kpiName & "|" & highlight & "|" & targets & querystringparams) 'Dim gzip As IO.Compression.GZipStream = New IO.Compression.GZipStream(memstream, IO.Compression.CompressionMode.Compress) 'Dim sw As New IO.StreamWriter(gzip) Catch ex As Exception End Try End Sub End Class