Public List GetKPIReport
(bool? PurchaseStatus List Both facs, List The status, List Types, string searchKey, string startDate, string endDate)
{
Using (SRMDatabaseEntities entity=new SRMDatabaseEntities ())
{
DateTime start=string. IsNullOrEmpty (startDate)? DateTime. MinValue: Convert. ToDateTime (startDate);
DateTime end=string. IsNullOrEmpty (endDate)? DateTime. MaxValue: Convert. ToDateTime (endDate);
Var model=the from p in the entity. KPISupplierReport
Join the q in the entity. SupplierInfoReport on p. upplierCode equals q.S upplierCode
The join j in the entity SystemUser on p.C reatedUser. The ToUpper () equals j.U serId. The ToUpper () into temp
The from k in temp. DefaultIfEmpty ()
Where
(
Status. The Contains (p. tatus)
& & Both facs. The Contains (p.F actoryCode)
& & Types. The Contains (p.R eportCycle)
& & (purchaseStatus==null | | q.P urchaseStatus==purchaseStatus)
& & (p.C reatedDate & gt; Start & amp; & P.C reatedDate & lt; End)
& &
(string) IsNullOrEmpty (searchKey)
| | p. upplierCode. The Contains (searchKey)
| | p. upplierName. The Contains (searchKey)
| | p.R eportNumber. The Contains (searchKey)
| | k.U serName. The Contains (searchKey)
| | p.C reatedUser. The Contains (searchKey)
| | p.R eportName. The Contains (searchKey)
)
)
Orderby p.I d item first-just
Select new
{
Q.P urchaseStatus,
P.I d,
P.A pprovalStatus,
P.C reatedDate,
K.U serName,
P.F actoryCode,
P.F actoryName,
P.F eedbackDate,
P.K PIMonthEnd,
P.K PIMonthStart,
P.K PIYear,
P. aterielCode,
P.R eportCycle,
P.R eportName,
P.R eportNumber,
P. core,
P. endDate,
P. tatus,
P. upplierCode,
P. upplierName
};
Var modelList=model. ToList ();
Var numberList=modelList. Select (I=& gt; I.R eportNumber). ToList ();
Var itemList=entity. KPISupplierItem. Where (I=& gt; NumberList. The Contains (i.R eportNumber)). ToList ();
//the above section access are quickly, is this part must carry on the transformation,
//write the detail in the corresponding column at the end of the line, test with 10000 records, this is about a 2 minute foreach,
//in addition to modify the timeout time constraints, there another way?
List ReportList=new List (a);
KPISupplierReportShow rshow;
List TempItemList;
KPISupplierItem tempItem;
The foreach (var kpi in modelList)
{
Rshow=new KPISupplierReportShow ()
{
PurchaseStatus=kpi. PurchaseStatus? "Activate", "suspend",
ApprovalStatus=EnumHelper. GetEnumDescription (EnumHelper. GetEnum (kpis. ApprovalStatus)),
CreatedDate=kpi. CreatedDate. ToString (" yyyy - MM - dd "),
CreatedUser=kpi. The UserName,
FactoryCode=kpi FactoryCode,
FactoryName=kpi FactoryName,
FeedbackDate=kpi FeedbackDate,
Id=kpi. Id,
KPIMonthEnd=kpi KPIMonthEnd,
KPIMonthStart=kpi KPIMonthStart,
KPIYear=kpi KPIYear,
MaterielCode=kpi MaterielCode,
ReportCycle=kpi ReportCycle,
ReportName=kpi ReportName,
ReportNumber=kpi ReportNumber,
Score=kpi Score,
SendDate=kpi SendDate,
Status=EnumHelper. GetEnumDescription (EnumHelper. GetEnum (kpi) Status),
SupplierCode=kpi SupplierCode,
SupplierName=kpi. SupplierName
};
TempItemList=itemList. Where (t=& gt; T.R eportNumber==kpi. ReportNumber). ToList ();
//quality
TempItem=tempItemList. FirstOrDefault (t=& gt; T.T itle. The Contains (KPISupplierReportShow. Key1));
If (tempItem!=null)
{
Rshow. Penalty1=0 - (tempItem TargetScore - (tempItem. Score. HasValue? TempItem. Score. Value: 0));
Rshow. PenaltyRemark1=tempItem. "Reason;
}
//delivery
TempItem=tempItemList. FirstOrDefault (t=& gt; T.T itle. The Contains (KPISupplierReportShow. Key2));
If (tempItem!=null)
{
Rshow. Penalty2=0 - (tempItem TargetScore - (tempItem. Score. HasValue? TempItem. Score. Value: 0));
Rshow. PenaltyRemark2=tempItem. "Reason;
}
//service
TempItem=tempItemList. FirstOrDefault (t=& gt; T.T itle. The Contains (KPISupplierReportShow. Key3));
If (tempItem!=null)
{
Rshow. Penalty3=0 - (tempItem TargetScore - (tempItem. Score. HasValue? TempItem. Score. Value: 0));
Rshow. PenaltyRemark3=tempItem. "Reason;
}
//additional freight
TempItem=tempItemList. FirstOrDefault (t=& gt; T.T itle. The Contains (KPISupplierReportShow. Key4));
If (tempItem!=null)
{
Rshow. Penalty4=0 - (tempItem TargetScore - (tempItem. Score. HasValue? TempItem. Score. Value: 0));
Rshow. PenaltyRemark4=tempItem. "Reason;
}
//
TempItem=tempItemList. FirstOrDefault (t=& gt; T.T itle. The Contains (KPISupplierReportShow. Key5));
If (tempItem!=null)
{
Rshow. Penalty5=0 - (tempItem TargetScore - (tempItem. Score. HasValue? TempItem. Score. Value: 0));
Rshow. PenaltyRemark5=tempItem. "Reason;
}
Cost//
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull