my code stock.com

liposhka

Report script for dataobject alterations
by liposhka

generating datasource or changing it in the code of appframe report

Snippet options

Download: Download snippet as report-script-for-dataobject-alterations.vbs.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

Imports System.Data
Imports Appframe3.Reporting
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraPrinting
Imports Microsoft.VisualBasic
Imports Appframe3.Common.Data
Imports System.StringComparison
Imports DevExpress.XtraCharts

Dim gChartTable As New DataTable
Dim gGridTable As New DataTable

Private Sub GroupHeader1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
    Try    	
	Dim vCurrentReport As afReport = Ctype(xtraReport1, afReport)
    	Dim vFilter As String = String.Format("WBSLevelTitle = '{0}' AND Year = '{1}' AND BLNo = '{2}'", GetCurrentColumnValue("WBSLevelTitle").ToString, GetCurrentColumnValue("Year").ToString, GetCurrentColumnValue("BLNo").ToString)
    
    Dim vView As DataView = New DataView(gChartTable, vFilter, "", DataViewRowState.CurrentRows)
    Dim vDataTable As New DataTable
    vDataTable = vView.ToTable.Copy
    
    FormatChart(vDataTable)

    BindChart(vDataTable)
    vDataTable.Dispose()

    Dim vGridFilter As String = String.Format("WBSLevelTitle = '{0}' AND Year = '{1}' AND BLNo = '{2}'", GetCurrentColumnValue("WBSLevelTitle").ToString, GetCurrentColumnValue("Year").ToString, GetCurrentColumnValue("BLNo").ToString)


    Dim vGridView As DataView = New DataView(gGridTable, vGridFilter, "", DataViewRowState.CurrentRows)    
    Dim vTempTable As New DataTable
    vTempTable = vGridView.ToTable.Copy

    Dim vColumnsList As String = "RowNum,ValueType,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec"
    Dim vGridTable As New DataTable()
    vGridTable = vTempTable.DefaultView.ToTable("GridTable", False, vColumnsList.Split(","))
    
    vTempTable.Dispose()
    vGridView.Dispose()

    BindGrid(vGridTable)
    vGridTable.Dispose()
    Catch ex As Exception
    End Try
End Sub

Private Sub FormatChart(ByVal pDataTable As DataTable)
    Dim vMaxValue As Decimal = 0
    Dim vTempValue As Decimal = 0
    
    If Not IsDBNull(pDataTable.Compute("MAX(ArchivedPerPlanned)", String.Empty)) Then
    	vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(ArchivedPerPlanned)", String.Empty))
    	If vTempValue > vMaxValue Then vMaxValue = vTempValue
    End If
    
    If Not IsDBNull(pDataTable.Compute("MAX(PerForecast)", String.Empty)) Then
    	vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(PerForecast)", String.Empty))
    	If vTempValue > vMaxValue Then vMaxValue = vTempValue
    End If
    
    If Not IsDBNull(pDataTable.Compute("MAX(PerPlanned)", String.Empty)) Then
    	vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(PerPlanned)", String.Empty))    
    	If vTempValue > vMaxValue Then vMaxValue = vTempValue
    End If

    Dim vDiagram As XYDiagram = CType(cChart.Diagram, XYDiagram)
    Dim vSpacing As Decimal = Math.Round(IsEvenMaxValue(vMaxValue) / 4, 0, MidpointRounding.AwayFromZero)
    If vSpacing = 0 Then
	vDiagram.AxisY.GridSpacingAuto = True
	
    Else
	vDiagram.AxisY.GridSpacingAuto = False
	vDiagram.AxisY.GridSpacing = vSpacing
    End If

    If vDiagram.SecondaryAxesY.Count > 0
	vMaxValue = 0
	If Not IsDBNull(pDataTable.Compute("MAX(ArchivedCumPlanned)", String.Empty)) Then
	    vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(ArchivedCumPlanned)", String.Empty))
	    If vTempValue > vMaxValue Then vMaxValue = vTempValue
	End If

	If Not IsDBNull(pDataTable.Compute("MAX(CumForecast)", String.Empty)) Then
	    vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(CumForecast)", String.Empty))
    	    If vTempValue > vMaxValue Then vMaxValue = vTempValue
	End If

	If Not IsDBNull(pDataTable.Compute("MAX(CumPlanned)", String.Empty)) Then
	    vTempValue = ConvertToDecimal(pDataTable.Compute("MAX(CumPlanned)", String.Empty))    
    	    If vTempValue > vMaxValue Then vMaxValue = vTempValue
	End If

	Dim vYSpacing As System.Decimal = Math.Round(IsEvenMaxValue(vMaxValue) / 4, 0, MidpointRounding.AwayFromZero)
	If vYSpacing = 0 Then
 	    vDiagram.SecondaryAxesY.Item(0).GridSpacingAuto = True
	Else
	    vDiagram.SecondaryAxesY.Item(0).GridSpacingAuto = False
            vDiagram.SecondaryAxesY.Item(0).GridSpacing = Math.Round(IsEvenMaxValue(vMaxValue) / 4, 0, MidpointRounding.AwayFromZero)
	End If
    End If
End Sub

Private Function IsEvenMaxValue(ByVal pMaxValue As Decimal) As Decimal
    If (pMaxValue Mod 2 = 0) = False Then pMaxValue += 1
    Return pMaxValue
End Function

Private Function ConvertToDecimal(ByVal pValue As String) As Decimal
    Return Convert.ToDecimal(pValue)
End Function

Private Sub BindGrid(ByVal pDataTable As DataTable)    
    Dim vGrid As New xrTable
    cPanel.Controls.Clear()	
    
    vGrid.Borders = DirectCast((((BorderSide.Left Or BorderSide.Top) Or BorderSide.Right) Or BorderSide.Bottom), BorderSide)
    vGrid.BeginInit()	
    vGrid.Width = 1050
    For Each vDataRow As DataRow in pDataTable.Rows
    	Dim vRow As New xrTableRow
    	vRow.Height = 46
	vGrid.Rows.Add(vRow)
	For Each vDataColumn As DataColumn in vDataRow.Table.Columns
	    If String.Equals(vDataColumn.Caption, "RowNum", CurrentCultureIgnoreCase) Then
		Dim vSignCell As New GridTableCell("", 46, False)

		Dim vLine As New XRLine
		vLine.BorderColor = System.Drawing.Color.Black
            	vLine.BorderWidth = 1	
            	vLine.StylePriority.UseBackColor = false
            	vLine.StylePriority.UseBorderColor = false
            	vLine.StylePriority.UseBorders = false
            	vLine.StylePriority.UseBorderWidth = false
            	vLine.StylePriority.UseFont = false
            	vLine.StylePriority.UseForeColor = false
            	vLine.StylePriority.UsePadding = false
            	vLine.StylePriority.UseTextAlignment = false	
		
		Select Case vDataRow(vDataColumn.Caption).ToString
		    Case "Row_1"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 6.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 8.5F)
			vLine.BackColor = Color.PaleGreen
			vLine.ForeColor = Color.PaleGreen
			vSignCell.Controls.Add(vLine)
		    Case "Row_2"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 6.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 8.5F)
			vLine.BackColor = Color.DarkOrange
			vLine.ForeColor = Color.DarkOrange
			vSignCell.Controls.Add(vLine)
		    Case "Row_3"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 6.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 8.5F)
			vLine.BackColor = Color.Gold
			vLine.ForeColor = Color.Gold
			vSignCell.Controls.Add(vLine)
		    Case "Row_4"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 8.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 4F)
			vLine.BackColor = Color.Blue
			vLine.ForeColor = Color.Blue
			vSignCell.Controls.Add(vLine)
		    Case "Row_5"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 8.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 4F)
			vLine.BackColor = Color.ForestGreen
			vLine.ForeColor = Color.ForestGreen
			vSignCell.Controls.Add(vLine)
		    Case "Row_6"
			vLine.LocationFloat = new DevExpress.Utils.PointFloat(8F, 8.70834F)
			vLine.SizeF = new System.Drawing.SizeF(15F, 4F)
			vLine.BackColor = Color.Red	
			vLine.ForeColor = Color.Red	
			vSignCell.Controls.Add(vLine)
		End Select
		
		vRow.Cells.Add(vSignCell)
	    ElseIf String.Equals(vDataColumn.Caption, "ValueType", CurrentCultureIgnoreCase) Then	
		Dim vTitleCell As New GridTableCell(vDataRow(vDataColumn.Caption).ToString, 300, False)
		vTitleCell.TextAlignment = TextAlignment.TopCenter	
	    	vRow.Cells.Add(vTitleCell)
	    Else
		Dim vCell As New GridTableCell(vDataRow(vDataColumn.Caption).ToString, 155, True)
		vCell.TextAlignment = TextAlignment.TopCenter	
	    	vRow.Cells.Add(vCell)
	    End If 
	Next
    Next
    vGrid.EndInit()
    cPanel.Controls.Add(vGrid)
End Sub

Private Sub BindChart(ByVal pDataTable As DataTable)
    cChart.Series("ArchivedPerPlanned").DataSource = pDataTable
    cChart.Series("ArchivedPerPlanned").ArgumentDataMember = "CutOff"
    cChart.Series("ArchivedPerPlanned").ValueDataMembers.AddRange(New String() {"ArchivedPerPlanned"})

    cChart.Series("PerForecast").DataSource = pDataTable
    cChart.Series("PerForecast").ArgumentDataMember = "CutOff"
    cChart.Series("PerForecast").ValueDataMembers.AddRange(New String() {"PerForecast"})

    cChart.Series("PerPlanned").DataSource = pDataTable
    cChart.Series("PerPlanned").ArgumentDataMember = "CutOff"
    cChart.Series("PerPlanned").ValueDataMembers.AddRange(New String() {"PerPlanned"})

    cChart.Series("ArchivedCumPlanned").DataSource = pDataTable
    cChart.Series("ArchivedCumPlanned").ArgumentDataMember = "CutOff"
    cChart.Series("ArchivedCumPlanned").ValueDataMembers.AddRange(New String() {"ArchivedCumPlanned"})

    cChart.Series("CumForecast").DataSource = pDataTable
    cChart.Series("CumForecast").ArgumentDataMember = "CutOff"
    cChart.Series("CumForecast").ValueDataMembers.AddRange(New String() {"CumForecast"})

    cChart.Series("CumPlanned").DataSource = pDataTable
    cChart.Series("CumPlanned").ArgumentDataMember = "CutOff"
    cChart.Series("CumPlanned").ValueDataMembers.AddRange(New String() {"CumPlanned"})

End Sub


Private Sub pageHeaderBand1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
    Try
  	If GetCurrentColumnValue("Year") IsNot System.DBNull.Value Then
	    'cReportTitleCustom.Text = "Cost Curve, Yearly - " & GetCurrentColumnValue("Year")
	    cYear.Text = GetCurrentColumnValue("Year")
	    cBLNo.Text = GetCurrentColumnValue("BLNo")
  	End If
    Catch ex As Exception
    End Try
End Sub

Public Class GridTableCell
    Inherits xrTableCell

    Sub New(Byval pValue As String, ByVal pWidth As Decimal, ByVal pIsValue As Boolean)
	If pIsValue = True AndAlso Not String.IsNullOrEmpty(pValue) Then
	    Text = Convert.ToDouble(pValue).ToString("n0")
	Else 
	    Text = pValue	
	End If
	
	Font = New System.Drawing.Font("Arial", 7)
	Width = pWidth
	Padding = New PaddingInfo(3, 3, 3, 3, 100)
	TextAlignment = TextAlignment.TopRight
    End Sub
End Class

Private Sub xtraReport1_BeforePrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
    Try
	Dim vAfProcedureCall As New afProcedureCall
        vAfProcedureCall.ProcedureName = "astp_PC_ProjBaseline_CostCurveByYearPeriodGetReportTable_Goliat"
	vAfProcedureCall.Parameters.Add("BLNo", xtraReport1.Parameters("cBLNoParam").Value, SqlDbType.NVarChar)
        vAfProcedureCall.Parameters.Add("WBSLevel", xtraReport1.Parameters("cWBSLevelParam").Value, SqlDbType.Int)
        vAfProcedureCall.Timeout = 20000
        vAfProcedureCall.UseTransaction = False
        gGridTable = afAccessLayer.ExecProcedure(vAfProcedureCall).Tables(0)
	
	Dim vAfProcedureCall2 As New afProcedureCall
        vAfProcedureCall2.ProcedureName = "astp_PC_ProjBaseline_CostCurveByYearPeriodChart_Goliat"
	vAfProcedureCall2.Parameters.Add("BLNo", xtraReport1.Parameters("cBLNoParam").Value, SqlDbType.NVarChar)
        vAfProcedureCall2.Parameters.Add("WBSLevel", xtraReport1.Parameters("cWBSLevelParam").Value, SqlDbType.Int)
        vAfProcedureCall2.Timeout = 10000
        vAfProcedureCall2.UseTransaction = False
        gChartTable = afAccessLayer.ExecProcedure(vAfProcedureCall2).Tables(0)

        Dim vCurrentReport As afReport = Ctype(xtraReport1, afReport)
	Dim vView As DataView = New DataView(gChartTable, vCurrentReport.Filter.ToString, "", DataViewRowState.CurrentRows)
		
	vCurrentReport.DataSource = vView.ToTable.Copy
	If xtraReport1.Parameters("cWBSLevelParam").Value = 1 Then
	    label2.Visible = False
	Else
	    label2.Visible = True
	End If
        vView.Dispose()
    Catch ex As Exception
    End Try    
End Sub

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.