/// calculate quantity and total price value for each ıtems private void nudQuantity_ValueChanged(object sender, EventArgs e) { var element = ShoppingCartClass.itemsToPurchase.Find(el => el.product.id == id); element.quantity = Convert.ToInt32(nudQuantity.Value); lblTotalPriceValue.Text = (Convert.ToInt32(nudQuantity.Value) * unitPriceValue).ToString(); System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["BookShopForm"]; ((BookShopForm)f).lblTotalPriceValueGeneral.Text = ShoppingCartClass.calculateActualTotalPrice().ToString(); }
/** * 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 != null) { while (readCustomer.Read()) { 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!"); } } }
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(); } }
private void pictureBox1_Click(object sender, EventArgs e) { var element = ShoppingCartClass.itemsToPurchase.Find(el => (el.product.id == id && el.product.GetType() == type)); ShoppingCartClass.removeProduct(element); int quantity = 0; foreach (var item in ShoppingCartClass.itemsToPurchase) { quantity += item.quantity; } System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["BookShopForm"]; ((BookShopForm)f).populateShoppingCartView(); ((BookShopForm)f).lblShoppinCartValue.Text = quantity.ToString(); }
/** 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; pbReport.Visible = false; } lblGeneralUserName.Text = user.name + " " + user.surName; tabControlGeneral.SelectedTab = tabHomePage; populateBooksViewInHomePage(); }
/** @ brief adds the purchased musicCDs to the shopping cart * create a book from MusicCDsClass * and item added shoppingcartclass */ private void btnMusicCDsAddToCart_Click(object sender, EventArgs e) { MusicCDsClass musicCDs = new MusicCDsClass(); musicCDs = MusicCDsClass.getAMusicCDsFromDB(musicCDID); ShoppingCartClass.addProduct(new ItemToPurchaseClass(musicCDs, 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); }
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(); }
/** @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(); }