private Bitmap DrawToBitmapOversiktChunk(int argX, int argY, DataTable dt, string argTitle, string argCaption, string argAgr, float argMax = 15, float argMaxWeek = 40, float argMaxMonth = 100, float argPercent = 1, bool screen = false) { Bitmap b = new Bitmap(argX, argY); using (Graphics g = Graphics.FromImage(b)) { try { float dpi = 1; if (screen) dpi = main.appConfig.graphScreenDPI; int fontHeight = Convert.ToInt32(29 * dpi); int boxLength = Convert.ToInt32(22 * dpi); int fontSepHeight = Convert.ToInt32((fontHeight / 5) * dpi); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.White); if (dt.Rows.Count == 0) { g.DrawString("Mangler transaksjoner!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0); return b; } DateTime firstdate = DateTime.Now; DateTime lastdate = DateTime.Now; firstdate = (DateTime)dt.Rows[0][1]; lastdate = (DateTime)dt.Rows[dt.Rows.Count - 1][1]; int offsetY = Convert.ToInt32(40 * dpi); int offsetX = Convert.ToInt32(150 * dpi); float X = argX - offsetX; float Y = argY - offsetY; int pSize = dt.Rows.Count; float Hstep = X / pSize; if (String.IsNullOrEmpty(argAgr)) { if (Hstep > (40 * dpi)) argAgr = "dag"; else if (Hstep <= (40 * dpi) && Hstep >= (8 * dpi)) argAgr = "uke"; else if (Hstep < (8 * dpi)) argAgr = "måned"; } Log.d("Hstpe: " + Hstep + " | argAgr: " + argAgr); float Vstep = Y / (argMax * 1.1f); if (argAgr == "uke") Vstep = Y / (argMaxWeek * 1.1f); if (argAgr == "måned") Vstep = Y / (argMaxMonth * 1.1f); PointF p1, p2, p3, p4, p6; Pen pen1 = new Pen(Color.Black, 3 * dpi); Pen pen2 = new Pen(Color.Green, 6 * dpi); Pen bPen = new Pen(Color.LightGray, 3 * dpi); SolidBrush bBrush = new SolidBrush(Color.Gray); Font fontBig = new Font("Helvetica", 20 * dpi, FontStyle.Bold); Font fontNormal = new Font("Helvetica", 18 * dpi, FontStyle.Regular); Font fontSmall = new Font("Helvetica", 13 * dpi, FontStyle.Regular); string[] strTjenester = new string[] { "Finans", "TA", "Strom", "Tjen" }; Color[] colorTjenester = new Color[] { System.Drawing.ColorTranslator.FromHtml("#f5954e"), System.Drawing.ColorTranslator.FromHtml("#6699ff"), System.Drawing.ColorTranslator.FromHtml("#FAF39E"), System.Drawing.ColorTranslator.FromHtml("#80c34a") }; int columnsCount = dt.Columns.Count; DagSjekk agr = new DagSjekk(argAgr); g.DrawString(main.avdeling.Get(main.appConfig.Avdeling) + " " + argCaption, new Font("Verdana", 36 * dpi, FontStyle.Bold), new SolidBrush(Color.LightGray), 330, 0); var step = Y / 4; g.DrawLine(bPen, new Point(0, (int)step * 3), new Point((int)X, (int)step * 3)); g.DrawLine(bPen, new Point(0, (int)step * 2), new Point((int)X, (int)step * 2)); g.DrawLine(bPen, new Point(0, (int)step), new Point((int)X, (int)step)); g.DrawString("2,5%", fontNormal, bBrush, X + 6, (step * 3) - 14); g.DrawString("5,0%", fontNormal, bBrush, X + 6, (step * 2) - 14); g.DrawString("7,5%", fontNormal, bBrush, X + 6, step - 14); float sumValue = 0, sumFinans = 0, sumTa = 0, sumStrom = 0, sumTjen = 0; var gp = new GraphicsPath(); var gpLines = new GraphicsPath(); var gpShapes = new GraphicsPath(FillMode.Winding); var gpTextMonth = new GraphicsPath(); var gpTextWeek = new GraphicsPath(); var gpLinesMonth = new GraphicsPath(); var gpLinesYear = new GraphicsPath(); for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageButikk)dt.Rows[d][2]; var tjenester = (StorageTjenester)dt.Rows[d][columnsCount - 1]; sumValue += store.btokr; sumFinans += tjenester.finans; sumTa += tjenester.ta; sumStrom += tjenester.strom; sumTjen += tjenester.tjen; if (agr.Sjekk(date)) { p1 = new PointF(Hstep * (I + 1), Y - (Vstep * sumValue)); p2 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sumValue)); p3 = new PointF(Hstep * (I + 1), Y); p4 = new PointF(Hstep * (I - agr.dager + 1), Y); gp.StartFigure(); gp.AddLine(p4, p2); gp.AddLine(p2, p1); gp.AddLine(p1, p3); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new RectangleF(p2, new SizeF(Hstep * agr.dager, Vstep * sumValue))); g.DrawString(ForkortTallEnkel(sumValue), fontNormal, new SolidBrush(Color.Black), p2); float sum = 0; sum += sumFinans; p6 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sum)); g.FillRectangle(new SolidBrush(colorTjenester[0]), new RectangleF(p6, new SizeF(Hstep * agr.dager, Vstep * sumFinans))); sum += sumTa; p6 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sum)); g.FillRectangle(new SolidBrush(colorTjenester[1]), new RectangleF(p6, new SizeF(Hstep * agr.dager, Vstep * sumTa))); sum += sumStrom; p6 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sum)); g.FillRectangle(new SolidBrush(colorTjenester[2]), new RectangleF(p6, new SizeF(Hstep * agr.dager, Vstep * sumStrom))); sum += sumTjen; p6 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sum)); g.FillRectangle(new SolidBrush(colorTjenester[3]), new RectangleF(p6, new SizeF(Hstep * agr.dager, Vstep * sumTjen))); sumValue = 0; sumFinans = 0; sumTa = 0; sumStrom = 0; sumTjen = 0; } if (date.DayOfWeek == DayOfWeek.Monday && Hstep > 15) { p1 = new PointF(Hstep * I, Y); p2 = new PointF(Hstep * I, Y + offsetY); p3 = new PointF(Hstep * I, Y + 7); var weekNo = FormMain.norway.Calendar.GetWeekOfYear(date, FormMain.norway.DateTimeFormat.CalendarWeekRule, FormMain.norway.DateTimeFormat.FirstDayOfWeek); gpTextWeek.AddString("Uke " + weekNo.ToString(), new FontFamily("Verdana"), (int)FontStyle.Regular, 18 * dpi, p3, StringFormat.GenericDefault); gpLines.StartFigure(); gpLines.AddLine(p1, p2); } if (date.DayOfWeek == DayOfWeek.Sunday && Hstep > 20 && argAgr == "dag") { p1 = new Point((int)(Hstep * I) + (int)(Hstep / 6), (int)Y - 90); p2 = new Point((int)(Hstep * I) + (int)(Hstep / 6), (int)Y - 60); g.DrawString(date.ToString("MMM"), fontNormal, new SolidBrush(Color.Black), p1); g.DrawString(date.ToString("dd."), fontNormal, new SolidBrush(Color.Black), p2); } if (date.Day == 1) { gpShapes.StartFigure(); gpShapes.AddRectangle(new RectangleF(new PointF(Hstep * I + 2, Y + 2), new SizeF(75, offsetY - 4))); gpTextMonth.AddString(date.ToString("MMM"), new FontFamily("Verdana"), (int)FontStyle.Regular, 32 * dpi, new PointF(Hstep * I, Y), StringFormat.GenericDefault); gpLinesMonth.StartFigure(); gpLinesMonth.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } if (date.DayOfYear == 1) { gpLinesYear.StartFigure(); gpLinesYear.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } } g.DrawPath(pen1, gp); float percentFinans = 0, percentTa = 0, percentStrom = 0, percentTjen = 0; var gpFinans = new GraphicsPath(); var gpTa = new GraphicsPath(); var gpStrom = new GraphicsPath(); var gpTjen = new GraphicsPath(); float sumInntjen = 0, sumOmset = 0, sumOmsetExMva = 0; sumFinans = 0; sumTa = 0; sumStrom = 0; sumTjen = 0; float percentFinansPrev = 0, percentTaPrev = 0, percentStromPrev = 0, percentTjenPrev = 0; for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageTjenester)dt.Rows[d][columnsCount - 1]; var butikk = (StorageButikk)dt.Rows[d][2]; sumInntjen += butikk.btokr; sumOmset += butikk.salgspris; sumOmsetExMva += butikk.salgexmva; sumFinans += store.finans; percentFinans = CalcPercent(sumFinans, sumInntjen); sumTa += store.taOmset; percentTa = CalcPercent(sumTa, sumOmsetExMva); sumStrom += store.strom; percentStrom = CalcPercent(sumStrom, sumInntjen); sumTjen += store.tjen; percentTjen = CalcPercent(sumTjen, sumInntjen); if ((firstdate.Month == date.Month && firstdate.Day < 8) || lastdate.Month == date.Month || lastdate.Month != date.Month && firstdate.Month != date.Month || (!main.appConfig.graphHitrateMTD && screen)) { p2 = new PointF((Hstep * (I + 1)), Y - (Y * percentFinans * 10)); p1 = new PointF((Hstep * I), Y - (Y * percentFinansPrev * 10)); gpFinans.AddLine(p1, p2); p2 = new PointF((Hstep * (I + 1)), Y - (Y * percentTa * 10)); p1 = new PointF((Hstep * I), Y - (Y * percentTaPrev * 10)); gpTa.AddLine(p1, p2); p2 = new PointF((Hstep * (I + 1)), Y - (Y * percentStrom * 10)); p1 = new PointF((Hstep * I), Y - (Y * percentStromPrev * 10)); gpStrom.AddLine(p1, p2); p2 = new PointF((Hstep * (I + 1)), Y - (Y * percentTjen * 10)); p1 = new PointF((Hstep * I), Y - (Y * percentTjenPrev * 10)); gpTjen.AddLine(p1, p2); } percentFinansPrev = percentFinans; percentTaPrev = percentTa; percentStromPrev = percentStrom; percentTjenPrev = percentTjen; if (date.AddDays(1).Day == 1 && !(firstdate.Month == 5 && firstdate.Day == 1) && !FormMain.datoPeriodeVelger && dt.Rows.Count != d + 1 && !(!main.appConfig.graphHitrateMTD && screen)) { sumFinans = 0; sumTa = 0; sumStrom = 0; sumTjen = 0; sumInntjen = 0; sumOmset = 0; sumOmsetExMva = 0; percentFinans = 0; percentTa = 0; percentStrom = 0; percentTjen = 0; percentFinansPrev = 0; percentTaPrev = 0; percentStromPrev = 0; percentTjenPrev = 0; gpFinans.StartFigure(); gpTa.StartFigure(); gpStrom.StartFigure(); gpTjen.StartFigure(); } } // Finans path g.DrawPath(new Pen(Color.White, 12 * dpi), gpFinans); g.DrawPath(new Pen(colorTjenester[0], 8 * dpi), gpFinans); g.DrawLine(new Pen(colorTjenester[0], 8 * dpi), X, Y - (Y * percentFinans * 10), argX, Y - (Y * percentFinans * 10)); PaintLabelPercent(g, percentFinans, X, Y, offsetX, offsetY, 10, dpi); // TA path g.DrawPath(new Pen(Color.White, 12 * dpi), gpTa); g.DrawPath(new Pen(colorTjenester[1], 8 * dpi), gpTa); g.DrawLine(new Pen(colorTjenester[1], 8 * dpi), X, Y - (Y * percentTa * 10), argX, Y - (Y * percentTa * 10)); PaintLabelPercent(g, percentTa, X, Y, offsetX, offsetY, 10, dpi); // Strøm path g.DrawPath(new Pen(Color.White, 12 * dpi), gpStrom); g.DrawPath(new Pen(colorTjenester[2], 8 * dpi), gpStrom); g.DrawLine(new Pen(colorTjenester[2], 8 * dpi), X, Y - (Y * percentStrom * 10), argX, Y - (Y * percentStrom * 10)); PaintLabelPercent(g, percentStrom, X, Y, offsetX, offsetY, 10, dpi); // RTG/SA path g.DrawPath(new Pen(Color.White, 12 * dpi), gpTjen); g.DrawPath(new Pen(colorTjenester[3], 8 * dpi), gpTjen); g.DrawLine(new Pen(colorTjenester[3], 8 * dpi), X, Y - (Y * percentTjen * 10), argX, Y - (Y * percentTjen * 10)); PaintLabelPercent(g, percentTjen, X, Y, offsetX, offsetY, 10, dpi); g.FillRectangle(new SolidBrush(Color.White), new RectangleF(0, Y, argX, offsetY)); g.DrawPath(pen1, gpLines); g.DrawPath(new Pen(Color.Green, 3 * dpi), gpLinesMonth); g.DrawPath(new Pen(Color.Red, 3 * dpi), gpLinesYear); g.FillPath(new SolidBrush(Color.Black), gpTextWeek); g.FillPath(new SolidBrush(Color.White), gpShapes); g.FillPath(new SolidBrush(Color.Black), gpTextMonth); g.DrawLine(pen1, new Point(0, (int)Y), new Point(argX, (int)Y)); g.DrawLine(pen1, new Point((int)X, (int)Y), new Point((int)X, 0)); g.DrawRectangle(pen1, new Rectangle(new Point(0, 0), new Size(argX - 1, argY - 1))); int height = 0; if (argY > 200) height += fontHeight * 4; using (var gpSkilt = new GraphicsPath()) // skilt skygge { gpSkilt.AddRectangle(new Rectangle(12, 12, 307, 47 + height)); using (PathGradientBrush _Brush = new PathGradientBrush(gpSkilt)) { _Brush.WrapMode = WrapMode.Clamp; ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[]{Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray)}; _ColorBlend.Positions = new float[] { 0f, .1f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillPath(_Brush, gpSkilt); } } g.FillRectangle(new SolidBrush(Color.White), new Rectangle(8, 8, 300, 40 + height)); g.DrawRectangle(pen1, new Rectangle(new Point(8, 8), new Size(300, 40 + height))); string s2 = argAgr; if (s2 == "måned") s2 = "mnd"; g.DrawString("Fortjeneste pr " + s2, fontNormal, new SolidBrush(Color.Black), 44, 15); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new Rectangle(18, 18, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 18, boxLength, boxLength)); int add = 0; if (argY > 200) { add += fontHeight; g.DrawString("Finans:", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawString(Math.Round(percentFinans * 100, 2).ToString("0.00") + " %", fontNormal, new SolidBrush(Color.Black), 130, 15 + add); g.DrawLine(new Pen(colorTjenester[0], 10 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); add += fontHeight; g.DrawString("TA:", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawString(Math.Round(percentTa * 100, 2).ToString("0.00") + " %", fontNormal, new SolidBrush(Color.Black), 130, 15 + add); g.DrawLine(new Pen(colorTjenester[1], 10 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); add += fontHeight; g.DrawString("Strøm:", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawString(Math.Round(percentStrom * 100, 2).ToString("0.00") + " %", fontNormal, new SolidBrush(Color.Black), 130, 15 + add); g.DrawLine(new Pen(colorTjenester[2], 10 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); add += fontHeight; g.DrawString("RTG/SA:", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawString(Math.Round(percentTjen * 100, 2).ToString("0.00") + " %", fontNormal, new SolidBrush(Color.Black), 130, 15 + add); g.DrawLine(new Pen(colorTjenester[3], 10 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); } } catch { } } return b; }
private Bitmap DrawToBitmapButikkChunk(int argX, int argY, DataTable dt, string argTitle, string argCaption, string argAgr, float argMax = 15, float argMaxWeek = 40, float argMaxMonth = 100, float argPercent = 1, bool screen = false, float argSumTotal = 1) { Bitmap b = new Bitmap(argX, argY); using (Graphics g = Graphics.FromImage(b)) { try { float dpi = 1; if (screen) dpi = main.appConfig.graphScreenDPI; int fontHeight = Convert.ToInt32(29 * dpi); int boxLength = Convert.ToInt32(22 * dpi); int fontSepHeight = Convert.ToInt32((fontHeight / 5) * dpi); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.White); if (dt.Rows.Count == 0) { g.DrawString("Mangler transaksjoner!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0); return b; } DateTime firstdate = DateTime.Now; DateTime lastdate = DateTime.Now; firstdate = (DateTime)dt.Rows[0][1]; lastdate = (DateTime)dt.Rows[dt.Rows.Count - 1][1]; int offsetY = Convert.ToInt32(40 * dpi); int offsetX = Convert.ToInt32(150 * dpi); float X = argX - offsetX; float Y = argY - offsetY; int pSize = dt.Rows.Count; float Hstep = X / pSize; if (String.IsNullOrEmpty(argAgr)) { if (Hstep > (40 * dpi)) argAgr = "dag"; else if (Hstep <= (40 * dpi) && Hstep >= (8 * dpi)) argAgr = "uke"; else if (Hstep < (8 * dpi)) argAgr = "måned"; } float Vstep = Y / (argMax * 1.1f); if (argAgr == "uke") Vstep = Y / (argMaxWeek * 1.1f); if (argAgr == "måned") Vstep = Y / (argMaxMonth * 1.1f); float VstepA = Y / (argSumTotal + (argSumTotal / 10)); PointF p1, p2, p3, p4, p6; Pen bPen = new Pen(Color.LightGray, 3 * dpi); SolidBrush bBrush = new SolidBrush(Color.Gray); Pen pen1 = new Pen(Color.Black, 3 * dpi); Pen pen2 = new Pen(Color.Green, 6 * dpi); Font fontBig = new Font("Helvetica", 20 * dpi, FontStyle.Bold); Font fontNormal = new Font("Helvetica", 18 * dpi, FontStyle.Regular); Font fontSmall = new Font("Helvetica", 13 * dpi, FontStyle.Regular); List<string> toppselgere = new List<string> { }; DagSjekk agr = new DagSjekk(argAgr); g.DrawString(main.avdeling.Get(main.appConfig.Avdeling) + " " + lastdate.ToString("MMMM yyyy"), new Font("Verdana", 36 * dpi, FontStyle.Bold), new SolidBrush(Color.LightGray), 400, 0); var step = Y / 4; g.DrawLine(bPen, new Point(0, (int)step * 3), new Point((int)X, (int)step * 3)); g.DrawLine(bPen, new Point(0, (int)step * 2), new Point((int)X, (int)step * 2)); g.DrawLine(bPen, new Point(0, (int)step), new Point((int)X, (int)step)); var verticalSum = argMax / 4; if (argAgr == "uke") verticalSum = argMaxWeek / 4; if (argAgr == "måned") verticalSum = argMaxMonth / 4; g.DrawString(ForkortTall(verticalSum + (verticalSum / 10)), fontNormal, bBrush, X + 6, (step * 3) - 14); g.DrawString(ForkortTall(verticalSum * 2 + (verticalSum / 10)), fontNormal, bBrush, X + 6, (step * 2) - 14); g.DrawString(ForkortTall(verticalSum * 3 + (verticalSum / 10)), fontNormal, bBrush, X + 6, step - 14); float sumValue = 0; var gp = new GraphicsPath(); var gpShapes = new GraphicsPath(FillMode.Winding); var gpTextMonth = new GraphicsPath(); var gpTextWeek = new GraphicsPath(); var gpLines = new GraphicsPath(); var gpLinesMonth = new GraphicsPath(); var gpLinesYear = new GraphicsPath(); for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageButikk)dt.Rows[d][2]; sumValue += store.btokr; if (agr.Sjekk(date)) { p1 = new PointF(Hstep * (I + 1), Y - (Vstep * sumValue)); p2 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sumValue)); p3 = new PointF(Hstep * (I + 1), Y); p4 = new PointF(Hstep * (I - agr.dager + 1), Y); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new RectangleF(p2, new SizeF(Hstep * agr.dager, Vstep * sumValue))); g.DrawString(ForkortTallEnkel(sumValue), fontNormal, new SolidBrush(Color.Black), p2); if (main.appConfig.graphAdvanced && argAgr == "dag") { int sumacc = 0; if (!DBNull.Value.Equals(dt.Rows[d]["TOP"])) { StorageTop s = (StorageTop)dt.Rows[d]["TOP"]; List<StorageSelger> selgere = s.selgere; for (int i = 0; i < selgere.Count; i++) { if (i == 0) toppselgere.Add(selgere[i].selger); // Legg til den beste selgeren sumacc += selgere[i].antall; if ((selgere[i].antall * Vstep) > 20) { p6 = new PointF(Hstep * I, Y - (Vstep * sumacc)); g.FillRectangle(new SolidBrush(GetSelgerkodeFarge(selgere[i].selger)), new RectangleF(p6, new SizeF(Hstep, Vstep * selgere[i].antall))); g.DrawString(selgere[i].selger.Substring(0, 3), fontNormal, new SolidBrush(Color.Black), p6); } } } } gp.StartFigure(); gp.AddLine(p4, p2); gp.AddLine(p2, p1); gp.AddLine(p1, p3); sumValue = 0; } if (date.DayOfWeek == DayOfWeek.Monday && Hstep > 20) { p1 = new PointF(Hstep * I, Y); p2 = new PointF(Hstep * I, Y + offsetY); p3 = new PointF(Hstep * I, Y + 7); var weekNo = FormMain.norway.Calendar.GetWeekOfYear(date, FormMain.norway.DateTimeFormat.CalendarWeekRule, FormMain.norway.DateTimeFormat.FirstDayOfWeek); gpTextWeek.AddString("Uke " + weekNo.ToString(), new FontFamily("Verdana"), (int)FontStyle.Regular, 18 * dpi, p3, StringFormat.GenericDefault); gpLines.StartFigure(); gpLines.AddLine(p1, p2); } if (date.DayOfWeek == DayOfWeek.Sunday && Hstep > 20 && argAgr == "dag") { p1 = new Point((int)(Hstep * I) + (int)(Hstep / 6), (int)Y - 90); p2 = new Point((int)(Hstep * I) + (int)(Hstep / 6), (int)Y - 60); g.DrawString(date.ToString("MMM"), fontNormal, new SolidBrush(Color.Black), p1); g.DrawString(date.ToString("dd."), fontNormal, new SolidBrush(Color.Black), p2); } if (date.Day == 1) { gpShapes.StartFigure(); gpShapes.AddRectangle(new RectangleF(new PointF(Hstep * I + 2, Y + 2), new SizeF(75, offsetY - 4))); gpTextMonth.AddString(date.ToString("MMM"), new FontFamily("Verdana"), (int)FontStyle.Regular, 32 * dpi, new PointF(Hstep * I, Y), StringFormat.GenericDefault); gpLinesMonth.StartFigure(); gpLinesMonth.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } if (date.DayOfYear == 1) { gpLinesYear.StartFigure(); gpLinesYear.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } } g.DrawPath(pen1, gp); List<int> favSum = new List<int> { }; float sumCompare = 0, prevCompare = 0; for (int i = Favoritter.Count; i-- > 0; ) { var gpSum = new GraphicsPath(); var gpSumCompare = new GraphicsPath(); float sum = 0, prev = 0; for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageButikk)dt.Rows[d][i + 2]; sum += store.btokr; if ((firstdate.Month == date.Month && firstdate.Day < 8) || lastdate.Month == date.Month || lastdate.Month != date.Month && firstdate.Month != date.Month || (!main.appConfig.graphHitrateMTD && screen)) { p2 = new PointF((Hstep * (I + 1)), Y - (VstepA * sum)); p1 = new PointF((Hstep * I), Y - (VstepA * prev)); gpSum.AddLine(p1, p2); if (main.appConfig.rankingCompareLastyear > 0 && i == 0) { sumCompare += store.ifjor_btokr; p2 = new PointF((Hstep * (I + 1)), Y - (VstepA * sumCompare)); p1 = new PointF((Hstep * I), Y - (VstepA * prevCompare)); gpSumCompare.AddLine(p1, p2); prevCompare = sumCompare; } } prev = sum; if (date.AddDays(1).Day == 1 && !(firstdate.Month == 5 && firstdate.Day == 1) && !FormMain.datoPeriodeVelger && dt.Rows.Count != d + 1 && !(!main.appConfig.graphHitrateMTD && screen)) { sum = 0; sumCompare = 0; prev = 0; prevCompare = 0; gpSum.StartFigure(); gpSumCompare.StartFigure(); } } if (main.appConfig.rankingCompareLastyear > 0 && i == 0) { g.DrawPath(new Pen(Color.White, 12 * dpi), gpSumCompare); g.DrawPath(new Pen(Color.Gray, 8 * dpi), gpSumCompare); g.DrawLine(new Pen(Color.Gray, 8 * dpi), X, Y - (VstepA * sumCompare), argX, Y - (VstepA * sumCompare)); PaintLabelTall(g, sumCompare, X, Y, offsetX, offsetY, VstepA, dpi); } g.DrawPath(new Pen(Color.White, 12 * dpi), gpSum); g.DrawPath(new Pen(FormMain.favColors[i], 8 * dpi), gpSum); g.DrawLine(new Pen(FormMain.favColors[i], 8 * dpi), X, Y - (VstepA * sum), argX, Y - (VstepA * sum)); PaintLabelTall(g, sum, X, Y, offsetX, offsetY, VstepA, dpi); favSum.Add(Convert.ToInt32(sum)); } g.FillRectangle(new SolidBrush(Color.White), new RectangleF(0, Y, argX, offsetY)); g.DrawPath(pen1, gpLines); g.DrawPath(new Pen(Color.Green, 3 * dpi), gpLinesMonth); g.DrawPath(new Pen(Color.Red, 3 * dpi), gpLinesYear); g.FillPath(new SolidBrush(Color.Black), gpTextWeek); g.FillPath(new SolidBrush(Color.White), gpShapes); g.FillPath(new SolidBrush(Color.Black), gpTextMonth); g.DrawLine(pen1, new Point(0, (int)Y), new Point(argX, (int)Y)); g.DrawLine(pen1, new Point((int)X, (int)Y), new Point((int)X, 0)); // slutt strek g.DrawRectangle(pen1, new Rectangle(new Point(0, 0), new Size(argX - 1, argY - 1))); toppselgere = toppselgere.Distinct().ToList(); // fjern duplikater favSum.Reverse(); int height = 0; if (argY > 400) height += Favoritter.Count * fontHeight; if (argY > 600 && main.appConfig.graphAdvanced) height += toppselgere.Count * fontHeight; if (main.appConfig.rankingCompareLastyear > 0 && sumCompare > 0) height += fontHeight; using (var gpSkilt = new GraphicsPath()) // skilt skygge { gpSkilt.AddRectangle(new Rectangle(12, 12, 347, 47 + height)); using (PathGradientBrush _Brush = new PathGradientBrush(gpSkilt)) { _Brush.WrapMode = WrapMode.Clamp; ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[]{Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray)}; _ColorBlend.Positions = new float[] { 0f, .1f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillPath(_Brush, gpSkilt); } } g.FillRectangle(new SolidBrush(Color.White), new Rectangle(8, 8, 340, 40 + height)); g.DrawRectangle(pen1, new Rectangle(new Point(8, 8), new Size(340, 40 + height))); string s2 = argAgr; if (s2 == "måned") s2 = "mnd"; g.DrawString("Fortjeneste pr " + s2, fontNormal, new SolidBrush(Color.Black), 44, 15); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new Rectangle(18, 15, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 15, boxLength, boxLength)); int add = 0; if (argY > 600 && main.appConfig.graphAdvanced) { for (int i = 0; i < toppselgere.Count; i++) { add += fontHeight; g.DrawString(toppselgere[i], fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.FillRectangle(new SolidBrush(GetSelgerkodeFarge(toppselgere[i])), new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); } } if (argY > 400) { for (int i = 0; i < Favoritter.Count; i++) { add += fontHeight; var prosent = Math.Round(CalcPercent(favSum[i], favSum[0]) * 100, 2).ToString("0.00") + " %"; g.DrawString(main.avdeling.Get(Favoritter[i]) + ": " + prosent, fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawLine(new Pen(FormMain.favColors[i], 8 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); } } if (main.appConfig.rankingCompareLastyear > 0 && sumCompare > 0) { add += fontHeight; var prosent = Math.Round(CalcPercent(sumCompare, favSum[0]) * 100, 2).ToString("0.00") + " %"; g.DrawString("Fortjeneste i fjor: " + prosent, fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawLine(new Pen(Color.Gray, 8 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); } } catch { } } return b; }
private Bitmap DrawToBitmapChunk(int argX, int argY, DataTable dt, string argTitle, string argCaption, string argAgr, float argMax = 15, float argMaxWeek = 40, float argMaxMonth = 100, float argPercent = 1, bool screen = false, string sk = "") { Bitmap b = new Bitmap(argX, argY); using (Graphics g = Graphics.FromImage(b)) { try { float dpi = 1; if (screen) dpi = main.appConfig.graphScreenDPI; int fontHeight = Convert.ToInt32(29 * dpi); int boxLength = Convert.ToInt32(22 * dpi); int fontSepHeight = Convert.ToInt32((fontHeight / 5) * dpi); g.SmoothingMode = SmoothingMode.AntiAlias; g.Clear(Color.White); if (dt.Rows.Count == 0) { g.DrawString("Mangler transaksjoner!", new Font("Verdana", 30, FontStyle.Bold), new SolidBrush(Color.Red), 400, 0); return b; } DateTime firstdate = DateTime.Now; DateTime lastdate = DateTime.Now; firstdate = (DateTime)dt.Rows[0][1]; lastdate = (DateTime)dt.Rows[dt.Rows.Count - 1][1]; int offsetY = Convert.ToInt32(40 * dpi); int offsetX = 150; float X = argX - offsetX; float Y = argY - offsetY; int pSize = dt.Rows.Count; float Hstep = X / pSize; if (String.IsNullOrEmpty(argAgr)) { if (Hstep > (40 * dpi)) argAgr = "dag"; else if (Hstep <= (40 * dpi) && Hstep >= (8 * dpi)) argAgr = "uke"; else if (Hstep < (8 * dpi)) argAgr = "måned"; } float Vstep = Y / (argMax * 1.1f); if (argAgr == "uke") Vstep = Y / (argMaxWeek * 1.1f); if (argAgr == "måned") Vstep = Y / (argMaxMonth * 1.1f); float zoom = 1; if (!screen || main.appConfig.graphScreenZoom && screen) { if (argPercent < 0.40F) zoom = 2; if (argPercent < 0.20F) zoom = 3; if (argPercent < 0.15F) zoom = 4; if (argPercent < 0.10F) zoom = 6; } PointF p1, p2, p3, p4, p6; Pen bPen = new Pen(Color.LightGray, 3 * dpi); SolidBrush bBrush = new SolidBrush(Color.Gray); Pen pen1 = new Pen(Color.Black, 3 * dpi); Pen pen2 = new Pen(Color.Green, 6 * dpi); Font fontBig = new Font("Helvetica", 20 * dpi, FontStyle.Bold); Font fontNormal = new Font("Helvetica", 18 * dpi, FontStyle.Regular); Color tjenColor = System.Drawing.ColorTranslator.FromHtml("#80c34a"); List<string> toppselgere = new List<string> { }; DagSjekk agr = new DagSjekk(argAgr); List<string> fav = new List<string> { }; if (!String.IsNullOrEmpty(sk)) fav.Add(main.appConfig.Avdeling.ToString()); else fav = Favoritter; g.DrawString(main.avdeling.Get(main.appConfig.Avdeling) + " " + argCaption, new Font("Verdana", 36 * dpi, FontStyle.Bold), new SolidBrush(Color.LightGray), 400, 0); var step = Y / 4; g.DrawLine(bPen, new Point(0, (int)step * 3), new Point((int)X, (int)step * 3)); g.DrawLine(bPen, new Point(0, (int)step * 2), new Point((int)X, (int)step * 2)); g.DrawLine(bPen, new Point(0, (int)step), new Point((int)X, (int)step)); g.DrawString((0.25 / zoom * 100).ToString("0.0") + "%", fontNormal, bBrush, X + 6, (step * 3) - 14); g.DrawString((0.50 / zoom * 100).ToString("0.0") + "%", fontNormal, bBrush, X + 6, (step * 2) - 14); g.DrawString((0.75 / zoom * 100).ToString("0.0") + "%", fontNormal, bBrush, X + 6, step - 14); float sumProduct = 0, sumService = 0; float sumProductAgr = 0, sumServiceAgr = 0; var gp = new GraphicsPath(); var gpShapes = new GraphicsPath(FillMode.Winding); var gpTextMonth = new GraphicsPath(); var gpTextWeek = new GraphicsPath(); var gpLines = new GraphicsPath(); var gpLinesMonth = new GraphicsPath(); var gpLinesYear = new GraphicsPath(); for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageData)dt.Rows[d][2]; int product = store.product; int service = store.service; sumProduct += product; sumService += service; sumProductAgr += product; sumServiceAgr += service; if (agr.Sjekk(date)) { p3 = new PointF(Hstep * (I + 1), Y); p4 = new PointF(Hstep * (I - agr.dager + 1), Y); if (sumProductAgr > 0) { p1 = new PointF(Hstep * (I + 1), Y - (Vstep * sumProductAgr)); p2 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sumProductAgr)); gp.StartFigure(); gp.AddLine(p4, p2); gp.AddLine(p2, p1); gp.AddLine(p1, p3); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new RectangleF(p2, new SizeF(Hstep * agr.dager, Vstep * sumProductAgr))); g.DrawString(sumProductAgr.ToString(), fontNormal, new SolidBrush(Color.Black), p2); } if (sumServiceAgr > 0) { p1 = new PointF(Hstep * (I + 1), Y - (Vstep * sumServiceAgr)); p2 = new PointF(Hstep * (I - agr.dager + 1), Y - (Vstep * sumServiceAgr)); gp.StartFigure(); gp.AddLine(p4, p2); gp.AddLine(p2, p1); gp.AddLine(p1, p3); g.FillRectangle(new SolidBrush(tjenColor), new RectangleF(p2, new SizeF(Hstep * agr.dager, Vstep * sumServiceAgr))); g.DrawString(sumServiceAgr.ToString(), fontNormal, new SolidBrush(Color.Black), p2); } if (agr.dager > 27) { var percentMonth = CalcPercent(sumServiceAgr, sumProductAgr); gpTextMonth.AddString(Math.Round(percentMonth * 100, 0).ToString("0") + "%", new FontFamily("Verdana"), (int)FontStyle.Regular, 32 * dpi, new PointF(Hstep * (I - 20), Y - offsetY), StringFormat.GenericDefault); } if (agr.dager <= 27 && agr.dager >= 7) { var percentMonth = CalcPercent(sumServiceAgr, sumProductAgr); gpTextMonth.AddString(Math.Round(percentMonth * 100, 0).ToString("0") + "%", new FontFamily("Verdana"), (int)FontStyle.Regular, 32 * dpi, new PointF(Hstep * (I - 5), Y - offsetY), StringFormat.GenericDefault); } sumProductAgr = 0; sumServiceAgr = 0; } if (main.appConfig.graphAdvanced && argAgr == "dag" && String.IsNullOrEmpty(sk)) { int sumacc = 0; if (!DBNull.Value.Equals(dt.Rows[d][dt.Columns.Count - 1])) { StorageTop s = (StorageTop)dt.Rows[d]["TOP"]; List<StorageSelger> selgere = s.selgere; for (int i = 0; i < selgere.Count; i++) { if (i == 0) toppselgere.Add(selgere[i].selger); // Legg til den beste selgeren sumacc += selgere[i].antall; p6 = new PointF(Hstep * I, Y - (Vstep * sumacc)); g.FillRectangle(new SolidBrush(GetSelgerkodeFarge(selgere[i].selger)), new RectangleF(p6, new SizeF(Hstep, Vstep * selgere[i].antall))); if (Vstep > 20) g.DrawString(selgere[i].selger.Substring(0, 3), fontNormal, new SolidBrush(Color.Black), p6); } } } if (date.DayOfWeek == DayOfWeek.Monday && Hstep > 20) { p1 = new PointF(Hstep * I, Y); p2 = new PointF(Hstep * I, Y + offsetY); p3 = new PointF(Hstep * I, Y + 7); var weekNo = FormMain.norway.Calendar.GetWeekOfYear(date, FormMain.norway.DateTimeFormat.CalendarWeekRule, FormMain.norway.DateTimeFormat.FirstDayOfWeek); gpTextWeek.AddString("Uke " + weekNo.ToString(), new FontFamily("Verdana"), (int)FontStyle.Regular, 18 * dpi, p3, StringFormat.GenericDefault); gpLines.StartFigure(); gpLines.AddLine(p1, p2); } if (date.DayOfWeek == DayOfWeek.Sunday && Hstep > 20 && argAgr == "dag") { p1 = new PointF((Hstep * I) + (Hstep / 6), Y - 90); p2 = new PointF((Hstep * I) + (Hstep / 6), Y - 60); g.DrawString(date.ToString("MMM"), fontNormal, new SolidBrush(Color.Black), p1); g.DrawString(date.ToString("dd."), fontNormal, new SolidBrush(Color.Black), p2); } if (date.Day == 1) { gpShapes.StartFigure(); gpShapes.AddRectangle(new RectangleF(new PointF(Hstep * I + 2, Y + 2), new SizeF(75, offsetY - 4))); gpTextMonth.AddString(date.ToString("MMM"), new FontFamily("Verdana"), (int)FontStyle.Regular, 32 * dpi, new PointF(Hstep * I, Y), StringFormat.GenericDefault); gpLinesMonth.StartFigure(); gpLinesMonth.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } if (date.DayOfYear == 1) { gpLinesYear.StartFigure(); gpLinesYear.AddLine(new PointF(Hstep * I, 0), new PointF(Hstep * I, argY)); } } g.DrawPath(pen1, gp); List<float> listPercent = new List<float> { }; float prev = 0, sum = 0; for (int i = fav.Count; i-- > 0; ) { gp = new GraphicsPath(); sum = 0; prev = 0; float sumTjen = 0, percent = 0; for (int d = 0; d < dt.Rows.Count; d++) { int I = d; DateTime date = Convert.ToDateTime(dt.Rows[d][1]); var store = (StorageData)dt.Rows[d][i + 2]; int value = store.product; int valueTjen = store.service; sum += value; sumTjen += valueTjen; percent = CalcPercent(sumTjen, sum); if ((firstdate.Month == date.Month && firstdate.Day < 8) || lastdate.Month == date.Month || lastdate.Month != date.Month && firstdate.Month != date.Month || (!main.appConfig.graphHitrateMTD && screen)) { p2 = new PointF((Hstep * (I + 1)), Y - (Y * percent * zoom)); p1 = new PointF((Hstep * I), Y - (Y * prev * zoom)); gp.AddLine(p1, p2); } prev = percent; if (date.AddDays(1).Day == 1 && !(firstdate.Month == 5 && firstdate.Day == 1) && !FormMain.datoPeriodeVelger && dt.Rows.Count != d + 1 && !(!main.appConfig.graphHitrateMTD && screen)) { sumTjen = 0; sum = 0; percent = 0; prev = 0; gp.StartFigure(); } } g.DrawPath(new Pen(Color.White, 12 * dpi), gp); g.DrawPath(new Pen(FormMain.favColors[i], 8 * dpi), gp); g.DrawLine(new Pen(FormMain.favColors[i], 8 * dpi), X, Y - (Y * percent * zoom), argX, Y - (Y * percent * zoom)); PaintLabelPercent(g, percent, X, Y, offsetY, offsetY, zoom, dpi); listPercent.Add(percent); gp.Dispose(); } g.FillRectangle(new SolidBrush(Color.White), new RectangleF(0, Y, argX, offsetY)); g.DrawPath(pen1, gpLines); g.DrawPath(new Pen(Color.Green, 3 * dpi), gpLinesMonth); g.DrawPath(new Pen(Color.Red, 3 * dpi), gpLinesYear); g.FillPath(new SolidBrush(Color.Black), gpTextWeek); g.FillPath(new SolidBrush(Color.White), gpShapes); g.FillPath(new SolidBrush(Color.Black), gpTextMonth); toppselgere = toppselgere.Distinct().ToList(); // fjern duplikater listPercent.Reverse(); // reverser listen int height = 0; if (argY > 600 && main.appConfig.graphAdvanced && String.IsNullOrEmpty(sk)) height += toppselgere.Count * fontHeight; if (argY > 400 && String.IsNullOrEmpty(sk)) height += fav.Count * fontHeight; if (!main.appConfig.graphAdvanced || argY <= 600) height += fontHeight; g.DrawLine(pen1, new Point(0, (int)Y), new Point(argX, (int)Y)); // understrek g.DrawLine(pen1, new Point((int)X, (int)Y), new Point((int)X, 0)); // slutt strek if (!screen) g.DrawRectangle(pen1, new Rectangle(new Point(0, 0), new Size(argX - 1, argY - 1))); // ramme else g.DrawRectangle(new Pen(Color.Black, 1), new Rectangle(new Point(0, 0), new Size(argX - 1, argY - 1))); // ramme using (var gpSkilt = new GraphicsPath()) // skilt skygge { gpSkilt.AddRectangle(new Rectangle(12, 12, 347, 47 + height)); using (PathGradientBrush _Brush = new PathGradientBrush(gpSkilt)) { _Brush.WrapMode = WrapMode.Clamp; ColorBlend _ColorBlend = new ColorBlend(3); _ColorBlend.Colors = new Color[]{Color.Transparent, Color.FromArgb(180, Color.DimGray), Color.FromArgb(180, Color.DimGray)}; _ColorBlend.Positions = new float[] { 0f, .1f, 1f }; _Brush.InterpolationColors = _ColorBlend; g.FillPath(_Brush, gpSkilt); } } g.FillRectangle(new SolidBrush(Color.White), new Rectangle(8, 8, 340, 40 + height)); // skilt g.DrawRectangle(pen1, new Rectangle(new Point(8, 8), new Size(340, 40 + height))); // skilt ramme string s2 = argAgr; if (s2 == "måned") s2 = "mnd"; g.DrawString(argTitle + " solgt pr " + s2, fontNormal, new SolidBrush(Color.Black), 44, 15); g.FillRectangle(new SolidBrush(Color.AntiqueWhite), new Rectangle(18, 18, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 18, boxLength, boxLength)); int add = 0; if (!main.appConfig.graphAdvanced || argY <= 600) { add += fontHeight; g.DrawString("Tjenester", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.FillRectangle(new SolidBrush(tjenColor), new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); } if (argY > 600 && main.appConfig.graphAdvanced && String.IsNullOrEmpty(sk)) { for (int i = 0; i < toppselgere.Count; i++) { add += fontHeight; g.DrawString(toppselgere[i], fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.FillRectangle(new SolidBrush(GetSelgerkodeFarge(toppselgere[i])), new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); g.DrawRectangle(pen1, new Rectangle(18, 15 + fontSepHeight + add, boxLength, boxLength)); } } if (argY > 400 && String.IsNullOrEmpty(sk)) { for (int i = 0; i < fav.Count; i++) { add += fontHeight; g.DrawString(main.avdeling.Get(fav[i]) + ": " + Math.Round(listPercent[i] * 100, 2).ToString("0.00") + " %", fontNormal, new SolidBrush(Color.Black), 44, 15 + add); g.DrawLine(new Pen(FormMain.favColors[i], 8 * dpi), new Point(18, 15 + (fontSepHeight * 3) + add), new Point(40, 15 + (fontSepHeight * 3) + add)); } } } catch { } } return b; }