Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Data Imports System.IO Imports System.Drawing Imports System.Drawing.Imaging Imports System.Drawing.Drawing2D Imports System.Drawing.Text Imports BVSoftware.BVC.Core Public Class reports_sales_graph Inherits BaseAdminPage #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load BVC2004Store.CheckThisPage(BVSoftware.BVC.Core.Security.RolePermission.LoginToAdmin, BVSoftware.BVC.Core.Security.RolePermission.AccessReportArea) If Not Page.IsPostBack() Then Dim sDateCode As String = "" Dim sMonth As String = "" Dim sYear As String = "" If Request.Params("DateCode") <> Nothing Then sDateCode = Request.Params("DateCode") End If If sDateCode.Length < 6 Then ' Defaults sMonth = Date.Today.Month sYear = Date.Today.Year Else sMonth = sDateCode.Substring(0, 2) sYear = sDateCode.Substring(2, 4) End If ' Setup Graphics Dim bGraph As New Bitmap(550, 215, PixelFormat.Format32bppArgb) Dim g As Graphics = Graphics.FromImage(bGraph) g.Clear(Color.White) ' Draw Border g.DrawLine(Pens.Black, 0, 0, 0, 214) g.DrawLine(Pens.Black, 549, 0, 549, 214) g.DrawLine(Pens.Black, 0, 0, 549, 0) g.DrawLine(Pens.Black, 0, 214, 549, 214) ' Draw PrepWork g.DrawLine(Pens.Black, 45, 10, 45, 180) g.DrawLine(Pens.Black, 45, 180, 525, 180) Dim iC As Integer = 0 For iC = 1 To 9 g.DrawLine(Pens.LightGray, 46, (180 - (iC * 17)), 525, (180 - (iC * 17))) Next g.FillRectangle(Brushes.Red, 45, 200, 10, 10) g.FillRectangle(Brushes.Green, 200, 200, 10, 10) Dim oFont As New Font("Arial", 8) g.DrawString("= Daily Order Count", oFont, Brushes.Black, 60, 197) g.DrawString("= Daily Dollar Total", oFont, Brushes.Black, 215, 197) ' Get Data to Render Try Dim dtInfo As DataTable = OrderServices.OrderHistory.GetMonthlyOrders(sMonth, sYear) ' Delete Summary Row Dim iRows As Integer = dtInfo.Rows.Count() If iRows > 0 Then dtInfo.Rows(iRows - 1).Delete() End If Dim iMax As Integer = 0 Dim iMin As Integer = -1 Dim dMax As Double = 0 Dim dMIn As Double = 0 Dim iCount As Integer = 0 For iCount = 0 To iRows - 2 If dtInfo.Rows(iCount).Item("OrderCount") > iMax Then iMax = dtInfo.Rows(iCount).Item("OrderCount") End If If iMax > 0 Then If iMin = -1 Then iMin = iMax End If End If If dtInfo.Rows(iCount).Item("OrderCount") < dMIn Then dMIn = dtInfo.Rows(iCount).Item("OrderCount") End If If dtInfo.Rows(iCount).Item("OrderTotal") > dMax Then dMax = dtInfo.Rows(iCount).Item("OrderTotal") End If If dMax > 0 Then If dMIn = -1 Then dMIn = dMax End If End If If dtInfo.Rows(iCount).Item("OrderTotal") < dMIn Then dMIn = dtInfo.Rows(iCount).Item("OrderTotal") End If Next 'g.DrawString("Max=" & iMax.ToString, oFont, Brushes.Blue, 5, 15) 'g.DrawString("Min=" & iMin.ToString, oFont, Brushes.Blue, 5, 30) 'g.DrawString("Max=" & dMax.ToString, oFont, Brushes.Blue, 5, 45) 'g.DrawString("Min=" & dMIn.ToString, oFont, Brushes.Blue, 5, 60) If iMax > 0 Then Dim iLasty As Integer = -1 Dim iLastx As Integer = -1 ' Draw Orders Volume For iCount = 0 To iRows - 2 Dim xStart As Integer Dim xLastStart As Integer xStart = 50 + (iCount * 15) g.DrawString((iCount + 1).ToString, oFont, Brushes.Black, xStart, 182) Dim ySize As Double = 0.0 ySize = 165 * (dtInfo.Rows(iCount).Item("OrderCount") / iMax) Math.Round(ySize, 0) Dim y As Integer = Convert.ToInt32(ySize) 'If ySize > 0 Then 'g.FillRectangle(Brushes.Red, xStart, (179 - (Convert.ToInt32(ySize))), 5, (Convert.ToInt32(ySize))) 'End If If iLasty > -1 Then Dim arrPoints() As Point = {New Point(iLastx + 5, 179), _ New Point(iLastx + 5, iLasty), _ New Point(xStart + 5, (179 - Convert.ToInt32(ySize))), _ New Point(xStart + 5, 179)} Dim yBrush As New SolidBrush(Color.FromArgb(100, Color.Red)) g.FillPolygon(yBrush, arrPoints) 'g.DrawLine(Pens.Black, iLastx + 5, iLasty, xStart + 5, (179 - Convert.ToInt32(ySize))) yBrush = Nothing arrPoints = Nothing Dim rPen As New Pen(Color.Red) rPen.Width = 1 g.DrawLine(rPen, iLastx + 5, iLasty, xStart + 5, (179 - Convert.ToInt32(ySize))) 'g.FillRectangle(Brushes.Red, xStart + 3, (179 - Convert.ToInt32(ySize) - 2), 4, 4) End If If ySize > 0 Then iLasty = (179 - (Convert.ToInt32(ySize))) Else iLasty = 179 End If iLastx = xStart xStart = Nothing xLastStart = Nothing Next iLasty = -1 iLastx = -1 ' Draw Amount For iCount = 0 To iRows - 2 Dim xStart As Integer xStart = 50 + (iCount * 15) Dim dySize As Double = 0.0 dySize = 165 * (dtInfo.Rows(iCount).Item("OrderTotal") / dMax) Math.Round(dySize, 0) Dim dy As Integer = Convert.ToInt32(dySize) 'If dySize > 0 Then 'Dim rBrush As New SolidBrush(Color.FromArgb(200, Color.Green)) 'g.FillRectangle(rBrush, xStart, (179 - (Convert.ToInt32(dySize))), 10, (Convert.ToInt32(dySize))) 'rBrush = Nothing 'End If If iLasty > -1 Then 'Dim arrPoints() As Point = {New Point(iLastx + 5, 179), _ ' New Point(iLastx + 5, iLasty), _ ' New Point(xStart + 5, (179 - Convert.ToInt32(dySize))), _ ' New Point(xStart + 5, 179)} 'Dim yBrush As New SolidBrush(Color.FromArgb(175, Color.Yellow)) 'g.FillPolygon(yBrush, arrPoints) Dim gPen As New Pen(Color.Green) gPen.Width = 1 g.DrawLine(gPen, iLastx + 5, iLasty, xStart + 5, (179 - Convert.ToInt32(dySize))) g.FillRectangle(Brushes.Green, xStart + 3, (179 - Convert.ToInt32(dySize) - 2), 4, 4) 'yBrush = Nothing 'arrPoints = Nothing End If If dySize > 0 Then iLasty = (179 - (Convert.ToInt32(dySize))) Else iLasty = 179 End If iLastx = xStart xStart = Nothing Next Else For iCount = 0 To iRows - 2 Dim xStart As Integer xStart = 50 + (iCount * 15) g.DrawString((iCount + 1).ToString, oFont, Brushes.Black, xStart, 182) xStart = Nothing Next End If Catch Ex As Exception End Try Response.ClearContent() Response.ContentType = "image/jpeg" bGraph.Save(Response.OutputStream, ImageFormat.Jpeg) Response.End() End If End Sub End Class