Exemple #1
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (combobox_Person1 != null && combobox_Person2 != null)
            {
                if (combobox_Afd.SelectedIndex == 0)
                {
                    combobox_Person1.IsEnabled = false;
                    combobox_Person2.IsEnabled = false;
                }
                else if (((string)(combobox_Afd.Items[combobox_Afd.SelectedIndex])) == "ALLE AFDELINGER")
                {
                    combobox_Person1.IsEnabled = true;
                    combobox_Person2.IsEnabled = true;
                    string[] sm = datahandler.GetYear(datahandler.FirstAvailableYear).GetSalesmen();

                    SalesmenCollection.Clear();
                    SalesmenCollection.Add("<INGEN SÆLGER VALGT>");

                    foreach (string s in sm)
                    {
                        SalesmenCollection.Add(s);
                    }
                }
                else
                {
                    combobox_Person1.IsEnabled = true;
                    combobox_Person2.IsEnabled = true;
                    foreach (string afdeling in departments.Keys)
                    {
                        if (afdeling == (string)combobox_Afd.Items[combobox_Afd.SelectedIndex])
                        {
                            SalesmenCollection.Clear();
                            SalesmenCollection.Add("<INGEN SÆLGER VALGT>");

                            for (int i = 0; i < departments[afdeling].Length; i++)
                            {
                                SalesmenCollection.Add(departments[afdeling][i]);
                            }
                        }
                    }
                }
            }
            StatusBox.Content = "Status: Combobox selection changed !";
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
        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);
        }