/**@brief getAllUserPurchases() function * * @param int userID */ public List <ItemToPurchaseClass> getAllUserPurchases(int userID) { try { DatabaseHelperClass dbHelper = DatabaseHelperClass.Instance; //SINGLETON PATTERN SqlConnection connection = dbHelper.getConnection(); SqlCommand command = new SqlCommand("SELECT * FROM ShoppingCartTable WHERE customerid=@id", connection); command.Parameters.AddWithValue("@id", userID); List <ItemToPurchaseClass> list = new List <ItemToPurchaseClass>(); SqlDataReader readShoppingCart = command.ExecuteReader(); if (readShoppingCart != null) { while (readShoppingCart.Read()) { ItemToPurchaseClass item = new ItemToPurchaseClass(); ProductClass book = new BookClass(); item.product = book; item.product.id = readShoppingCart["itemid"].ToString(); item.quantity = Convert.ToInt32(readShoppingCart["quantity"]); item.product.price = Convert.ToDouble(readShoppingCart["paymentamount"]); item.product.name = readShoppingCart["name"].ToString(); item.product.cover_page_picture = readShoppingCart["picture"].ToString(); list.Add(item); } } return(list); } catch (Exception e) { FileWriterClass.WriteFile(AppConstants.EXCEPTION_LOG_FILE_LOCATION, "Exception at getAllUserPurchases function" + e.Message); Console.WriteLine("Click {0}", e.Message); return(null); } }
public List <ItemToPurchaseClass> getMostBoughtItems(string itemtype) { try { DatabaseHelperClass dbHelper = DatabaseHelperClass.Instance; //SINGLETON PATTERN SqlConnection connection = dbHelper.getConnection(); SqlCommand command = new SqlCommand("SELECT S.itemid,S.picture,S.name,S.paymentamount,SUM(S.quantity) AS totalquantity FROM ShoppingCartTable S WHERE S.itemtype = @itemtype GROUP BY S.itemid, S.picture, S.name, S.paymentamount Order by totalquantity desc", connection); command.Parameters.AddWithValue("@itemtype", itemtype); List <ItemToPurchaseClass> list = new List <ItemToPurchaseClass>(); SqlDataReader readShoppingCart = command.ExecuteReader(); if (readShoppingCart != null) { while (readShoppingCart.Read()) { ItemToPurchaseClass item = new ItemToPurchaseClass(); ProductClass book = new BookClass(); item.product = book; item.product.id = readShoppingCart["itemid"].ToString(); item.quantity = Convert.ToInt32(readShoppingCart["totalquantity"]); item.product.price = Convert.ToDouble(readShoppingCart["paymentamount"]); item.product.name = readShoppingCart["name"].ToString(); item.product.cover_page_picture = readShoppingCart["picture"].ToString(); list.Add(item); } } return(list); } catch (Exception e) { FileWriterClass.WriteFile(AppConstants.EXCEPTION_LOG_FILE_LOCATION, "Exception at getMostBoughtItems function" + e.Message); Console.WriteLine("Click {0}", e.Message); return(null); } }
/** * A list of allbooks in the book class' getAllBooksFromDB() function is created. * bookUserControlsis created from the BookUserControl class. * The size of bookusercontrols is up to the length of allbooks. */ private void populateBooksViewInHomePage() { List <BookClass> allBooks = BookClass.getAllBooksFromDB(); BookUserControl[] bookUserControls = new BookUserControl[allBooks.Count]; if (flpHomePage.Controls.Count > 0) { flpHomePage.Controls.Clear(); } int i = 0; foreach (var item in allBooks) { bookUserControls[i] = new BookUserControl(); bookUserControls[i].bookID = item.id; bookUserControls[i].bookName = item.name; bookUserControls[i].bookAuthor = item.author; bookUserControls[i].bookPrice = item.price; bookUserControls[i].stock = item.stock; bookUserControls[i].cover_page_picture = item.cover_page_picture; flpHomePage.Controls.Add(bookUserControls[i]); i++; } }
private void pbHomePage_Click(object sender, EventArgs e) { tabControlGeneral.SelectedTab = tabHomePage; lblNavigator.Text = "Home Page"; BookClass book = new BookClass(); book.printProperties(); }
/**this function read book item in database * and assign bookclass parameter(id,name,price,stock,author,publisher,isbn,page,cover_page_picture) * @param string id * @return book */ public static BookClass getaBooksFromDBByID(string id) { DatabaseHelperClass dbHelper = DatabaseHelperClass.Instance; //SINGLETON PATTERN BookClass book = new BookClass(); book = dbHelper.getABookFromDBByID(id); return(book); }
/** @ brief adds the purchased book to the shopping cart * create a book from BookClass * and item added shoppingcartclass */ private void btnBookAddToCart_Click(object sender, EventArgs e) { BookClass book = new BookClass(); book = BookClass.getaBooksFromDBByID(bookID); ShoppingCartClass.addProduct(new ItemToPurchaseClass(book, Convert.ToInt32(Math.Round(nudQuantity.Value, 0)))); System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["BookShopForm"]; int quantity = 0; foreach (var item in ShoppingCartClass.itemsToPurchase) { quantity += item.quantity; } ((BookShopForm)f).lblShoppinCartValue.Text = quantity.ToString(); MessageBox.Show("Added to cart.", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void btnUpdateBook_Click(object sender, EventArgs e) { BookClass book = new BookClass(txtBookName.Text, txtBookId.Text, Convert.ToDouble(txtBookPrice.Text), Convert.ToInt32(txtBookStock.Text), txtBookIsbn.Text, txtBookAuthor.Text, txtBookPublisher.Text, Convert.ToInt32(txtBookPage.Text), txtBookImage.Text); //bool affected = dbHelper.updateAProductAtDB(book); AdminUserClass adminOps = AdminUserClass.Instance; bool affected = adminOps.updateProduct(book); if (!affected) { MessageBox.Show("Error not successful"); } else { MessageBox.Show("Book updated successfully", "INFORMATION", MessageBoxButtons.OK, MessageBoxIcon.Information); clearBookControls(); } }
public List <BookClass> getAllBooksFromDB() { try { List <BookClass> books = new List <BookClass>(); DatabaseHelperClass dbHelper = DatabaseHelperClass.Instance; //SINGLETON PATTERN SqlConnection connection = dbHelper.getConnection(); SqlCommand command = new SqlCommand("SELECT * FROM BookTable", connection); SqlDataReader readBooks = command.ExecuteReader(); if (readBooks != null) { while (readBooks.Read()) { BookClass book = new BookClass(); book.id = readBooks["id"].ToString(); book.name = readBooks["name"].ToString(); book.price = Convert.ToDouble(readBooks["price"]); book.stock = Convert.ToInt32(readBooks["stock"]); book.author = readBooks["author"].ToString(); book.publisher = readBooks["publisher"].ToString(); book.isbn = readBooks["isbn"].ToString(); book.page = Convert.ToInt32(readBooks["page"]); book.cover_page_picture = readBooks["cover_page_picture"].ToString(); books.Add(book); } } return(books); } catch (Exception e) { FileWriterClass.WriteFile(AppConstants.EXCEPTION_LOG_FILE_LOCATION, "Exception at getAllBooksFromDB function" + e.Message); Console.WriteLine("Click {0}", e.Message); return(null); } }