Ejemplo n.º 1
0
        /// <summary>
        /// This function add book button click operation.
        /// This function is used to add product list and save for util function.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnAdd.Text, DateTime.Now);
            if (!isBlank())
            {
                MessageBox.Show("Please fill all blanks!");
                return;
            }
            else if (pboxBook.Image == null)
            {
                MessageBox.Show("Please select an image.");
                return;
            }
            else if (isExist())
            {
                MessageBox.Show("Please change product ID! It's already taken.");
                return;
            }
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            Creator c = new BookFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider), txtISBN.Text, txtAuthor.Text,
                                        txtPublisher.Text, Convert.ToInt32(txtPages.Text), pboxBook.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtISBN.Text, txtAuthor.Text, txtPublisher.Text, txtPages.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            listViewBooks.Items.Add(item);
            StoreMainScreen.productList.Add(c.FactoryMethod());
            UtilSave.Save(c.FactoryMethod());
            MessageBox.Show("Added succesfully!");
            listViewBooks.Refresh();
            panelAddBook.Visible = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This function add magazine button click operation.
        /// This function is used to add product list and save for util function.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnAdd.Text, DateTime.Now);
            if (!isBlank())
            {
                MessageBox.Show("Please fill all blanks!");
                return;
            }
            else if (pboxMagazine.Image == null)
            {
                MessageBox.Show("Please select an image.");
                return;
            }
            else if (isExist())
            {
                MessageBox.Show("Please change product ID! It's already taken.");
                return;
            }
            NumberFormatInfo provider = new NumberFormatInfo();

            provider.NumberDecimalSeparator = ".";
            Magazine_Type type = Magazine_Type.Actual;

            switch (cBoxType.SelectedIndex)
            {
            case 1:
                type = Magazine_Type.Computer;
                break;

            case 2:
                type = Magazine_Type.News;
                break;

            case 3:
                type = Magazine_Type.Sport;
                break;

            case 4:
                type = Magazine_Type.Technology;
                break;

            default:
                break;
            }
            Creator c = new MagazineFactory(txtName.Text, txtID.Text, Convert.ToDouble(txtPrice.Text, provider),
                                            txtIssue.Text, type, pboxMagazine.Image);

            string[]     lvItem = { txtID.Text, txtName.Text, txtPrice.Text, txtIssue.Text, cBoxType.Text };
            ListViewItem item   = new ListViewItem(lvItem);

            listViewMagazines.Items.Add(item);
            StoreMainScreen.productList.Add(c.FactoryMethod());
            UtilSave.Save(c.FactoryMethod());
            MessageBox.Show("Added succesfully!");
            listViewMagazines.Refresh();
            panelAddMagazine.Visible = false;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This function includes Add button click operation.
        /// This function used to called the add product for shopping card and save for util function.
        /// </summary>
        /// <returns> This function does not return a value </returns>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog(LoginedCustomer.getInstance().User.Username, btnAdd.Text, DateTime.Now);
            ItemToPurchase itemToPurchase = new ItemToPurchase();

            itemToPurchase.Product = book;
            foreach (ItemToPurchase item in StoreMainScreen.shoppingCards[LoginScreen.shoppingCardIndex].itemsToPurchase)
            {
                if (item.Product.ID1 == itemToPurchase.Product.ID1)
                {
                    MessageBox.Show("It's already in the cart!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            itemToPurchase.Quantity = quantityBook;
            StoreMainScreen.shoppingCards[LoginScreen.shoppingCardIndex].AddProduct(itemToPurchase);
            int i = StoreMainScreen.shoppingCards[LoginScreen.shoppingCardIndex].itemsToPurchase.Count;

            UtilSave.Save(StoreMainScreen.shoppingCards[LoginScreen.shoppingCardIndex], i);
            MessageBox.Show("Added!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This function signup button click operation.
        /// This function is used to sign up application.
        /// </summary>
        /// <returns> This function does not return a value  </returns>
        private void btnSignUp_Click(object sender, EventArgs e)
        {
            Logger.GetLogger().WriteLog("Unknown user", btnSignUp.Text, DateTime.Now);
            if (!IsEmptyTextbox())
            {
                MessageBox.Show("You have to fill all fields.");
                return;
            }
            else if (!IsValidEmail(txtMail.Text))
            {
                MessageBox.Show("You can't use this mail adress." + Environment.NewLine + "Ex: [email protected]");
                return;
            }
            foreach (Customer item in OceanBookStore.customerList)
            {
                if (item.Username == txtUsername.Text)
                {
                    MessageBox.Show("This username is already taken.");
                    return;
                }
            }
            string   hashedPassword = UtilConvert.ComputeSha256Hash(txtPassword.Text);
            Customer customer       = new Customer(txtName.Text, txtAddress.Text, txtMail.Text, txtUsername.Text,
                                                   hashedPassword, UtilSave.registrationNo.ToString());

            Customer.SaveCustomer(customer);
            OceanBookStore.customerList.Add(customer);
            ShoppingCard shoppingCard = new ShoppingCard();

            shoppingCard.CustomerID = customer.CustomerId;
            UtilSave.Save(shoppingCard);
            StoreMainScreen.shoppingCards.Add(shoppingCard);
            MessageBox.Show("Your account was created!");
            RefreshForm();
            this.Hide();
            OceanBookStore.loginScreen.Show();
        }