Click here to Skip to main content
15,847,903 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I`m making application for blood donations. I have almost done it, but I have a problem with one form, and I really don`t know how to make it working right, so I hope You`ll have some tips and advices.

What I want is to make a form with combobox which is populate with months, and by selecting desired month, datagridview should be populated with donors who can give blood that month.

I have a table tblBloodDonorsSchedule which has these fields:(int) ScheduleID, (int)DonorID, (DateTime)DateOfDonation, (int)Quantity.

I need a query which will select all donors who can give blood in selected month.

For example, if is DateOfDonation 10.07.2012. for DonorID 10,he should be shown in grid when someone select November in combobox (Donor can give blood every 4 months).

Hope you`ll have some advices for me.
Thank You.
Posted

1 solution

Is this what you are looking for?
C#
DateTime selecteddate = new DateTime(2012,11,8); // Selected date here
var candidates = (from p in tblBloodDonorsSchedule
                         where p.DateOfDonation.Month == selecteddate.Month
                         select p);
 
Share this answer
 
Comments
bbirajdar 8-Nov-12 9:08am    
perfect answer+5
ellisbay 8-Nov-12 9:14am    
Not sure. What you suggest to put in combobox? List of month numbers (1-12) or list of month strings (January...December)?
And also this thing: For example, if is DateOfDonation 10.07.2012. for DonorID 10,he should be shown in grid when someone select November in combobox (Donor can give blood every 4 months).
bbirajdar 8-Nov-12 9:33am    
I think it should be october for 10.07.2012
ellisbay 9-Nov-12 2:10am    
This doesn`t work. Any suggestions, anyone?
ellisbay 9-Nov-12 3:22am    
What I have done so far. I add dateTimePicker on my form..
Made query something like "jlopez788" suggested. And it works well. But the final touch have to be done. I have to show in my grid people who should/ can give blood that month.
So, to do that, I have one function which will calculate when is the time for next donation (Male blood donor can give blood each 3 months, female blood donors each 4 months).
Here is that function:
public static DateTime get_Schedule(string Gender, DateTime date)
{
DateTime dt;
if (Convert.ToString(Gender) == "Female")
{
dt = date.AddMonths(4);
}
else
{
dt = date.AddMonths(3);
}
return dt;
}
But here is a problem. How can I compare this function to dt.Month value?!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900