Incrementing Serial Number in PDF Creation - ASP.NET - asp.net

I am generating a PDF using ITextSharp in ASP.NET. I need to display a table, with some data and Serial No auto incremented. I tried the following (using loop - increment) but it doesn't seem to work.
Dim dsGetStudentFeeDetails = dbl.usp_GetFeeReceiptDetailsForStudent(sid).AsQueryable
For Each f1 In dsGetStudentFeeDetails
Dim i As Integer = 1
stuName = New PdfPCell(FormatPhrase(i))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
stuName = New PdfPCell(FormatPhrase(f1.FeeAmountPaidDate))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
i = i + 1
Next
When I run through this during execution, I noticed that the i = i + 1 doesn't get incremented. Why so?

you have to declare and set default value Above for loop use below code
Dim dsGetStudentFeeDetails = dbl.usp_GetFeeReceiptDetailsForStudent(sid).AsQueryable
Dim i As Integer = 1
For Each f1 In dsGetStudentFeeDetails
stuName = New PdfPCell(FormatPhrase(i))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
stuName = New PdfPCell(FormatPhrase(f1.FeeAmountPaidDate))
'stuName.Colspan = 4
'stuName.Border = 0
stuName.NoWrap = True
stuName.HorizontalAlignment = Element.ALIGN_LEFT
pdftable4.AddCell(stuName)
i = i + 1
Next

Related

ASP.NET Stackedbar chart markers

I am trying to add markers on my stacked bar chart programmatically and they do not seem to show up. In reality, I need to show a marker on the average of the datapoint but right now, I cannot even show a simple marker on the chart.
What am I doing wrong ?
Code:
Dim chart As New Chart
chart.ID = DtDistinct.Rows(I)("CourseSisID")
Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)
chart.Series.Clear()
chart.DataBindCrossTable(DtRecords.DefaultView, "Outcomescore", "ShortName", "RecordsPerGroup", "")
chart.ChartAreas(0).AxisY.Interval = 1
chart.ChartAreas(0).AxisY.Enabled = AxisEnabled.False
chart.Palette = ChartColorPalette.None
chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}
chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False
For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedBar
cs.Points().FindMaxByValue.MarkerColor = Color.AliceBlue
cs.Points().FindMaxByValue.MarkerSize = 13
cs.Points().FindMaxByValue.MarkerStyle = MarkerStyle.Diamond
Next
pnlcharts.Controls.Add(chart)
Here is an image of what I am trying to do. I know that the above code will not give me the below image but I was trying to find a workaround with the above code, before I realized that markers cannot appear on bar charts.
I would like to see that striped line on the bar chart. The striped line should appear on the calculated average of the points.
So, an another way I could do was to use annotations since markers are not supported by stackedbar charts. I wrote the following code to add an annotation line, but it still does not give me the output I need only because I do not know how to do it for each Y value on the chart.
Here is my code:
Dim chart As New Chart
chart.ID = DtDistinct.Rows(I)("CourseSisID")
Dim chartareas As New ChartArea
chart.ChartAreas.Add(chartareas)
chart.DataBindCrossTable(DtRecords.DefaultView, "OutcomeScore", "ShortName", "RecordsPerGroup", "Label=RecordsPerGroup")
chart.Palette = ChartColorPalette.None
chart.PaletteCustomColors = New Color() {ColorTranslator.FromHtml("#DF5B59"), ColorTranslator.FromHtml("#E0D773 "), ColorTranslator.FromHtml("#8AAC53"), ColorTranslator.FromHtml("#6A843F")}
chart.ChartAreas(0).AxisX.MajorGrid.Enabled = False
chart.ChartAreas(0).AxisY.MajorGrid.Enabled = False
Dim charttitle As New Title
charttitle.Text = DtDistinct.Rows(I)("CourseSisID")
chart.Titles.Add(charttitle)
For Each cs As Series In chart.Series
cs.ChartType = SeriesChartType.StackedBar
Next
Dim ann1 As New VerticalLineAnnotation()
ann1.AxisX = chart.ChartAreas(0).AxisX
ann1.AxisY = chart.ChartAreas(0).AxisY
ann1.IsSizeAlwaysRelative = False
ann1.X = chart.DataManipulator.Statistics.Mean(chart.Series(0).Name)
ann1.IsInfinitive = True
ann1.ClipToChartArea = chart.ChartAreas(0).Name
ann1.LineColor = Color.Coral
ann1.LineWidth = 3
ann1.AnchorX = 1
ann1.AnchorY = 5
chart.Annotations.Add(ann1)
ann1.LineDashStyle = ChartDashStyle.Dash
pnlcharts.Controls.Add(chart)
Here is what I get with the above code:
Here is what I need : Notice how the strip line is at a different value for each bar.
Dim annotation2 As New LineAnnotation()
annotation2.IsSizeAlwaysRelative = False
annotation2.AxisX = chart.ChartAreas(0).AxisX
annotation2.AxisY = chart.ChartAreas(0).AxisY
annotation2.Height = 1
annotation2.Width = 0
annotation2.LineWidth = 1.5
annotation2.StartCap = LineAnchorCapStyle.None
annotation2.EndCap = LineAnchorCapStyle.None
annotation2.AnchorX = AvgVar
annotation2.ToolTip = "Average=" & AvgVar
Select Case row
Case 1
annotation2.AnchorY = 4.5
Case 2
annotation2.AnchorY = 3.5
Case 3
annotation2.AnchorY = 2.5
Case 4
annotation2.AnchorY = 1.5
Case 5
annotation2.AnchorY = 0.5
End Select
' <- your point
annotation2.LineColor = Color.Gray
annotation2.LineDashStyle = ChartDashStyle.Dash
' <- your color
chart.Annotations.Add(annotation2)

Devexpress Xtragrid TileView

I'm using Devexpress Xtragrid TileView module.
Basically I want my code works like this :
user input member ID on the upper left textbox and press load.
If they exists, then a Tile will be appeared.
A tile should contain : Name, Status, member ID and a photo.
If user press load again (either same ID or another ID) a Tile will be added also, and so on. Unless they press Clear & Load, It should be only 1 latest tile left.
So, I'm able to produce up to Step 3.
But I couldn't be able to load the picture.
The picture itself, It's not a byte array. It's a Image path.
e.q : D:/test/1.jpg
So, how do I load the picture?
Protected Overridable Sub InitData()
Try
Dim homesTable = ds.Tables(0)
homesTable.Columns.Add("ImageCol")
For Each row_Renamed As DataRow In homesTable.Rows
Dim img As Image = Image.FromFile(row_Renamed("memberPhoto")) 'I tried this, but didn't work
row_Renamed("ImageCol") = img
Next row_Renamed
GridControl1.DataSource = homesTable
Catch
End Try
End Sub
Private Sub setupTile()
'For i = 0 To j - 1
Try
TileView1.BeginUpdate()
'TileView1.DataSource = ds.Tables(0)
TileView1.OptionsTiles.RowCount = 3
TileView1.OptionsTiles.Padding = New Padding(20)
TileView1.OptionsTiles.ItemPadding = New Padding(10)
TileView1.OptionsTiles.IndentBetweenItems = 20
TileView1.OptionsTiles.ItemSize = New Size(320, 170)
TileView1.Appearance.ItemNormal.ForeColor = Color.White
TileView1.Appearance.ItemNormal.BorderColor = Color.Transparent
'Setup tiles template
Dim leftPanel As New TileViewItemElement()
Dim splitLine As New TileViewItemElement()
Dim nameCaption As New TileViewItemElement()
Dim nameValue As New TileViewItemElement()
Dim statusCaption As New TileViewItemElement()
Dim statusValue As New TileViewItemElement()
Dim RGPCaption As New TileViewItemElement()
Dim RGPvalue As New TileViewItemElement()
Dim imageTile As New TileViewItemElement()
TileView1.TileTemplate.Add(leftPanel)
TileView1.TileTemplate.Add(splitLine)
TileView1.TileTemplate.Add(nameCaption)
TileView1.TileTemplate.Add(nameValue)
TileView1.TileTemplate.Add(statusCaption)
TileView1.TileTemplate.Add(statusValue)
TileView1.TileTemplate.Add(RGPCaption)
TileView1.TileTemplate.Add(RGPvalue)
TileView1.TileTemplate.Add(imageTile)
'
'nameValue.Text = ""
'statusValue.Text = ""
'RGPvalue.Text = ""
'imageTile.Image = Nothing
'
leftPanel.StretchVertical = True
leftPanel.Width = 190
leftPanel.TextLocation = New Point(-10, 0)
leftPanel.Appearance.Normal.BackColor = Color.FromArgb(58, 166, 101)
'
splitLine.StretchVertical = True
splitLine.Width = 3
splitLine.TextAlignment = TileItemContentAlignment.Manual
splitLine.TextLocation = New Point(190, 0)
splitLine.Appearance.Normal.BackColor = Color.White
'
nameCaption.Text = "Name"
nameCaption.TextAlignment = TileItemContentAlignment.TopLeft
nameCaption.Appearance.Normal.FontSizeDelta = -1
'
nameValue.Column = TileView1.Columns("preferredName")
nameValue.AnchorElement = nameCaption
nameValue.AnchorIndent = 2
nameValue.MaxWidth = 200
nameValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'nameValue.Text = ds.Tables(0).Rows(i)("preferredName").ToString
'
statusCaption.Text = "Status"
statusCaption.AnchorElement = nameValue
statusCaption.AnchorIndent = 14
statusCaption.Appearance.Normal.FontSizeDelta = -1
'
statusValue.Column = TileView1.Columns("memberStatus")
statusValue.AnchorElement = statusCaption
statusValue.AnchorIndent = 2
statusValue.Appearance.Normal.FontStyleDelta = FontStyle.Bold
'statusValue.Text = ds.Tables(0).Rows(i)("memberStatus").ToString
'
RGPCaption.Text = "RGP"
RGPCaption.AnchorElement = nameValue
RGPCaption.AnchorIndent = 65
'RGPCaption.TextLocation
'RGPCaption.Appearance.Normal.FontSizeDelta = -1
RGPCaption.Appearance.Normal.Font = New Font("Segoe UI Semibold", 12.0F, System.Drawing.FontStyle.Regular)
'
RGPvalue.Column = TileView1.Columns("code")
RGPvalue.AnchorElement = RGPCaption
RGPvalue.AnchorIndent = 1
RGPvalue.TextAlignment = TileItemContentAlignment.BottomLeft
RGPvalue.Appearance.Normal.Font = New Font("Segoe UI Semilight", 25.75F, System.Drawing.FontStyle.Regular)
'RGPvalue.Text = ds.Tables(0).Rows(i)("code").ToString
'
imageTile.Column = TileView1.Columns("ImageCol")
imageTile.ImageSize = New Size(120, 170)
imageTile.ImageAlignment = TileItemContentAlignment.MiddleRight
imageTile.ImageScaleMode = TileItemImageScaleMode.Stretch
imageTile.ImageLocation = New Point(12, 0)
Catch ex As Exception
XtraMessageBox.Show(ex.Message)
Finally
TileView1.EndUpdate()
End Try
'Next
End Sub
Private Sub loadBtn_Click(sender As Object, e As EventArgs) Handles loadBtn.Click
initData()
setupTile()
End Sub
Maybe it's too late but in my case only need to read file from disk and assign to a byte() column.
First of all, table column should be byte array so replace:
homesTable.Columns.Add("ImageCol")
for:
homesTable.Columns.Add(New DataColumn("ImageCol", GetType(Byte)))
Then I'd try to replace:
row_Renamed("ImageCol") = img
for:
row_Renamed("ImageCol") = IO.File.ReadAllBytes(row_Renamed("memberPhoto"))
That would load disk file to byte array and shown in tile. I'd check if file exists to avoid exceptions.
That's what I do to load image from disk.
Hope it helps.

Generate Xtrareport

I want to generate dynamic table in Xtrareport in a proper format.
So I am using this code
dynamicTable.Borders = DevExpress.XtraPrinting.BorderSide.All
dynamicTable.BorderWidth = 1
But it is not giving proper output as I desire..
It is generating table by separating each cell row by row, so it doesn't give a table appearance.!
[1]: http://i.stack.imgur.com/iaKl9.png
The complete code:
Dim label As New XRLabel()
label.Width = 500
label.Font = New System.Drawing.Font("Verdana", 10.0F, FontStyle.Bold)
PageHeader1.Controls.Add(label)
If rowsCount > 0 Then
Dim padding As Integer = 5
Dim tableWidth As Integer = Me.PageWidth - Me.Margins.Left - Me.Margins.Right - padding * 2
Dim dynamicTable As XRTable = XRTable.CreateTable(New Rectangle(padding, 1, tableWidth, 40), 1, 0) ' table column count
dynamicTable.Width = tableWidth
dynamicTable.Rows.FirstRow.Width = tableWidth
dynamicTable.Borders = DevExpress.XtraPrinting.BorderSide.All
'dynamicTable.Borders = DirectCast(((DevExpress.XtraPrinting.BorderSide.Left Or DevExpress.XtraPrinting.BorderSide.Top) Or DevExpress.XtraPrinting.BorderSide.Right) Or DevExpress.XtraPrinting.BorderSide.Bottom, DevExpress.XtraPrinting.BorderSide)
dynamicTable.BorderWidth = 1
Dim i As Integer = 0
dynamicTable.BeginInit()
For Each dc As DataColumn In ds.Tables(0).Columns
Dim cell As New XRTableCell()
Dim binding As New XRBinding("Text", ds, ds.Tables(0).Columns(i).ColumnName)
cell.DataBindings.Add(binding)
cell.CanGrow = False
cell.CanShrink = True
cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter
'cell.WidthF = 10
'cell.Width = 20
cell.Text = dc.ColumnName
dynamicTable.Rows.FirstRow.Cells.Add(cell)
i += 1
Next dc
dynamicTable.Font = New System.Drawing.Font("Verdana", 8.0F)
dynamicTable.AdjustSize()
dynamicTable.EndInit()
Detail.Controls.Add(dynamicTable)
'label.Text = String.Format("Data table: {0}", Test)
Me.DataSource = ds
Me.DataMember = Test

Any ideas how to convert array into FOR Loop?

The code below works great as is:
dashboard1.Text = charArray(0)
dashboard2.Text = charArray(1)
dashboard3.Text = charArray(2)
dashboard4.Text = charArray(3)
dashboard5.Text = charArray(4)
dashboard6.Text = charArray(5)
dashboard7.Text = ""
dashboard8.Text = ""
dashboard9.Text = ""
dashboard10.Text = ""
If dashboardl >= 7 Then
dashboard7.Text = charArray(6)
End If
If dashboardl >= 8 Then
dashboard8.Text = charArray(7)
End If
If dashboardl >= 9 Then
dashboard9.Text = charArray(8)
End If
If dashboardl >= 10 Then
dashboard10.Text = charArray(9)
End If
However, I would like to convert them to FOR Loop as in example below but I am getting errors.
For i = 1 To (dashboardl)
("dashboard" & CStr(i)) = charArray(i - 1)
Next i
Your assistance is greatly appreciated.
You can try this...
For i = 1 To dashboardl
Dim txtBox As TextBox = FindControl("dashboard" & i)
txtBox.Text = charArray(i - 1)
Next i
Ha, I missed the point. Still not on a real computer, but try this...
For i = 1 To dashboardl
Me.Controls("dashboard" & CStr(i)).Text = charArray(i - 1)
Next i

counting shopping cart 2d Array items in asp-classic

I have a shopping cart that using 2d array Cart(3, 20) to store user shop in a session.
It storing data like this:
Cart(0,0) = Product_ID
Cart(1,0) = Product_Name
Cart(2,0) = Product_Price
Cart(3,0) = Product_Qty
I want to count Items based on product_id ( we have not repetitive product_id)
I found a function here:
Function UniqueEntryCount(SourceRange)
Dim MyDataset
Dim dic
Set dic=Server.CreateObject("Scripting.Dictionary")
MyDataset = SourceRange
For i = 1 To UBound(MyDataset, 2)
if not dic.Exists(MyDataset(0, i)) then dic.Add MyDataset(0, i), ""
Next
UniqueEntryCount = dic.Count
Set dic = Nothing
End Function
But one problem is remain, When my Cart is empty, it show me 1
How can solved it?
An unitialized fixed array (Dim a(i, j)) contains i * j empty elements; your
if not dic.Exists(MyDataset(0, i)) then dic.Add MyDataset(0, i), ""
will pick up and count the first empty item. Demonstrated in code:
Dim afCart(3, 4)
Dim dicPID : Set dicPID = countPID00(afCart)
Dim aKeys : aKeys = dicPID.Keys
Dim vKey : vKey = aKeys(0)
WScript.Echo "A", dicPID.Count, TypeName(vKey)
Set dicPID = countPID(afCart)
WScript.Echo "B", dicPID.Count
afCart(0, 0) = "ignored"
afCart(0, 1) = 4711
afCart(0, 2) = 4712
afCart(0, 3) = 4711
' afCart(0, 4) = "not initialized/Empty"
Set dicPID = countPID(afCart)
WScript.Echo "C"
For Each vKey In dicPID.Keys
WScript.Echo "", vKey, "=", dicPID(vKey)
Next
Function countPID00(afCart)
Dim dicRVal : Set dicRVal = CreateObject("Scripting.Dictionary")
Dim MyDataset : MyDataset = afCart ' waste of ressources
Dim iRow
For iRow = 1 To UBound(MyDataset, 2)
If Not dicRVal.Exists(MyDataset(0, iRow)) Then
dicRVal(MyDataset(0, iRow)) = "" ' loss of info; will pick up Empty item
End If
Next
Set countPID00 = dicRVal
End Function ' countPID00
Function countPID(afCart)
Dim dicRVal : Set dicRVal = CreateObject("Scripting.Dictionary")
Dim iRow
For iRow = 1 To UBound(afCart, 2)
If Not IsEmpty(afCart(0, iRow)) Then
dicRVal(afCart(0, iRow)) = dicRVal(afCart(0, iRow)) + 1
End If
Next
Set countPID = dicRVal
End Function ' countPID
output:
A 1 Empty
B 0
C
4711 = 2
4712 = 1

Resources