我经常调用此方法,但是当我首先调用totalNumberofRecords方法时,下次我调用此方法时,应维护totototalnumberofrecords。
public static EGResponse<List<Assets>> GetPlantAttributes(string templateId, string searchColumn, string searchValue, string pageCount)
{
string query = string.Empty;
//int totalNumberOfRecords = 0;
List<Assets> summary = null;
DateTime currentdate=DateTime.Now;
EGResponse<List<Assets>> resp = new EGResponse<List<Assets>>(EGResult.Failure, null, EGDataLayer.CommonUtility.OPERATIONFAIL);
int totalNumberOfRecords;
if (!string.IsNullOrEmpty(searchColumn) && searchColumn == "Empty")
{
totalNumberOfRecords = 0;
pageCount = "0";
}
else
{
////if (!string.IsNullOrEmpty(searchValue) && searchValue == "Empty" && totalNumberOfRecords<0)
//{
// totalNumberOfRecords = GetCountOfPlantAttributes(searchColumn, searchValue);
//}
//totalNumberOfRecords = GetCountOfPlantAttributes(searchColumn, searchValue);
if (pageCount.ToLower() == "first" && !string.IsNullOrEmpty(searchValue) )
{
pageCount = "0";
totalNumberOfRecords = GetCountOfPlantAttributes(searchColumn, searchValue);
}
if (pageCount.ToLower() == "last")
{
//totalNumberOfRecords = GetCountOfPlantAttributes(searchColumn, searchValue);
pageCount = (totalNumberOfRecords / 20).ToString();
}
}
getCountofplantAttributes的方法将返回DataTable中的totalNumberOfRecords。
下次我调用此方法时,应维护 tototalnumberofRecords。
否,这是不可能的,因为它是一个局部变量(该方法的局部变量(,如下代码所示,一旦方法执行结束后,它将不在范围。如果要保留它,请使用某种存储机制。.在扁平文件,db或缓存等中...再次,如果是任何Web应用程序,则可以使用session
,但不确定您的帖子
public static EGResponse<List<Assets>> GetPlantAttributes(string templateId, string searchColumn, string searchValue, string pageCount)
{
string query = string.Empty;
.....
int totalNumberOfRecords;
如果您完全确定自己的方法不会从多个线程中调用,同时您可以将totalNumberofRecords移到方法外作为静态字段。