public Students() { LoginDetails = new LoginDetails(); Parents = new Parents(); Classes = new Classes(); }
private static List <Students> _GetListOfStudents() { List <Students> students = new List <Students>(); try { Command = @"select * from tblStudents std join tblLoginDetails lgn on std.LoginDetail_ID=lgn.Id join tblParents pts on std.Parent_ID=pts.Id join tblClasses cls on std.Class_ID=cls.Id"; db.cmd.CommandText = Command; db.con.Open(); SqlDataReader rdr = db.cmd.ExecuteReader(); while (rdr.Read()) { Students singleStudents = new Students(); singleStudents.Id = (int)rdr[0]; singleStudents.RegistrationId = rdr[1].ToString(); singleStudents.DiscountPercentage = Convert.ToSingle(rdr[2]); singleStudents.IdentityCardUrl = rdr[3].ToString(); singleStudents.AdmissionCard = rdr[4].ToString(); singleStudents.PostalAddress = rdr[5].ToString(); singleStudents.ResidentialAddress = rdr[6].ToString(); singleStudents.PersonsId = (int)rdr[7]; singleStudents.LoginDetailsId = (int)rdr[8]; singleStudents.ParentsId = (int)rdr[9]; singleStudents.ClassesId = (int)rdr[10]; var logindetail = new LoginDetails(); singleStudents.LoginDetails = LoginDetails.ListOfLoginDetails.SingleOrDefault(lg => lg.Id == singleStudents.LoginDetailsId); //singleStudents.LoginDetails.Id= (int)rdr[11]; //singleStudents.LoginDetails.Username = rdr[12].ToString(); //singleStudents.LoginDetails.Password = rdr[13].ToString(); //singleStudents.LoginDetails.AllowAccess = (int)rdr[14]; var parents = new Parents(); singleStudents.Parents = Parents.ListOfParents.SingleOrDefault(p => p.Id == singleStudents.ParentsId); //singleStudents.Parents.Id = (int)rdr[15]; //singleStudents.Parents.PersonsId = (int)rdr[16]; //singleStudents.Parents.LoginDetailsId = (int)rdr[17]; var classes = new Classes(); singleStudents.Classes = Classes.ListOfClasses.SingleOrDefault(cls => cls.Id == singleStudents.ClassesId); //singleStudents.Classes.Id = (int)rdr[18]; //singleStudents.Classes.ClassesName = rdr[19].ToString() ; //singleStudents.Classes.GradesId = (int)rdr[20]; var person = Persons.ListOfPersons.SingleOrDefault(p => p.PersonId == singleStudents.PersonsId); singleStudents.Id = person.PersonId; singleStudents.FirstName = person.FirstName; singleStudents.LastName = person.LastName; singleStudents.DateOfBirth = person.DateOfBirth; singleStudents.CNIC = person.CNIC; singleStudents.ImageUrlPath = person.ImageUrlPath; singleStudents.Phone1 = person.Phone1; singleStudents.Phone2 = person.Phone2; singleStudents.GendersId = person.GendersId; singleStudents.Genders.Id = person.Genders.Id; singleStudents.Genders.GenderName = person.Genders.GenderName; students.Add(singleStudents); } } catch (SqlException sqlex) { SqlExceptionErrorHandling rh = new SqlExceptionErrorHandling(); rh.GetError(sqlex); } finally { db.con.Close(); } return(students); }
private static List <Parents> _GetListOfParents() { List <Parents> parents = new List <Parents>(); try { Command = @" select * from tblPersons prs join tblGenders gndr on prs.Gender_ID = gndr.id join tblParents prnt on prs.Id=prnt.Person_ID join tblLoginDetails lgn on prnt.LoginDetail_ID=lgn.id;" ; db.cmd.CommandText = Command; db.con.Open(); SqlDataReader rdr = db.cmd.ExecuteReader(); while (rdr.Read()) { Parents singleparent = new Parents(); singleparent.PersonId = (int)rdr[0]; singleparent.FirstName = rdr[1].ToString(); singleparent.LastName = rdr[2].ToString(); singleparent.DateOfBirth = rdr[3].ToString(); singleparent.CNIC = rdr[4].ToString(); singleparent.ImageUrlPath = rdr[5].ToString(); singleparent.Phone1 = rdr[6].ToString(); singleparent.Phone2 = rdr[7].ToString(); singleparent.GendersId = (int)rdr[8]; singleparent.Genders.Id = (int)rdr[9]; singleparent.Genders.GenderName = rdr[10].ToString(); singleparent.Id = (int)rdr[11]; singleparent.PersonId = (int)rdr[12]; singleparent.LoginDetailsId = (int)rdr[13]; // var logindetail = new LoginDetails(); singleparent.LoginDetails = LoginDetails.ListOfLoginDetails.SingleOrDefault(lg => lg.Id == singleparent.LoginDetailsId); // //singleparent.LoginDetails.Id = (int)rdr[14]; //singleparent.LoginDetails.Username = rdr[15].ToString(); //singleparent.LoginDetails.Password = rdr[16].ToString(); //singleparent.LoginDetails.AllowAccess = (int)rdr[17]; parents.Add(singleparent); } } catch (SqlException sqlex) { SqlExceptionErrorHandling rh = new SqlExceptionErrorHandling(); rh.GetError(sqlex); } finally { db.con.Close(); } return(parents); }