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()));
            }
        }
        private void AddControlsToPanel(List <GraphBinding> collection)
        {
            HtmlTableRow tRow  = new HtmlTableRow();
            HtmlTable    table = new HtmlTable();

            table.Style.Add("width", "100%");

            foreach (GraphBinding item in collection)
            {
                UserControlGraph ucf2 = (UserControlGraph)LoadControl("~/UserControls/UserControlGraph.ascx");
                //ucf2.ID = model.KodaStranke + "_UserControlGraph_" + (collection.Count + 1).ToString();
                ucf2.btnPostClk          += ucf2_btnPostClk;
                ucf2.btnDeleteGraphClick += ucf2_btnDeleteGraphClick;
                ucf2.btnAddEventClick    += ucf2_btnAddEventClick;

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

                ChartsCallback.Controls.Add(table);
                ucf2.Period.SelectedIndex  = ucf2.Period.Items.FindByValue((item.obdobje >= 0 ? item.obdobje : 0).ToString()).Index;
                ucf2.Period.Visible        = btnDisplayAllCharts.Checked ? false : true;
                ucf2.Type.SelectedIndex    = ucf2.Type.Items.FindByValue((item.tip >= 0 ? item.tip : 0).ToString()).Index;
                ucf2.Type.Visible          = btnDisplayAllCharts.Checked ? false : true;
                ucf2.HeaderName.HeaderText = item.HeaderText;
                ucf2.HeaderLink.Visible    = false;
                ucf2.RenderChart.Text      = "Izriši " + item.HeaderText;
                ucf2.RenderChart.Visible   = btnDisplayAllCharts.Checked ? false : true;
                ucf2.CategorieID           = item.CategorieID;
                ucf2.YAxisTitle            = item.YAxisTitle;
                ucf2.ShowFromToDateFilteringUserControl = item.ShowFilterFromToDate;

                if (item.chartData != null)
                {
                    ucf2.CreateGraph(item.chartData);
                }
                else if (item.chartDataMultiplePanes != null & item.chartDataMultiplePanes.Count > 0)
                {
                    //rbTypeDetail.SelectedIndex = rbTypeDetail.Items.FindByValue((item.obdobje != null ? item.obdobje : 0).ToString()).Index;
                    ucf2.CreateGraphMultiPane(item.chartDataMultiplePanes);
                }
            }
        }
        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);
        }