protected void btn_AddCart_Click(object sender, EventArgs e) { Bookstore_BO bookstorebo = new Bookstore_BO(); productId = bookstorebo.retrieveProductId(lbl_Item.Text).ToString(); int OldQuantity = Convert.ToInt32(bookstorebo.retrieveProductQuantity(Convert.ToInt32(productId))); int NewQuantity = OldQuantity - Convert.ToInt32(TB_Quantity.Text); if (NewQuantity >= 0) { int IdExist = Convert.ToInt32(bookstorebo.retrieveProductIdFromCart(Convert.ToInt32(productId))); if (IdExist > 0) { bookstorebo.updateQuantityInCartDB(Convert.ToInt32(productId), Convert.ToInt32(TB_Quantity.Text)); } else { ImageURL = bookstorebo.retrieveImageString(Convert.ToInt32(productId)); NAME = GridView1.SelectedRow.Cells[2].Text.ToString(); PRICE = Convert.ToDecimal(GridView1.SelectedRow.Cells[3].Text); Quantity = Convert.ToInt32(TB_Quantity.Text.Trim()); bookstorebo.AddProduct(Convert.ToInt32(productId), ImageURL, NAME, PRICE, Quantity); } } else { lbl_Error.Visible = true; } lbl_Item.Text = ""; TB_Quantity.Text = ""; lbl_Success.Visible = true; }
protected void PurchaseHistoryGridView_PageIndexChanging(object sender, GridViewPageEventArgs e) { List <PurchasedItem> itemsList = new List <PurchasedItem>(); Bookstore_BO bookstorebo = new Bookstore_BO(); itemsList = bookstorebo.purchaseHistory(current_logged_in_user); itemsList.Reverse(); PurchaseHistoryGridView.DataSource = itemsList; PurchaseHistoryGridView.PageIndex = e.NewPageIndex; PurchaseHistoryGridView.DataBind(); }
protected void btn_Delete_Click(object sender, EventArgs e) { if (TB_ID_Delete.Text == "") { TB_Error_Delete.Text = "Please Enter a product ID"; TB_Error_Delete.Visible = true; } else { //delete product Bookstore_BO bookstorebo = new Bookstore_BO(); bookstorebo.deleteProduct(TB_ID_Delete.Text); TB_ID_Delete.Text = ""; lbl_Message2.Visible = true; lbl_Message2.Text = "Product has been deleted successfully!"; TB_Error_Delete.Text = ""; TB_Error_Delete.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { current_logged_in_user = Request.Cookies["CurrentLoggedInUser"].Value; List <PurchasedItem> itemsList = new List <PurchasedItem>(); Bookstore_BO bookstorebo = new Bookstore_BO(); itemsList = bookstorebo.purchaseHistory(current_logged_in_user); receiptPanel.Visible = false; if (itemsList == null || itemsList.Count == 0) { ErrorMsgGridView.Visible = true; } else { itemsList.Reverse(); PurchaseHistoryGridView.DataSource = itemsList; PurchaseHistoryGridView.DataBind(); ErrorMsgGridView.Visible = false; } }
protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetCacheability(HttpCacheability.NoCache); if (!this.IsPostBack) { /*Session Fixation*/ // check if the 2 sessions n cookie is not null if (Session["LoginUserName"] != null && Session["AuthToken"] != null && Request.Cookies["AuthToken"] != null && Request.Cookies["CurrentLoggedInUser"] != null) { //second check for cookie has the same value as the second session if ((Session["AuthToken"].ToString().Equals(Request.Cookies["AuthToken"].Value))) /*End of Session Fixation*/ { current_logged_in_user = Request.Cookies["CurrentLoggedInUser"].Value; ErrorConsentForm.Visible = false; ErrorLabelPurchase.Visible = false; UserBO userbo = new UserBO(); current_user_obj = userbo.getUserById(current_logged_in_user); ProfileName_LB.Text = current_user_obj.name; Role_LB.Text = current_user_obj.role; UserID_LB.Text = current_user_obj.User_ID; CCAPoints_LB.Text = current_user_obj.cca_point.ToString(); OrionPoints_LB.Text = current_user_obj.orion_point.ToString(); Bookstore_BO bookstorebo = new Bookstore_BO(); List <PurchasedItem> itemsList = new List <PurchasedItem>(); itemsList = bookstorebo.purchaseHistory(current_logged_in_user); if (itemsList == null || itemsList.Count == 0) { ErrorLabelPurchase.Visible = true; } else if (itemsList.Count() < 3) { itemsList.Reverse(); purchaseHistoryGridView.DataSource = itemsList.GetRange(0, itemsList.Count()); purchaseHistoryGridView.DataBind(); ErrorLabelPurchase.Visible = false; } else if (itemsList.Count() >= 3) { itemsList.Reverse(); purchaseHistoryGridView.DataSource = itemsList.GetRange(0, 3); purchaseHistoryGridView.DataBind(); ErrorLabelPurchase.Visible = false; } //hide certain panels according to user type if (current_user_obj.role == "Student") { RegisteredActivities_Col.Visible = true; ConsentForms_Col.Visible = false; Response.Cookies["Current_Edu_Level"].Value = current_user_obj.education_level; eventBO eventbo = new eventBO(); List <events> eventList = eventbo.loadSignUpEvent(current_logged_in_user); //event stuff if (eventList == null || eventList.Count == 0) { EventsErrorMsg.Visible = true; } else if (eventList.Count() < 3) { eventList.Reverse(); RegisteredEventGridView.DataSource = eventList.GetRange(0, eventList.Count()); RegisteredEventGridView.DataBind(); EventsErrorMsg.Visible = false; } else if (eventList.Count() >= 3) { itemsList.Reverse(); RegisteredEventGridView.DataSource = eventList.GetRange(0, 3); RegisteredEventGridView.DataBind(); EventsErrorMsg.Visible = false; } //insert pending items [check class, check the amount of unsigned forms] ConsentFormBO consentformbo = new ConsentFormBO(); List <ConsentForm> consentFormList = consentformbo.selectUnsignedFormsByUser(current_user_obj.User_ID, current_user_obj.school, current_user_obj.education_class); if (consentFormList == null || consentFormList.Count == 0) { pendingItemsLabel.Text = "You have no pending items."; } else { pendingItemsLabel.Text = "You have (" + consentFormList.Count + ") pending items."; } } else if (current_user_obj.role == "Parent") { RegisteredActivities_Col.Visible = true; ConsentForms_Col.Visible = false; RegisteredActivities_Col.Visible = false; //insert pending items [check class, check the amount of unsigned forms] //find child user childuser = new user(); UserBO childuserbo = new UserBO(); childuser = childuserbo.getUserById(current_user_obj.child_ID); ConsentFormBO consentformbo = new ConsentFormBO(); List <ConsentForm> consentFormList = consentformbo.selectUnsignedFormsByUser(childuser.User_ID, childuser.school, childuser.education_class); if (consentFormList == null || consentFormList.Count == 0) { pendingItemsLabel.Text = "You have no pending items."; } else { pendingItemsLabel.Text = "You have (" + consentFormList.Count + ") pending items."; } } else if (current_user_obj.role == "Teacher") { ConsentForms_Col.Visible = true; RegisteredActivities_Col.Visible = false; pendingItemsLabel.Text = "You have no pending items.";//tentative //insert 3 recently sent forms here ConsentFormBO consentformbo = new ConsentFormBO(); List <ConsentForm> consentFormList = consentformbo.getConsentFormsBySenderID(current_user_obj.User_ID); if (consentFormList == null || consentFormList.Count == 0) { ErrorConsentForm.Visible = true; } else if (consentFormList.Count() < 3) { consentFormList.Reverse(); GridViewSentForms.DataSource = consentFormList.GetRange(0, consentFormList.Count()); GridViewSentForms.DataBind(); ErrorConsentForm.Visible = false; } else if (consentFormList.Count() >= 3) { consentFormList.Reverse(); GridViewSentForms.DataSource = consentFormList.GetRange(0, 3); GridViewSentForms.DataBind(); ErrorConsentForm.Visible = false; } } else if (current_user_obj.role == "Staff") { ConsentForms_Col.Visible = false; RegisteredActivities_Col.Visible = false; pendingItemsLabel.Text = "You have no pending items."; RegisteredActivities_Col.Visible = false; } else if (current_user_obj.role == "Admin") { ConsentForms_Col.Visible = false; RegisteredActivities_Col.Visible = false; pendingItemsLabel.Text = "You have no pending items."; RegisteredActivities_Col.Visible = false; } ToConsentFormsManagementBtn.NavigateUrl = Response.ApplyAppPathModifier("ManageConsentFormsPage.aspx"); } } else { Response.Redirect("LoginPage.aspx"); } } }
protected void btn_Submit_Add_Click(object sender, EventArgs e) { Bookstore_BO bookstorebo = new Bookstore_BO(); int ProductId = Convert.ToInt32(TB_ID_Add.Text); bookstorebo.retrieveProduct(ProductId); Product prodObj = bookstorebo.retrieveProduct(ProductId); if (prodObj != null) { TB_Error_Add.Text = "Product already exist, consider updating instead"; TB_Error_Add.Visible = true; } else { { int count = 0; //validate file upload string filename; if (FileUploadImage.HasFile) { string extension = System.IO.Path.GetExtension(FileUploadImage.FileName); if (extension == ".jpg" || extension == ".png") { filename = FileUploadImage.FileName; FileUploadImage.PostedFile.SaveAs(Server.MapPath("~/Image/") + filename); string ImageURL = "~/Image/" + filename; lbl_Image_Name.Text = ImageURL; //codes to send to BO } else { sb.AppendLine("File has to be .jpg or .png only"); count++; } } else { sb.AppendLine("Please upload an image"); count++; } //validate ID Textbox if (TB_ID_Add.Text.Trim() == "") { sb.AppendLine("Please indicate product ID"); count++; } else if (System.Text.RegularExpressions.Regex.IsMatch(TB_ID_Update.Text, " ^ [0-9]")) { sb.AppendLine("Please enter valid product ID"); count++; } //validate Name Textbox if (TB_Name_Add.Text.Trim() == "") { sb.AppendLine("Please indicate product name"); count++; } //validate Price Textbox if (TB_Price_Add.Text.Trim() == "" || TB_Price_Add.Text.All(Char.IsLetter)) { sb.AppendLine("Please amend product price"); count++; } //validate Education DDL if (Ddl_Edu_Add.SelectedItem.Text == "~Education Level~") { sb.AppendLine("Please indicate Education Level of product"); count++; } //validate Item DDL if (Ddl_Item_Add.SelectedItem.Text == "~Item Type~") { sb.AppendLine("Please indicate product type"); count++; } //validate Quantity if (TB_Quantity_Add.Text == "") { sb.AppendLine("Please enter available quantity of product"); count++; } if (count > 0) { lbl_Message.Text = ""; TB_Error_Add.Visible = true; TB_Error_Add.Text = sb.ToString(); } else { //codes to send to database bookstorebo.uploadProduct(TB_ID_Add.Text, lbl_Image_Name.Text, TB_Name_Add.Text, Convert.ToDouble(TB_Price_Add.Text), Ddl_Edu_Add.SelectedItem.Text, Ddl_Item_Add.SelectedItem.Text, Convert.ToInt32(TB_Quantity_Add.Text), lbl_Any.Text, lbl_AnyType.Text); FileUploadImage.Attributes.Clear(); TB_ID_Add.Text = ""; TB_Name_Add.Text = ""; TB_Price_Add.Text = ""; Ddl_Edu_Add.SelectedIndex = -1; Ddl_Item_Add.SelectedIndex = -1; TB_Quantity_Add.Text = ""; lbl_Message.Visible = true; lbl_Message.Text = "Product has been added successfully!"; TB_Error_Add.Text = ""; TB_Error_Add.Visible = false; } } } }
protected void btn_Submit_Update_Click(object sender, EventArgs e) { Bookstore_BO bookstorebo = new Bookstore_BO(); int ProductId = Convert.ToInt32(TB_ID_Update.Text); bookstorebo.retrieveProduct(ProductId); Product prodObj = bookstorebo.retrieveProduct(ProductId); int count = 0; //validate file upload string filename; if (FileUploadImage_Update.Visible == true) { if (FileUploadImage_Update.HasFile) { string extension = System.IO.Path.GetExtension(FileUploadImage_Update.FileName); if (extension == ".jpg" || extension == ".png") { filename = FileUploadImage_Update.FileName; FileUploadImage_Update.PostedFile.SaveAs(Server.MapPath("~/Image/") + filename); string ImageURL = "~/Image/" + filename; lbl_Image_Name1.Text = ImageURL; } else { Response.Write("File has to be a jpg or png file"); } } else { sb.AppendLine("Please upload an image"); count++; } } else { filename = prodObj.ImageURL.ToString(); filename = filename.Substring(8); FileUploadImage_Update.SaveAs(Server.MapPath("~/Image/") + filename); lbl_Image_Name.Text = filename; } //validate ID Textbox if (TB_ID_Update.Text.Trim() == "") { sb.AppendLine("Please indicate product ID"); count++; } //validate Name Textbox if (TB_Name_Update.Text.Trim() == "") { sb.AppendLine("Please indicate product name"); count++; } //validate Price Textbox if (TB_Price_Update.Text == "" || TB_Price_Update.Text.All(Char.IsLetter)) { sb.AppendLine("Please amend product price"); count++; } //validate Education DDL if (Ddl_Edu_Update.SelectedItem.Text == "~Education Level~") { sb.AppendLine("Please indicate Education Level of product"); count++; } //validate Item DDL if (Ddl_Item_Update.SelectedItem.Text == "~Item Type~") { sb.AppendLine("Please indicate product type"); count++; } //validate Quantity if (TB_Quantity_Update.Text == "") { sb.AppendLine("Please enter available quantity of product"); count++; } if (count > 0) { lbl_Message1.Text = ""; TB_Error_Update.Visible = true; TB_Error_Update.Text = sb.ToString(); } else { //update database bookstorebo.updateProduct(TB_ID_Update.Text, lbl_Image_Name1.Text, TB_Name_Update.Text, Convert.ToDouble(TB_Price_Update.Text), Ddl_Edu_Update.SelectedItem.Text, Ddl_Item_Update.SelectedItem.Text, Convert.ToInt32(TB_Quantity_Update.Text)); FileUploadImage_Update.Attributes.Clear(); TB_ID_Update.Text = ""; TB_Name_Update.Text = ""; TB_Price_Update.Text = ""; Ddl_Edu_Add.SelectedIndex = -1; Ddl_Item_Add.SelectedIndex = -1; TB_Quantity_Update.Text = ""; lbl_Message1.Visible = true; lbl_Message1.Text = "Product has been updated successfully!"; TB_Error_Update.Text = ""; TB_Error_Update.Visible = false; } }
protected void btn_ID_search_Click(object sender, EventArgs e) { if (TB_ID_Update.Text == "") { TB_Error_Update.Visible = true; TB_Error_Update.Text = "Please input product's ID"; } else if (Regex.Matches(TB_ID_Update.Text, @"[a-zA-Z]").Count > 0) { TB_Error_Update.Visible = true; TB_Error_Update.Text = "Please input valid product ID"; } else { //retrieve data from database Bookstore_BO bookstorebo = new Bookstore_BO(); int ProductId = Convert.ToInt32(TB_ID_Update.Text); bookstorebo.retrieveProduct(ProductId); FileUploadImage_Update.Attributes.Clear(); Product prodObj = bookstorebo.retrieveProduct(ProductId); try { lbl_Image_Name1.Text = prodObj.ImageURL.ToString(); TB_Name_Update.Text = prodObj.Name; TB_Price_Update.Text = prodObj.Price.ToString(); if (prodObj.EduLevel.ToString() == "Any") { Ddl_Edu_Update.SelectedIndex = 1; } else if (prodObj.EduLevel.ToString() == "Primary") { Ddl_Edu_Update.SelectedIndex = 2; } else if (prodObj.EduLevel.ToString() == "Secondary") { Ddl_Edu_Update.SelectedIndex = 3; } else { Ddl_Edu_Update.SelectedIndex = 4; } if (prodObj.Type.ToString() == "Textbooks") { Ddl_Item_Update.SelectedIndex = 1; } else if (prodObj.Type.ToString() == "Stationary") { Ddl_Item_Update.SelectedIndex = 2; } else { Ddl_Item_Update.SelectedIndex = 3; } TB_Quantity_Update.Text = prodObj.Quantity.ToString(); TB_Error_Update.Text = ""; TB_Error_Update.Visible = false; } catch { TB_Error_Update.Text = "Product ID does no exist in database"; TB_Error_Update.Visible = true; } } }