private bool FilteringByColumnIsActive()
 {
     if (!_grid.AllowFilteringByColumn && !_grid.MasterTableView.AllowFilteringByColumn)
     {
         return false;
     }
     // Se abilitato cerco se c'è almeno una colonna con filtraggio abilitato
     foreach (object obj in _grid.Columns)
     {
         GridEditableColumn column = obj as GridEditableColumn;
         if (column != null && column.SupportsFiltering())
         {
             return true;
         }
     }
     return false;
 }
        protected void rgLedger_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
        {
            if (e.Item.ItemType == GridItemType.Header)
            {
                Balance = 0;
            }
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem)
            {
                DayCarePL.LedgerProperties objLedger = e.Item.DataItem as DayCarePL.LedgerProperties;
                Label        lblBalance      = e.Item.FindControl("lblBalance") as Label;
                TextBox      txtDebit        = e.Item.FindControl("txtDebit") as TextBox;
                TextBox      txtCredit       = e.Item.FindControl("txtCredit") as TextBox;
                Label        lblOperation    = e.Item.FindControl("lblOperation") as Label;
                Label        lblPaymentLabel = e.Item.FindControl("lblPaymentLabel") as Label;
                Label        lblChargesLable = e.Item.FindControl("lblChargesLable") as Label;
                DropDownList ddlPayment      = e.Item.FindControl("ddlPayment") as DropDownList;
                DropDownList ddlCategory     = e.Item.FindControl("ddlCategory") as DropDownList;
                //For Edit
                RadDatePicker rdpDate = e.Item.FindControl("rdpDate") as RadDatePicker;
                Common.BindChargeCode(ddlCategory);
                RadioButton rdbPayment  = e.Item.FindControl("rdbPayment") as RadioButton;
                RadioButton rdbDiscount = e.Item.FindControl("rdbDiscount") as RadioButton;
                //Label lblTransactionDate1=e.Item.FindControl("lblTransactionDate1") as Label;
                //GridEditableColumn edSelect1 = e.Item.OwnerTableView.Columns[12] as GridEditableColumn;
                //end
                GridEditableColumn edSelect = e.Item.OwnerTableView.Columns[1] as GridEditableColumn;
                edSelect.Display = true;
                if (objLedger != null)
                {
                    lblPaymentLabel.Visible    = true;
                    lblChargesLable.Visible    = true;
                    ViewState["ChildFamilyId"] = objLedger.ChildFamilyId;

                    if (objLedger.TransactionDate != null)
                    {
                        rdpDate.SelectedDate = objLedger.TransactionDate;
                    }
                    if (objLedger.AllowEdit)
                    {
                        if (objLedger.PaymentId != null)
                        {
                            //edSelect = e.Item.OwnerTableView.Columns[1] as GridEditableColumn;
                            lblPaymentLabel.Visible = false;
                            lblChargesLable.Visible = false;
                            //edSelect.Display = false;
                            rdbPayment.Style.Add("display", "none");
                            rdbDiscount.Style.Add("display", "none");
                            ddlPayment.SelectedValue = objLedger.PaymentMethodId.ToString();
                        }
                        else if (objLedger.PaymentMethodId != null)
                        {
                            rdbPayment.Checked       = true;
                            rdbDiscount.Checked      = false;
                            ddlPayment.SelectedValue = objLedger.PaymentMethodId.ToString();
                        }
                        else if (objLedger.ChargeCodeCategoryId != null)
                        {
                            rdbPayment.Checked        = false;
                            rdbDiscount.Checked       = true;
                            ddlCategory.SelectedValue = objLedger.ChargeCodeCategoryId.ToString();
                        }
                        else
                        {
                            rdbPayment.Checked  = true;
                            rdbDiscount.Checked = false;
                        }

                        if (rdbPayment.Checked)
                        {
                            //edSelect.Display = true;
                            ddlPayment.Style.Add("display", "block");
                            ddlCategory.Style.Add("display", "none");
                            txtDebit.Enabled = false;

                            //itm["Select"].Visible = true;
                            //itm["Select"].Controls[1].Visible = true;
                            // itm["operation"].Visible = true;
                        }
                        else
                        {
                            //edSelect.Display = true;
                            ddlCategory.Style.Add("display", "block");
                            ddlPayment.Style.Add("display", "none");
                        }
                    }
                    else
                    {
                        //edSelect = e.Item.OwnerTableView.Columns[1] as GridEditableColumn;
                        lblPaymentLabel.Visible = false;
                        lblChargesLable.Visible = false;
                        //edSelect.Display = false;
                        rdpDate.Enabled = false;
                        if (objLedger.TransactionDate != null)
                        {
                            rdpDate.SelectedDate = objLedger.TransactionDate;
                        }
                        ddlCategory.Visible = false;
                        ddlPayment.Visible  = false;
                        rdbPayment.Visible  = false;
                        rdbDiscount.Visible = false;
                        //itm["Select"].Visible = false;
                        // itm["operation"].Visible = false;
                    }

                    //if (objLedger.PaymentMethodId != null)
                    //{
                    //    switch (objLedger.PaymentMethodId)
                    //    {
                    //        case 0:
                    //            {

                    //                ddlPayment.SelectedValue = "Cash";
                    //                break;
                    //            }
                    //        case 1:
                    //            {
                    //                ddlPayment.SelectedValue = "Check";
                    //                break;
                    //            }
                    //        case 2:
                    //            {
                    //                ddlPayment.SelectedValue = "Credit";
                    //                break;
                    //            }
                    //    }
                    //}
                    //else if (objLedger.ChargeCodeCategoryId != null)
                    //{
                    //    ddlCategory.SelectedValue = objLedger.ChargeCodeCategoryId.ToString();
                    //}
                    if (objLedger.Debit > 0)
                    {
                        Balance += objLedger.Debit;
                    }
                    else
                    {
                        Balance -= objLedger.Credit;
                        YTDPay  += objLedger.Credit;
                    }
                    lblBalance.Text = Balance.ToString();
                    //txtBalance.Text = Balance.ToString();
                    //txtYTDPay.Text = YTDPay.ToString();
                }
            }
            if (e.Item.ItemType == GridItemType.EditItem)
            {
                GridEditableItem           itm       = e.Item as GridEditableItem;
                DayCarePL.LedgerProperties objLedger = e.Item.DataItem as DayCarePL.LedgerProperties;
                RadDatePicker rdpDate     = e.Item.FindControl("rdpDate") as RadDatePicker;
                DropDownList  ddlPayment  = e.Item.FindControl("ddlPayment") as DropDownList;
                DropDownList  ddlCategory = e.Item.FindControl("ddlCategory") as DropDownList;
                Common.BindChargeCode(ddlCategory);
                RadioButton rdbPayment  = e.Item.FindControl("rdbPayment") as RadioButton;
                RadioButton rdbDiscount = e.Item.FindControl("rdbDiscount") as RadioButton;
                TextBox     txtDebit    = e.Item.FindControl("txtDebit") as TextBox;
                //Label lblTransactionDate1=e.Item.FindControl("lblTransactionDate1") as Label;
                GridEditableColumn edSelect1 = e.Item.OwnerTableView.Columns[12] as GridEditableColumn;
                //edSelect1.Display = false;
                if (objLedger != null)
                {
                    if (objLedger.TransactionDate != null)
                    {
                        rdpDate.SelectedDate = objLedger.TransactionDate;
                    }
                    if (objLedger.AllowEdit)
                    {
                        if (objLedger.PaymentId != null)
                        {
                            GridEditableColumn edSelect = e.Item.OwnerTableView.Columns[3] as GridEditableColumn;
                            edSelect.Display = false;
                            rdbPayment.Style.Add("display", "none");
                            rdbDiscount.Style.Add("display", "none");
                            ddlPayment.SelectedValue = objLedger.PaymentMethodId.ToString();
                        }
                        else if (objLedger.PaymentMethodId != null)
                        {
                            rdbPayment.Checked       = true;
                            rdbDiscount.Checked      = false;
                            ddlPayment.SelectedValue = objLedger.PaymentMethodId.ToString();
                        }
                        else if (objLedger.ChargeCodeCategoryId != null)
                        {
                            rdbPayment.Checked        = false;
                            rdbDiscount.Checked       = true;
                            ddlCategory.SelectedValue = objLedger.ChargeCodeCategoryId.ToString();
                        }
                        else
                        {
                            rdbPayment.Checked  = true;
                            rdbDiscount.Checked = false;
                        }

                        if (rdbPayment.Checked)
                        {
                            ddlPayment.Style.Add("display", "block");
                            ddlCategory.Style.Add("display", "none");
                            txtDebit.Enabled = false;

                            //itm["Select"].Visible = true;
                            //itm["Select"].Controls[1].Visible = true;
                            // itm["operation"].Visible = true;
                        }
                        else
                        {
                            ddlCategory.Style.Add("display", "block");
                            ddlPayment.Style.Add("display", "none");
                        }
                    }
                    else
                    {
                        GridEditableColumn edSelect = e.Item.OwnerTableView.Columns[3] as GridEditableColumn;
                        edSelect.Display = false;
                        rdpDate.Enabled  = false;
                        if (objLedger.TransactionDate != null)
                        {
                            rdpDate.SelectedDate = objLedger.TransactionDate;
                        }
                        ddlCategory.Visible = false;
                        ddlPayment.Visible  = false;
                        rdbPayment.Visible  = false;
                        rdbDiscount.Visible = false;
                        //itm["Select"].Visible = false;
                        // itm["operation"].Visible = false;
                    }
                }
                else
                {
                    if (rdbPayment.Checked)
                    {
                        ddlCategory.Style.Add("display", "none");
                        txtDebit.Enabled     = false;
                        rdpDate.SelectedDate = DateTime.Now;
                        rdbPayment.TextAlign = TextAlign.Right;
                    }
                }
            }
        }
        public static void UtworzKolumny(List <GridViewColumn> kolumny, RadGrid radGrid, bool isPostBack, Page page)
        {
            foreach (var opisKolumny in kolumny)
            {
                GridEditableColumn column = null;
                if (opisKolumny.ColumnType == GridColumnType.CheckboxColumn)
                {
                    var cbColumn = new GridCheckBoxColumn();
                    cbColumn.DataField = opisKolumny.Name;


                    column = cbColumn;
                }
                else if (opisKolumny.ColumnType == GridColumnType.BoundColumn)
                {
                    var bColumn = new GridBoundColumn();
                    bColumn.DataField = opisKolumny.Name;
                    bColumn.Aggregate = (Telerik.Web.UI.GridAggregateFunction)opisKolumny.Aggregate;
                    if (string.IsNullOrEmpty(opisKolumny.DataTypeName) == false)
                    {
                        bColumn.DataType = Type.GetType(opisKolumny.DataTypeName);
                    }
                    if (bColumn.Aggregate == GridAggregateFunction.Count)
                    {
                        bColumn.FooterText = "Ilość: ";
                    }
                    bColumn.DataFormatString = opisKolumny.DataFormatString;

                    column = bColumn;
                }
                else if (opisKolumny.ColumnType == GridColumnType.EnumColumn)
                {
                    var templateColumn = new GridTemplateColumn();
                    templateColumn.DataField = opisKolumny.Name;
                    templateColumn.Aggregate = (Telerik.Web.UI.GridAggregateFunction)opisKolumny.Aggregate;
                    if (string.IsNullOrEmpty(opisKolumny.DataTypeName) == false)
                    {
                        templateColumn.DataType = Type.GetType(opisKolumny.DataTypeName);
                    }
                    var typEnuma = Type.GetType(opisKolumny.DataTypeName);
                    templateColumn.EditItemTemplate = new EnumEditColumnTemplate(opisKolumny.Name, typEnuma);
                    templateColumn.ItemTemplate     = new EnumItemColumnTemplate(opisKolumny.Name);
                    templateColumn.FilterTemplate   = new EnumFilterColumnTemplate(opisKolumny.Name, typEnuma, page);
                    column = templateColumn;
                }


                column.UniqueName = opisKolumny.Name;

                column.HeaderText         = opisKolumny.GetReadableName();
                column.HeaderTooltip      = opisKolumny.ToolTip;
                column.FilterControlWidth = new Unit("80px");
                column.ReadOnly           = opisKolumny.ReadOnly;

                //boundColumn.ColumnEditorID = opisKolumny.ColumnEditorID;
                if (opisKolumny.Width != null)
                {
                    column.HeaderStyle.Width = new Unit(opisKolumny.Width.ToString());
                }
                //if (opisKolumny.NazwaTypuPola == "Decimal")
                //{

                //}
                if (opisKolumny.ShowColumnFilter)
                {
                    column.AutoPostBackOnFilter  = true;
                    column.CurrentFilterFunction = (Telerik.Web.UI.GridKnownFunction)opisKolumny.FilterFunction;
                    column.ShowFilterIcon        = false;

                    if (isPostBack == false)
                    {
                        column.CurrentFilterValue = opisKolumny.FilterDefaultValue;
                        if (string.IsNullOrEmpty(opisKolumny.FilterDefaultValue) == false)
                        {
                            var filtr = "([" + opisKolumny.Name + "] = '" + opisKolumny.FilterDefaultValue + "')";

                            if (string.IsNullOrEmpty(radGrid.MasterTableView.FilterExpression))
                            {
                                radGrid.MasterTableView.FilterExpression = filtr;
                            }
                            else
                            {
                                radGrid.MasterTableView.FilterExpression = radGrid.MasterTableView.FilterExpression +
                                                                           " AND " +
                                                                           filtr;
                            }
                        }
                    }
                }
                else
                {
                    column.AllowFiltering = false;
                }

                radGrid.MasterTableView.Columns.Add(column);
            }
        }