Esempio n. 1
0
        public ChartDisplayed(ChartParam CPTransmitted, BookingsStagesAnalysis pcModelTransmitted)
        {
            CP      = CPTransmitted;
            pcModel = pcModelTransmitted;
            culture = pcModelTransmitted.culture;



            ChartCreated = new Chart();
            Series s1 = ChartCreated.Series.Add("s1");


            ChartCreated.Width  = 900;
            ChartCreated.Height = 600;
            ChartCreated.ChartAreas.Add("c1");



            // fill the series in the chart
            FillDataPoints(s1);



            // Graphics and visuals

            // set the chart as pie
            s1.ChartType = SeriesChartType.Pie;

            // if many labels
            if (s1.Points.Count >= 5)
            {
                // labels are then set outside
                s1.SetCustomProperty("PieLabelStyle", "Outside");
                s1.BorderWidth     = 1;
                s1.BorderDashStyle = ChartDashStyle.Dot;
                s1.BorderColor     = System.Drawing.Color.FromArgb(200, 26, 59, 105);

                // Set the pie chart to be 3D
                ChartCreated.ChartAreas[0].Area3DStyle.Enable3D = true;

                // By setting the inclination to 0, the chart essentially goes back to being a 2D chart
                ChartCreated.ChartAreas[0].Area3DStyle.Inclination = 0;
            }


            //  if client or departemental overview : add a big title
            if (((CP.at == analysisType.departmentName) || (CP.at == analysisType.clientName)) && (CP.vd == valueDisplayed.bookingsAmount))
            {
                // add title
                Title t1 = ChartCreated.Titles.Add("Total offers received: " + Total);
                System.Drawing.Font f1 = new System.Drawing.Font("Microsoft Sans Serif", 16);
                t1.Font = f1;
            }
            else
            {
                //  else being: secondary chart in size
                // increase the font size for the label
                if (s1.Points.Count != 0)
                {
                    for (int p = 0; p < s1.Points.Count; p++)
                    {
                        s1.Points[p].Font = new System.Drawing.Font("Microsoft Sans Serif", 16);
                    }
                }
            }


            // generate data for the popover window
            PopElem = new PopoverElements(this);
        }
        public void UpdateChartsList(ViewDataDictionary ViewDataTransmitted)
        {
            // this should be a reflection of the Index view

            // method called from the controller before initialisation of the Index view or on form submit inside Index view
            // charts are all created before the call to the view

            ListChartsCreated = null;



            int ChartId = 1;



            DateTime bTF = DateTime.Parse(ViewDataTransmitted["BeginningTF"].ToString(), culture);
            DateTime eTF = DateTime.Parse(ViewDataTransmitted["EndTF"].ToString(), culture);
            string   ds  = ViewDataTransmitted["DeptSelected"].ToString();
            string   bTS = ViewDataTransmitted["bkgTypeSelected"].ToString();



            // the bookings are only selected after  the "01/02/2015"
            var deadlineTable  = perfRepo.GenerateDeadlineTable();
            var keyStagesDates = compDbRepo.RetrieveKeyStagesDates();

            AllBookingsForAnalysis = AllBookingsForAnalysis ?? tpRepo.TransformAllBookings(BeginningFY15, deadlineTable, keyStagesDates);


            // list of all precalculated charts that  will be displayed on the view
            IList <ChartDisplayed> lCD = new List <ChartDisplayed>();


            // Year on year analysis charts
            ChartParam cpYOY1 = new ChartParam {
                BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = analysisType.YearOnYear, bs = bookingStage.received, vd = valueDisplayed.bookingsAmount
            };
            ChartDisplayed cdYOY1 = new ChartDisplayed(cpYOY1, this, ReportType: "YearOnYear");

            cdYOY1.ChartId = ChartId;
            ChartId++;
            lCD.Add(cdYOY1);

            ChartParam cpYOY2 = new ChartParam {
                BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = analysisType.YearOnYearCumulative, bs = bookingStage.received, vd = valueDisplayed.bookingsAmount
            };
            ChartDisplayed cdYOY2 = new ChartDisplayed(cpYOY2, this, ReportType: "YearOnYear");

            cdYOY2.ChartId = ChartId;
            ChartId++;
            lCD.Add(cdYOY2);



            // Departmental and clients overview

            for (int iAT = 0; iAT < 2; iAT++)
            {
                ChartParam cp = new ChartParam {
                    BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = (analysisType)iAT, bs = bookingStage.received, vd = valueDisplayed.bookingsAmount
                };
                ChartDisplayed cd = new ChartDisplayed(cp, this);
                cd.ChartId = ChartId;
                ChartId++;
                lCD.Add(cd);
            }


            //  turnover:  location analysis , Clients Category analysis ,client name analysis
            for (int iBS = 1; iBS < 4; iBS++)
            {
                for (int iAT = 1; iAT < 4; iAT++)
                {
                    ChartParam cp = new ChartParam {
                        BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = (analysisType)iAT, bs = (bookingStage)iBS, vd = valueDisplayed.turnover
                    };
                    ChartDisplayed cd = new ChartDisplayed(cp, this);
                    cd.ChartId = ChartId;
                    ChartId++;
                    lCD.Add(cd);
                }
            }


            // offers received , sent , confirmed , cancelled , pending , pending past deadline , pendingSalesBDOPS
            for (int iAT = 2; iAT < 7; iAT++)
            {
                for (int iBS = 0; iBS < 8; iBS++)
                {
                    ChartParam cp = new ChartParam {
                        BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = (analysisType)iAT, bs = (bookingStage)iBS, vd = valueDisplayed.bookingsAmount
                    };
                    ChartDisplayed cd = new ChartDisplayed(cp, this);
                    cd.ChartId = ChartId;
                    ChartId++;
                    lCD.Add(cd);
                }
            }

            // offers pending as requotes , per consultant
            ChartParam cpRequote = new ChartParam {
                BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = analysisType.BDconsultant, bs = bookingStage.pendingSalesBDOPSRequote, vd = valueDisplayed.bookingsAmount
            };
            ChartDisplayed cdRequote = new ChartDisplayed(cpRequote, this);

            cdRequote.ChartId = ChartId;
            ChartId++;
            lCD.Add(cdRequote);

            // offers pending as first quotes , per consultant
            ChartParam cpFirstquote = new ChartParam {
                BeginningTF = bTF, EndTF = eTF, dptSelected = ds, btSelected = bTS, at = analysisType.BDconsultant, bs = bookingStage.pendingSalesBDOPSFirstQuote, vd = valueDisplayed.bookingsAmount
            };
            ChartDisplayed cdFirstquote = new ChartDisplayed(cpFirstquote, this);

            cdFirstquote.ChartId = ChartId;
            ChartId++;
            lCD.Add(cdFirstquote);



            ListChartsCreated = lCD.AsQueryable <ChartDisplayed>();



            // Creation of a Table of bookings used to check the charts

            BkgsSelectedInView = AllBookingsForAnalysis;

            //   filter by department:
            if (ds != "All")
            {
                BkgsSelectedInView = BkgsSelectedInView.Where(b => b.CompanyDepartment == ds);
            }

            //   filter by booking type:
            IList <string> btCodesSelected = (IList <string>)compSpec.bookingTypes[bTS];

            BkgsSelectedInView = BkgsSelectedInView.Where(b => btCodesSelected.Contains(b.BkgType.Trim()));

            //      sort by date entered belonging to the time frame
            IEnumerable <BkgAnalysisInfo> BkgsSelectedDE = BkgsSelectedInView.Where(b => (b.DateEntered >= bTF) && (b.DateEntered <= eTF)).OrderBy(b => b.DateEntered);

            //      sort by date confirmed belonging to the timeframe
            IEnumerable <BkgAnalysisInfo> BkgsSelectedDC = BkgsSelectedInView.Where(b => !string.Equals(b.DateConfirmed, ""));

            BkgsSelectedDC = BkgsSelectedDC
                             .Where(b => b.DateConfirmed >= bTF && b.DateConfirmed <= eTF)
                             .OrderBy(b => b.DateConfirmed);


            //      merge the 2 lists sorted by timeframe
            BkgsSelectedInView = BkgsSelectedDC.Union(BkgsSelectedDE);



            // creation of a second table where data are to be exported to Excel and sorted by date entered
            BkgsSelectedInView2 = BookingsToBeExported(bTF, eTF, ds, bTS);
        }
Esempio n. 3
0
        // constructor used for year on year analysis
        public ChartDisplayed(ChartParam CPTransmitted, BookingsStagesAnalysis pcModelTransmitted, string ReportType)
        {
            CP      = CPTransmitted;
            pcModel = pcModelTransmitted;

            if (ReportType == "YearOnYear")
            {
                // calculation of the data

                IEnumerable <BkgAnalysisInfo> BkgsSelected = pcModel.AllBookingsForAnalysis;


                //   filter by department:
                if (CP.dptSelected != "All")
                {
                    BkgsSelected = BkgsSelected.Where(b => b.CompanyDepartment == CP.dptSelected);
                }

                //   filter by booking type:
                IList <string> btCodesSelected = (IList <string>)pcModel.compSpec.bookingTypes[CP.btSelected];
                BkgsSelected = BkgsSelected.Where(b => btCodesSelected.Contains(b.BkgType.Trim()));


                // filter by the booking stage
                List <string> StatusCodes = (List <string>)pcModel.compSpec.BookingStageCodes[CP.bs];
                BkgsSelected = BkgsSelected.Where(b => StatusCodes.Contains(b.BookingStatus));



                string tCurrentYear  = "";
                string tPreviousYear = "";
                switch (CP.at)
                {
                case analysisType.YearOnYear:
                    tCurrentYear  = "Current year weekly";
                    tPreviousYear = "Previous year weekly";
                    break;

                case analysisType.YearOnYearCumulative:
                    tCurrentYear  = "Current year cumulative";
                    tPreviousYear = "Previous year cumulative";
                    break;
                }

                // chart initialisation
                int chartsWidth  = 1200;
                int chartsHeight = 600;
                ChartCreated = new Chart()
                {
                    Width = chartsWidth, Height = chartsHeight
                };
                ChartArea ca     = ChartCreated.ChartAreas.Add("c1");
                Series    CurrFY = ChartCreated.Series.Add(tCurrentYear);
                Series    PrevFY = ChartCreated.Series.Add(tPreviousYear);



                // find the first Sunday of the current FY:

                int CurrentFY = DateTime.Today.Month != 1 ? DateTime.Today.Year : DateTime.Today.Year - 1;

                // starting from the 01/02 of the current FY
                DateTime FirstDayWeek = new DateTime(CurrentFY, 2, 1);

                // first Sunday of the current FY
                DateTime LastDayWeek = FirstDayWeek.DayOfWeek == DayOfWeek.Sunday ? FirstDayWeek : FirstDayWeek.AddDays(7 - (int)FirstDayWeek.DayOfWeek);



                // populating the data for CurrentFY and PreviousFY
                // the data are populated until the end of the current FY to allow the year on year comparison
                // calculation by sum of the date entered in [FirstDayWeek;LastDayWeek]
                DateTime FirstDayNextFY = new DateTime(CurrentFY + 1, 2, 1);


                // populating the series but for the current FY it stops at the last sunday
                DateTime LastSunday = DateTime.Today.AddDays(-1 * (int)DateTime.Today.DayOfWeek);
                do
                {
                    int curr = BkgsSelected.Where(b => b.DateEntered >= FirstDayWeek && b.DateEntered <= LastDayWeek).Count();
                    int prev = BkgsSelected.Where(b => b.DateEntered >= FirstDayWeek.AddYears(-1) && b.DateEntered <= LastDayWeek.AddYears(-1)).Count();


                    // only show label for cumulative if the LastDayWeek is LastSunday

                    bool ShowLabel = CP.at == analysisType.YearOnYear || (CP.at == analysisType.YearOnYearCumulative && LastDayWeek == LastSunday);

                    if (curr != 0 && LastDayWeek <= LastSunday)
                    {
                        int pt = CurrFY.Points.AddXY(LastDayWeek, curr);
                        if (ShowLabel)
                        {
                            CurrFY.Points[pt].Label = curr.ToString();
                        }
                    }
                    if (prev != 0)
                    {
                        int pt = PrevFY.Points.AddXY(LastDayWeek, prev);
                        if (ShowLabel)
                        {
                            PrevFY.Points[pt].Label = prev.ToString();
                        }
                    }



                    if (CP.at != analysisType.YearOnYearCumulative)
                    {
                        FirstDayWeek = LastDayWeek.AddDays(1);
                    }
                    LastDayWeek = LastDayWeek.AddDays(7);
                } while (LastDayWeek < FirstDayNextFY);


                // graphics and visuals

                CurrFY.ChartType = SeriesChartType.Line;
                PrevFY.ChartType = SeriesChartType.Line;

                ca.AxisX.LabelStyle.Format             = "dd MMM";
                ca.AxisX.Interval                      = 30; // 30 days interval
                ca.AxisX.MajorGrid.Enabled             = false;
                ca.AxisY.MajorGrid.Enabled             = false;
                ca.AxisY.LabelStyle.Enabled            = false;
                ca.AxisY.MajorTickMark.Enabled         = false;
                ChartCreated.Legends.Add("l1").Docking = Docking.Top;


                ca.BackColor = System.Drawing.Color.Azure;
            }
        }