Example #1
0
 //
 //====================================================================================================
 //
 public override void GoFirst()
 {
     try {
         cs.goFirst(false);
     } catch (Exception ex) {
         LogController.logError(cp.core, ex);
         throw;
     }
 }
        //
        //=============================================================================
        // Normalize the Index page Columns, setting proper values for IndexColumn, etc.
        //=============================================================================
        //
        private static void NormalizeIndexColumns(CoreController core, int ContentID)
        {
            try {
                //
                int ColumnWidth      = 0;
                int ColumnWidthTotal = 0;
                int ColumnCounter    = 0;
                int IndexColumn      = 0;
                using (var csData = new CsModel(core)) {
                    csData.open("Content Fields", "(ContentID=" + ContentID + ")", "IndexColumn");
                    if (!csData.ok())
                    {
                        throw (new GenericException("Unexpected exception")); // Call handleLegacyClassErrors2("NormalizeIndexColumns", "Could not read Content Field Definitions")
                    }
                    else
                    {
                        //
                        // Adjust IndexSortOrder to be 0 based, count by 1
                        //
                        ColumnCounter = 0;
                        while (csData.ok())
                        {
                            IndexColumn = csData.getInteger("IndexColumn");
                            ColumnWidth = csData.getInteger("IndexWidth");
                            if ((IndexColumn == 0) || (ColumnWidth == 0))
                            {
                                csData.set("IndexColumn", 0);
                                csData.set("IndexWidth", 0);
                                csData.set("IndexSortPriority", 0);
                            }
                            else
                            {
                                //
                                // Column appears in Index, clean it up
                                //
                                csData.set("IndexColumn", ColumnCounter);
                                ColumnCounter    += 1;
                                ColumnWidthTotal += ColumnWidth;
                            }
                            csData.goNext();
                        }
                        if (ColumnCounter == 0)
                        {
                            //
                            // No columns found, set name as Column 0, active as column 1
                            //
                            csData.goFirst();
                            while (csData.ok())
                            {
                                switch (GenericController.toUCase(csData.getText("name")))
                                {
                                case "ACTIVE": {
                                    csData.set("IndexColumn", 0);
                                    csData.set("IndexWidth", 20);
                                    ColumnWidthTotal += 20;
                                    break;
                                }

                                case "NAME": {
                                    csData.set("IndexColumn", 1);
                                    csData.set("IndexWidth", 80);
                                    ColumnWidthTotal += 80;
                                    break;
                                }

                                default: {
                                    // do nothing
                                    break;
                                }
                                }
                                csData.goNext();
                            }
                        }
                        //
                        // ----- Now go back and set a normalized Width value
                        //
                        if (ColumnWidthTotal > 0)
                        {
                            csData.goFirst();
                            while (csData.ok())
                            {
                                ColumnWidth = csData.getInteger("IndexWidth");
                                ColumnWidth = encodeInteger((ColumnWidth * 100) / (double)ColumnWidthTotal);
                                csData.set("IndexWidth", ColumnWidth);
                                csData.goNext();
                            }
                        }
                    }
                }
                //
                // ----- now fixup Sort Priority so only visible fields are sorted.
                //
                using (var csData = new CsModel(core)) {
                    csData.open("Content Fields", "(ContentID=" + ContentID + ")", "IndexSortPriority, IndexColumn");
                    if (!csData.ok())
                    {
                        throw (new GenericException("Unexpected exception")); // Call handleLegacyClassErrors2("NormalizeIndexColumns", "Error reading Content Field Definitions")
                    }
                    else
                    {
                        //
                        // Go through all fields, clear Sort Priority if it does not appear
                        //
                        int SortValue     = 0;
                        int SortDirection = 0;
                        SortValue = 0;
                        while (csData.ok())
                        {
                            SortDirection = 0;
                            if (csData.getInteger("IndexColumn") == 0)
                            {
                                csData.set("IndexSortPriority", 0);
                            }
                            else
                            {
                                csData.set("IndexSortPriority", SortValue);
                                SortDirection = csData.getInteger("IndexSortDirection");
                                if (SortDirection == 0)
                                {
                                    SortDirection = 1;
                                }
                                else
                                {
                                    if (SortDirection > 0)
                                    {
                                        SortDirection = 1;
                                    }
                                    else
                                    {
                                        SortDirection = -1;
                                    }
                                }
                                SortValue += 1;
                            }
                            csData.set("IndexSortDirection", SortDirection);
                            csData.goNext();
                        }
                    }
                }
                return;
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
        }