public PlaybackManager( MediaPlayer player, SettingsService settingsService, IPlayerPlaylistService playerPlaylistService, ILogService logService, IMusicCacheService musicCacheService) { _settingsService = settingsService; _player = player; _playerPlaylistService = playerPlaylistService; _logService = logService; _musicCasheService = musicCacheService; _database = new LibraryDatabase(); _player.AutoPlay = false; _player.MediaOpened += Player_MediaOpened; _player.MediaEnded += Player_MediaEnded; _player.MediaFailed += Player_MediaFailed; _currentTrackID = settingsService.GetNoCache(PLAYER_TRACK_ID, -1); _isShuffleMode = settingsService.GetNoCache(PLAYER_SHUFFLE_MODE, false); UpdateRepeatMode(); UpdateScrobbleMode(); }
public override global::System.Data.DataSet Clone() { LibraryDatabase cln = ((LibraryDatabase)(base.Clone())); cln.InitVars(); cln.SchemaSerializationMode = this.SchemaSerializationMode; return(cln); }
public List <UserBooks> GetUserBooks() { using (LibraryDatabase db = new LibraryDatabase()) { return(db.UserBooks.OrderBy(b => b.Title).ToList()); } //return UserBooks.Books.OrderBy(book => book.Title).ToList(); }
public LibraryDatabaseService( LibraryDatabase database, ISettingsService settingsService, ILogService logService) { _database = database; _settingsService = settingsService; _logService = logService; _cleaner = new Lazy <LibraryDatabaseCleaner>(() => new LibraryDatabaseCleaner(_database, this)); }
public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs) { LibraryDatabase ds = new LibraryDatabase(); global::System.Xml.Schema.XmlSchemaComplexType type = new global::System.Xml.Schema.XmlSchemaComplexType(); global::System.Xml.Schema.XmlSchemaSequence sequence = new global::System.Xml.Schema.XmlSchemaSequence(); global::System.Xml.Schema.XmlSchemaAny any = new global::System.Xml.Schema.XmlSchemaAny(); any.Namespace = ds.Namespace; sequence.Items.Add(any); type.Particle = sequence; global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable(); if (xs.Contains(dsSchema.TargetNamespace)) { global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream(); global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream(); try { global::System.Xml.Schema.XmlSchema schema = null; dsSchema.Write(s1); for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();) { schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current)); s2.SetLength(0); schema.Write(s2); if ((s1.Length == s2.Length)) { s1.Position = 0; s2.Position = 0; for (; ((s1.Position != s1.Length) && (s1.ReadByte() == s2.ReadByte()));) { ; } if ((s1.Position == s1.Length)) { return(type); } } } } finally { if ((s1 != null)) { s1.Close(); } if ((s2 != null)) { s2.Close(); } } } xs.Add(dsSchema); return(type); }
public Books ReturnBook(string title) { using (LibraryDatabase db = new LibraryDatabase()) { var book = db.UserBooks.FirstOrDefault(b => b.Title.ToLower() == title.ToLower()); if (book != null) { db.UserBooks.Remove(book); var returnedBook = db.Books.FirstOrDefault(b => b.Title.ToLower() == title.ToLower()); returnedBook.Copies++; db.SaveChanges(); return(returnedBook); } } return(null); }
/// <summary> /// Returns list of all available books /// </summary> /// <returns></returns> public List <Books> GetAvailableBooks() { // //return LibraryBooks.AvBooks // // .Where(book => book.Copies > 0) // // .OrderBy(book => book.Title) // // .ToList(); // List<Book> result = new List<Book>(); // string cs = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Stephen\Documents\Natalija\Accenture .Net\Bootcamp1\LibraryDB.mdf;Integrated Security=True;Connect Timeout=30"; using (LibraryDatabase db = new LibraryDatabase()) { return(db.Books.Where(b => b.Copies > 0) .OrderBy(b => b.Title).ToList()); } }
public MainWindow() { InitializeComponent(); try { string filePath = LibraryDatabase.GetApplicationFolderPath() + "\\library.info"; string str = "TÊN THƯ VIỆN"; using (StreamReader sr = new StreamReader(filePath)) { str = sr.ReadLine(); } Application.Current.Resources["LibraryName"] = str; } catch (Exception) { } }
private void btnOK_Click(object sender, RoutedEventArgs e) { if (pwxPassword.Password == "" || !LibraryDatabase.CheckPassword(this.idPerson, pwxPassword.Password, this.accountT)) { tblPasswordWarning.Visibility = Visibility.Visible; return; } else { tblPasswordWarning.Visibility = Visibility.Hidden; } if (pwxPasswordNew.Password.Length < 5) { tblPasswordNewWarning.Visibility = Visibility.Visible; return; } else { tblPasswordNewWarning.Visibility = Visibility.Hidden; } if (pwxRetypePasswordNew.Password != pwxPasswordNew.Password) { tblRetypePasswordNewWarning.Visibility = Visibility.Visible; return; } else { tblRetypePasswordNewWarning.Visibility = Visibility.Hidden; } LibraryDatabase.SetNewPassword(this.idPerson, pwxPasswordNew.Password, this.accountT); this.Hide(); KBox.KMessageBox.Show("Đổi mật khẩu thành công !", "Thông báo", "OK", "", MessageBoxImage.Information); pwxPassword.Password = pwxPasswordNew.Password = pwxRetypePasswordNew.Password = ""; this.Close(); }
public Books TakeBook(string title) { //Book book = LibraryBooks.AvBooks.Find(book => //book.Title.Equals(title, StringComparison.OrdinalIgnoreCase)); using (LibraryDatabase db = new LibraryDatabase()) { var book = db.Books.FirstOrDefault(b => b.Title.ToLower() == title.ToLower()); if (book != null && book.Copies > 0) { book.Copies--; db.UserBooks.Add(new UserBooks() { Author = book.Author, Title = book.Title, Year = book.Year }); db.SaveChanges(); return(book); } } return(null); }
public BookCategoryManagerUCViewModel() { ListBookCategory = LibraryDatabase.BookCategories(); AddBookCategoryCommand = new RelayCommand <object>((p) => { return(true); }, (p) => { AddBookCategoryWindow addBookCategoryWindow = new AddBookCategoryWindow(); addBookCategoryWindow.DataContext = new AddBookCategoryWindowViewModel(); addBookCategoryWindow.ShowDialog(); ListBookCategory = LibraryDatabase.BookCategories(); }); UpdateBookCategoryCommand = new RelayCommand <UserControl>((p) => { return(p != null); }, (p) => { var tbxName = p.FindName("tbxName") as TextBox; var tbxBorrowTime = p.FindName("tbxBorrowTime") as TextBox; var tblNameWarning = p.FindName("tblNameWarning") as TextBlock; var tblBorrowTimeWarning = p.FindName("tblBorrowTimeWarning") as TextBlock; if (tbxName.Text == "") { tblNameWarning.Visibility = Visibility.Visible; return; } else { tblNameWarning.Visibility = Visibility.Hidden; } int newBorrowTime; if (tbxBorrowTime.Text == "" || int.TryParse(tbxBorrowTime.Text, out newBorrowTime) == false) { tblBorrowTimeWarning.Visibility = Visibility.Visible; return; } else { tblBorrowTimeWarning.Visibility = Visibility.Hidden; } BookCategorySelected.Name = tbxName.Text.Substring(0, 1).ToUpper() + tbxName.Text.Substring(1); BookCategorySelected.BorrowTime = newBorrowTime; bookCategorySelected.Update(); ListBookCategory = LibraryDatabase.BookCategories(); }); RemoveBookCategoryCommand = new RelayCommand <object>((p) => { return(BookCategorySelected != null && BookCategorySelected.NumberOfBook == 0); }, (p) => { /* * MessageBoxResult messageBoxResult = MessageBox.Show("Bạn có muốn xóa chuyên mục \"" + BookCategorySelected.Name + "\" không ?", "Cảnh báo", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); * if (messageBoxResult == MessageBoxResult.No) { return; } */ if (!KBox.KMessageBox.Show("Bạn có muốn xóa chuyên mục \"" + BookCategorySelected.Name + "\" không ?", "Cảnh báo", "Có", "Không", MessageBoxImage.Warning)) { return; } BookCategorySelected.RemoveFromData(); ListBookCategory.Remove(BookCategorySelected); }); }
public ActionResult TestFill() { if (User.IsInRole("Admin")) { using (var db = new LibraryDatabase()) { if (!db.Authors.Any()) { for (int i = 0; i < 6; i++) { db.Authors.Add(Author.FillBlanks()); } db.SaveChanges(); } var authors = db.Authors.ToArray(); if (!db.Readers.Any()) { for (int i = 0; i < 10; i++) { db.Readers.Add(Reader.FillBlanks()); } db.SaveChanges(); } var readers = db.Readers.ToArray(); Courses[] courses; if (!db.Courses.Any()) { courses = new[] { new Courses { Id = 1, Course = 1 }, new Courses { Id = 2, Course = 2 }, new Courses { Id = 3, Course = 3 }, new Courses { Id = 4, Course = 4 }, }; foreach (var t in courses) { db.Courses.Add(t); } db.SaveChanges(); } courses = db.Courses.ToArray(); Discipline[] disciplines; if (!db.Disciplines.Any()) { disciplines = new[] { new Discipline { Id = 1, Name = "Программирование", }, new Discipline { Id = 2, Name = "Конструирование ПО", }, new Discipline { Id = 3, Name = "НИС", } }; foreach (var t in disciplines) { db.Disciplines.Add(t); } db.SaveChanges(); } disciplines = db.Disciplines.ToArray(); Publication[] publications; if (!db.Publications.Any()) { publications = new[] { new Publication("Принципы программирования", authors[2], ePublicationType.None, eBookPublication.Book, new DateTime(1985, 4, 1), "Росмэн") { Id = 1, Courses = new[] { courses[0], courses[1] }, Disciplines = new[] { disciplines[0] } }, new Publication("Справочник по C#", new[] { authors[1], authors[2] }, ePublicationType.None, eBookPublication.Book, new DateTime(2011, 6, 1), "Справочники") { Id = 3, Courses = new[] { courses[0], }, Disciplines = new[] { disciplines[0], } }, new Publication("Pascal.NET programming guide", new[] { authors[2], authors[3] }, ePublicationType.Educational, eBookPublication.Publication, new DateTime(2001, 8, 1), "Питер") { Id = 2, Courses = new[] { courses[1], courses[3] }, Disciplines = new[] { disciplines[0], disciplines[1] } }, new Publication("Как писать божественный код", authors[5], ePublicationType.Scientific, eBookPublication.Publication, new DateTime(2018, 3, 1), null) { Id = 6, InternetLocation = "https://youtube.com/", Courses = new[] { courses[2], courses[3] }, Disciplines = new[] { disciplines[0], } }, new Publication("Почему Perl 6 - лучший язык программирования", new[] { authors[3], authors[4], }, ePublicationType.Educational, eBookPublication.Publication, new DateTime(2015, 1, 1), null) { Id = 4, InternetLocation = "https://google.com/", Courses = new[] { courses[1], courses[2] }, Disciplines = new[] { disciplines[1], } }, new Publication("Где учиться на программиста", authors[5], ePublicationType.Educational, eBookPublication.Publication, new DateTime(2016, 11, 1), null) { Id = 5, InternetLocation = "https://wikipedia.org/", Courses = new[] { courses[1], courses[3], }, Disciplines = new[] { disciplines[2], } }, }; foreach (var t in publications) { db.Publications.Add(t); } db.SaveChanges(); } publications = db.Publications.ToArray(); Stats[] stats; if (!db.Stats.Any()) { stats = new[] { new Stats { Id = 1, DateTaken = new DateTime(2016, 01, 09), Publication = publications[2] }, new Stats { Id = 2, DateTaken = new DateTime(2017, 06, 10), Publication = publications[2] }, new Stats { Id = 3, DateTaken = new DateTime(2017, 11, 15), Publication = publications[1] }, new Stats { Id = 4, DateTaken = new DateTime(2018, 08, 20), Publication = publications[1] }, new Stats { Id = 5, DateTaken = new DateTime(2018, 03, 01), Publication = publications[2] }, }; foreach (var t in stats) { db.Stats.Add(t); } db.SaveChanges(); } BookLocation[] locations; if (!db.BookLocations.Any()) { locations = new[] { new BookLocation { Id = 1, Room = 307, Place = "здесь", IsTaken = true, Reader = readers[2], Publication = publications[2] }, new BookLocation { Id = 2, Room = 321, Place = "где-то была", IsTaken = false, Publication = publications[2] }, new BookLocation { Id = 3, Room = 501, Place = "в столе", IsTaken = true, Reader = readers[1], Publication = publications[1] }, new BookLocation { Id = 4, Room = 321, Place = "на верхней полке шкафа", IsTaken = false, Publication = publications[2] }, new BookLocation { Id = 5, Room = 318, Place = "в правом шкафу слева", IsTaken = false, Publication = publications[0] }, new BookLocation { Id = 6, Room = 302, Place = "на столе", IsTaken = false, Publication = publications[1] }, new BookLocation { Id = 7, Room = 323, Place = "под потолком", IsTaken = false, Publication = publications[0] }, }; foreach (var t in locations) { db.BookLocations.Add(t); } db.SaveChanges(); } } } return(RedirectToAction("Index", "Home")); }
public ActionResult Report(int?reportType, DateTime?dateStart, DateTime?dateEnd, int[] authors) { string fileName = string.Empty; using (var db = new LibraryDatabase()) { var Authors = db.Authors.ToList(); if (authors != null) { Authors = Authors.Where(e => authors.Contains(e.Id)).ToList(); } var publications = db.Publications.ToList().Where(e => e.Authors.Any(f => Authors.Contains(f))); var stats = db.Stats.ToList().Where(e => publications.Contains(e.Publication)).ToList(); if (dateStart.HasValue) { stats = stats.Where(e => e.DateTaken >= dateStart).ToList(); } if (dateEnd.HasValue) { stats = stats.Where(e => e.DateTaken <= dateEnd).ToList(); } var app = new Application { DisplayAlerts = true, Visible = false, }; var wbook = app.Workbooks.Add(1); Worksheet wsheet = wbook.Worksheets[1]; wsheet.Name = "Отчёт"; switch (reportType) { case 0: { var res = publications.Where(d => Authors.Any(e => d.Authors.Contains(e))) .OrderBy(d => d.DDate) .ToArray(); wsheet.Cells[1, 1] = "Название"; wsheet.Cells[1, 2] = "Авторы"; wsheet.Cells[1, 3] = "Опубликовано"; for (int i = 0, offset = 2; i < res.Length; i++) { var authors1 = res[i].Authors .OrderBy(d => d.WriterType) .Select(d => d.ToString()) .ToArray(); wsheet.Cells[i + offset, 1] = res[i].Name; wsheet.Cells[i + offset, 2] = string.Join("\n", authors1); wsheet.Cells[i + offset, 3] = $"{res[i].DDate}"; } break; } case 1: { var res = publications.Where(e => e.Stats.Count > 0) .OrderByDescending(d => d.Stats.Count(e => stats.Contains(e))) .ToArray(); wsheet.Cells[1, 1] = "Название"; wsheet.Cells[1, 2] = "Авторы"; wsheet.Cells[1, 3] = "Взято раз"; for (int i = 0; i < res.Length; i++) { var authors1 = res[i].Authors .OrderBy(d => d.WriterType) .Select(d => d.ToString()) .ToArray(); wsheet.Cells[i + 2, 1] = res[i].Name; wsheet.Cells[i + 2, 2] = string.Join("\n", authors1); wsheet.Cells[i + 2, 3] = res[i].Stats.Count(e => stats.Contains(e)); } break; } case 2: { var res = publications.SelectMany(d => d.Locations) .Where(d => d.IsTaken) .OrderBy(d => d.Publication.Stats.Last().DateTaken.ToNiceDate()) .ToArray(); wsheet.Cells[1, 1] = "Название"; wsheet.Cells[1, 2] = "Авторы"; wsheet.Cells[1, 3] = "Взявший"; wsheet.Cells[1, 4] = "Взято"; for (int i = 0; i < res.Length; i++) { var el = res[i]; wsheet.Cells[i + 2, 1] = el.Publication.Name; wsheet.Cells[i + 2, 2] = string.Join("\n", el.Publication.Authors.Select(d => d.ToString())); wsheet.Cells[i + 2, 3] = $"{el.Reader}, {el.Reader.Group}"; wsheet.Cells[i + 2, 4] = el.Publication.Stats.Last().DateTaken; } break; } case null: return(HttpNotFound()); } wsheet.Columns.ColumnWidth = 255; wsheet.Rows.RowHeight = 255; wsheet.Columns.AutoFit(); wsheet.Rows.AutoFit(); fileName = $@"D:\Projects\WebLibraryProject2\WebLibraryProject2\bin\Report{reportType}.xlsx"; if (System.IO.File.Exists(fileName)) { System.IO.File.Delete(fileName); } wbook.SaveAs(fileName); wbook.Close(0); app.Quit(); } var file = new FileInfo(fileName); { Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); Response.AddHeader("Content-Length", file.Length.ToString()); Response.Flush(); Response.TransmitFile(file.FullName); Response.End(); } return(RedirectToAction("Index")); }