在API抓取数据后,仅显示从当前日期起90天内的结果
本文关键字:当前日期 90天 结果 显示 抓取 API 数据 | 更新日期: 2023-09-27 18:08:17
我把我的代码粘贴在下面。现在我完全失去了在哪里和什么代码插入,让我们说我想只显示数据,其中有一个开始日期内(日期今天- 90天)。请帮帮我。这件事我已经纠结了好几个星期了
顺便说一下,这段代码将在通过API从另一个程序获取数据后运行。
public DataTable FGetHasData(int iMode)
{
DataTable dtHASDataReturn = new DataTable();
DataTable dtHASData = new DataTable();
string sSorter = String.Empty;
if (iMode.Equals(0))
{
try
{
dtHASData = this.oHASData.RetrievePayments();
dtHASData.Columns[0].ColumnName = "Agency Code";
dtHASData.Columns[1].ColumnName = "Agency Name";
dtHASData.Columns[2].ColumnName = "Patient Code";
dtHASData.Columns[3].ColumnName = "Claim Code";
dtHASData.Columns[5].ColumnName = "Insurance Company Name";
dtHASData.Columns[6].ColumnName = "Amount";
dtHASData.Columns[7].ColumnName = "Document Number";
dtHASData.Columns[8].ColumnName = "To Print";
dtHASData.Columns[9].ColumnName = "Payment Type";
dtHASData.Columns[10].ColumnName = "Memo";
dtHASData.Columns[11].ColumnName = "Balance Type";
dtHASData.Columns[12].ColumnName = "RAP";
dtHASData.Columns[13].ColumnName = "Outlier";
sSorter = "periodstart";
}
catch (Exception e)
{
this.FLogTrans(e.Message.ToString());
return dtHASDataReturn;
}
}
else if (iMode.Equals(1))
{
try
{
dtHASData = this.oHASData.RetrieveRemittanceAdvices();
dtHASData.Columns[0].ColumnName = "Agency Code";
dtHASData.Columns[1].ColumnName = "Agency Name";
dtHASData.Columns[3].ColumnName = "Check Amount";
dtHASData.Columns[4].ColumnName = "Remittance Advice Memo";
dtHASData.Columns[5].ColumnName = "Insurance Company Name";
dtHASData.Columns[6].ColumnName = "Amount Paid";
dtHASData.Columns[7].ColumnName = "Net Reimbursement";
dtHASData.Columns[8].ColumnName = "Withheld";
dtHASData.Columns[9].ColumnName = "Document Number";
dtHASData.Columns[10].ColumnName = "To Print";
dtHASData.Columns[11].ColumnName = "Payment Type";
dtHASData.Columns[12].ColumnName = "Memo";
sSorter = "RADate";
}
catch (Exception e)
{
this.FLogTrans(e.Message.ToString());
return dtHASDataReturn;
}
}
DataView dvSorter = new DataView(dtHASData);
if (this.FConfigVarRetriever(4).Equals("1"))
{
int iRowsMany = int.Parse(this.FConfigVarRetriever(5));
dvSorter.Sort = sSorter + " desc";
dtHASData = dvSorter.ToTable();
if (iMode.Equals(0))
{
dtHASData.Columns[4].ColumnName = "Period Start";
}
else if (iMode.Equals(1))
{
dtHASData.Columns[2].ColumnName = "Remittance Advice Date";
}
dtHASDataReturn = dtHASData.AsEnumerable().Take(iRowsMany).CopyToDataTable();
}
else if (this.FConfigVarRetriever(4).Equals("2"))
{
dvSorter.RowFilter = sSorter + " >= '" + this.FConfigVarRetriever(6) + "'";
dvSorter.Sort = sSorter + " desc";
dtHASData = dvSorter.ToTable();
if (iMode.Equals(0))
{
dtHASData.Columns[4].ColumnName = "Period Start";
}
else if (iMode.Equals(1))
{
dtHASData.Columns[2].ColumnName = "Remittance Advice Date";
}
dtHASDataReturn = dtHASData;
}
return dtHASDataReturn;
}
您说它作为IEnumerable
进入,我将假设该类具有以下结构:
public class Record
{
DateTime StartDate {get; set;}
//A whole bunch of other stuff
}
在这种情况下,我们将使用Where
查询来进行过滤,并结合一些DateTime
计算和比较:
IEnumerable<Record> results = original.Where(r => r.StartDate >= DateTime.Now.AddDays(-90));
你可以在你有"原始"的地方使用"结果",所以你只对过滤后的数据进行操作。
对注释作出回应:
你可以把它放在任何你想要过滤发生的地方。我会在你实际使用它之前马上把它放上去:
dtHASData = dtHASData.Where(....); //Add here
DataView dvSorter = new DataView(dtHASData);
它是作为一个数组来的,这些是IEnumerable
,所以LINQ扩展对它们工作。