using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using System.Linq;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        int itemCount = (sender as RadGrid).MasterTableView.GetItems(GridItemType.Item).Length + (sender as RadGrid).MasterTableView.GetItems(GridItemType.AlternatingItem).Length;
        foreach (GridItem item in (sender as RadGrid).Items)
        {
            if (item is GridDataItem && item.ItemIndex < itemCount - 1)
            {
                ((item as GridDataItem)["ProductID"] as TableCell).Controls.Add(new LiteralControl("<table style='display:none;'><tr><td>"));
            }
        }
    }

    protected void RadGrid1_Init(object sender, System.EventArgs e)
    {
        //GridFilterMenu menu = RadGrid1.FilterMenu;
        //int i = 0;
        //while (i < menu.Items.Count)
        //{
        //    if (menu.Items[i])
        //    {
        //        menu.Items.RemoveAt(i);
                
        //    }
        //    else
        //    {
        //        i++;
        //    }
        //}
    }

    int totalUnitsInStock, totalUnitsOnOrder;
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            int unitsInStock = int.Parse(dataItem["UnitsInStock"].Text);
            totalUnitsInStock += unitsInStock;
            int unitsOnOrder = int.Parse(dataItem["UnitsOnOrder"].Text);
            totalUnitsOnOrder += unitsOnOrder;
        }
        if (e.Item is GridFooterItem)
        {
            GridFooterItem footerItem = e.Item as GridFooterItem;
            footerItem["UnitsInStock"].Text = "total: " + totalUnitsInStock.ToString();
            footerItem["UnitsOnOrder"].Text = "total: " + totalUnitsOnOrder.ToString();
        }
    }
    protected void RadGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DataTable dt = new DataTable();
        DataRow dr;
        int rowsNum = 130;
        string[][] colsInfo = {
        new string[] { "ProdPlanDocHeaderId", "number" },
        new string[] { "MrkDocHeaderId", "number" },
        new string[] { "ProdPlanStatus", "string" },
        new string[] { "UretimMuhendisi", "string" },
        new string[] { "Custom4", "string" },
        new string[] { "Custom5", "string" },
        new string[] { "Custom6", "string" },
        new string[] { "Custom7", "string" },
        new string[] { "Custom8", "string" },
        new string[] { "Custom9", "string" },
        //new string[] { "Custom10", "string" },
        //new string[] { "Custom11", "string" },
        //new string[] { "Custom12", "string" },
        //new string[] { "Custom13", "string" },
        //new string[] { "Custom14", "string" },
        //new string[] { "Custom15", "string" },
        //new string[] { "Custom16", "string" },
        //new string[] { "Custom17", "string" },
        //new string[] { "Custom18", "string" },
        //new string[] { "Custom19", "string" },
        //new string[] { "Custom20", "string" },
        //new string[] { "Custom21", "string" },
        //new string[] { "Custom22", "string" },
        //new string[] { "Custom23", "string" },
        //new string[] { "Custom24", "string" },
        //new string[] { "Custom25", "string" },
        //new string[] { "Custom26", "string" },
        //new string[] { "Custom27", "string" },
        //new string[] { "Custom28", "string" },
        //new string[] { "Custom29", "string" },
        //new string[] { "Custom30", "string" },
        //new string[] { "OrderDate", "date" },
        //new string[] { "DueDate", "date" },
        //new string[] { "ShipDate", "date" },
        //new string[] { "CreditCardApprovalCode", "number" },
        //new string[] { "SubTotal", "number" },
        //new string[] { "TaxAmt", "number" },
        //new string[] { "Freight", "number" },
        //new string[] { "Status", "string" },
        //new string[] { "PurchaseOrderNumber", "number" },
        //new string[] { "ModifiedDate", "date" }


    };

        for (int i = 0; i < colsInfo.Length; i++)
        {
            switch (colsInfo[i][1])
            {
                case "string":
                    dt.Columns.Add(new DataColumn(colsInfo[i][0], typeof(String)));
                    break;
                case "number":
                    dt.Columns.Add(new DataColumn(colsInfo[i][0], typeof(Int32)));
                    break;
                case "date":
                    dt.Columns.Add(new DataColumn(colsInfo[i][0], typeof(DateTime)));
                    break;
                case "bool":
                    dt.Columns.Add(new DataColumn(colsInfo[i][0], typeof(Boolean)));
                    break;
                default:
                    break;
            }
        }

        for (int j = -10; j <= rowsNum; j++)
        {
            dr = dt.NewRow();

            for (int k = 0; k < colsInfo.Length; k++)
            {
                switch (colsInfo[k][1])
                {
                    case "string":
                        dr[colsInfo[k][0]] = String.Format("{0} Row{1}", colsInfo[k][0], j);
                        break;
                    case "number":
                        dr[colsInfo[k][0]] = j;
                        break;
                    case "date":
                        dr[colsInfo[k][0]] = DateTime.Now;
                        break;
                    case "bool":
                        dr[colsInfo[k][0]] = j % 2 == 1 ? true : false;
                        break;
                    default:
                        break;
                }
            }
            dt.Rows.Add(dr);
        }

        (sender as RadGrid).DataSource = dt;
    }
}
