Пример #1
0
        public BookChapterLabel()
        {
            this.Orientation = StackOrientation.Horizontal;
            this.HorizontalOptions = LayoutOptions.FillAndExpand;
            this.VerticalOptions = LayoutOptions.StartAndExpand;

            // Book & chapter layout
            StackLayout bookChapter = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Spacing = 0,
                HorizontalOptions = LayoutOptions.CenterAndExpand
            };

            this.chapterLabel = new ChapterLabel();
            bookChapter.Children.Add(chapterLabel);

            this.bookLabel = new BookLabel();
            bookChapter.Children.Add(this.bookLabel);

            // Main layout
            this.settingsLabel = new SettingsLabel();
            this.Children.Add(this.settingsLabel);

            this.Children.Add(bookChapter);

            this.verseLabel = new VerseLabel();
            this.Children.Add(this.verseLabel);
        }
Пример #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize a list of book names available from the import file list.
		/// </summary>
		/// <returns>the number of books available for import</returns>
		/// ------------------------------------------------------------------------------------
		private int InitBookNameList()
		{
			List<int> booksPresent = null;
			try
			{
				booksPresent = m_importSettings.BooksForProject();
			}
			catch
			{
				// TODO: Add a message to tell the user that the paratext project could
				// not be loaded.
			}
			if (booksPresent == null || booksPresent.Count == 0)
			{
				// This can probably only happen in the weird case where a Paratext project
				// that previously had books now has none.
				radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = false;
				return 0;
			}
			radImportRange.Enabled = true;
			scrPsgFrom.Enabled = scrPsgTo.Enabled = radImportRange.Checked;

			MultilingScrBooks mlBook = new MultilingScrBooks((IScrProjMetaDataProvider)m_scr);
			// Get list of books in import files
			BookLabel[] bookNames = new BookLabel[booksPresent.Count];
			int iName = 0;
			foreach (int bookOrd in booksPresent)
				bookNames[iName++] = new BookLabel(mlBook.GetBookName(bookOrd), bookOrd);
			scrPsgFrom.BookLabels = bookNames;
			scrPsgTo.BookLabels = bookNames;

			return bookNames.Length;
		}
Пример #3
0
        public static void xx()
        {
            var book = new BookLabel()
            {
                ID       = Guid.NewGuid(),
                FileName = "1111",
                Labels   = new ObservableCollection <Label> {
                    new Label()
                    {
                        ID = Guid.NewGuid(), Location = 1
                    }
                }
            };

            MyContext.GetRepository <BookLabel>().Insert(book);
        }
Пример #4
0
        public static void SetBookLabel(string filename, Label label)
        {
            var list = GetBookLabel(filename);

            if (list.Count > 0)
            {
                var bl = list[0];
                bl.Labels.Add(label);
                MyContext.GetRepository <BookLabel>().Update(bl);
            }
            else
            {
                var book = new BookLabel()
                {
                    ID       = Guid.NewGuid(),
                    FileName = filename,
                    Labels   = new ObservableCollection <Label> {
                        label
                    }
                };
                MyContext.GetRepository <BookLabel>().Insert(book);
            }
        }
Пример #5
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                CheckBoxRightPoint = Point.Empty;

                if (TypeFilterLabel != null)
                {
                    if (!TypeFilterLabel.IsDisposed)
                    {
                        TypeFilterLabel.Dispose();
                    }

                    TypeFilterLabel = null;
                }

                if (GradeFilterLabel != null)
                {
                    if (!GradeFilterLabel.IsDisposed)
                    {
                        GradeFilterLabel.Dispose();
                    }

                    GradeFilterLabel = null;
                }

                if (BookLabel != null)
                {
                    if (!BookLabel.IsDisposed)
                    {
                        BookLabel.Dispose();
                    }

                    BookLabel = null;
                }

                if (WeaponCheckBox != null)
                {
                    if (!WeaponCheckBox.IsDisposed)
                    {
                        WeaponCheckBox.Dispose();
                    }

                    WeaponCheckBox = null;
                }

                if (ArmourCheckBox != null)
                {
                    if (!ArmourCheckBox.IsDisposed)
                    {
                        ArmourCheckBox.Dispose();
                    }

                    ArmourCheckBox = null;
                }

                if (HelmetCheckBox != null)
                {
                    if (!HelmetCheckBox.IsDisposed)
                    {
                        HelmetCheckBox.Dispose();
                    }

                    HelmetCheckBox = null;
                }

                if (ShieldCheckBox != null)
                {
                    if (!ShieldCheckBox.IsDisposed)
                    {
                        ShieldCheckBox.Dispose();
                    }

                    ShieldCheckBox = null;
                }

                if (NecklaceCheckBox != null)
                {
                    if (!NecklaceCheckBox.IsDisposed)
                    {
                        NecklaceCheckBox.Dispose();
                    }

                    NecklaceCheckBox = null;
                }

                if (BraceletCheckBox != null)
                {
                    if (!BraceletCheckBox.IsDisposed)
                    {
                        BraceletCheckBox.Dispose();
                    }

                    BraceletCheckBox = null;
                }

                if (RingCheckBox != null)
                {
                    if (!RingCheckBox.IsDisposed)
                    {
                        RingCheckBox.Dispose();
                    }

                    RingCheckBox = null;
                }

                if (ShoesCheckBox != null)
                {
                    if (!ShoesCheckBox.IsDisposed)
                    {
                        ShoesCheckBox.Dispose();
                    }

                    ShoesCheckBox = null;
                }

                if (BookWarriorCheckBox != null)
                {
                    if (!BookWarriorCheckBox.IsDisposed)
                    {
                        BookWarriorCheckBox.Dispose();
                    }

                    BookWarriorCheckBox = null;
                }

                if (BookWizardCheckBox != null)
                {
                    if (!BookWizardCheckBox.IsDisposed)
                    {
                        BookWizardCheckBox.Dispose();
                    }

                    BookWizardCheckBox = null;
                }

                if (BookTaoistCheckBox != null)
                {
                    if (!BookTaoistCheckBox.IsDisposed)
                    {
                        BookTaoistCheckBox.Dispose();
                    }

                    BookTaoistCheckBox = null;
                }

                if (BookAssassinCheckBox != null)
                {
                    if (!BookAssassinCheckBox.IsDisposed)
                    {
                        BookAssassinCheckBox.Dispose();
                    }

                    BookAssassinCheckBox = null;
                }

                if (PotionCheckBox != null)
                {
                    if (!PotionCheckBox.IsDisposed)
                    {
                        PotionCheckBox.Dispose();
                    }

                    PotionCheckBox = null;
                }

                if (OreCheckBox != null)
                {
                    if (!OreCheckBox.IsDisposed)
                    {
                        OreCheckBox.Dispose();
                    }

                    OreCheckBox = null;
                }

                if (GoldCheckBox != null)
                {
                    if (!GoldCheckBox.IsDisposed)
                    {
                        GoldCheckBox.Dispose();
                    }

                    GoldCheckBox = null;
                }

                if (CommonCheckBox != null)
                {
                    if (!CommonCheckBox.IsDisposed)
                    {
                        CommonCheckBox.Dispose();
                    }

                    CommonCheckBox = null;
                }

                if (EliteCheckBox != null)
                {
                    if (!EliteCheckBox.IsDisposed)
                    {
                        EliteCheckBox.Dispose();
                    }

                    EliteCheckBox = null;
                }

                if (SuperiorCheckBox != null)
                {
                    if (!SuperiorCheckBox.IsDisposed)
                    {
                        SuperiorCheckBox.Dispose();
                    }

                    SuperiorCheckBox = null;
                }
            }
        }
Пример #6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// If name of one book is not available in the first (primary) writing system,
		/// the info in the next available (secondary) writing system is substituted.
		/// If not available in any given writing system, the 3-letter SIL/UBS book code is
		/// returned.
		/// </summary>
		/// <param name="fAvailable">Normally, the output array only includes available books
		/// if fAvailable is true. Ignored in this implementation, since all names are
		/// returned.</param>
		/// <returns>An array of BookNameInfo objects in the requested primary writing system,
		/// as far as possible.</returns>
		/// ------------------------------------------------------------------------------------
		public virtual BookLabel[] GetBookNames(bool fAvailable)
		{
			// TODO: ToddJ (BryanW)	Implement the description above
			// foreach (int nEnc in m_requestedEncodings)
			// Assert that knWsSilCodes is in the list

			BookLabel[] rgblBookNames = new BookLabel[ScriptureBooksLim];
			WsNames wsNames;

			if (PrimaryEncoding != 0)
			{
				wsNames = GetWsNames(PrimaryEncoding);
				if (wsNames != null)
				{
					for(int i = 0; i < ScriptureBooksLim; i++)
						rgblBookNames[i] = new BookLabel(wsNames.Name[i], (i + 1));

					return rgblBookNames;
				}
			}

			Debug.Assert(false);
			return rgblBookNames;
		}
Пример #7
0
        public ActionResult Edit(BookEditViewModel bevm)
        {
            if (bevm.BookViewModel.Contents == null && !string.IsNullOrEmpty(bevm.OldContent))
            {
                ModelState["BookViewModel.Contents"].Errors.Clear();
            }
            if (ModelState.IsValid)
            {
                var book = db.Books
                           .Include(b => b.Writers)
                           .Include(b => b.Labels)
                           .Include(b => b.Category)
                           .Single(b => b.BookID == bevm.BookViewModel.BookID);

                var    directory = Path.Combine(Server.MapPath("~/App_Data/uploads"), book.BookID.ToString());
                string filename;
                if (bevm.BookViewModel.Contents != null)
                {
                    var oldfilepath = Path.Combine(directory, book.Contents);
                    if (System.IO.File.Exists(oldfilepath))
                    {
                        System.IO.File.Delete(oldfilepath);
                    }
                    var extension = Path.GetExtension(bevm.BookViewModel.Contents.FileName);
                    filename = bevm.BookViewModel.BookID + "_contents" + extension;
                    bevm.BookViewModel.Contents.SaveAs(Path.Combine(directory, filename));
                }
                else
                {
                    filename = bevm.OldContent;
                }

                book.Amount      = bevm.BookViewModel.Amount;
                book.Contents    = filename;
                book.Title       = bevm.BookViewModel.Title;
                book.ISBN        = bevm.BookViewModel.ISBN;
                book.Year        = bevm.BookViewModel.Year;
                book.Description = bevm.BookViewModel.Description;
                book.CategoryID  = bevm.BookViewModel.CategoryID;
                book.Category    = db.Categories.FirstOrDefault(x => x.CategoryID == bevm.BookViewModel.CategoryID);
                var selectedwriterslist = new List <Writer>();
                var selectedlabelslist  = new List <Label>();

                for (int i = 0; i < bevm.BookViewModel.SelectedWriters.Length; i++)
                {
                    var id     = bevm.BookViewModel.SelectedWriters[i];
                    var writer = db.Writers.FirstOrDefault(x => x.WriterID == id);
                    if (writer != null)
                    {
                        selectedwriterslist.Add(writer);
                    }
                }
                db.SaveChanges();
                for (int i = 0; i < bevm.BookViewModel.SelectedLabels.Length; i++)
                {
                    var id    = bevm.BookViewModel.SelectedLabels[i];
                    var label = db.Labels.FirstOrDefault(x => x.LabelID == id);
                    if (label != null)
                    {
                        selectedlabelslist.Add(label);
                    }
                }

                //Check Writers
                var actualwriters = db.Writers.Where(w => w.BookWriters.Any(b => b.BookID == bevm.BookViewModel.BookID)).ToList();
                db.SaveChanges();
                foreach (var dbWriter in db.Writers.ToList())
                {
                    if (selectedwriterslist.Contains(dbWriter))
                    {
                        if (!actualwriters.Contains(dbWriter))
                        {
                            var bw = new BookWriter()
                            {
                                WriterID = dbWriter.WriterID,
                                BookID   = bevm.BookViewModel.BookID
                            };
                            db.BookWriters.Add(bw);
                        }
                    }
                    else
                    {
                        if (actualwriters.Contains(dbWriter))
                        {
                            var bw =
                                db.BookWriters.FirstOrDefault(
                                    x => x.WriterID == dbWriter.WriterID && x.BookID == bevm.BookViewModel.BookID);
                            db.BookWriters.Remove(bw);
                        }
                    }
                    db.SaveChanges();
                }

                //Check Labels
                var actuallabels = db.Labels.Where(w => w.BookLabels.Any(b => b.BookID == bevm.BookViewModel.BookID)).ToList();
                db.SaveChanges();
                foreach (var dbLabel in db.Labels.ToList())
                {
                    if (selectedlabelslist.Contains(dbLabel))
                    {
                        if (!actuallabels.Contains(dbLabel))
                        {
                            var bl = new BookLabel()
                            {
                                BookID  = bevm.BookViewModel.BookID,
                                LabelID = dbLabel.LabelID
                            };
                            db.BookLabels.Add(bl);
                        }
                    }
                    else
                    {
                        if (actuallabels.Contains(dbLabel))
                        {
                            var bl =
                                db.BookLabels.FirstOrDefault(x => x.LabelID == dbLabel.LabelID && x.BookID == bevm.BookViewModel.BookID);
                            db.BookLabels.Remove(bl);
                        }
                    }
                    db.SaveChanges();
                }

                //Check Files
                List <string> editedfilessource;
                List <string> editedfilestext;
                if (bevm.OldFiles != null)
                {
                    editedfilessource = bevm.OldFiles;
                }
                else
                {
                    editedfilessource = new List <string>();
                }
                if (bevm.OldFilesText != null)
                {
                    editedfilestext = bevm.OldFilesText;
                }
                else
                {
                    editedfilestext = new List <string>();
                }
                var allfiles       = db.Files.Where(f => f.BookID == bevm.BookViewModel.BookID).ToList();
                var allfilessource = allfiles.Select(f => f.Source).ToList();

                //Add new files to list of sources and disc
                if (bevm.BookViewModel.Files != null)
                {
                    for (var i = 0; i < bevm.BookViewModel.Files.Count; i++)
                    {
                        if (bevm.BookViewModel.Files[i] != null)
                        {
                            var source = bevm.BookViewModel.Files[i].FileName;
                            var path   = Path.Combine(directory, source);
                            bevm.BookViewModel.Files [i].SaveAs(path);
                            editedfilessource.Add(source);
                            editedfilestext.Add(bevm.BookViewModel.FilesNames [i]);
                        }
                    }
                }

                foreach (var dbfile in allfiles)
                {
                    //if in base exist file that we remove while editing, then remove it from db and from disc
                    if (!editedfilessource.Contains(dbfile.Source))
                    {
                        if (System.IO.File.Exists(Path.Combine(directory, dbfile.Source)))
                        {
                            System.IO.File.Delete(Path.Combine(directory, dbfile.Source));
                        }

                        db.Files.Remove(dbfile);
                    }
                }

                if (editedfilessource.Count > 0)
                {
                    for (var i = 0; i < editedfilessource.Count; i++)
                    {
                        //if file that we edited is not in db, which means it's new file, add it to db
                        if (!allfilessource.Contains(editedfilessource [i]))
                        {
                            File file = new File()
                            {
                                BookID = bevm.BookViewModel.BookID,
                                Name   = editedfilestext[i],
                                Source = editedfilessource[i]
                            };
                            db.Files.Add(file);
                            db.SaveChanges();
                        }
                        else
                        {
                            //find file text in db
                            var source   = editedfilessource[i];
                            var filetext =
                                db.Files.FirstOrDefault(
                                    f => f.BookID == bevm.BookViewModel.BookID && f.Source == source);

                            //if it is in db, check if text is still the same
                            //if it's not, change it
                            if (editedfilestext != null)
                            {
                                if (editedfilestext [i] != filetext.Name)
                                {
                                    filetext.Name = editedfilestext [i];
                                    db.SaveChanges();
                                }
                            }
                        }
                        //if its already in db and text still the same, nothing to do
                        db.SaveChanges();
                    }
                }


                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            //Not valid
            SetViewBag();
            return(View(bevm));
        }
Пример #8
0
        public ActionResult Create(BookViewModel bvm)
        {
            if (ModelState.IsValid)
            {
                var extension = Path.GetExtension(bvm.Contents.FileName);

                Book book = new Book()
                {
                    AddDate     = DateTime.Now,
                    Amount      = bvm.Amount,
                    CategoryID  = bvm.CategoryID,
                    Year        = bvm.Year,
                    Title       = bvm.Title,
                    ISBN        = bvm.ISBN,
                    Description = bvm.Description,
                    Writers     = new List <BookWriter>(),
                    Labels      = new List <BookLabel>()
                };
                db.Books.Add(book);
                db.SaveChanges();
                var filename = book.BookID + "_contents" + extension;
                book.Contents = filename;
                var directory = Path.Combine(Server.MapPath("~/App_Data/uploads"), book.BookID.ToString());
                Directory.CreateDirectory(directory);
                var path = Path.Combine(directory, filename);
                bvm.Contents.SaveAs(path);
                db.SaveChanges();
                for (int i = 0; i < bvm.SelectedWriters.Length; i++)
                {
                    var id     = bvm.SelectedWriters[i];
                    var writer = db.Writers.FirstOrDefault(x => x.WriterID == id);
                    if (writer != null)
                    {
                        var bw = new BookWriter()
                        {
                            BookID   = book.BookID,
                            WriterID = writer.WriterID
                        };
                        db.BookWriters.Add(bw);
                        db.SaveChanges();
                    }
                }
                for (int i = 0; i < bvm.SelectedLabels.Length; i++)
                {
                    var id    = bvm.SelectedLabels[i];
                    var label = db.Labels.FirstOrDefault(x => x.LabelID == id);
                    if (label != null)
                    {
                        var bl = new BookLabel()
                        {
                            BookID  = book.BookID,
                            LabelID = label.LabelID
                        };
                        db.BookLabels.Add(bl);
                        db.SaveChanges();
                    }
                }
                db.Entry(book).State = EntityState.Modified;
                db.SaveChanges();

                for (var i = 0; i < bvm.Files.Count; i++)
                {
                    if (bvm.Files[i] != null)
                    {
                        File file = new File();
                        file.BookID = book.BookID;
                        file.Book   = book;
                        file.Name   = bvm.FilesNames[i];
                        file.Source = bvm.Files[i].FileName;
                        bvm.Files[i].SaveAs(Path.Combine(directory, bvm.Files [i].FileName));
                        db.Files.Add(file);
                        db.SaveChanges();
                    }
                }


                return(RedirectToAction("Index"));
            }


            IEnumerable <SelectListItem> writers = from w in db.Writers
                                                   select new SelectListItem
            {
                Value = w.WriterID.ToString(),
                Text  = w.Name + " " + w.Surname
            };

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "Name");
            ViewBag.Writers    = new SelectList(writers, "Value", "Text");
            ViewBag.Labels     = new SelectList(db.Labels, "LabelID", "Name");
            return(View(bvm));
        }
Пример #9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private void InitializeBookLabels()
		{
			// Get list of books in import files
			BookLabel[] bookNames = new BookLabel[m_rgnAvailableBooks.Length];
			int iName = 0;
			foreach (int bookOrd in m_rgnAvailableBooks)
				bookNames[iName++] = new BookLabel(m_mulScrBooks.GetBookName(bookOrd), bookOrd);

			BookLabels = bookNames;
		}
Пример #10
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize a list of book names available from the import file list.
		/// </summary>
		/// <returns>the number of books available for import</returns>
		/// ------------------------------------------------------------------------------------
		private int InitBookNameList()
		{
			List<int> booksPresent = null;
			try
			{
				booksPresent = m_importSettings.BooksForProject;
			}
			catch
			{
				// TODO: Add a message to tell the user that the paratext project could
				// not be loaded.
			}
			if (booksPresent == null || booksPresent.Count == 0)
			{
				// This can probably only happen in the weird case where a Paratext project
				// that previously had books now has none.
				radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = false;
				return 0;
			}
			radImportRange.Enabled = scrPsgFrom.Enabled = scrPsgTo.Enabled = true;

			MultilingScrBooks mlBook =
				new MultilingScrBooks((IScrProjMetaDataProvider)m_cache.LangProject.TranslatedScriptureOA);
			// Get list of books in import files
			BookLabel[] bookNames = new BookLabel[booksPresent.Count];
			int iName = 0;
			foreach (int bookOrd in booksPresent)
				bookNames[iName++] = new BookLabel(mlBook.GetBookName(bookOrd), bookOrd);
			scrPsgFrom.BookLabels = bookNames;
			scrPsgTo.BookLabels = bookNames;

			return bookNames.Length;
		}