Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there,

I have a small issue, which I hope you can help me solve it.
So, I have to display in gridview some information about patients and theirs schedules for next appointments.
The only problem is that I`m not sure (trust me, I`ve tried a lot of things before I submitted my question here) how to do this:
From all users, I want to select some infos (address, contact, birthdate, etc) and then if the user is male schedule appointment for 3 months and if is a female schedule it for 4 months.
How can I do that? Please, I would really appreciate it!
The query (the main one- without this comparison which I really dont know how to handle):
C#
public static object getUsersAppointments()
{
var qUsersApp=(from u in dc.UsersApp
select new
{
   u.lname,
   u.bday,
   u.address,
   u.lastapp,
   NextApp = lastapp.Value.AddMonths(and this is part I dont know how to handle)
}).ToList();
return qUsersApp;
}



Text moved from OP's "not solution" below:
Of course it have sex property. My doubt is how to inside this query filter by sex?! Probably very stupid question, but I`m exhausted and dont think very good these days. Thank you for replays and suggestions.
Posted
Updated 12-Oct-12 4:26am
v3
Comments
n.podbielski 12-Oct-12 5:54am    
Did you want to add this appoitment to DB?
If yes: you cannot mix select and insert in one statement like this.
If no: just select all user data from DB and then iterate collection and create new appointment
ellisbay 12-Oct-12 5:58am    
No, no, of course not. I`m aware that`s not possible :) I just want to display in datagridview this information. I`d like to have output, for example, lik|e this:

NAME ADDRESS TELEPH APPOINT. NEXT APP
John Doe | Street no 23 | 344/333 | 10/7/12 | 10/10/12
Jane Doe | Street no 23 | 344/333 | 10/7/12 | 10/11/12
n.podbielski 12-Oct-12 7:36am    
I don't think that is good idea to mix fetching DB data and presentation data.
I would prefer to create some GridUserDataClass and in special property NextApointment have something like this:
NextApointment{
{get{
if(Sex==Sexes.Male)
//LastApp + 3month
else{
//LastApp + 4month
}
}}
Silent Guardian 12-Oct-12 6:09am    
does it have a "sex" property?
if no then how you gona identify whether its female or male?
if yes then just get it and use lambda expression to set the month interval

public static object getUsersAppointments()
{
  var qUsersApp=(from u in dc.UsersApp
  select new
   {
    u.lname,
    u.bday,
    u.address,
    u.lastapp,
    NextApp=get_Schedule(dc.Gender,u.lastapp)
   }).ToList();
  return qUsersApp;
}

 private DateTime get_Schedule(string Gender,DateTime date)
 {
   DateTime dt;
    if(Convert.ToString(Gender)=="male")
     {
       dt=date.AddMonths(3);
     }
    else
     {
       dt=date.AddMonths(4);
     }
  return dt;
}
 
Share this answer
 
v3
Comments
ellisbay 13-Oct-12 7:23am    
Works like a charm! Thank you very, very much. So simple and elegant, was doing something like this, but inside this function, so didn`t work as well. This is great!
vasim sajad 15-Oct-12 0:40am    
welcome... am just shown a example, do changes whatever u needed..
Hi i got your prob..
Hope your database tabel is like this..

Table Name => "PersonData"

Name Address Tel LastApp Gender
Male | Street no 23 | 344/333 | 10/7/12 | M
Female | Street no 23 | 344/333 | 10/7/12 | F

C#
var PersonDtls=from Person in PersonData.AsEnumerable()
               select{
                        Name=Person.Field<string>("Name"),
                        Address=Person.Field<string>("Address"),
                        Phone=Person.Field<string>("Tel"),
                        LastApp=Person.Field<datetime>("LastApp"),
                        NextApp=Person.Field<string>("Gender")=="M"?Person.Field<datetime>("LastApp").AddMonths(3):Person.Field<datetime>("LastApp").AddMonths(4)
                     };


Hope this will help you..
All the bets..
 
Share this answer
 
v3

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