question on linq select join
I would like to list out all the students who have yet to pay off their course fee i.e. when a student is clicked, list out all pending fees by months.
This is what I have done so far..
These are all the students active courses.Below are the payments record paid by student to their course.
Now i would like to list out all the pending payment foreach students e.g. last payment to the course is on 2/11/2011. If the datetime now is May, Then i would like to show the pending amount as Month Amount March 100 April 200 May 400This is what I tried..
foreach (var result in activeCourses)
{
//Sho开发者_JAVA百科w all the pending paid coures from dateJoin till datetime.Now
DateTime JoinedDate = Convert.ToDateTime(result.cus.Date);
for (DateTime d = JoinedDate; d.Month <= DateTime.Now.Month; d = d.AddMonths(1))
{
Payment payment = new Payment();
payment.Course.Id = result.c.Id;
payment.Course.Name = result.c.Name;
payment.Course.Fee = result.c.Fee;
payment.CourseByStudent.CourseUserStatus.Date = result.cu.Date;
payment.CourseByTutor.TutorId = result.t.TutorId;
payment.User.Name = result.u.Name;
payment.MonthId = d.Month;
payment.MonthToPay = d.ToString("MMM");
output.Add(payment);
}
}
The logic given above does not seem to be efficient in case the student does not pay anything for his courses, then I have to check the pending payment since his first JoinedDate. OtherWise I need to check the pending payment from the DateIssue in the Payment table according to that particular course..please advice thanksi will use back the same approach to show the late payment.
for (DateTime d = lastPaidDate.AddMonths(1); d.Month <= DateTime.Now.Month; d = d.AddMonths(1))
Thanks
精彩评论