Пример #1
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();
            }
        }
Пример #2
0
        public void NewAuthorToDB(Librarydb db, int nextaudb)
        {
            Author adb = new Author();

            adb.Id              = nextaudb;
            this.iaudb          = nextaudb;
            adb.Familyname      = this.familyname;
            adb.FamilynameAscii = dbutil.RemoveDiacritics(this.familyname);
            if (String.IsNullOrEmpty(this.firstname))
            {
                adb.Givenname = this.initials;
            }
            else
            {
                adb.Givenname = this.firstname;
            }
            adb.GivennameAscii = dbutil.RemoveDiacritics(adb.Givenname);
            adb.Name           = authorclass.GetFullname(adb);

            db.Author.InsertOnSubmit(adb);

            if (this.affid > 0)
            {
                Authoraffiliation aaff = new Authoraffiliation();
                aaff.Id = 1;
                if ((from c in db.Authoraffiliation select c).Count() > 0)
                {
                    aaff.Id = (from c in db.Authoraffiliation select c.Id).Max() + 1;
                }
                aaff.Author      = this.iaudb;
                aaff.Affiliation = this.affid;
                db.Authoraffiliation.InsertOnSubmit(aaff);
            }
            db.SubmitChanges();
        }
Пример #3
0
 private void Savebutton_Click(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(TB_familyname.Text))
     {
         a.Familyname = TB_familyname.Text;
     }
     if (!String.IsNullOrEmpty(TB_givenname.Text))
     {
         a.Givenname = TB_givenname.Text;
     }
     a.FamilynameAscii = dbutil.RemoveDiacritics(a.Familyname);
     a.GivennameAscii  = dbutil.RemoveDiacritics(a.Givenname);
     a.Name            = authorclass.GetFullname(a);
     db.SubmitChanges();
     this.Close();
 }
Пример #4
0
        private void Savebutton_Click(object sender, EventArgs e)
        {
            if (!String.IsNullOrEmpty(TB_name.Text))
            {
                p.Name = TB_name.Text;
            }
            if (!String.IsNullOrEmpty(TB_location.Text))
            {
                p.Location = TB_location.Text;
            }
            if (!String.IsNullOrEmpty(TB_URL.Text))
            {
                p.URL = TB_URL.Text;
            }
            db.SubmitChanges();

            this.Close();
        }
Пример #5
0
        public static void MergePublishers(Librarydb db, Publisher pp1, Publisher pp2)
        {
            if (pp1.Id == pp2.Id)
            {
                return;
            }

            var qbook = from c in db.BookAlbum where c.Publisher == pp2.Id select c;

            foreach (BookAlbum ba in qbook)
            {
                ba.Publisher = pp1.Id;
            }

            var qjournal = from c in db.Journal where c.Publisher == pp2.Id select c;

            foreach (Journal jj in qjournal)
            {
                jj.Publisher = pp1.Id;
            }

            if (pp1.URL == null)
            {
                pp1.URL = pp2.URL;
            }
            if (pp1.Location == null)
            {
                pp1.Location = pp2.Location;
            }
            else if (pp2.Location != null)
            {
                pp1.Location += ", " + pp2.Location;
            }

            db.Publisher.DeleteOnSubmit(pp2);

            db.SubmitChanges();
        }
Пример #6
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);
        }
Пример #7
0
        public static void MergeDB(Librarydb db, Author adb1, Author adb2)//, Form1 parentform) //Merge adb2 into adb1 in database
        {
            //parentform.memo("Merging " + authorclass.GetFullname(adb2) + " into " + authorclass.GetFullname(adb1));
            //Affiliation relations
            var qaff = from c in db.Authoraffiliation where c.Author == adb2.Id select c;

            foreach (Authoraffiliation aa in qaff)
            {
                if ((from c in db.Authoraffiliation where c.Author == adb1.Id where c.Affiliation == aa.Affiliation select c).Count() > 0)
                {
                    db.Authoraffiliation.DeleteOnSubmit(aa);
                }
                else
                {
                    aa.Author = adb1.Id;
                }
            }

            //Article relations
            var qart = from c in db.AuthorArticle where c.Author == adb2.Id select c;

            foreach (AuthorArticle aa in qart)
            {
                if ((from c in db.AuthorArticle where c.Author == adb1.Id where c.Article == aa.Article select c).Count() > 0)
                {
                    db.AuthorArticle.DeleteOnSubmit(aa);
                }
                else
                {
                    aa.Author = adb1.Id;
                }
            }

            //Book relations
            var qbook = from c in db.AuthorBook where c.Author == adb2.Id select c;

            foreach (AuthorBook aa in qbook)
            {
                if ((from c in db.AuthorBook where c.Author == adb1.Id where c.BookAlbum == aa.BookAlbum select c).Count() > 0)
                {
                    db.AuthorBook.DeleteOnSubmit(aa);
                }
                else
                {
                    aa.Author = adb1.Id;
                }
            }

            //Chapter relations
            var qChapter = from c in db.AuthorChapter where c.Author == adb2.Id select c;

            foreach (AuthorChapter aa in qChapter)
            {
                if ((from c in db.AuthorChapter where c.Author == adb1.Id where c.ChapterSong == aa.ChapterSong select c).Count() > 0)
                {
                    db.AuthorChapter.DeleteOnSubmit(aa);
                }
                else
                {
                    aa.Author = adb1.Id;
                }
            }

            //Redirect any old aliases
            var qaa = from c in db.AuthorAlias where c.Author == adb2.Id select c;

            foreach (AuthorAlias caa in qaa)
            {
                caa.Author = adb1.Id;
            }

            //Create alias:
            AuthorAlias ala = new AuthorAlias();
            var         q   = (from c in db.AuthorAlias select c);
            int         ij  = 1;

            if (q.Count() > 0)
            {
                ij = (from c in db.AuthorAlias select c.Id).Max() + 1;
            }
            ala.Id         = ij;
            ala.Name       = adb2.Name;
            ala.Familyname = adb2.Familyname;
            ala.Givenname  = adb2.Givenname;
            ala.Author     = adb1.Id;
            db.AuthorAlias.InsertOnSubmit(ala);


            //Merge the actual authors. Assume FamilynameAscii same
            string oldname1  = authorclass.GetFullname(adb1);
            string oldfamily = adb1.Familyname;
            string oldgiven  = adb1.Givenname;

            if (adb1.Familyname != adb2.Familyname)
            {
                int d1 = dbutil.LevenshteinDistance(adb1.Familyname, adb1.FamilynameAscii);
                int d2 = dbutil.LevenshteinDistance(adb2.Familyname, adb1.FamilynameAscii);
                if (d2 > d1)
                {
                    adb1.Familyname = adb2.Familyname;
                }
            }
            if (adb2.Givenname.Length > adb1.Givenname.Length)
            {
                adb1.Givenname = adb2.Givenname;
            }
            else if (adb2.Givenname.Length == adb1.Givenname.Length)
            {
                int d1 = dbutil.LevenshteinDistance(adb1.Givenname, adb1.GivennameAscii);
                int d2 = dbutil.LevenshteinDistance(adb2.Givenname, adb1.GivennameAscii);
                if (d2 > d1)
                {
                    adb1.Givenname = adb2.Givenname;
                }
            }
            adb1.Name            = authorclass.GetFullname(adb1);
            adb1.FamilynameAscii = dbutil.RemoveDiacritics(adb1.Familyname);
            adb1.GivennameAscii  = dbutil.RemoveDiacritics(adb1.Givenname);
            db.Author.DeleteOnSubmit(adb2);

            if (authorclass.GetFullname(adb1) != oldname1)
            {
                //make alias from original adb1 name
                AuthorAlias ala1 = new AuthorAlias();
                ij++;
                ala1.Id         = ij;
                ala1.Name       = oldname1;
                ala1.Familyname = oldfamily;
                ala1.Givenname  = oldgiven;
                ala1.Author     = adb1.Id;
                db.AuthorAlias.InsertOnSubmit(ala1);
            }

            db.SubmitChanges();
        }