Ejemplo n.º 1
0
        void AddBook()
        {
            AddEditBookViewModel newBook = new AddEditBookViewModel("Add", BookType.None);
            AddEditBook          newWin  = new AddEditBook();

            newWin.DataContext = newBook;
            newWin.ShowDialog();

            if (newWin.DialogResult == true)
            {
                BookProduct bookToAdd = new BookProduct();
                bookToAdd.BookID      = AllBooks.Count + 1;
                bookToAdd.BookType    = newBook.AddEditItem.BookType;
                bookToAdd.BookName    = newBook.AddEditItem.BookName;
                bookToAdd.BookWriter  = newBook.AddEditItem.BookWriter;
                bookToAdd.PublishYear = newBook.AddEditItem.PublishYear;
                switch (newBook.AddEditItem.BookType)
                {
                case BookType.EBook:
                    (bookToAdd as EbookItem).NumOfDownloads = (newBook.AddEditItem as EbookItem).NumOfDownloads;
                    foreach (var item in (newBook.AddEditItem as EbookItem).LanguagesTranslations)
                    {
                        (bookToAdd as EbookItem).LanguagesTranslations.Add(item);
                    }
                    break;

                case BookType.Printed:
                    (bookToAdd as PrintedItem).NumOfCopied = (newBook.AddEditItem as PrintedItem).NumOfCopied;
                    (bookToAdd as PrintedItem).BookWeight  = (newBook.AddEditItem as PrintedItem).BookWeight;
                    (bookToAdd as PrintedItem).IsAvilable  = (newBook.AddEditItem as PrintedItem).IsAvilable;
                    break;
                }
                AllBooks.Add(bookToAdd);
            }
        }
Ejemplo n.º 2
0
        void EditBook()
        {
            AddEditBookViewModel tempBook = new AddEditBookViewModel("Edit", SelectedBook.BookType);

            // The item to work on
            tempBook.AddEditItem.BookType    = SelectedBook.BookType;
            tempBook.AddEditItem.BookName    = SelectedBook.BookName;
            tempBook.AddEditItem.BookWriter  = SelectedBook.BookWriter;
            tempBook.AddEditItem.PublishYear = SelectedBook.PublishYear;
            switch (SelectedBook.BookType)
            {
            case BookType.EBook:
                tempBook.SelectedBookType = "E-Book";
                (tempBook.AddEditItem as EbookItem).NumOfDownloads = (SelectedBook as EbookItem).NumOfDownloads;
                foreach (var item in (SelectedBook as EbookItem).LanguagesTranslations)
                {
                    (tempBook.AddEditItem as EbookItem).LanguagesTranslations.Add(item);
                }
                break;

            case BookType.Printed:
                tempBook.SelectedBookType = "Printed";
                (tempBook.AddEditItem as PrintedItem).NumOfCopied = (SelectedBook as PrintedItem).NumOfCopied;
                (tempBook.AddEditItem as PrintedItem).BookWeight  = (SelectedBook as PrintedItem).BookWeight;
                (tempBook.AddEditItem as PrintedItem).IsAvilable  = (SelectedBook as PrintedItem).IsAvilable;
                break;
            }

            // The item for cancel
            tempBook.OldItem.BookType    = SelectedBook.BookType;
            tempBook.OldItem.BookName    = SelectedBook.BookName;
            tempBook.OldItem.BookWriter  = SelectedBook.BookWriter;
            tempBook.OldItem.PublishYear = SelectedBook.PublishYear;
            switch (SelectedBook.BookType)
            {
            case BookType.EBook:
                tempBook.SelectedBookType = "E-Book";
                (tempBook.OldItem as EbookItem).NumOfDownloads = (SelectedBook as EbookItem).NumOfDownloads;
                foreach (var item in (SelectedBook as EbookItem).LanguagesTranslations)
                {
                    (tempBook.OldItem as EbookItem).LanguagesTranslations.Add(item);
                }
                break;

            case BookType.Printed:
                tempBook.SelectedBookType = "Printed";
                (tempBook.OldItem as PrintedItem).NumOfCopied = (SelectedBook as PrintedItem).NumOfCopied;
                (tempBook.OldItem as PrintedItem).BookWeight  = (SelectedBook as PrintedItem).BookWeight;
                (tempBook.OldItem as PrintedItem).IsAvilable  = (SelectedBook as PrintedItem).IsAvilable;
                break;
            }

            AddEditBook newWin = new AddEditBook();

            switch (SelectedBook.BookType)
            {
            case BookType.EBook:
                ucAddEBookFields newEBookUserControlFields = new ucAddEBookFields();
                newEBookUserControlFields.DataContext = tempBook;
                foreach (var wnd in Application.Current.Windows)
                {
                    if (wnd is View.AddEditBook)
                    {
                        (wnd as View.AddEditBook).ExpandWindow(newEBookUserControlFields);
                        break;
                    }
                }
                break;

            case BookType.Printed:
                ucAddPrintedBookFields newPrintedBookUserControlFields = new ucAddPrintedBookFields();
                newPrintedBookUserControlFields.DataContext = tempBook;
                foreach (var wnd in Application.Current.Windows)
                {
                    if (wnd is View.AddEditBook)
                    {
                        (wnd as View.AddEditBook).ExpandWindow(newPrintedBookUserControlFields);
                        break;
                    }
                }
                break;
            }
            newWin.DataContext = tempBook;
            newWin.ShowDialog();

            if (newWin.DialogResult == true)
            {
                SelectedBook.BookType    = tempBook.AddEditItem.BookType;
                SelectedBook.BookName    = tempBook.AddEditItem.BookName;
                SelectedBook.BookWriter  = tempBook.AddEditItem.BookWriter;
                SelectedBook.PublishYear = tempBook.AddEditItem.PublishYear;
                switch (SelectedBook.BookType)
                {
                case BookType.EBook:
                    (SelectedBook as EbookItem).NumOfDownloads = (tempBook.AddEditItem as EbookItem).NumOfDownloads;
                    (SelectedBook as EbookItem).LanguagesTranslations.Clear();
                    foreach (var item in (tempBook.AddEditItem as EbookItem).LanguagesTranslations)
                    {
                        (SelectedBook as EbookItem).LanguagesTranslations.Add(item);
                    }
                    break;

                case BookType.Printed:
                    (SelectedBook as PrintedItem).NumOfCopied = (tempBook.AddEditItem as PrintedItem).NumOfCopied;
                    (SelectedBook as PrintedItem).BookWeight  = (tempBook.AddEditItem as PrintedItem).BookWeight;
                    (SelectedBook as PrintedItem).IsAvilable  = (tempBook.AddEditItem as PrintedItem).IsAvilable;
                    break;
                }
            }
            else
            {
                if (tempBook.isWindowClosedFromXButton)
                {
                    tempBook.CancelAddEditBook();
                }

                SelectedBook.BookType    = tempBook.OldItem.BookType;
                SelectedBook.BookName    = tempBook.OldItem.BookName;
                SelectedBook.BookWriter  = tempBook.OldItem.BookWriter;
                SelectedBook.PublishYear = tempBook.OldItem.PublishYear;
                switch (SelectedBook.BookType)
                {
                case BookType.EBook:
                    (SelectedBook as EbookItem).NumOfDownloads = (tempBook.OldItem as EbookItem).NumOfDownloads;
                    (SelectedBook as EbookItem).LanguagesTranslations.Clear();
                    foreach (var item in (tempBook.OldItem as EbookItem).LanguagesTranslations)
                    {
                        (SelectedBook as EbookItem).LanguagesTranslations.Add(item);
                    }
                    break;

                case BookType.Printed:
                    (SelectedBook as PrintedItem).NumOfCopied = (tempBook.OldItem as PrintedItem).NumOfCopied;
                    (SelectedBook as PrintedItem).BookWeight  = (tempBook.OldItem as PrintedItem).BookWeight;
                    (SelectedBook as PrintedItem).IsAvilable  = (tempBook.OldItem as PrintedItem).IsAvilable;
                    break;
                }
            }
        }