private Dictionary <string, double[]> CalculateKGMData(string person, YearInfo year) { Dictionary <String, double[]> kgmdata = new Dictionary <string, double[]>(); foreach (CheckBox cb in GroupCheckBoxes) { if (cb.IsChecked == true) { String[] kgms = Groups[(string)cb.Content]; double[] percentages = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { percentages[i] = sm.PercentOfTotal(kgms); } else { percentages[i] = 0; } } else { percentages[i] = 0; } } kgmdata.Add((string)cb.Content, percentages); } } return(kgmdata); }
private static double[] CalculateIndtjening(string person, YearInfo year) { double[] indtjening = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { indtjening[i] = sm.Indtjening; } else { indtjening[i] = 0; } } else { indtjening[i] = 0; } } return(indtjening); }
private Dictionary <string, double[]> CalculateRatioData(string person, YearInfo year) { Dictionary <String, double[]> ratiodata = new Dictionary <string, double[]>(); foreach (CheckBox cb in RatioCheckBoxes) { if (cb.IsChecked == true) { string a = ""; string b = ""; for (int i = 0; i < Ratios.Count; i++) { string rationame = Ratios[i][0] + " / " + Ratios[i][1]; if (rationame == (string)cb.Content) { a = Ratios[i][0]; b = Ratios[i][1]; } } if (Groups.ContainsKey(a) && Groups.ContainsKey(b)) { double[] ratios = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { ratios[i] = sm.PartOfSum(Groups[a], Groups[b]); } else { ratios[i] = 0; } } else { ratios[i] = 0; } } ratiodata.Add((string)cb.Content, ratios); } } } return(ratiodata); }
private void ProcessEntry(NeaReader reader) { String[] fields = new String[fieldcount]; for (int i = 0; i < fieldcount; i++) { fields[i] = reader.ReadUntilAny(";"); if (reader.Peek() == -1) { return; } } int month; int year; try { String smonth = fields[datefield].Substring(3, 2); String syear = fields[datefield].Substring(6, 2); month = int.Parse(smonth) - 1; year = int.Parse(syear) + 2000; if (month < 4) { year--; } //make month 0 be May, and month 11 be April month -= 4; if (month < 0) { month += 12; } } catch (Exception e) { return; } YearInfo y = GetYear(year); if (y == null) { y = new YearInfo(year); years.Add(y); } y.AddEntry(month, fields); }
public MainWindow(DataHandler data, Dictionary <string, string[]> groups, List <string[]> ratios) { Groups = groups; Ratios = ratios; SalesmenCollection = new ObservableCollection <string>(); SalesmenCollection.Add("<INGEN SÆLGER VALGT>"); datahandler = data; YearInfo year = datahandler.GetYear(datahandler.FirstAvailableYear); string[] salesMen = year.GetSalesmen(); salesMen = salesMen.OrderBy(x => x).ToArray(); foreach (string s in salesMen) { allSalesMen.Add(s); } InitializeComponent(); LoadDepFiles(); groupcolors = GetColors(Groups.Count); ratiocolors = GetColors(Ratios.Count); int i = 0; foreach (KeyValuePair <String, String[]> group in Groups) { AddGroupCheckboxEntry(group.Key, groupcolors[i]); i++; } for (i = 0; i < Ratios.Count; i++) { AddRatioCheckboxEntry(Ratios[i][0] + " / " + Ratios[i][1], ratiocolors[i]); } SizeChanged += MainWindow_SizeChanged; TextMay.Content = "Maj\n" + year.Year; TextJune.Content = "Juni\n" + year.Year; TextJuly.Content = "Juli\n" + year.Year; TextAug.Content = "Aug\n" + year.Year; TextSep.Content = "Sep\n" + year.Year; TextOct.Content = "Okt\n" + year.Year; TextNov.Content = "Nov\n" + year.Year; TextDec.Content = "Dec\n" + year.Year; TextJan.Content = "Jan\n" + (year.Year + 1); TextFeb.Content = "Feb\n" + (year.Year + 1); TextMarch.Content = "Marts\n" + (year.Year + 1); TextApril.Content = "April\n" + (year.Year + 1); graph = new ElGraph( datahandler, graph_Person1, graph_Person2, Groups, Ratios, GroupCheckBoxList.ToArray(), RatioCheckBoxList.ToArray(), Omsætning, Indtjening, groupcolors, ratiocolors); graph.UpdateSize(canvasgrid1.ActualWidth, canvasgrid1.ActualHeight); }
private void UpdateGraph(CanvasGroup canvasgroup) { foreach (Polyline line in canvasgroup.GroupLines) { line.Points.Clear(); } foreach (Polyline line in canvasgroup.RatioLines) { line.Points.Clear(); } //canvasgroup.LineVs.Points.Clear(); canvasgroup.LineOms.Points.Clear(); canvasgroup.LineInd.Points.Clear(); if (canvasgroup.Person == null || canvasgroup.Person == "" || canvasgroup.Person == "<Ingen sælger valgt>") { return; } YearInfo year = datahandler.GetYear(datahandler.FirstAvailableYear); double[] omsætning = CalculateOmsætning(canvasgroup.Person, year); double[] indtjening = CalculateIndtjening(canvasgroup.Person, year); //double[] tvvswall = CalculateTvVsWall(canvasgroup.Person, year); Dictionary <String, double[]> kgmdata = CalculateKGMData(canvasgroup.Person, year); Dictionary <String, double[]> ratiodata = CalculateRatioData(canvasgroup.Person, year); double maxkroner = CalculateMaxKroner(omsætning); canvasgroup.Krone100.Content = maxkroner; canvasgroup.Krone75.Content = maxkroner * 0.75; canvasgroup.Krone50.Content = maxkroner * 0.5; canvasgroup.Krone25.Content = maxkroner * 0.25; double maxPerc = 0.01; foreach (KeyValuePair <String, double[]> pair in kgmdata) { var tempmax = pair.Value.Max(); if (tempmax > maxPerc) { maxPerc = tempmax; } } canvasgroup.Percent100.Content = String.Format("{0:0.0}", maxPerc * 100); canvasgroup.Percent75.Content = String.Format("{0:0.0}", maxPerc * 75); canvasgroup.Percent50.Content = String.Format("{0:0.0}", maxPerc * 50); canvasgroup.Percent25.Content = String.Format("{0:0.0}", maxPerc * 25); //if (CheckBoxVs.IsChecked == true) // DrawLines(tvvswall, canvasgroup.LineVs, 1.0, canvasgroup.Canvas); if (CheckBoxOms.IsChecked == true) { DrawLines(omsætning, canvasgroup.LineOms, maxkroner, canvasgroup.Canvas); } if (CheckBoxInd.IsChecked == true) { DrawLines(indtjening, canvasgroup.LineInd, maxkroner, canvasgroup.Canvas); } int n = 0; foreach (KeyValuePair <String, string[]> pair in Groups) { if (kgmdata.ContainsKey(pair.Key)) { Polyline line = canvasgroup.GroupLines[n]; DrawLines(kgmdata[pair.Key], line, maxPerc, canvasgroup.Canvas); } n++; } for (int i = 0; i < Ratios.Count; i++) { string rationame = Ratios[i][0] + " / " + Ratios[i][1]; if (ratiodata.ContainsKey(rationame)) { Polyline line = canvasgroup.RatioLines[i]; DrawLines(ratiodata[rationame], line, 1.0, canvasgroup.Canvas); } } }
private static void DefineCharts(Document document, string person, Dictionary <string, string[]> groups, DataHandler datahandler) { List <double[]> list = new List <double[]>(); List <String> names = new List <string>(); YearInfo year = datahandler.GetYear(datahandler.FirstAvailableYear); /***** Calculate series data ******/ foreach (KeyValuePair <string, string[]> pair in groups) { String[] kgms = pair.Value; double[] percentages = new double[12]; names.Add(pair.Key); for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { percentages[i] = sm.PercentOfTotal(kgms); } else { percentages[i] = 0; } } else { percentages[i] = 0; } } list.Add(percentages); } double[] oms = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { oms[i] = sm.Omsaetning; } else { oms[i] = 0; } } else { oms[i] = 0; } } double[] ind = new double[12]; for (int i = 0; i < 12; i++) { if (year[i] != null) { Salesman sm = year[i].GetSalesman(person); if (sm != null) { ind[i] = sm.Indtjening; } else { ind[i] = 0; } } else { ind[i] = 0; } } /***** Create chart for omsætning/indtjening series ******/ MigraDoc.DocumentObjectModel.Paragraph paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); Chart chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); MigraDoc.DocumentObjectModel.Shapes.Charts.Series series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(oms); series.SetNull(); series.Name = "Omsætning"; series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(ind); series.SetNull(); series.Name = "Indtjening"; XSeries xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); /***** Create chart for KGM series ******/ paragraph = document.LastSection.AddParagraph("Sælger Diagram", "Heading1"); chart = new Chart(); chart.Left = 0; chart.Width = Unit.FromCentimeter(22); chart.Height = Unit.FromCentimeter(15); for (int i = 0; i < list.Count; i++) { series = chart.SeriesCollection.AddSeries(); series.ChartType = ChartType.Line; series.LineFormat.Width = 10; series.Add(list[i]); series.SetNull(); series.Name = names[i]; } xseries = chart.XValues.AddXSeries(); xseries.Add(new string[] { "Maj", "Juni", "Juli", "Aug", "Sep", "Okt", "Nov", "Dec", "Jan", "Feb", "Marts", "April" }); chart.XAxis.MajorTickMark = TickMarkType.Inside; chart.XAxis.Title.Caption = "MÅNEDER"; chart.YAxis.TickLabels.Format = "#0%"; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.LeftArea.AddLegend(); document.LastSection.Add(chart); }