示例#1
0
        private void BookButton_Click(object sender, EventArgs e)
        {
            // Waiting / hour glass
            Cursor.Current = Cursors.WaitCursor;

            var q = from c in db.AuthorBook where c.Author == a.Id select c;

            Bookcountlabel.Text = q.Count().ToString() + " books";
            if (q.Count() > 0)
            {
                foreach (AuthorBook c in q)
                {
                    BookAlbum art = c.BookAlbumBookAlbum;
                    string    s   = " (" + art.YearFirst + ") " + art.Title; // + ", " + art.PublisherPublisher.Name;
                    if (art.PublisherPublisher != null)
                    {
                        s += ", " + art.PublisherPublisher.Name;
                    }
                    memo(s);
                    CB_books.Items.Add("(" + art.YearFirst + ") " + util.addid(art.Title, art.Id, 100));
                }
            }
            else
            {
                CB_books.Items.Add("(no books)");
            }
            // Back to normal
            Cursor.Current = Cursors.Default;
        }
示例#2
0
        private void delete_book(int bookid)
        {
            var qcs = from c in db.ChapterSong
                      where c.BookAlbum == bookid
                      select c.Id;

            foreach (int csid in qcs)
            {
                delete_chapter(csid);
            }

            var qab = from c in db.AuthorBook
                      where c.BookAlbum == bookid
                      select c;

            memo("qab " + qab.Count());
            db.AuthorBook.DeleteAllOnSubmit(qab);
            db.SubmitChanges();
            BookAlbum ba = (from c in db.BookAlbum
                            where c.Id == bookid
                            select c).FirstOrDefault();

            memo("ba = " + ba.Title);
            if (ba != null)
            {
                db.BookAlbum.DeleteOnSubmit(ba);
                db.SubmitChanges();
            }
        }
示例#3
0
        public static string BookAuthorString(Librarydb db, BookAlbum ba)
        {
            string s   = "";
            string sep = "";

            foreach (AuthorBook ab in ba.AuthorBook)
            {
                s  += sep + ab.AuthorAuthor.Name;
                sep = "&";
            }

            return(s);
        }
示例#4
0
        private void CoauthorButton_Click(object sender, EventArgs e)
        {
            // Waiting / hour glass
            Cursor.Current = Cursors.WaitCursor;

            List <Author> colist = new List <Author>();
            var           q      = from c in db.AuthorArticle where c.Author == a.Id select c;

            foreach (AuthorArticle aa in q)
            {
                Article art = aa.ArticleArticle;
                var     qc  = from c in db.AuthorArticle where c.Article == art.Id select c;
                foreach (AuthorArticle aa2 in qc)
                {
                    if (aa2.Author != a.Id)
                    {
                        if (!colist.Contains(aa2.AuthorAuthor))
                        {
                            colist.Add(aa2.AuthorAuthor);
                        }
                    }
                }
            }
            var qb = from c in db.AuthorBook where c.Author == a.Id select c;

            foreach (AuthorBook aa in qb)
            {
                BookAlbum art = aa.BookAlbumBookAlbum;
                var       qc  = from c in db.AuthorBook where c.BookAlbum == art.Id select c;
                foreach (AuthorBook aa2 in qc)
                {
                    if (aa2.Author != a.Id)
                    {
                        if (!colist.Contains(aa2.AuthorAuthor))
                        {
                            colist.Add(aa2.AuthorAuthor);
                        }
                    }
                }
            }

            foreach (Author aac in colist)
            {
                CB_coauthor.Items.Add(util.addid(aac.Name, aac.Id, 50));
            }
            // Back to normal
            Cursor.Current = Cursors.Default;
        }
示例#5
0
 public FormDoBook(Librarydb dbpar, int bookid)
 {
     InitializeComponent();
     db = dbpar;
     bb = (from c in db.BookAlbum where c.Id == bookid select c).FirstOrDefault();
     if (bb == null)
     {
         this.Text = "(invalid book)";
     }
     else
     {
         this.Text           = bb.Title;
         Titlelabel.Text     = bb.Title;
         Publisherlabel.Text = bb.PublisherPublisher.Name;
         if (bb.YearThis != null)
         {
             Yearlabel.Text = util.addcentury(bb.YearThis);
             if ((bb.YearFirst != null) && (bb.YearFirst != bb.YearThis))
             {
                 Yearlabel.Text += " (" + util.addcentury(bb.YearFirst) + ")";
             }
         }
         var qa = (from c in db.AuthorBook where c.BookAlbum == bookid select c);
         foreach (AuthorBook ab in qa)
         {
             string s = util.addid(ab.AuthorAuthor.Name, ab.Author, 100);
             CB_author.Items.Add(s);
         }
         var qc = (from c in db.ChapterSong where c.BookAlbum == bookid select c);
         foreach (ChapterSong cs in qc)
         {
             var           qac = (from c in db.AuthorChapter where c.ChapterSong == cs.Id select c);
             List <string> ls  = new List <string>();
             foreach (AuthorChapter ac in qac)
             {
                 ls.Add(ac.AuthorAuthor.Name);
             }
             string s = util.addid(util.format_authorlist(ls) + ": " + cs.Title, cs.Id, 100);
             CB_chapter.Items.Add(s);
         }
     }
 }
示例#6
0
        public FormNewBook(Librarydb dbpar, int authorid, BookAlbum bapar)
        {
            InitializeComponent();
            db   = dbpar;
            ba   = bapar;
            auid = authorid;
            if ((auid < 0) && (ba == null))
            {
                string            message = "Must have either author or book in FormNewBook";
                string            caption = "No title";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result  = MessageBox.Show(message, caption, buttons);
                return;
            }

            if (auid > 0)
            {
                au = (from c in db.Author where c.Id == auid select c).FirstOrDefault();
                if (au != null)
                {
                    TB_author.Text = au.Name;
                }
                populate_booklist();
            }

            populate_subjectlist();
            populate_typelist();

            if (ba != null)
            {
                int i = 1;
                foreach (Author aa in (from c in db.AuthorBook where c.BookAlbum == ba.Id select c.AuthorAuthor))
                {
                    if (i == 1)
                    {
                        TB_author.Text = aa.Name;
                    }
                    else
                    {
                        LB_coauthor.Items.Add(aa.Name);
                    }
                    i++;
                }
                TB_title.Text     = ba.Title;
                TB_publisher.Text = ba.PublisherPublisher.Name;

                Object qsel = null;
                foreach (Object q in LB_subject.Items)
                {
                    memo(q.ToString());
                    if (q.ToString().Contains(ba.Subject.PadRight(7) + "| "))
                    {
                        qsel = q;
                    }
                }
                LB_subject.SelectedItem = qsel;

                if (ba.Liked != null)
                {
                    hScrollBar1.Value = (int)ba.Liked;
                }
            }
        }
示例#7
0
        private bool savebook()
        {
            memo("Saving book...");
            if (String.IsNullOrEmpty(TB_title.Text))
            {
                string            message = "Cannot save book with empty title";
                string            caption = "No title";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result  = MessageBox.Show(message, caption, buttons);
                return(false);
            }

            //The book itself:
            bool wasnull = (ba == null);

            if (ba == null)
            {
                ba    = new BookAlbum();
                ba.Id = (from c in db.BookAlbum select c.Id).Max() + 1;
            }
            ba.Title = TB_title.Text;

            if (!String.IsNullOrEmpty(TB_firstyear.Text))
            {
                ba.YearFirst = util.tryconvert(TB_firstyear.Text);
                if (ba.YearFirst <= DateTime.Now.Year % 100)
                {
                    ba.YearFirst += 2000;
                }
                else
                {
                    ba.YearFirst += 1900;
                }
            }

            if (!String.IsNullOrEmpty(TB_thisyear.Text))
            {
                ba.YearThis = util.tryconvert(TB_thisyear.Text);
                if (ba.YearThis <= DateTime.Now.Year % 100)
                {
                    ba.YearThis += 2000;
                }
                else
                {
                    ba.YearThis += 1900;
                }
            }

            if (pubid >= 0)
            {
                ba.Publisher = pubid;
            }
            else
            {
                if (!String.IsNullOrEmpty(TB_publisher.Text))
                {
                    var q = from c in db.Publisher where c.Name == TB_publisher.Text select c;
                    if (q.Count() > 0)
                    {
                        ba.PublisherPublisher = q.First();
                    }
                    else
                    {
                        Publisher pp = new Publisher();
                        pp.Id   = (from c in db.Publisher select c.Id).Max() + 1;
                        pp.Name = TB_publisher.Text;
                        db.Publisher.InsertOnSubmit(pp);
                        db.SubmitChanges();
                        ba.Publisher = pp.Id;
                    }
                }
                else
                {
                    ba.Publisher = null;
                }
            }

            ba.Subject = LB_subject.SelectedItem.ToString().Split('|')[0].Trim();

            if (!String.IsNullOrEmpty(TB_when.Text))
            {
                try
                {
                    string s = TB_when.Text;
                    if (s.Length < 2)
                    {
                        s = s.PadLeft(2, '0');
                    }
                    if (s.Length < 6)
                    {
                        s = s.PadRight(6, '0');
                    }
                    int year = util.tryconvert(TB_when.Text.Substring(0, 2));
                    if (year < 50)
                    {
                        year += 2000;
                    }
                    else
                    {
                        year += 1900;
                    }
                    int month = util.tryconvert(TB_when.Text.Substring(2, 2));
                    if (month == 0)
                    {
                        month = 1;
                    }
                    int day = util.tryconvert(TB_when.Text.Substring(4, 2));
                    if (day == 0)
                    {
                        day = 1;
                    }
                    ba.DateBought = new DateTime(year, month, day);
                }
                catch (Exception ee)
                {
                    ba.DateBought = null;
                }
            }

            if (String.IsNullOrEmpty(TB_where.Text) || (TB_where.Text == "?"))
            {
                if (String.IsNullOrEmpty(ba.WhereBought))
                {
                    ba.WhereBought = null;
                }
            }
            else
            {
                ba.WhereBought = TB_where.Text;
            }

            if (String.IsNullOrEmpty(TB_price.Text) || (TB_price.Text == "?"))
            {
                if (!(ba.Price > 0))
                {
                    ba.Price = null;
                }
            }
            else
            {
                ba.Price = util.tryconvert(TB_price.Text);
            }

            ba.Type     = LB_type.SelectedIndex;
            ba.Liked    = hScrollBar1.Value;
            ba.Havecopy = CB_havecopy.Checked;
            if (wasnull)
            {
                db.BookAlbum.InsertOnSubmit(ba);
            }
            db.SubmitChanges();

            //Author(s):
            if (wasnull)
            {
                int        iab = (from c in db.AuthorBook select c.Id).Max() + 1;
                AuthorBook ab  = new AuthorBook();
                ab.Id = iab;
                iab++;
                ab.Author    = auid;
                ab.BookAlbum = ba.Id;
                db.AuthorBook.InsertOnSubmit(ab);
                foreach (string s in LB_coauthor.Items)
                {
                    AuthorBook abb = new AuthorBook();
                    abb.Id = iab;
                    iab++;
                    abb.BookAlbum = ba.Id;
                    abb.Author    = util.getid(s);
                    db.AuthorBook.InsertOnSubmit(abb);
                }
                db.SubmitChanges();
            }

            memo("... book saved.");
            return(true);
        }
示例#8
0
        public FormBookList(Librarydb dbpar, List <Author> authorlist, bool music, bool count, bool location)
        {
            InitializeComponent();
            db = dbpar;
            string indrag = "   ";
            Dictionary <int, string> typenamedict = new Dictionary <int, string>();

            foreach (Bookmusictype bm in (from c in db.Bookmusictype select c))
            {
                typenamedict.Add(bm.Id, bm.Type);
            }
            foreach (Author aa in authorlist)
            {
                int nb = 0;
                //listBox1.Items.Add(aa.Name);
                List <int>            books        = new List <int>();
                List <string>         bookitems    = new List <string>();
                List <string>         chapteritems = new List <string>();
                List <int>            cassettes    = new List <int>();
                Dictionary <int, int> typedict     = new Dictionary <int, int>();

                foreach (AuthorBook ab in aa.AuthorBook)
                {
                    books.Add(ab.BookAlbum);
                    string s = indrag + ab.BookAlbumBookAlbum.Title + " (" + dbutil.bkbprice(ab.BookAlbumBookAlbum.YearThis) + ")";
                    if ((ab.BookAlbumBookAlbum.Type == 0) != music)
                    {
                        if (!typedict.ContainsKey(ab.BookAlbumBookAlbum.Type))
                        {
                            typedict.Add(ab.BookAlbumBookAlbum.Type, 1);
                        }
                        else
                        {
                            typedict[ab.BookAlbumBookAlbum.Type]++;
                        }


                        if (ab.BookAlbumBookAlbum.Type > 0)
                        {
                            s += " " + ab.BookAlbumBookAlbum.Bookmusictype.Type;
                            if (ab.BookAlbumBookAlbum.Price > 0)
                            {
                                s += ab.BookAlbumBookAlbum.Price.ToString();
                                if (!cassettes.Contains((int)ab.BookAlbumBookAlbum.Price))
                                {
                                    cassettes.Add((int)ab.BookAlbumBookAlbum.Price);
                                }
                            }
                        }
                        //listBox1.Items.Add(s);
                        bookitems.Add(s);
                        nb++;
                    }
                }
                //if (nb > 0)
                //    listBox1.Items.Add("");
                int nc = 0;
                //int ncall = 0;
                foreach (AuthorChapter ac in aa.AuthorChapter)
                {
                    if (!books.Contains(ac.ChapterSongChapterSong.BookAlbum))
                    {
                        string    s  = indrag + indrag + ac.ChapterSongChapterSong.Title + ". in: ";
                        BookAlbum ba = ac.ChapterSongChapterSong.BookAlbumBookAlbum;
                        s += authorclass.BookAuthorString(db, ba) + " (" + dbutil.bkbprice(ba.YearThis) + ") " + ba.Title;
                        if ((ba.Type == 0) != music)
                        {
                            if (ba.Type > 0)
                            {
                                s += " " + ba.Bookmusictype.Type;
                                if (ba.Price > 0)
                                {
                                    s += ba.Price.ToString();
                                }
                            }
                            //listBox1.Items.Add(s);
                            chapteritems.Add(s);
                            nc++;
                        }
                    }
                }
                //if (nc > 0)
                //    listBox1.Items.Add("");
                string aas         = aa.Name;
                string bookalbum   = "books";
                string chaptersong = "chapters";
                if (music)
                {
                    bookalbum   = "albums";
                    chaptersong = "songs";
                }
                if (count)
                {
                    if (nb > 0)
                    {
                        aas += ", " + nb.ToString() + " " + bookalbum;
                    }
                    if (aa.AuthorChapter.Count > 0)
                    {
                        aas += ", " + aa.AuthorChapter.Count.ToString() + " " + chaptersong;
                    }
                }
                listBox1.Items.Add(aas);
                if (location)
                {
                    cassettes.Sort();
                    string locs = indrag;
                    foreach (int itype in typedict.Keys)
                    {
                        locs += " " + typedict[itype] + " " + typenamedict[itype];
                        if (itype == 2)
                        {
                            foreach (int ic in cassettes)
                            {
                                locs += " " + ic;
                            }
                        }
                        locs += ";";
                    }
                    listBox1.Items.Add(locs);
                }
                else
                {
                    foreach (string s in bookitems)
                    {
                        listBox1.Items.Add(s);
                    }
                    foreach (string s in chapteritems)
                    {
                        listBox1.Items.Add(s);
                    }
                }
            }
        }