Beispiel #1
0
        private void Startup(object sender, RoutedEventArgs e)
        {
            using (LibAppContext DbConn = new LibAppContext())
            {
                string password;


                using (MD5 md5Hash = MD5.Create())
                {
                    EncryptionTools obj = new EncryptionTools(md5Hash);
                    password = obj.GetMd5Hash("avertis");
                }

                int count = DbConn.Users.Count();
                if (count == 0)
                {
                    User Obj = new User(name: "admin", password: password);
                    DbConn.Users.Add(Obj);
                    DbConn.SaveChanges();
                }

                #region BorrowerTypes

                int currentTypes = DbConn.BorrowerTypes.Count();
                if (currentTypes == 0)
                {
                    //MessageBox.Show(currentTypes.ToString());
                    List <BorrowerType> defaults = new List <BorrowerType> {
                        new BorrowerType()
                        {
                            TypeName = "Student"
                        },
                        new BorrowerType()
                        {
                            TypeName = "Teacher"
                        }
                    };
                    DbConn.BorrowerTypes.AddRange(defaults);
                    DbConn.SaveChanges();
                }
                #endregion

                DbConn.Dispose();
            }
        }
Beispiel #2
0
        public void LoadReport(string ReportName)
        {
            LibAppContext conn = new LibAppContext();

            switch (ReportName)
            {
            case "Lost_Books":
                List <LostItemsReport> res = (from item in conn.LostBooks
                                              join books in conn.Books on item.BookID equals books.Id
                                              select new LostItemsReport
                {
                    Id = item.Id,
                    Title = books.Title,
                    Author = books.Author,
                    //WriteOffDate = item.LossDate,
                    Narration = item.LossReason
                }
                                              ).ToList();
                ExportListUsingEPPlus <LostItemsReport>(res, namePrefix: "Write off Books");
                break;

            case "Registered_Borrowers":
                List <RegisteredBorrowers> borrowers = (from row in conn.Borrowers
                                                        join names in conn.BorrowerTypes on row.TypeName_Id equals names.Id
                                                        select new RegisteredBorrowers
                {
                    Id = row.IdentificationNumber,
                    Name = row.FirstName + " " + row.LastName,
                    Email = row.EmailAddress,
                    Type = names.TypeName
                }).ToList();
                ExportListUsingEPPlus(borrowers, "Registered Borrowers");
                break;

            case "Borrowed_Books":
                ExportListUsingEPPlus(BorrowedBooksView, "BorrowedBooks");
                break;

            default:
                ExportListUsingEPPlus(LibraryBooks, "All Books");
                break;
            }
            conn.Dispose();
        }