public FormNewShorts(Librarydb dbpar, FormNewBook parentpar, string mainauthorpar) { InitializeComponent(); db = dbpar; parent = parentpar; mainauthor = mainauthorpar; var q = from c in db.Author select c.Name; AutoCompleteStringCollection acs = new AutoCompleteStringCollection(); foreach (string s in q) { acs.Add(s); } TB_author.AutoCompleteCustomSource = acs; TB_author.Text = mainauthor; ics = (from c in db.ChapterSong select c.Id).Max() + 1; if (parent.shortslist.Count > 0) { int ics2 = (from c in parent.shortslist select c.Id).Max() + 1; ics = Math.Max(ics, ics2); } iac = (from c in db.AuthorChapter select c.Id).Max() + 1; if (parent.shortsauthorlist.Count > 0) { int iac2 = (from c in parent.shortsauthorlist select c.Id).Max() + 1; iac = Math.Max(iac, iac2); } }
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(); }
public List <Author> GetCompatibles(Librarydb db, int mincomp) { var q = from c in db.Author where c.FamilynameAscii == dbutil.RemoveDiacritics(this.familyname) select c; List <Author> compatibles = new List <Author>(); int icompmax = mincomp; //if (q.Count() > 0) // parentform.memo(this.firstname + "--------"); foreach (Author adb in q) { int icomp = this.Compatible(adb); //if (icomp > 0) // parentform.memo(icomp + " " + adb.Givenname); if (icomp > icompmax) { compatibles.Clear(); compatibles.Add(adb); icompmax = icomp; } else if (icomp == icompmax) { compatibles.Add(adb); } } return(compatibles); }
public FormSubject(Librarydb dbpar) { InitializeComponent(); db = dbpar; var qs = from c in db.Subject select c.Name; foreach (string s in qs) { CBmysubj.Items.Add(s); } var qc = from c in db.CrossrefSubject select c.Name; foreach (string s in qc) { CBcrossref.Items.Add(s); } var qp = from c in db.PubmedSubject select c.Name; foreach (string s in qp) { CBpubmed.Items.Add(s); } var qe = from c in db.EvolangSubject select c.Name; foreach (string s in qe) { CBevolang.Items.Add(s); } }
public FormFindAuthor(Librarydb dbpar) { db = dbpar; InitializeComponent(); textBox1.Text = ""; Init_Letterbuttons(); foreach (int i in buttondict.Keys) { this.Controls.Add(Letterbuttons[i]); Letterbuttons[i].Click += new System.EventHandler(Letterbutton_Click); } //dta.Columns.Add("Id", typeof(int)); //dta.Columns.Add("Name", typeof(string)); ////bind to combobox //this.comboBox1.DataSource = dta.DefaultView; //this.comboBox1.DisplayMember = "Name"; //this.comboBox1.ValueMember = "Id"; //suppose default ID is 4 then code as follow }
public FormDoAuthor(Librarydb dbpar, int authorid) { db = dbpar; InitializeComponent(); var q = from c in db.Author where c.Id == authorid select c; if (q.Count() == 0) { MessageBox.Show("Author not found, Id = " + authorid); this.Close(); } else { a = q.First(); this.Text = a.Name; } ArticleButton_Click(null, null); BookButton_Click(null, null); ShortsButton_Click(null, null); if (CB_articles.Items.Count > 1) { SubjectButton_Click(null, null); } }
public FormDoPublisher(Librarydb dbpar, int pid) { InitializeComponent(); db = dbpar; var qq = from c in db.Publisher where c.Id == pid select c; if (qq.Count() == 0) { MessageBox.Show("Author not found, Id = " + pid); this.Close(); } else { a = qq.First(); this.Text = a.Name; } // Waiting / hour glass Cursor.Current = Cursors.WaitCursor; var q = from c in db.BookAlbum where c.Publisher == a.Id select c; Bookcountlabel.Text = q.Count().ToString() + " books"; if (q.Count() > 0) { foreach (BookAlbum art in q) { //string s = art.AuthorBook.First().AuthorAuthor.Familyname+" (" + art.YearFirst + ") " + art.Title + ", " + a.Name; CB_books.Items.Add(art.AuthorBook.First().AuthorAuthor.Familyname + "(" + art.YearFirst + ") " + util.addid(art.Title, art.Id, 100)); } } else { CB_books.Items.Add("(no books)"); } var qj = from c in db.Journal where c.Publisher == a.Id select c; Journalcountlabel.Text = qj.Count().ToString() + " journals"; if (qj.Count() > 0) { foreach (Journal art in qj) { string s = art.Name; CB_journals.Items.Add(util.addid(art.Name, art.Id, 100)); } } else { CB_journals.Items.Add("(no journals)"); } // Back to normal Cursor.Current = Cursors.Default; }
public FormArticleList(Librarydb dbpar, List <Article> la) { InitializeComponent(); db = dbpar; foreach (Article aa in la) { CBart.Items.Add(artref(aa)); } }
public FormBookList(Librarydb dbpar, List <BookAlbum> booklist) { InitializeComponent(); db = dbpar; foreach (BookAlbum ba in booklist) { string s = authorclass.BookAuthorString(db, ba) + " (" + dbutil.bkbprice(ba.YearThis) + ") " + ba.Title; listBox1.Items.Add(s); } }
public static int NewAuthor(Librarydb db, string name) { int authorid = -1; authorclass ac = authorclass.Parse(name).FirstOrDefault(); if (ac != null) { authorid = ac.AuthorToDB(db); } return(authorid); }
public Form1() { //xx.Location = new Point(100, 100); //xx.Text = "Test button"; //xx.Size = new System.Drawing.Size(75, 23); ////xx.TabIndex = 0; //xx.UseVisualStyleBackColor = true; ////xx.Click += new System.EventHandler(xx_Click); //this.Controls.Add(xx); InitializeComponent(); db = new Librarydb(connectionstring); }
public static string ChapterAuthorString(Librarydb db, ChapterSong cs) { string s = ""; string sep = ""; foreach (AuthorChapter ab in cs.AuthorChapter) { s += sep + ab.AuthorAuthor.Name; sep = "&"; } return(s); }
public FormFindPublisher(Librarydb dbpar) { InitializeComponent(); db = dbpar; textBox1.Text = ""; Init_Letterbuttons(); foreach (int i in buttondict.Keys) { this.Controls.Add(Letterbuttons[i]); Letterbuttons[i].Click += new System.EventHandler(Letterbutton_Click); } }
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); }
public FormModifyPublisher(Librarydb dbpar, Publisher ppar) { InitializeComponent(); db = dbpar; p = ppar; TB_name.Text = p.Name; if (p.URL != null) { TB_URL.Text = p.URL; } if (p.Location != null) { TB_location.Text = p.Location; } }
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); } } }
public FormModifyAuthor(Librarydb dbpar, int authorid) { db = dbpar; InitializeComponent(); var q = from c in db.Author where c.Id == authorid select c; if (q.Count() == 0) { MessageBox.Show("Author not found, Id = " + authorid); this.Close(); } else { a = q.First(); this.Text = a.Name; } TB_familyname.Text = a.Familyname; TB_givenname.Text = a.Givenname; }
public FormDoArticle(Librarydb dbpar, int idpar) { InitializeComponent(); db = dbpar; id = idpar; art = (from c in db.Article where c.Id == id select c).FirstOrDefault(); if (art == null) { TB_title.Text = "(invalid article)"; } else { TB_title.Text = art.Title; this.Text = art.Title; Yearlabel.Text = art.Year.ToString(); var qa = (from c in db.AuthorArticle where c.Article == id select c); foreach (AuthorArticle aa in qa) { string s = util.addid(aa.AuthorAuthor.Name, aa.Author, 100); CB_author.Items.Add(s); } if (art.Journal != null) { Journallabel.Text = art.JournalJournal.Name; Volumelabel.Text = "Volume " + art.Volume.ToString(); Pageslabel.Text = "Pages " + art.Pages; } else { Journallabel.Text = art.Refstring; Volumelabel.Text = ""; Pageslabel.Text = ""; } if (art.Summary != null) { AbstractBox.AppendText(art.Summary); } } }
public FormDoJournal(Librarydb dbpar, int jid) { InitializeComponent(); db = dbpar; jj = (from c in db.Journal where c.Id == jid select c).FirstOrDefault(); if (jj == null) { this.Text = "(invalid journal)"; } else { this.Text = jj.Name; if (jj.Publisher != null) { Publisherlabel.Text = jj.PublisherPublisher.Name; } if (jj.ISSN != null) { ISSNlabel.Text = jj.ISSN; } } }
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(); }
public FormDelete(Librarydb dbpar) { db = dbpar; InitializeComponent(); }
public FormModify(Librarydb dbpar) { InitializeComponent(); db = dbpar; }
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; } } }
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); } } } }
public FormLook(Librarydb dbpar) { InitializeComponent(); db = dbpar; }
public FormListmaker(Librarydb dbpar, bool musicpar) { InitializeComponent(); db = dbpar; music = musicpar; }
public int AuthorToDB(Librarydb db) { if (!active) { return(-1); } if (iaudb > 0) { return(iaudb); } if (aliaslist.ContainsKey(this.GetFullname())) { //parentform.memo("Alias found for " + this.GetFullname()); return(aliaslist[this.GetFullname()]); } if (nextaudb < 0) { nextaudb = 1; var qq = (from c in db.Author select c); if (qq.Count() > 0) { nextaudb = (from c in db.Author select c.Id).Max() + 1; } } List <Author> compatibles = this.GetCompatibles(db, 4); if (compatibles.Count == 1) { iaudb = compatibles.First().Id; this.Merge(compatibles.First()); aliaslist.Add(this.GetFullname(), iaudb); } else if (compatibles.Count > 1) { //find which one is right. How? string msg = "Multiple matches for " + this.GetFullname() + ":"; string[] auarray = new string[compatibles.Count()]; int i = 0; foreach (Author adb in compatibles) { msg += "\n" + adb.Familyname + ", " + adb.Givenname; auarray[i] = adb.Familyname + ", " + adb.Givenname; i++; } //MessageBox.Show(msg); //Form2 f2 = new Form2(this, this.GetFullname(), auarray); //f2.ShowDialog(); //f2.Dispose(); //parentform.memo("form2choice = " + form2choice); if ((form2choice >= 0) && (form2choice < auarray.Length)) { iaudb = compatibles[form2choice].Id; this.Merge(compatibles[form2choice]); aliaslist.Add(this.GetFullname(), iaudb); } } if (iaudb < 0) { //New post: this.NewAuthorToDB(db, nextaudb); nextaudb++; } return(this.iaudb); }
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(); }