/// <summary>
        /// Udate existing ClientCategorie in client model session
        /// </summary>
        /// <param name="model">Existing clientCategorie instance to update</param>
        /// <returns>Returns true if updating was succesfull. Otherwise false.</returns>
        public bool UpdateCategorieToClientModelSession(ClientCategorieModel model)
        {
            ClientFullModel fullModel = GetFullModelFromClientModel();

            if (fullModel != null)
            {
                var record = fullModel.StrankaKategorija.Where(sK => sK.idStrankaKategorija == model.idStrankaKategorija).FirstOrDefault();
                if (record != null)
                {
                    int index = fullModel.StrankaKategorija.IndexOf(record);
                    if (index != -1)
                    {
                        fullModel.StrankaKategorija[index] = model;
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }

                AddValueToSession(Enums.ClientSession.ClientModel, fullModel);

                return(true);
            }
            return(false);
        }
        protected void btnDisplayAllCharts_Click(object sender, EventArgs e)
        {
            RemoveSession(Enums.ChartSession.GraphCollection);
            if (btnDisplayAllCharts.Checked)
            {//Display all type charts
                btnDisplayAllCharts.Text     = "Skrij vse tipe";
                btnDisplayAllCharts.ImageUrl = "~/Images/DisplayAllChartsPressed.png";
                filteringBlock.Style.Add("display", "flex");
                ClientCategorieModel ccm = model.StrankaKategorija.Where(kat => kat.idKategorija == categorieID).FirstOrDefault();
                string catName           = "";
                if (ccm != null)
                {
                    catName = ccm.Kategorija.Naziv;
                }

                rbTypeDetail.SelectedIndex = rbTypeDetail.Items.FindByValue(((int)Enums.ChartRenderPeriod.MESECNO).ToString()).Index;
                GetClientDataProviderInstance().SetSelectedPeriod_AllTypesDisplay(CommonMethods.ParseInt(rbTypeDetail.SelectedItem.Value));
            }
            else
            {//Hide all chart types
                btnDisplayAllCharts.Text     = "Prikaži vse tipe";
                btnDisplayAllCharts.ImageUrl = "~/Images/DisplayAllCharts.png";
                filteringBlock.Style.Add("display", "none");
            }
        }
        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);
        }
        /// <summary>
        /// Add new ClientCategorie instance to client model session
        /// </summary>
        /// <param name="model">New clientCategorie instance to add</param>
        /// <returns>Returns true if adding was succesfull. Otherwise false.</returns>
        public bool AddCategorieToClientModelSession(ClientCategorieModel model)
        {
            ClientFullModel fullModel = GetFullModelFromClientModel();

            if (fullModel != null)
            {
                fullModel.StrankaKategorija.Add(model);
                AddValueToSession(Enums.ClientSession.ClientModel, fullModel);

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Delete ClientCateogire instance from client model session and add new data to session.
        /// </summary>
        /// <param name="planID">Categorie ID</param>
        /// <param name="clientID">Client ID</param>
        /// <returns>Return true if delete is succesfull. Otherwise false.</returns>
        public bool DeleteCategorieFromClientModelSession(int clientCategorieID, int clientID)
        {
            ClientCategorieModel model = GetCategorieFromClientModelSession(clientCategorieID, clientID);
            ClientFullModel      tmp   = GetFullModelFromClientModel();

            if (model != null && tmp != null)
            {
                bool isDeleted = tmp.StrankaKategorija.Remove(model);
                AddValueToSession(Enums.ClientSession.ClientModel, tmp);

                return(isDeleted);
            }
            return(false);
        }
        private bool AddOrEditEntityObject(bool add = false)
        {
            if (add)
            {
                model = new ClientCategorieModel();

                model.idStrankaKategorija = 0;
                model.idStranka           = clientID;
                model.tsIDOseba           = PrincipalHelper.GetUserPrincipal().ID;
                model.ts = DateTime.Now;
            }
            else if (model == null && !add)
            {
                model = GetClientDataProviderInstance().GetCategorieFromClientModelSession(clientCategorieID, clientID);
            }

            int selectedValue = CommonMethods.ParseInt(ComboBoxKategorije.Value.ToString());

            if (selectedValue <= 0)
            {
                return(false);
            }
            else
            {
                model.idKategorija = selectedValue;
            }


            ClientCategorieModel newModel = CheckModelValidation(GetDatabaseConnectionInstance().SaveClientCategorieChanges(model));

            if (newModel != null)//If new record is added we need to refresh aspxgridview. We add new record to session model.
            {
                if (add)
                {
                    return(GetClientDataProviderInstance().AddCategorieToClientModelSession(newModel));
                }
                else
                {
                    return(GetClientDataProviderInstance().UpdateCategorieToClientModelSession(newModel));
                }
            }
            else
            {
                return(false);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         ComboBoxKategorije.DataBind();
         if (action == (int)Enums.UserAction.Edit || action == (int)Enums.UserAction.Delete)
         {
             if (clientCategorieID > 0 && SessionHasValue(Enums.ClientSession.ClientModel))
             {
                 model = GetClientDataProviderInstance().GetCategorieFromClientModelSession(clientCategorieID, clientID);
                 FillForm();
             }
         }
         else if (action == (int)Enums.UserAction.Add)//acion ADD
         {
             txtIdStranke.Text = clientID.ToString();
             ComboBoxKategorije.SelectedIndex = 0;
         }
         UserActionConfirmBtnUpdate(btnConfirmPopUp, action, true);
     }
     Initialize();
 }
        public WebResponseContentModel <ClientCategorieModel> SaveClientCategorieChanges(ClientCategorieModel newData)
        {
            WebResponseContentModel <ClientCategorieModel> model = new WebResponseContentModel <ClientCategorieModel>();

            try
            {
                model.Content = newData;
                model         = PostWebRequestData <WebResponseContentModel <ClientCategorieModel> >(WebServiceHelper.SaveClientCategorieChanges(), "post", model);
            }
            catch (Exception ex)
            {
                model.ValidationErrorAppSide = ConcatenateExceptionMessage(ex);
            }

            return(model);
        }
        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);
        }