Exemple #1
0
 public void btnSearch_Click(object sender, EventArgs e)
 {
     using (context = new LibContext(LibConnection.GetConnString()))
     {
         var authors = from a in context.authors
                       where a.name.ToLower().Contains(tbAuthorName.Text.ToLower()) &&
                       a.surname.ToLower().Contains(tbAuthorSur.Text.ToLower())
                       select a;
         var books = from b in context.books
                     join c in authors on b.bID equals c.bID into a1
                     from a in a1.DefaultIfEmpty()
                     where b.name.ToLower().StartsWith(cbName.Text.ToLower()) &&
                     b.ISBN10.ToLower().Contains(tbISBN10.Text.ToLower()) &&
                     b.ISBN13.ToLower().Contains(tbISBN13.Text.ToLower()) &&
                     b.language.ToLower().Contains(cbLang.Text.ToLower()) &&
                     b.genre.ToLower().Contains(tbGenre.Text.ToLower()) &&
                     b.publish.ToLower().Contains(tbPub.Text.ToLower()) &&
                     b.publish.ToLower().Contains(tbPub.Text.ToLower()) &&
                     b.pubDate.ToLower().Contains(tbPubDate.Text.ToLower()) &&
                     b.pubCountry.ToLower().Contains(tbPubCntry.Text.ToLower()) &&
                     b.coverType.ToLower().Contains(cbCover.Text.ToLower()) &&
                     b.state == 0
                     select new { Name     = b.name, Author = a.name.Trim() + " " + a.surname.Trim(), Category = b.department, Genre = b.genre, ID = b.bID,
                                  Language = b.language, Country = b.pubCountry, Publishing = b.publish, Date = b.pubDate };
         viewBooks.RowHeadersVisible     = false;
         viewBooks.DataSource            = books;
         viewBooks.Columns["ID"].Visible = false;
     }
     this.Close();
 }
Exemple #2
0
        private void baddReader_Click(object sender, EventArgs e)
        {
            bool success = false;

            if (tbName.Text.Trim().Equals(""))
            {
                tbName.BackColor = Color.Tomato;
                return;
            }

            if (tbSurname.Text.Trim().Equals(""))
            {
                tbSurname.BackColor = Color.Tomato;
                return;
            }

            if (tbPassport.Text.Trim().Equals(""))
            {
                tbPassport.BackColor = Color.Tomato;
                return;
            }

            if (tbAddress.Text.Trim().Equals(""))
            {
                tbAddress.BackColor = Color.Tomato;
                return;
            }
            if (tbPhoneNumber.Text.Trim().Equals(""))
            {
                tbPhoneNumber.BackColor = Color.Tomato;
                return;
            }
            using (context = new LibContext(LibConnection.GetConnString()))
            {
                context.Connection.Open();

                readers newReader = new readers();
                fillReader(newReader);

                try
                {
                    context.readers_.InsertOnSubmit(newReader);
                    context.SubmitChanges();
                    success = true;
                }
                catch (System.Exception ex)
                {
                    success = false;
                    throw new Exception($"Error: Could not add reader\n", ex);;
                }

                if (success)
                {
                    Close();
                }
            }
        }
Exemple #3
0
        private void btnDone_Click(object sender, EventArgs e)
        {
            using (context = new LibContext(LibConnection.GetConnString()))
            {
                var book1 = context.books.Where(b => b.bID == book.bID).First();
                fillBook(book1);
                var author1 = context.authors.Where(a => a.bID == book.bID);
                if (viewAuthors.RowCount - 1 >= author1.Count())
                {
                    int i = 0;
                    foreach (var a in author1)
                    {
                        fillAuthor(a, i, book.bID);
                        i++;
                    }
                    if (viewAuthors.RowCount > author1.Count())
                    {
                        for (int j = i; j < viewAuthors.RowCount - 1; j++)
                        {
                            Author a = new Author();
                            fillAuthor(a, j, book.bID);
                            context.authors.InsertOnSubmit(a);
                        }
                    }
                }
                else
                {
                    int i = 0;
                    foreach (var a in author1)
                    {
                        if (i < viewAuthors.RowCount - 1)
                        {
                            fillAuthor(a, i, book.bID);
                        }
                        else
                        {
                            context.authors.DeleteOnSubmit(a);
                        }
                        i++;
                    }
                }

                context.SubmitChanges();
            }
            btnDone.Visible   = false;
            btnDelete.Visible = false;
            btnEdit.Visible   = true;
            foreach (Control c in tabControl.Controls)
            {
                c.Enabled = false;
            }
        }
Exemple #4
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     using (context = new LibContext(LibConnection.GetConnString()))
     {
         var bookDel = context.books.Where(b => b.bID == book.bID).First();
         context.books.DeleteOnSubmit(bookDel);
         var auths = context.authors.Where(a => a.bID == book.bID);
         foreach (var a in auths)
         {
             context.authors.DeleteOnSubmit(a);
         }
         context.SubmitChanges();
     }
     this.Close();
 }
Exemple #5
0
 private void cbLang_SelectedValueChanged(object sender, EventArgs e)
 {
     using (context = new LibContext(LibConnection.GetConnString()))
     {
         try
         {
             var langs = context.langs.Where(c => c.code == cbLang.Text).Select(l => l.name);
             lbLangName.Text = langs.First();
         }
         catch (System.Exception ex)
         {
             MessageBox.Show(this, "Error: Could not load language\n" +
                             "Original error: " + ex.Message, "Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #6
0
        private void cbName_TextUpdate(object sender, EventArgs e)
        {
            cbName.Items.Clear();

            cbName.SelectionStart  = cbName.Text.Length;
            cbName.SelectionLength = 0;

            using (context = new LibContext(LibConnection.GetConnString()))
            {
                var books = from b in context.books
                            where b.name.ToLower().StartsWith(cbName.Text.ToLower())
                            group b by b.name into g
                            select g.Key;
                cbName.Items.AddRange(books.ToArray());
                cbName.DroppedDown = true;
            }
        }
Exemple #7
0
 private void cbCategory_DropDown(object sender, EventArgs e)
 {
     cbCategory.Items.Clear();
     using (var contex = new LibContext(LibConnection.GetConnString()))
     {
         try
         {
             var category = contex.categories.Select(l => l.name).ToArray();
             cbCategory.Items.AddRange(category);
         }
         catch (System.Exception ex)
         {
             MessageBox.Show(this, "Error: Could not load categories\n" +
                             "Original error: " + ex.Message, "Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #8
0
 private void cbLang_DropDown(object sender, EventArgs e)
 {
     cbLang.Items.Clear();
     using (context = new LibContext(LibConnection.GetConnString()))
     {
         try
         {
             var langs = context.langs.Select(l => l.code).ToArray();
             cbLang.Items.AddRange(langs);
         }
         catch (System.Exception ex)
         {
             MessageBox.Show(this, "Error: Could not load language\n" +
                             "Original error: " + ex.Message, "Error",
                             MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #9
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool succsse = true;

            if (tbCode.Text.Trim().Equals("") || tbName.Text.Trim().Equals(""))
            {
                if (tbCode.Text.Trim().Equals(""))
                {
                    tbCode.BackColor = Color.Tomato;
                }
                if (tbName.Text.Trim().Equals(""))
                {
                    tbName.BackColor = Color.Tomato;
                }
                return;
            }
            using (LibContext context = new LibContext(LibConnection.GetConnString()))
            {
                Category newCategory;
                fillCategory(out newCategory);
                try
                {
                    context.categories.InsertOnSubmit(newCategory);
                    context.SubmitChanges();
                }
                catch (System.Exception ex)
                {
                    succsse = false;
                    MessageBox.Show(this, "Error: Could not add category\n" +
                                    "Original error: " + ex.Message, "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            if (succsse)
            {
                tbName.Clear();
                tbCode.Clear();
            }
        }
Exemple #10
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            bool success = true;

            if (tbName.Text.Trim().Equals(""))
            {
                tbName.BackColor = Color.Tomato;
                return;
            }
            using (context = new LibContext(LibConnection.GetConnString()))
            {
                context.Connection.Open();
                for (int j = 0; j < nadCount.Value; j++)
                {
                    Book newBook = new Book();
                    fillBook(newBook);
                    try
                    {
                        context.Transaction = context.Connection.BeginTransaction();

                        try
                        {
                            context.books.InsertOnSubmit(newBook);
                            context.SubmitChanges();
                        }
                        catch (System.Exception ex)
                        {
                            throw new Exception($"Error: Could not add book\n", ex);;
                        }

                        if (viewAuthors.Rows[0].Cells[0].Value != null)
                        {
                            for (int i = 0; i < viewAuthors.RowCount - 1; i++)
                            {
                                Author newAuthor = new Author();
                                fillAuthor(newAuthor, i, newBook.bID);
                                try
                                {
                                    context.authors.InsertOnSubmit(newAuthor);
                                    context.SubmitChanges();
                                }
                                catch (System.Exception ex)
                                {
                                    throw new Exception($"Error: Could not add author N{i}", ex);
                                }
                            }
                        }
                        context.Transaction.Commit();
                    }
                    catch (System.Exception ex)
                    {
                        context.Transaction.Rollback();
                        //context.Connection.Close();
                        success = false;
                        MessageBox.Show(this, ex.Message + "\n" + "Original Error: " +
                                        ex.InnerException?.Message, "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                    //context.Connection.Close();
                }
            }
            if (success)
            {
                this.Close();
            }
        }