internal static IEnumerable<SelectListItem> GetPageSizes(Int32[] pageSizes = null, Int32? currentSize = null)
 {
     if (pageSizes == null)
         pageSizes = TableModel.DefaultPageSizes;
     if (currentSize.HasValue && !pageSizes.Contains(currentSize.Value))
         pageSizes = pageSizes.Union(new[] { currentSize.Value }).OrderBy(p => p).ToArray();
     return pageSizes.Select(i => new SelectListItem { Text = i.ToString(), Value = i.ToString(), Selected = i == TableModel.DefaultPageSize });
 }
        private Int32 TranslateExtractSource( ExtractSource extractSource, Generation generation, bool femalesOnly, Int32[] passoverValues, DataTable dtImport )
        {
            Int32 gen1ReponseRecordsAddedCount = 0;
            LinksDataSet.tblVariableRow[] drsVariablesToTranslate = VariablesToTranslate(extractSource);
            _dsLinks.tblResponse.BeginLoadData();

            string subjectIDColumnName;
            string genderColumnName;
            switch ( generation ) {
                case Generation.Gen1:
                    subjectIDColumnName = Constants.Gen1SubjectIDColumn;
                    genderColumnName = Constants.Gen1GenderColumn;
                    break;
                case Generation.Gen2:
                    subjectIDColumnName = Constants.Gen2SubjectIDColumn;
                    genderColumnName = Constants.Gen2GenderColumn;
                    break;
                default:
                    throw new ArgumentOutOfRangeException("generation", generation, "The generation value was not recognized.");
            }

            foreach ( DataRow drImport in dtImport.Rows ) {
                GenderBothGenerations gender = (GenderBothGenerations)Convert.ToInt32(drImport[genderColumnName]);
                if ( !femalesOnly || gender == GenderBothGenerations.Female ) {
                    Int32 subjectID = Convert.ToInt32(drImport[subjectIDColumnName]);
                    Int32 subjectTag = Retrieve.SubjectTagFromSubjectIDAndGeneration(subjectID, generation, _dsLinks);
                    foreach ( LinksDataSet.tblVariableRow drVariable in drsVariablesToTranslate ) {
                        string columnName = drVariable.VariableCode;
                        LinksDataSet.tblResponseRow drResponse = _dsLinks.tblResponse.NewtblResponseRow();
                        drResponse.Generation = (byte)generation;
                        drResponse.SubjectTag = subjectTag;
                        drResponse.ExtendedID = GetExtendedID(subjectTag);
                        drResponse.SurveySource = drVariable.SurveySource;
                        drResponse.SurveyYear = drVariable.SurveyYear;
                        drResponse.Item = drVariable.Item; //if ( drResponse.Item == 13 ) Trace.Assert(true);
                        drResponse.Value = Convert.ToInt32(drImport[columnName]);

                        LinksDataSet.tblItemRow drItem = drVariable.tblItemRow;
                        if ( !(drItem.MinValue <= drResponse.Value && drResponse.Value <= drItem.MaxValue) )
                            throw new InvalidOperationException(string.Format("For Item '{0}', variable '{1}', the value '{2}' exceeded the bounds of [{3}, {4}].", drVariable.Item, drVariable.ID, drResponse.Value, drItem.MinValue, drItem.MaxValue));
                        if ( 0 <= drResponse.Value && drResponse.Value < drItem.MinNonnegative )
                            throw new InvalidOperationException(string.Format("For Item '{0}', variable '{1}', the value '{2}' dipped below the minimum nonnegative value of {3}.", drVariable.Item, drVariable.ID, drResponse.Value, drItem.MinNonnegative));
                        if ( !passoverValues.Contains(drResponse.Value) ) {
                            drResponse.LoopIndex = drVariable.LoopIndex;
                            _dsLinks.tblResponse.AddtblResponseRow(drResponse);
                            gen1ReponseRecordsAddedCount += 1;
                        }
                    }
                }
            }
            _dsLinks.tblResponse.EndLoadData();
            return gen1ReponseRecordsAddedCount;
        }
        /// <summary>
        ///  Fills an array of size N with the numbers from 1 to N in random order without duplicates
        /// </summary>
        /// <param name="arrayToFill">Array To fill</param>
        public static void RandomArrayFill(Int32[] arrayToFill)
        {
            int n = arrayToFill.Length;

            Int32 currentNum = Int32.MinValue;
            Random randNum = new Random();

            //Input cleaning
            for (int i = 0; i < n; i++)
            {
                arrayToFill[i] = Int32.MinValue;
            }

            //Array filled by rondom number form 1 to n
            for (int i = 0; i < n; i++)
            {
                currentNum = randNum.Next(0, n) + 1;

                while (arrayToFill.Contains(currentNum))
                {
                    currentNum = randNum.Next(0, n) + 1;
                }

                arrayToFill[i] = currentNum;

            }
        }