private void GetAllRows()
    {
        string oCol = OwnerColumn;
        string oID  = OwnerID;

        if (func.IsAdminUser() || func.GetsAdvSecurityMethod(strTableName) == "2")
        {
            oCol = string.Empty;
            oID  = string.Empty;
        }
        {
            collection = controller.FetchAllPaged((PageNumber - 1) * PageSize, PageSize, OrderBy, oCol, oID);
            numrows    = controller.FetchAllCount(oCol, oID);
        }
    }
    private void GetSearchRows()
    {
        string oCol = OwnerColumn;
        string oID  = OwnerID;
        IDictionary <string, object> par = new Dictionary <string, object>();

        if (func.IsAdminUser() || func.GetsAdvSecurityMethod(strTableName) == "2")
        {
            oCol = string.Empty;
            oID  = string.Empty;
        }
        if (string.IsNullOrEmpty(SearchField))
        {
            if (par.Count > 0)
            {
                collection = controller.FetchByAllParameters(SearchOption, SearchFor, (PageNumber - 1) * PageSize, PageSize, OrderBy, OwnerColumn, OwnerID, par);
                numrows    = controller.FetchByAllParametersCount(SearchOption, SearchFor, oCol, oID, par);
            }
            else
            {
                collection = controller.FetchByAllParameters(SearchOption, SearchFor, (PageNumber - 1) * PageSize, PageSize, OrderBy, OwnerColumn, OwnerID);
                numrows    = controller.FetchByAllParametersCount(SearchOption, SearchFor, oCol, oID);
            }
        }
        else
        {
            if (par.Count > 0)
            {
                collection = controller.FetchByParameter(SearchField, SearchOption, SearchFor, (PageNumber - 1) * PageSize, PageSize, OrderBy, OwnerColumn, OwnerID, par);
                numrows    = controller.FetchByParameterCount(SearchField, SearchOption, SearchFor, oCol, oID, par);
            }
            else
            {
                collection = controller.FetchByParameter(SearchField, SearchOption, SearchFor, (PageNumber - 1) * PageSize, PageSize, OrderBy, OwnerColumn, OwnerID);
                numrows    = controller.FetchByParameterCount(SearchField, SearchOption, SearchFor, oCol, oID);
            }
        }
    }
    private void GetData()
    {
        bool bNoRecordsFirstPage = false;

        if (bNoRecordsFirstPage)
        {
            collection = new Data.KELOMPOKPENGGUNACollection();
            numrows    = 0;
        }
        else
        {
            if (Search == 0)
            {
                GetSearchRows();
            }
            else if (Search == 2)
            {
                GetAdvancedSearchRows();
            }
            else
            {
                GetAllRows();
            }
        }


        Data.PENGGUNAController PENGGUNA_detailController = new Data.PENGGUNAController();
        //foreach @TABLE.arrKeyFields as @tk
        ArrayList PENGGUNA_masterids = new ArrayList();

        for (int i = 0; i < collection.Count; ++i)
        {
            try{
                PENGGUNA_masterids.Add(collection[i].KODEKELOMPOK.ToString());
            }
            catch
            {
            }
        }
        PENGGUNA_detailCollection = PENGGUNA_detailController.FetchForDetails("KODEKELOMPOK", PENGGUNA_masterids.ToArray(), OwnerColumn, OwnerID);
        //	save SQL for use in "Export" and "Printer-friendly" pages
        //	select and display records
        if (allow_search)
        {
            //	 Pagination:
            if (numrows == 0)
            {
                rowsfound = false;
                message   = "No records found";
                IDictionary message_block = array();
                message_block["begin"] = "<span name=\"notfound_message\">";
                message_block["end"]   = "</span>";
                smarty.Add("message_block", message_block);
                smarty.Add("message", message);
            }
            else
            {
                rowsfound = true;
                int maxRecords = numrows;
                smarty.Add("records_found", numrows);
                int maxpages = (int)Math.Ceiling((double)maxRecords / PageSize);
                if (mypage > maxpages)
                {
                    mypage = maxpages;
                }
                if (mypage < 1)
                {
                    mypage = 1;
                }
                smarty.Add("page", mypage);
                smarty.Add("maxpages", maxpages);


                //	write pagination
                if (maxpages > 1)
                {
                    smarty.Add("pagination_block", true);
                    string pagination = string.Format("<script language=\"JavaScript\">WritePagination({0},{1});function GotoPage(nPageNumber)", mypage, maxpages);
                    pagination += "{window.location='KELOMPOKPENGGUNA_list.aspx?goto=' + nPageNumber;}</script>";
                    smarty.Add("pagination", pagination);
                }
            }

            //	hide colunm headers if needed
            int recordsonpage = numrows - (mypage - 1) * PageSize;
            if (recordsonpage > PageSize)
            {
                recordsonpage = PageSize;
            }
            colsonpage = 1;
            if (colsonpage > recordsonpage)
            {
                colsonpage = recordsonpage;
            }
            if (colsonpage < 1)
            {
                colsonpage = 1;
            }
        }
    }
    private void GetAdvancedSearchRows()
    {
        string[] asearchfield = this.Request.Form.GetValues("asearchfield[]");
        if (asearchfield == null)
        {
            asearchfield = Asearchfield;
        }
        IDictionary <string, object> par = new Dictionary <string, object>();
        string oCol = OwnerColumn;
        string oID  = OwnerID;

        if (func.IsAdminUser() || func.GetsAdvSecurityMethod(strTableName) == "2")
        {
            oCol = string.Empty;
            oID  = string.Empty;
        }
        if (par.Count > 0)
        {
            collection = controller.FetchForAdvancedSearch(asearchfield,
                                                           Asearchopt,
                                                           Asearchfor,
                                                           Asearchfor2,
                                                           Asearchnot,
                                                           (Asearchtype == "and"),
                                                           (PageNumber - 1) * PageSize,
                                                           PageSize,
                                                           OrderBy,
                                                           oCol, oID, par);

            numrows = controller.FetchForAdvancedSearchCount(asearchfield,
                                                             Asearchopt,
                                                             Asearchfor,
                                                             Asearchfor2,
                                                             Asearchnot,
                                                             (Asearchtype == "and"),
                                                             (PageNumber - 1) * PageSize,
                                                             PageSize,
                                                             OrderBy,
                                                             oCol, oID, par);
        }
        else
        {
            collection = controller.FetchForAdvancedSearch(asearchfield,
                                                           Asearchopt,
                                                           Asearchfor,
                                                           Asearchfor2,
                                                           Asearchnot,
                                                           (Asearchtype == "and"),
                                                           (PageNumber - 1) * PageSize,
                                                           PageSize,
                                                           OrderBy,
                                                           oCol, oID);

            numrows = controller.FetchForAdvancedSearchCount(asearchfield,
                                                             Asearchopt,
                                                             Asearchfor,
                                                             Asearchfor2,
                                                             Asearchnot,
                                                             (Asearchtype == "and"),
                                                             (PageNumber - 1) * PageSize,
                                                             PageSize,
                                                             OrderBy,
                                                             oCol, oID);
        }
    }