Exemplo n.º 1
0
        public void Give_Penalty_To_User(User user, Book book, Receipt penalty, Detail detail)
        {
            penalty.Add();
            user.Fee += penalty.Fee;
            user.Change_Fee();
            detail.Tb_5.Text = user.Fee + "₺";



            if (penalty.Pt_name == "LOST" || penalty.Pt_name == "DAMAGED")
            {
                user.Book_count--;
                string    query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, user.User_id);
                DataTable dt           = DataBaseEvents.ExecuteQuery(query_select, data_source);

                if (dt.Rows.Count <= 0)
                {
                    return;
                }

                int current_count = int.Parse(dt.Rows[0][0].ToString());
                if (current_count > 1)
                {
                    current_count--;
                    string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, user.User_id);
                    DataBaseEvents.ExecuteNonQuery(query_update, data_source);
                }
                else
                {
                    string query_delete = string.Format("Delete From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, user.User_id);
                    DataBaseEvents.ExecuteNonQuery(query_delete, data_source);
                }

                detail.Dgw_users.DataSource = Book.Show_All_Books(user);
                detail.Tb_6.Text            = user.Book_count.ToString();
            }
        }
Exemplo n.º 2
0
        public override void Revert_Changes(Book book, User user)
        {
            if (this.mode == MODE.GIVE)
            {
                book.Count++;
                book.Change_Count();

                string    query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.User_id);
                DataTable dt           = DataBaseEvents.ExecuteQuery(query_select, data_source);

                if (dt.Rows.Count <= 0)
                {
                    return;
                }

                int current_count = int.Parse(dt.Rows[0][0].ToString());
                if (current_count > 1)
                {
                    current_count--;
                    string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, this.user_id);
                    DataBaseEvents.ExecuteNonQuery(query_update, data_source);
                }
                else
                {
                    string query_delete = string.Format("Delete From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.user_id);
                    DataBaseEvents.ExecuteNonQuery(query_delete, data_source);
                }



                // Popularity
                Author   aut = main_page.Main_author_list.Find_Author_By_ID(book.Author_id);
                Category ctg = main_page.Main_category_list.Find_Category_By_ID(book.Category_id);

                book.Popularity_score -= 5;
                aut.Popularity_score  -= 5;
                ctg.Popularity_score  -= 5;

                book.Change_Popularity_Score();
                aut.Change_Popularity_Score();
                ctg.Change_Popularity_Score();
            }
            else
            {
                book.Count--;
                book.Change_Count();

                string    query_select = string.Format("Select Book_User.COUNT From Book_User Where Book_User.BOOK_ID = {0} and Book_User.USER_ID = {1}", book.Book_id, this.User_id);
                DataTable dt           = DataBaseEvents.ExecuteQuery(query_select, data_source);

                if (dt.Rows.Count <= 0)
                {
                    string query_delete = string.Format("Insert Into Book_User(BOOK_ID, USER_ID, COUNT) Values({0},{1},{2})", book.Book_id, this.user_id, 1);
                    DataBaseEvents.ExecuteNonQuery(query_delete, data_source);
                }
                else
                {
                    int current_count = int.Parse(dt.Rows[0][0].ToString());
                    if (current_count > 0)
                    {
                        current_count++;
                        string query_update = string.Format("Update Book_User Set COUNT = {0} Where Book_User.BOOK_ID = {1} and Book_User.USER_ID = {2}", current_count, book.Book_id, this.user_id);
                        DataBaseEvents.ExecuteNonQuery(query_update, data_source);
                    }
                }
            }
        }