public Boolean ShowUserBook(int uid, MainControl mc, TabPage tb) { List <User_Book> booklist = User_BookServices.GetUserBooks(uid); //int i = Convert.ToInt32(booklist[1].book_id); //List<Book> book = null; if (booklist.Count != 0) { int i = 0; List <Book> book = new List <Book>(); foreach (var b in booklist) { book.Add(BookServices.GetById(Convert.ToInt32(booklist[i++].book_id))); } // = BookServices.CatagorySearch(category); foreach (var o in book) { IndividualBook ib = new IndividualBook(); ib.setData(o, tb); flowLayoutPanel.Controls.Add(ib); } return(true); //MessageBox.Show("Book available.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { //MetroFramework.MetroMessageBox.Show(mc, "No Book available.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); //MessageBox.Show("No Book available.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); //Console.WriteLine("no book found"); return(false); } }
public void setData(User u) { textName.Text = u.name; textEmail.Text = u.email; if (u.picture != null) { pictureBox.Image = byteArrayToImage(u.picture); } textAverageRating.Text = User_BookServices.AvarageRating(u.id).ToString(); textTotalRead.Text = User_BookServices.CountBook(u.id).ToString(); }
public void setData(Book b, TabPage tb) { this.b = b; this.tb = tb; textName.Text = b.name; textRating.Text = b.rating.ToString(); textAuthor.Text = b.author; textCategory.Text = b.category; textBoxDescription.Text = b.description; textRating.Text = b.rating.ToString(); if (b.picture != null) { pictureBox.Image = byteArrayToImage(b.picture); } if (StarterForm.loggedStatus == true) { int uid = StarterForm.loggedInUser.id; int bid = b.id; User_Book combination = User_BookServices.DuplicateCombination(uid, bid); metroLabel11.Visible = true; textBoxGiveRating.Visible = true; btnSave.Visible = true; metroLabel12.Visible = true; comboSelect.Visible = true; if (combination != null) { textBoxGiveRating.Text = combination.rating.ToString(); if (combination.subscribe == 0) { comboSelect.SelectedIndex = 0; } else if (combination.subscribe == 1) { comboSelect.SelectedIndex = 1; } else if (combination.subscribe == 2) { comboSelect.SelectedIndex = 2; } else if (combination.subscribe == 3) { comboSelect.SelectedIndex = 3; } } } }
private void btnSave_Click(object sender, EventArgs e) { //User u = UserServices.GetByEmail(Form2.loggedInUser.email); int uid = StarterForm.loggedInUser.id; int bid = b.id; User_Book ub = new User_Book(); ub.book_id = bid; ub.user_id = uid; User_Book combination = User_BookServices.DuplicateCombination(uid, bid); if (combination == null) { if (comboSelect.Text == "Want to Read") { ub.subscribe = 1; } else if (comboSelect.Text == "Currently Reading") { ub.subscribe = 2; } else if (comboSelect.Text == "Read") { ub.subscribe = 3; } else { ub.subscribe = 0; } if (textBoxGiveRating.Text != "") { ub.rating = Convert.ToInt32(textBoxGiveRating.Text); } User_BookServices.Insert(ub); } else { if (comboSelect.Text == "Want to Read") { combination.subscribe = 1; } else if (comboSelect.Text == "Currently Reading") { combination.subscribe = 2; } else if (comboSelect.Text == "Read") { combination.subscribe = 3; } else { combination.subscribe = 0; } if (textBoxGiveRating.Text != "") { combination.rating = Convert.ToInt32(textBoxGiveRating.Text); } User_BookServices.Update(combination); } double avg = User_BookServices.SpecificAvarageRating(bid); Book book = BookServices.GetById(bid); if (avg <= 10) { book.rating = Convert.ToInt32(avg); } else { MetroFramework.MetroMessageBox.Show(this, "Rating should be between (0-10).", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } BookServices.Update(book); }