public IList <SurveyRecordInfo> GetList(int startRowIndexId, int maxNumberRows, int surveyId, int recordId) { Database database = DatabaseFactory.CreateDatabase(); DbCommand storedProcCommand = database.GetStoredProcCommand("PR_Common_GetList"); database.AddInParameter(storedProcCommand, "@StartRows", DbType.Int32); database.AddInParameter(storedProcCommand, "@PageSize", DbType.Int32); database.AddInParameter(storedProcCommand, "@SortColumn", DbType.String); database.AddInParameter(storedProcCommand, "@StrColumn", DbType.String); database.AddInParameter(storedProcCommand, "@Sorts", DbType.String); database.AddInParameter(storedProcCommand, "@Filter", DbType.String); database.AddInParameter(storedProcCommand, "@TableName", DbType.String); database.SetParameterValue(storedProcCommand, "@StartRows", startRowIndexId); database.SetParameterValue(storedProcCommand, "@PageSize", maxNumberRows); database.SetParameterValue(storedProcCommand, "@SortColumn", "RecordID"); database.SetParameterValue(storedProcCommand, "@StrColumn", "*"); database.SetParameterValue(storedProcCommand, "@Sorts", "DESC"); database.SetParameterValue(storedProcCommand, "@TableName", "PE_SurveyRecord" + surveyId); if (recordId > 0) { database.SetParameterValue(storedProcCommand, "@Filter", "RecordID = " + recordId); } database.AddOutParameter(storedProcCommand, "@Total", DbType.Int32, 10); IList <SurveyRecordInfo> list = new List <SurveyRecordInfo>(); using (NullableDataReader reader = new NullableDataReader(database.ExecuteReader(storedProcCommand))) { DataTable dataTable = new DataTable(); bool flag = false; while (reader.Read()) { if (!flag) { for (int i = 0; i < reader.FieldCount; i++) { if (reader.GetName(i).Contains("Q") || reader.GetName(i).Contains("Input")) { dataTable.Columns.Add(reader.GetName(i)); } } flag = true; } list.Add(SurveyRecordFromrdr(reader, dataTable)); } } this.m_TotalOfSurveyRecord = (int)database.GetParameterValue(storedProcCommand, "@Total"); return(list); }
private static SurveyRecordInfo SurveyRecordFromrdr(NullableDataReader rdr, DataTable dataTable) { SurveyRecordInfo info = new SurveyRecordInfo(); info.RecordId = rdr.GetInt32("RecordID"); info.SurveyId = rdr.GetInt32("SurveyID"); info.UserName = rdr.GetString("UserName"); info.IP = rdr.GetString("IP"); info.SubmitTime = rdr.GetDateTime("SubmitTime"); DataRow row = dataTable.NewRow(); for (int i = 0; i < rdr.FieldCount; i++) { if (rdr.GetName(i).Contains("Q") || rdr.GetName(i).Contains("Input")) { row[rdr.GetName(i)] = rdr[i]; } } dataTable.Rows.Add(row); info.Answer = dataTable; return(info); }