Exemplo n.º 1
0
        public void CreateGraph(ChartRenderModel model)
        {
            InitializeWebChartControl();

            Series series1 = new Series("My Series", ViewType.Line);

            series1.ArgumentDataMember = "Datum";
            series1.ArgumentScaleType  = ScaleType.DateTime;

            series1.ValueDataMembers[0]               = "Vrednost";
            series1.ValueScaleType                    = ScaleType.Numerical;
            series1.Label.ResolveOverlappingMode      = ResolveOverlappingMode.JustifyAllAroundPoint;
            series1.Label.ResolveOverlappingMinIndent = 1;
            series1.LabelsVisibility                  = DevExpress.Utils.DefaultBoolean.True;

            foreach (ChartRenderSimple item in model.chartRenderData)
            {
                SeriesPoint point1 = new SeriesPoint(item.Datum, new double[] { Convert.ToDouble(item.Vrednost) });
                point1.ToolTipHint = item.Datum.ToString("dd MMMM yyyy");
                series1.Points.Add(point1);
                series1.ToolTipEnabled      = DevExpress.Utils.DefaultBoolean.True;
                series1.ToolTipPointPattern = "Datum: {HINT}";
                series1.CrosshairEnabled    = DevExpress.Utils.DefaultBoolean.False;
            }

            WebChartControl1.Series.Add(series1);
            CreateEventsOnCharts(model, GetChartDivWidth(), GetChartsCount());

            ((XYDiagram2D)WebChartControl1.Diagram).GetAllAxesY()[0].Title.Visible   = true;
            ((XYDiagram2D)WebChartControl1.Diagram).GetAllAxesY()[0].Title.Alignment = StringAlignment.Center;
            ((XYDiagram2D)WebChartControl1.Diagram).GetAllAxesY()[0].Title.Text      = YAxisTitle;
        }
        public IHttpActionResult SaveClientCategorie([FromBody] object clientCategorieData)
        {
            WebResponseContentModel <ClientCategorieModel> returnModel = new WebResponseContentModel <ClientCategorieModel>();

            try
            {
                returnModel = JsonConvert.DeserializeObject <WebResponseContentModel <ClientCategorieModel> >(clientCategorieData.ToString());

                if (returnModel.Content != null)
                {
                    if (returnModel.Content.idStrankaKategorija > 0)//We update existing record in DB
                    {
                        clientRepo.SaveClientCategorie(returnModel.Content);
                        returnModel.Content.Kategorija = clientRepo.GetCategorieByID(returnModel.Content.idKategorija);
                    }
                    else// We add and save new recod to DB
                    {
                        returnModel.Content.idStrankaKategorija = clientRepo.SaveClientCategorie(returnModel.Content, false);
                        returnModel.Content.Kategorija          = clientRepo.GetCategorieByID(returnModel.Content.idKategorija);
                        ChartRenderModel chartData = chartsRepo.GetDataForChart(returnModel.Content.idStranka, returnModel.Content.idKategorija, (int)Enums.ChartRenderPeriod.MESECNO, (int)Enums.ChartRenderType.KOLICINA);

                        if (chartData != null)
                        {
                            if (chartData.chartRenderData.Count > 0)
                            {
                                returnModel.Content.HasChartDataForCategorie = true;
                            }
                        }
                    }

                    returnModel.IsRequestSuccesful = true;
                }
                else
                {
                    returnModel.IsRequestSuccesful = false;
                    returnModel.ValidationError    = ValidationExceptionError.res_09;
                }
            }
            catch (Exception ex)
            {
                returnModel.IsRequestSuccesful = false;
                returnModel.ValidationError    = ExceptionValidationHelper.GetExceptionSource(ex);
                return(Json(returnModel));
            }

            return(Json(returnModel));
        }
        private void ucf2_btnPostClk(object sender, EventArgs e)
        {
            UserControlGraph ucf2 = (UserControlGraph)sender;

            int period = CommonMethods.ParseInt(ucf2.Period.SelectedItem.Value);
            int type   = CommonMethods.ParseInt(ucf2.Type.SelectedItem.Value);

            if (period != (int)Enums.ChartRenderPeriod.TEDENSKO)
            {
                DateTime?selectedDateFrom = null;
                DateTime?selectedDateTo   = null;

                if (!ucf2.DateEdit_OD.Date.Equals(DateTime.MinValue))
                {
                    selectedDateFrom = ucf2.DateEdit_OD.Date;
                }
                if (!ucf2.DateEdit_DO.Date.Equals(DateTime.MinValue))
                {
                    selectedDateTo = ucf2.DateEdit_DO.Date;
                }

                ChartRenderModel chart = CheckModelValidation(GetDatabaseConnectionInstance().GetChartDataFromSQLFunction(clientID, ucf2.CategorieID, period, type, selectedDateFrom, selectedDateTo));

                if (period == (int)Enums.ChartRenderPeriod.MESECNO)
                {
                    chart.chartRenderData = CheckForMissingMoths(chart.chartRenderData, period, type, ucf2.CategorieID, 0);
                }


                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).chartData  = chart;
                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).YAxisTitle = chart.chartRenderData.Count > 0 ? chart.chartRenderData[0].EnotaMere : "";
                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).obdobje    = period;
                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).tip        = type;
                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).dateFrom   = ucf2.DateEdit_OD.Date;
                GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).dateTo     = ucf2.DateEdit_DO.Date;

                ucf2.CreateGraph(chart);
            }
            else
            {
                int previousPeriod = GetClientDataProviderInstance().GetGraphBindingList().Find(gb => gb.CategorieID == ucf2.CategorieID).obdobje;
                ucf2.Period.SelectedIndex = ucf2.Period.Items.IndexOf(ucf2.Period.Items.FindByValue(previousPeriod.ToString()));
            }
        }
        public List <ChartRenderModel> GetDataChartAllTypesSQLFunction(int clientID, int categorieID, int period, DateTime?dateFROM, DateTime?dateTO)
        {
            List <ChartRenderModel> list = new List <ChartRenderModel>();

            try
            {
                foreach (var item in Enum.GetValues(typeof(Enums.ChartRenderType)))
                {
                    ChartRenderModel model = GetDataForChartFromSQLFunction(clientID, categorieID, period, (int)((Enums.ChartRenderType)item), dateFROM, dateTO);
                    list.Add(model);
                }

                return(list);
            }
            catch (Exception ex)
            {
                throw new Exception(ValidationExceptionError.res_06, ex);
            }
        }
Exemplo n.º 5
0
        private void RenderEventTableOnReport(ChartRenderModel model)
        {
            if (model.EventList != null && model.EventList.Count > 0)
            {
                PaddingInfo info = new PaddingInfo();
                info.Top    = 10;
                info.Bottom = 5;

                foreach (var item in model.EventList)
                {
                    XRTableRow  row  = new XRTableRow();
                    XRTableCell cell = new XRTableCell();
                    cell.WidthF        = 182.5f;
                    cell.Text          = item.DatumOtvoritve.ToShortDateString();
                    cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                    row.Cells.Add(cell);

                    cell               = new XRTableCell();
                    cell.WidthF        = 182.5f;
                    cell.Text          = item.Rok.CompareTo(DateTime.MaxValue) > 0 ? item.Rok.ToShortDateString() : "Not-defined";
                    cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                    row.Cells.Add(cell);

                    cell               = new XRTableCell();
                    cell.WidthF        = 515f;
                    cell.Text          = !String.IsNullOrEmpty(item.Opis) ? item.Opis : "Not-defined";
                    cell.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
                    cell.Multiline     = true;
                    row.Cells.Add(cell);

                    row.Padding = info;

                    xrTableDogodki.Rows.Add(row);
                }
            }
            else
            {
                xrTableDogodki.Visible      = false;
                xrLabelTitleDogodki.Visible = false;
            }
        }
        public ChartRenderModel GetDataForChart(int clientID, int categorieID, int period, int type, DateTime?dateFROM = null, DateTime?dateTO = null)
        {
            try
            {
                ChartRenderModel model = new ChartRenderModel();

                if ((dateFROM != null && dateTO != null) && (dateFROM.Value.CompareTo(DateTime.MinValue) > 0 && dateTO.Value.CompareTo(DateTime.MinValue) > 0))
                {
                    model.chartRenderData = QueryChartDataForDateFromTO(clientID, categorieID, type, dateFROM.Value, dateTO.Value);
                }
                else
                {
                    model.chartRenderData = QueryChartDataForPeriod(clientID, categorieID, period, type);
                }

                if (model.chartRenderData.Count > 0)
                {
                    DateTime min = model.chartRenderData.Min(crd => crd.Datum);
                    DateTime max = model.chartRenderData.Max(crd => crd.Datum);
                    if (period == 2)//Year chart render
                    {
                        if (model.chartRenderData.Count > 0)
                        {
                            model.chartRenderData[model.chartRenderData.Count - 1].Datum = model.chartRenderData[model.chartRenderData.Count - 1].Datum.AddMonths(11);
                        }
                        max = max.AddMonths(12);
                    }
                    model.EventList = eventRepo.GetEventsByClientIDAndCategorieID(clientID, categorieID, min, max);
                }
                else
                {
                    model.EventList = new List <EventSimpleModel>();
                }

                return(model);
            }
            catch (Exception ex)
            {
                throw new Exception(ValidationExceptionError.res_06, ex);
            }
        }
Exemplo n.º 7
0
        private void CreateEventsOnCharts(ChartRenderModel model, bool isMultiPaneChart = false)
        {
            Series series2 = new Series("My Series2", ViewType.Bar);

            series2.ArgumentDataMember  = "Datum";
            series2.ArgumentScaleType   = ScaleType.DateTime;
            series2.ValueDataMembers[0] = "Vrednost";

            series2.LabelsVisibility = DevExpress.Utils.DefaultBoolean.False;

            series2.ValueScaleType = ScaleType.Numerical;

            ((SideBySideBarSeriesView)series2.View).BarWidth = 1.4;

            double maxVrednost = Convert.ToDouble(model.chartRenderData.Max(crd => crd.Vrednost));

            if (model.EventList.Count > 0)
            {
                //EventLinkWrap.Style.Add("max-width", ((width / chartsCount) - 50).ToString() + "px");
                model.EventList = model.EventList.OrderBy(el => el.DatumOtvoritve).ToList();//we sor elements from the youngest event to the oldest
                foreach (EventSimpleModel item in model.EventList)
                {
                    SeriesPoint point = new SeriesPoint(item.DatumOtvoritve, new double[] { maxVrednost });
                    point.ToolTipHint = item.DatumOtvoritve.ToString("dd MMMM yyyy") + (String.IsNullOrEmpty(item.Opis) ? "" : "\r\n" + "Opis: " + item.Opis);
                    series2.Points.Add(point);

                    /*string link = RedirectToEvent(item.idDogodek, item.idStranka, item.idKategorija, item.Izvajalec);
                    *  EventLinkWrap.InnerHtml += "<div class='eventLinkWrap'><a class='eventLink' href='" + link + "' title='Pojdi na dogodek st.: "
                    + item.idDogodek.ToString() + "'>" + item.DatumOtvoritve.ToString("dd MMMM yyyy") + "</a></div>";*/
                }

                /*ToolTipRelativePosition relativePosition = new ToolTipRelativePosition();
                 * xrDataChart.ToolTipOptions.ToolTipPosition = relativePosition;
                 *
                 * relativePosition.OffsetX = 2;
                 * relativePosition.OffsetY = 2;*/

                series2.ToolTipEnabled      = DevExpress.Utils.DefaultBoolean.True;
                series2.ToolTipPointPattern = "Datum dogodka: {HINT}";

                series2.CrosshairEnabled = DevExpress.Utils.DefaultBoolean.False;
            }

            xrDataChart.Series.Add(series2);

            int newMinValue = -10;

            if (maxVrednost > 1000)
            {
                newMinValue = -100;
            }
            else if (maxVrednost > 100)
            {
                newMinValue = -10;
            }
            else
            {
                newMinValue = -1;
            }

            DateTimeGridAlignment dateTimeGridAlignment = DateTimeGridAlignment.Month;

            if (CommonMethods.ParseInt(model.chartRenderData[0].Obdobje) == (int)Enums.ChartRenderPeriod.LETNO)
            {
                dateTimeGridAlignment = DateTimeGridAlignment.Year;
            }


            ((XYDiagram)xrDataChart.Diagram).AxisX.Label.ResolveOverlappingOptions.AllowHide = false;
            if (!isMultiPaneChart)
            {
                ((XYDiagram)xrDataChart.Diagram).AxisX.DateTimeScaleOptions.GridAlignment = dateTimeGridAlignment;
            }
            //((XYDiagram)WebChartControl1.Diagram).AxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Month;
            ((XYDiagram)xrDataChart.Diagram).AxisX.Label.ResolveOverlappingOptions.AllowRotate = true;
            ((XYDiagram2D)xrDataChart.Diagram).EnableAxisYZooming = true;
            ((XYDiagram2D)xrDataChart.Diagram).GetAllAxesY()[0].WholeRange.MinValue = newMinValue;
        }
        public ChartRenderModel GetDataForChartFromSQLFunction(int clientID, int categorieID, int period, int type, DateTime?dateFROM = null, DateTime?dateTO = null)
        {
            try
            {
                ChartRenderModel model = new ChartRenderModel();

                Stranka    stranka    = context.Stranka.Where(s => s.idStranka.Equals(clientID)).FirstOrDefault();
                Kategorija kategorija = context.Kategorija.Where(k => k.idKategorija.Equals(categorieID)).FirstOrDefault();

                //if the dates FROM and TO are not set, then we set the dates based on period
                if (dateFROM == null && dateTO == null)
                {
                    switch (period)
                    {
                    case (int)Enums.ChartRenderPeriod.LETNO:
                        dateTO   = DateTime.Now;
                        dateFROM = new DateTime(dateTO.Value.AddYears(-5).Year, 1, 1);
                        break;

                    case (int)Enums.ChartRenderPeriod.MESECNO:
                        dateTO   = DateTime.Now;
                        dateFROM = new DateTime(dateTO.Value.AddYears(-3).Year, 1, 1);
                        break;
                    }
                }


                List <IzrisGrafa_Result> list = context.IzrisGrafa(stranka.KodaStranke, kategorija.Koda, type, period, dateFROM, dateTO).ToList();

                var query = from db in list
                            select new ChartRenderSimple
                {
                    Datum        = db.Datum.Value,
                    EnotaMere    = db.EnotaMere,
                    IzpisGrafaID = -1,
                    KategorijaID = db.KategorijaID.Value,
                    Obdobje      = db.Obdobje.Value,
                    Opis         = db.Opis,
                    StrankaID    = db.StrankaID.Value,
                    Tip          = db.Tip.Value,
                    Vrednost     = db.Vrednost.Value
                };


                model.chartRenderData = query.ToList();

                if (model.chartRenderData.Count > 0)
                {
                    DateTime min = model.chartRenderData.Min(crd => crd.Datum);
                    DateTime max = model.chartRenderData.Max(crd => crd.Datum);
                    if (period == 2)//Year chart render
                    {
                        if (model.chartRenderData.Count > 0)
                        {
                            model.chartRenderData[model.chartRenderData.Count - 1].Datum = model.chartRenderData[model.chartRenderData.Count - 1].Datum.AddMonths(11);
                        }
                        max = max.AddMonths(12);
                    }
                    model.EventList = eventRepo.GetEventsByClientIDAndCategorieID(clientID, categorieID, min, max);
                }
                else
                {
                    model.EventList = new List <EventSimpleModel>();
                }

                return(model);
            }
            catch (Exception ex)
            {
                throw new Exception(ValidationExceptionError.res_06, ex);
            }
        }
        private GraphBinding IncializeChartAndChartData(HtmlTable table, HtmlTableRow tRow, ClientCategorieModel item,
                                                        Enums.ChartRenderType type     = Enums.ChartRenderType.KOLICINA,
                                                        Enums.ChartRenderPeriod period = Enums.ChartRenderPeriod.MESECNO,
                                                        bool showFilterOnChart         = true,
                                                        DateTime?dateFROM = null,
                                                        DateTime?dateTO   = null)
        {
            UserControlGraph ucf2 = (UserControlGraph)LoadControl("~/UserControls/UserControlGraph.ascx");

            ChartRenderModel        chart = null;
            List <ChartRenderModel> list  = null;

            if (showFilterOnChart)
            {
                chart = CheckModelValidation(GetDatabaseConnectionInstance().GetChartDataFromSQLFunction(clientID, item.Kategorija.idKategorija, (int)period, (int)type));
            }
            else//if we want to see all types
            {
                list = CheckModelValidation(GetDatabaseConnectionInstance().GetChartDataForAllTypesSQLFunction(clientID, item.Kategorija.idKategorija, (int)period, dateFROM, dateTO));
            }

            if ((chart != null && chart.chartRenderData.Count > 0) || (list != null && list.Count > 0 && list.Exists(c => c.chartRenderData.Count > 0)))
            {
                item.HasChartDataForCategorie = true;
                //ucf2.ID = model.KodaStranke + "_UserControlGraph_" + (bindingCollection.Count + 1).ToString();
                ucf2.btnPostClk          += ucf2_btnPostClk;
                ucf2.btnDeleteGraphClick += ucf2_btnDeleteGraphClick;
                ucf2.btnAddEventClick    += ucf2_btnAddEventClick;


                tRow = AddChartsToCell(ucf2, tRow, 1);
                table.Rows.Add(tRow);

                ChartsCallback.Controls.Add(table);

                GraphBinding instance = new GraphBinding();

                if (period.Equals(Enums.ChartRenderPeriod.MESECNO))
                {
                    if (chart != null)
                    {
                        chart.chartRenderData = CheckForMissingMoths(chart.chartRenderData, (int)period, (int)type, item.Kategorija.idKategorija, 0);
                    }
                    else
                    {
                        foreach (var obj in list)
                        {
                            if (obj.chartRenderData.Count > 0)
                            {
                                obj.chartRenderData = CheckForMissingMoths(obj.chartRenderData, (int)period, obj.chartRenderData[0].Tip, item.Kategorija.idKategorija, 0);
                            }
                        }
                    }
                }

                ucf2.HeaderName.HeaderText = item.Kategorija.Naziv;
                ucf2.HeaderLink.Visible    = false;
                ucf2.Period.SelectedIndex  = ucf2.Period.Items.FindByValue(((int)period).ToString()).Index;
                ucf2.Period.Visible        = showFilterOnChart ? true : false;
                ucf2.Type.SelectedIndex    = ucf2.Type.Items.FindByValue(((int)type).ToString()).Index;
                ucf2.Type.Visible          = showFilterOnChart ? true : false;
                ucf2.RenderChart.Text      = "Izriši " + item.Kategorija.Koda;
                ucf2.RenderChart.Visible   = showFilterOnChart ? true : false;
                ucf2.CategorieID           = item.Kategorija.idKategorija;
                ucf2.YAxisTitle            = (chart != null && chart.chartRenderData.Count > 0) ? chart.chartRenderData[0].EnotaMere : "";
                ucf2.ShowFromToDateFilteringUserControl = showFilterOnChart ? true : false;

                if (chart != null)
                {
                    ucf2.CreateGraph(chart);
                }
                else if (list != null && list.Count > 0)
                {
                    //rbTypeDetail.SelectedIndex = rbTypeDetail.Items.FindByValue(((int)period).ToString()).Index;
                    ucf2.CreateGraphMultiPane(list);
                }

                instance.obdobje                = (int)period;
                instance.tip                    = (int)type;
                instance.YAxisTitle             = ucf2.YAxisTitle;
                instance.chartData              = chart;
                instance.chartDataMultiplePanes = list;
                instance.control                = ucf2;
                instance.HeaderText             = item.Kategorija.Koda;
                instance.CategorieID            = item.Kategorija.idKategorija;
                instance.ShowFilterFromToDate   = showFilterOnChart ? true : false;
                instance.dateFrom               = DateEdit_OD.Date;
                instance.dateTo                 = DateEdit_DO.Date;

                return(instance);
            }

            return(null);
        }