Ejemplo n.º 1
0
        public void BindDataGrid(DataGrid ReadersGrid, DataGrid RecordsGrid, DataTable RecordsDt)
        {
            RecordsDt.Clear();

            readerRepo.Readers().Load();
            ReadersGrid.ItemsSource = readerRepo.Readers().Local;

            DataRow row;

            foreach (var record in recordRepo.Records().ToList <Record>()) // for every record in Records
            {
                var reader = (from r in readerRepo.Readers()               // Getting reader where reader.Id == record.ReaderId
                              where r.Id == record.ReaderId
                              select r).FirstOrDefault();

                var book = (from b in bookRepo.Books() // Getting reader where reader.Id == record.ReaderId
                            where b.Id == record.BookId
                            select b).First();

                row = RecordsDt.NewRow();
                row["Reader Name"]    = reader.LastName + ' ' + reader.FirstName[0] + ". " + reader.MiddleName[0] + '.';
                row["Book"]           = '"' + book.Name + '"';
                row["Date of Issue"]  = record.DateOfIssue;
                row["Date Of Return"] = record.DateOfReturn;

                if (!record.Returned)
                {
                    row["Returned"] = "No";
                }
                else
                {
                    row["Returned"] = "Yes";
                }
                RecordsDt.Rows.Add(row);
            }
            RecordsGrid.ItemsSource = RecordsDt.DefaultView;
        }