public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { LinkedList <BookGeneralData> books = dbPackingClass.getBooksWithGeneralDataWithin05hour(user); int recentlySearched = 0; foreach (BookGeneralData b in books) { if (b.id == book.id) { recentlySearched++; } } int recentlySearchedCategs = 0; LinkedList <string> bookCategs = dbPackingClass.getBookCategories(book); foreach (BookWithAuthorsAndCategories b in books) { LinkedList <string> secondBookCategs = dbPackingClass.getBookCategories(b); foreach (string categ in bookCategs) { if (secondBookCategs.Contains(categ)) { recentlySearchedCategs++; } } } makeConsoleLog(ModuleInfo.MainMultiplicator * (recentlySearched * ModuleInfo.getMultiplicatorAt("recentlySearched") + recentlySearchedCategs * ModuleInfo.getMultiplicatorAt("categories"))); return(ModuleInfo.MainMultiplicator * (recentlySearched * ModuleInfo.getMultiplicatorAt("recentlySearched") + recentlySearchedCategs * ModuleInfo.getMultiplicatorAt("categories"))); } return(0); }
public LinkedList <Bonus> getBonusFromAdmin(BookGeneralData book) { string commandText = "select multiplicator, bonusPeriodStart, bonusPeriodEnd, id_bonus from bonuses where id_book =@book_id and bonusPeriodStart <= GETDATE() and bonusPeriodEnd >= GETDATE()"; SqlCommand command2 = new SqlCommand(commandText, cnn); command2.Parameters.AddWithValue("@book_id", book.id); command2.CommandType = CommandType.Text; LinkedList <Bonus> bonuses = new LinkedList <Bonus>(); using (SqlDataReader oReader = command2.ExecuteReader()) { while (oReader.Read()) { int multiplicator = oReader.GetInt32(0); DateTime begin = oReader.GetDateTime(1); DateTime end = oReader.GetDateTime(2); int id = oReader.GetInt32(3); Bonus b = new Bonus(); b.multiplicator = multiplicator; b.begin = begin; b.end = end; b.bonus_id = id; bonuses.AddLast(b); } } return(bonuses); }
public LinkedList <BookGeneralData> getBooksWithGeneralDataWithin05hour(CurrentUser user) { string commandText = "select books.ID_book, title, price, priceMinusDiscountInProcent from books join SearchResHist on books.ID_book = SearchResHist.ID_book where id_user=@userId and DATEDIFF(MINUTE, dateOfSearch, getDate())<=@minutes"; SqlCommand command2 = new SqlCommand(commandText, cnn); command2.Parameters.AddWithValue("@userId", user.id); command2.Parameters.AddWithValue("@minutes", 120); command2.CommandType = CommandType.Text; LinkedList <BookGeneralData> recentlySearchedBooks = new LinkedList <BookGeneralData>(); using (SqlDataReader oReader = command2.ExecuteReader()) { while (oReader.Read()) { int book_id = oReader.GetInt32(0); string title = oReader.GetString(1); decimal price = (decimal)(oReader.GetSqlMoney(2)); int priceMinusdiscount = oReader.GetInt32(3); Book b = new Book(); b.id = book_id; b.title = title; b.price = price; b.priceMinusDiscountInProcent = priceMinusdiscount; BookGeneralData book = b; recentlySearchedBooks.AddLast(book); } } return(recentlySearchedBooks); }
protected override ManagerStory.Story PrintFormattedStory(StoryProgressionObject manager, string text, string summaryKey, object[] parameters, string[] extended, ManagerStory.StoryLogging logging) { Writing skill = Sim.SkillManager.GetSkill <Writing>(SkillNames.Writing); WrittenBookData writing = skill.LastCompletedWriting; List <BookGeneralData> randomList = new List <BookGeneralData>(BookData.BookGeneralDataList.Values); BookGeneralData randomObjectFromList = RandomUtil.GetRandomObjectFromList(randomList); int genre = RandomUtil.GetInt(1, Writing.kDialogsPerGenre); int quality = RandomUtil.GetInt(1, Writing.kDialogsPerQuality); text = Writing.LocalizeString(Sim.IsFemale, "Finished" + writing.Genre.ToString() + genre, new object[] { Sim, writing.NumPages, writing.Title, randomObjectFromList.Title }); if (writing.Quality != Writing.WrittenBookQuality.Normal) { string str2 = Writing.LocalizeString(Sim.IsFemale, "Finished" + writing.Quality.ToString() + quality, new object[] { Sim, writing.NumPages, writing.Title }); text = text + " " + str2; } string str3 = Writing.LocalizeString(Sim.IsFemale, "RoyaltyDetails", new object[] { Sim, Writing.kRoyaltyLength, writing.Royalty, SimClockUtils.GetText(Writing.kRoyaltyPayHour) }); text = text + Common.NewLine + Common.NewLine + str3; if (extended == null) { extended = new string[] { writing.Title, EAText.GetNumberString(writing.Royalty) }; } return(base.PrintFormattedStory(manager, text, summaryKey, parameters, extended, logging)); }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { makeConsoleLog(ModuleInfo.MainMultiplicator * dbPackingClass.getNewBooksBonus(book)); return(ModuleInfo.MainMultiplicator * dbPackingClass.getNewBooksBonus(book)); } return(0); }
public void removeBookfromToBuy(BookGeneralData book, CurrentUser user) { string commandText = "delete from UserBooksToBuy where ID_user=@par_user_id and ID_book=@par_book_id;"; SqlCommand cmd = new SqlCommand(commandText, cnn); cmd.Parameters.AddWithValue("@par_book_id", book.id); cmd.Parameters.AddWithValue("@par_user_id", user.id); int rowAffected = cmd.ExecuteNonQuery(); }
public void viewBook(BookGeneralData book, CurrentUser user) { String query = "insert into ViewingHistory (ID_user,ID_book, DateOfViewing) values (@curr_usr, @viewed_book, GETDATE())"; SqlCommand command = new SqlCommand(query, cnn); command.Parameters.Add("@curr_usr", user.id); command.Parameters.Add("@viewed_book", book.id); command.ExecuteNonQuery(); }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (!ModuleInfo.Active) { int howManySimilarCategsBooksViewedIn05h = dbPackingClass.getNoOfSimilarBooksViewedWithinHalfAnHour(book, user); makeConsoleLog(howManySimilarCategsBooksViewedIn05h); return(ModuleInfo.MainMultiplicator * howManySimilarCategsBooksViewedIn05h); } return(0); }
public void setGeneralDataFromOtherBook(BookGeneralData otherBook) { id = otherBook.id; title = otherBook.title; price = otherBook.price; priceMinusDiscountInProcent = otherBook.priceMinusDiscountInProcent; quantity = otherBook.Quantity; startSellingDate = otherBook.StartSellingDate; deleted = otherBook.Deleted; }
public void unrate(BookGeneralData book, CurrentUser user) { String query = "delete from UsersBooksRates where ID_user=@curr_usr and ID_book=@unrated_book_id"; SqlCommand command = new SqlCommand(query, cnn); command.Parameters.Add("@curr_usr", user.id); command.Parameters.Add("@unrated_book_id", book.id); command.ExecuteNonQuery(); }
public void setRate(BookGeneralData book, CurrentUser user, int rate) { SqlCommand cmd = new SqlCommand("deleteAndInsertNewRate", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@par_book_id", book.id); cmd.Parameters.AddWithValue("@par_user_id", user.id); cmd.Parameters.AddWithValue("@par_new_rate", rate); int rowAffected = cmd.ExecuteNonQuery(); }
private void buttonRemoveFromToBuy_Click(object sender, EventArgs e) { if (guiManager.isShowingToBuyBooks() & guiManager.DGVhasSelectedCell()) { BookGeneralData toRemove = getSelectedBook(); if (toRemove != null) { accountInterfaceObject.removeBookFromToBuy(toRemove); guiManager.reloadLastOperation(); } } }
private void dataGridViewBooks_CellContentClick(object sender, DataGridViewCellEventArgs e) { BookGeneralData currentBook = getSelectedBook(); if (currentBook != null) { int currentBookRate = accountInterfaceObject.getBookRate(currentBook); prepareComboBox(); comboBox1.SelectedIndex = currentBookRate; //comboBox1.Refresh(); } }
public static int countAllSameAuthors(BookGeneralData thisBook, LinkedList <BookGeneralData> Books, IRecommendationsGetters dbPackingClass) { LinkedList <Author> thisBookAuthors = dbPackingClass.getBookAuthors(thisBook); int totalAuthorCount = 0; foreach (Book boughtBook in Books) { int authorsCount = countAuthors(boughtBook, thisBookAuthors, dbPackingClass); totalAuthorCount += authorsCount; } return(totalAuthorCount); }
public void saveBookInToBuy(BookGeneralData book, CurrentUser user) { try { string cmdText = "Insert into UserBooksToBuy (ID_user, ID_book) values (@id_user, @id_book)"; SqlCommand cmd = new SqlCommand(cmdText, cnn); cmd.Parameters.AddWithValue("@id_user", user.id); cmd.Parameters.AddWithValue("@id_book", book.id); cmd.ExecuteNonQuery(); } catch (Exception e) { } }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { LinkedList <BookGeneralData> booksToBuy = dbPackingClass.getToBuyBooks(user); int booksWithTheSameCategs = FunctionsUtils.countSameCategoriesBooks(book, booksToBuy, dbPackingClass); int booksWithTheSameAuthors = FunctionsUtils.countAllSameAuthors(book, booksToBuy, dbPackingClass); makeConsoleLog(ModuleInfo.MainMultiplicator * (booksWithTheSameCategs * ModuleInfo.getMultiplicatorAt("SameCategory") + booksWithTheSameAuthors * ModuleInfo.getMultiplicatorAt("SameAuthor"))); return(ModuleInfo.MainMultiplicator * (booksWithTheSameCategs * ModuleInfo.getMultiplicatorAt("SameCategory") + booksWithTheSameAuthors * ModuleInfo.getMultiplicatorAt("SameAuthor"))); } return(0); }
/* * void setDGVScoreColumnVisibilty(bool par) * { * dataGridViewBooks.Columns[2].Visible = par; * } */ private void dataGridViewBooks_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (!guiManager.cellSelectedAndContainsValue()) { return; } BookGeneralData currentBook = guiManager.getSelectedBook(); if (currentBook != null) { int currentBookRate = searchFunctions.getBookRate(currentBook); comboBoxRate.SelectedIndex = currentBookRate; } }
public string buyBook(BookGeneralData bookToBuy, int quantity) { if (bookToBuy.Deleted) { return("Unable to buy unavailable book"); } if (quantity <= 0 || quantity > bookToBuy.Quantity) { return("Quantity must be integer value greater than 0 and lesser or equal than number of books available (" + bookToBuy.Quantity.ToString() + ")"); } databaseFunctions.buyBook(bookToBuy, User, quantity); return(operationSuccesful()); }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { LinkedList <Bonus> bonuses = dbPackingClass.getBonusFromAdmin(book); int sum = 0; foreach (Bonus b in bonuses) { sum += b.multiplicator; } makeConsoleLog(sum * ModuleInfo.MainMultiplicator); return(sum * ModuleInfo.MainMultiplicator); } return(0); }
public void buyBook(BookGeneralData book, CurrentUser user, int quantity) { try { SqlCommand cmd = new SqlCommand("buyBook", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@bookId", book.id); cmd.Parameters.AddWithValue("@userId", user.id); cmd.Parameters.AddWithValue("@howMany", quantity); int rowAffected = cmd.ExecuteNonQuery(); } catch (Exception e) { } }
/* * private Book getSelectedBook() * { * if(guiManager.cellSelectedAndContainsValue()) * { * try * { * Book toReturn = (dataGridViewBooks.CurrentCell.Value as BookInfoContainer).book; * return toReturn; * } * catch(Exception e) * { * return null; * } * } * return null; * } */ private void comboBoxRate_SelectedIndexChanged(object sender, EventArgs e) { BookGeneralData currentBook = guiManager.getSelectedBook(); if (currentBook != null) { if (comboBoxRate.SelectedIndex == 0) { searchFunctions.unrateBook(currentBook); } else { searchFunctions.setBookRate(currentBook, comboBoxRate.SelectedIndex); } } }
public static int countAuthors(BookGeneralData boughtBook, LinkedList <Author> thisBookAuthors, IRecommendationsGetters dbPackingClass) { LinkedList <Author> boughtBookAuthors = dbPackingClass.getBookAuthors(boughtBook); int authcount = 0; foreach (Author tba in thisBookAuthors) { foreach (Author bba in boughtBookAuthors) { if (bba.Id == tba.Id) { authcount++; } } } return(authcount); }
public int getBookRate(BookGeneralData currentBook, CurrentUser user) { int bookRate = 0; string oString = "Select Rate from UsersBooksRates ubr join Books b on b.ID_book = ubr.ID_book join Users u on u.ID=ubr.ID_user where u.ID=@currUsrID and b.ID_book=@currBook"; SqlCommand oCmd = new SqlCommand(oString, cnn); oCmd.Parameters.AddWithValue("@currUsrID", user.id); oCmd.Parameters.AddWithValue("@currBook", currentBook.id); using (SqlDataReader oReader = oCmd.ExecuteReader()) { if (oReader.Read()) { bookRate = oReader.GetInt32(0); } } return(bookRate); }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { LinkedList <BookGeneralData> recentlyRecommended = dbPackingClass.getBooksRecommendedWithin05h(user); int bonus = 0; foreach (Book b in recentlyRecommended) { if (b.id == book.id) { bonus++; } } makeConsoleLog(ModuleInfo.MainMultiplicator * bonus); return(ModuleInfo.MainMultiplicator * bonus); } return(0); }
public override int calculateScore(IRecommendationsGetters dbPackingClass, BookGeneralData book, CurrentUser user) { if (ModuleInfo.Active) { LinkedList <string> likedCategs = dbPackingClass.getLikedCategories(user); LinkedList <string> bookcategs = dbPackingClass.getBookCategories(book); int categsCount = 0; foreach (string categ in bookcategs) { if (likedCategs.Contains(categ)) { categsCount++; } } makeConsoleLog(categsCount * ModuleInfo.MainMultiplicator); return(categsCount * ModuleInfo.MainMultiplicator); } return(0); }
public int getNewBooksBonus(BookGeneralData book) { string commandText = "select 1 from books where DATEDIFF(day, start_selling_date, getdate()) <=@timeWhenBookNew and id_book=@book_id;"; SqlCommand command2 = new SqlCommand(commandText, cnn); command2.Parameters.AddWithValue("@book_id", book.id); command2.Parameters.AddWithValue("@timeWhenBookNew", 60); command2.CommandType = CommandType.Text; LinkedList <Bonus> bonuses = new LinkedList <Bonus>(); using (SqlDataReader oReader = command2.ExecuteReader()) { if (oReader.Read()) { return(1); } } return(0); }
public LinkedList <string> getBookCategories(BookGeneralData book) { string commandText2 = "select categName from Categories join Bookcategories on CategName=categoryName where id_book=@book_id "; SqlCommand command2 = new SqlCommand(commandText2, cnn); command2.Parameters.AddWithValue("@book_id", book.id); command2.CommandType = CommandType.Text; LinkedList <string> categories = new LinkedList <string>(); using (SqlDataReader oReader = command2.ExecuteReader()) { while (oReader.Read()) { string category = oReader.GetString(0); categories.AddLast(category); } } return(categories); }
/* * private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) * { * * } */ private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e) { if (comboBox1.SelectedIndex != -1) { BookGeneralData ratedBook = getSelectedBook(); if (ratedBook == null) { return; } if (comboBox1.SelectedIndex == 0) { accountInterfaceObject.unrateBook(ratedBook); } else { accountInterfaceObject.setBookRate(ratedBook, comboBox1.SelectedIndex); } } guiManager.reloadLastOperation(); }
public LinkedList <UserRatesInfoSet> getAllRowsInRates(BookGeneralData book) { string commandText = "select ID_user, ID_book, Rate from UsersBooksRates where ID_book=" + book.id.ToString() + ";"; SqlCommand command2 = new SqlCommand(commandText, cnn); command2.CommandType = CommandType.Text; LinkedList <UserRatesInfoSet> rates = new LinkedList <UserRatesInfoSet>(); using (SqlDataReader oReader = command2.ExecuteReader()) { while (oReader.Read()) { int id_user = oReader.GetInt32(0); int id_book = oReader.GetInt32(1); int rate = oReader.GetInt32(2); UserRatesInfoSet uris = new UserRatesInfoSet(id_book, id_user, rate); rates.AddLast(uris); } } return(rates); }
public int getNoOfSimilarBooksViewedWithinHalfAnHour(BookGeneralData book, CurrentUser user) { SqlCommand cmd = new SqlCommand("viewsWithinMinutes", cnn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@argUserID", user.id); cmd.Parameters.AddWithValue("@argBookID", book.id); cmd.Parameters.AddWithValue("@time", 30); var returnParameter = new SqlParameter("@count", SqlDbType.Int); returnParameter.Direction = ParameterDirection.Output; cmd.Parameters.Add(returnParameter); cmd.ExecuteNonQuery(); var countSQL = returnParameter.Value; int count = Convert.ToInt32(cmd.Parameters["@count"].Value); return(count); }