private void CreateCharts(bool allCategorieTypes = false) { List <GraphBinding> bindingCollection = new List <GraphBinding>(); HtmlTable table = new HtmlTable(); table.Style.Add("width", "100%"); bindingCollection.Select(item => item.control).ToList();//get all controls and only controls from list GetClientDataProviderInstance().SetMainContentWidthForCharts(CommonMethods.ParseDouble(hiddenField["browserWidth"])); GetClientDataProviderInstance().SetChartsCoutInRow(1); HtmlTableRow tRow = new HtmlTableRow(); if (allCategorieTypes)//we show all categorie types in one chart { ClientCategorieModel ccm = model.StrankaKategorija.Where(kat => kat.idKategorija == categorieID).FirstOrDefault(); Enums.ChartRenderPeriod period = Enums.ChartRenderPeriod.MESECNO; if (isSelectedPeriodChanged()) { period = (Enums.ChartRenderPeriod)CommonMethods.ParseInt(rbTypeDetail.SelectedItem.Value); } DateTime?selectedDateFrom = null; DateTime?selectedDateTo = null; if (!DateEdit_OD.Date.Equals(DateTime.MinValue)) { selectedDateFrom = DateEdit_OD.Date; } if (!DateEdit_DO.Date.Equals(DateTime.MinValue)) { selectedDateTo = DateEdit_DO.Date; } GraphBinding instance = IncializeChartAndChartData(table, tRow, ccm, Enums.ChartRenderType.KOLICINA, period, false, selectedDateFrom, selectedDateTo); if (instance != null) { bindingCollection.Add(instance); } } else//we show only default type for selected categorie { foreach (var item in model.StrankaKategorija) { if (item.idKategorija == categorieID) { GraphBinding instance = IncializeChartAndChartData(table, tRow, item); if (instance != null) { bindingCollection.Add(instance); } } } } GetClientDataProviderInstance().SetClientFullModel(model);//we set new model because it might changed in the procees of filling data for charts (if there is chart data we change status to true on ClientCategorieModel item) GetClientDataProviderInstance().SetGraphBindingList(bindingCollection); }
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); }