public void populateShoppingCartView() { ShoppingCartItemsUserControl[] shoppingCartItemsUserControl = new ShoppingCartItemsUserControl[ShoppingCartClass.itemsToPurchase.Count]; shoppingCartItemsUserControl = ShoppingCartClass.printProducts(); if (flpShoppingCart.Controls.Count > 0) { flpShoppingCart.Controls.Clear(); } int i = 0; foreach (ItemToPurchaseClass item in ShoppingCartClass.itemsToPurchase) { flpShoppingCart.Controls.Add(shoppingCartItemsUserControl[i]); i++; } lblTotalPriceValueGeneral.Text = ShoppingCartClass.calculateActualTotalPrice().ToString(); if (ShoppingCartClass.itemsToPurchase.Count == 0) { lblShoppingCartEmpty.Visible = true; lblShoppinCartValue.Text = "0"; } else { lblShoppingCartEmpty.Visible = false; } }
/** * click the login button if usernam and password are correct ,opens bookshopform * and read customer's information from database */ private void btnLogin_Click(object sender, EventArgs e) { if (txtUserName.Text == "" || txtPassword.Text == "") { MessageBox.Show("username or password should not be empty!"); } else { UserClass cs = null; connection.Open(); SqlCommand commandCustomer = new SqlCommand("Select * from CustomerTable WHERE username=@username AND password=@password", connection); commandCustomer.Parameters.AddWithValue("@username", txtUserName.Text); commandCustomer.Parameters.AddWithValue("@password", txtPassword.Text); SqlDataReader readCustomer = commandCustomer.ExecuteReader(); if (readCustomer.Read() && readCustomer != null) { if (!(bool)readCustomer["isconfirmed"]) { MessageBox.Show("You're not confirmed. Wait for confirmation"); return; } bool isAdmin = (bool)readCustomer["isadmin"]; if (!isAdmin) { cs = CustomerClass.Instance; //SINGLETON PATTERN } else { cs = AdminUserClass.Instance; } cs.customerID = readCustomer["id"].ToString(); cs.name = readCustomer["name"].ToString(); cs.surName = readCustomer["surname"].ToString(); cs.address = readCustomer["address"].ToString(); cs.email = readCustomer["email"].ToString(); cs.userName = readCustomer["username"].ToString(); cs.password = readCustomer["password"].ToString(); cs.IsAdmin = (bool)readCustomer["isadmin"]; connection.Close(); ShoppingCartClass shoppingCartClass = ShoppingCartClass.Instance; //SINGLETON PATTERN ShoppingCartClass.customerID = cs.customerID; ShoppingCartClass.user = cs; BookShopForm bookShopForm = new BookShopForm(cs); bookShopForm.Show(); this.Hide(); } else { MessageBox.Show("username or password is not correct!"); connection.Close(); } } }
private void pbCancelOrder_Click(object sender, EventArgs e) { ShoppingCartClass.cancelOrder(name, unitPriceValue); DatabaseHelperClass dbHelper = DatabaseHelperClass.Instance; //SINGLETON PATTERN DialogResult dialogResult = MessageBox.Show("Want to cancel your item? ", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogResult == DialogResult.Yes) { dbHelper.removeSelectedItemsFromShoppingCart(name); System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["BookShopForm"]; ((BookShopForm)f).populateMyAccountView(); } }
/** BookShopForm_Load() finds whether the user is admin or not. * If the user is admin, the admin panel and report panel'visibility will be true . * */ private void BookShopForm_Load(object sender, EventArgs e) { //Attach Observers ShoppingCartClass.attach(new CustomerObserverClass()); ShoppingCartClass.attach(new EmailAndSMSLoggerObserverClass()); if (!user.isAdmin()) { pbAdminPanel.Visible = false; } lblGeneralUserName.Text = user.name + " " + user.surName; tabControlGeneral.SelectedTab = tabHomePage; populateBooksViewInHomePage(); }
/** @ brief adds the purchased magzine to the shopping cart * create a magzine from MagazineClass * and item added shoppingcartclass */ private void btnMagazineAddToCart_Click(object sender, EventArgs e) { MagazineClass magazine = new MagazineClass(); magazine = MagazineClass.getAMagazineFromDB(magazineID); ShoppingCartClass.addProduct(new ItemToPurchaseClass(magazine, 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); }
/** @brief makePayment() function * @param PaymentType paymentType * call placeorder from ShoppingCartClass * placeorder() function have customerıd and paymenttype parameters */ private void makePayment(PaymentType paymentType) { ShoppingCartClass.placeOrder(user.customerID, paymentType, ShoppingCartClass.calculateActualTotalPrice()); }
/** * call calculateActualTotalPrice() from ShoppingCartClass * and assign lblPaymentAmountValue and lblPaymentAmountCashValue */ private void PaymentForm_Load(object sender, EventArgs e) { lblPaymentAmountValue.Text = ShoppingCartClass.calculateActualTotalPrice().ToString(); lblPaymentAmountCashValue.Text = ShoppingCartClass.calculateActualTotalPrice().ToString(); }