Ejemplo n.º 1
0
 public static bool RemoveProduct(Product product)
 {
     DatabaseFunctions.RemoveProduct(product);
     DatabaseFunctions.GetAllProducts();
     productRemoved(product);
     return(true);
 }
Ejemplo n.º 2
0
 public static bool UpdateProduct(Product product)
 {
     DatabaseFunctions.UpdateProduct(product);
     DatabaseFunctions.GetAllProducts();
     productChanged?.Invoke(product);
     return(true);
 }
Ejemplo n.º 3
0
 private void ProductsForm_Load(object sender, EventArgs e)
 {
     this.StartPosition       = FormStartPosition.CenterScreen;
     this.MaximizeBox         = false;
     this.addBtn.BackColor    = Color.FromArgb(5, 179, 245);
     this.addBtn.FlatStyle    = FlatStyle.Flat;
     this.searchBtn.BackColor = Color.FromArgb(5, 179, 245);
     this.searchBtn.FlatStyle = FlatStyle.Flat;
     this.BackColor           = Color.FromArgb(193, 162, 254);
     try
     {
         DatabaseFunctions.GetAllProducts();
         productsLw.Items.Clear();
         foreach (var item in Products.products)
         {
             AddItem(item);
         }
     }
     catch (NoConnectionException)
     {
         MessageBox.Show("Connection unsuccessful, please restart", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     catch (NotExistingException)
     {
         MessageBox.Show("Department is non-existent, please restart", "Error", MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
     AnimateWindow(this.Handle, 500, AnimateWindowFlags.AW_SLIDE);
 }
Ejemplo n.º 4
0
        private void confirmBtn_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(nameTb.Text) && !string.IsNullOrWhiteSpace(priceTb.Text) && !string.IsNullOrWhiteSpace(quantityTb.Text))
            {
                if (categoryCb.SelectedIndex > 0)
                {
                    string productName = nameTb.Text;

                    double          productPrice    = double.Parse(priceTb.Text);
                    int             productQuantity = int.Parse(quantityTb.Text);
                    bool            stockRequest    = stockCbx.Checked;
                    ProductCategory type            = (ProductCategory)Enum.Parse(typeof(ProductCategory), categoryCb.Text, true);

                    if (_editProduct)
                    {
                        _productToBeEdited.Name         = productName;
                        _productToBeEdited.Price        = productPrice;
                        _productToBeEdited.Quantity     = productQuantity;
                        _productToBeEdited.Category     = type;
                        _productToBeEdited.StockRequest = stockRequest;
                        Products.UpdateProduct(_productToBeEdited);
                    }
                    else
                    {
                        Product newProduct = new Product(productName, type, productPrice, productQuantity, stockRequest);
                        Products.AddProduct(newProduct);
                    }
                    DatabaseFunctions.GetAllProducts();
                    this.Close();
                }

                else
                {
                    MessageBox.Show("Choose type!");
                }
            }
            else
            {
                MessageBox.Show("Fill in the empty fields!");
            }
        }
Ejemplo n.º 5
0
        public MainForm()
        {
            InitializeComponent();

            usernameTb.Click += new EventHandler(click_username);
            usernameTb.Leave += new EventHandler(leave_username);
            passwordTb.Click += new EventHandler(click_password);
            passwordTb.Leave += new EventHandler(leave_password);
            try
            {
                if (!DatabaseFunctions.GetAllUsers() && !DatabaseFunctions.GetAllProducts())
                {
                    MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
                if (!DatabaseFunctions.GetAllDepartments())
                {
                    MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

                if (!File.Exists("idSeeder"))
                {
                    string id = (Users.LastGenUsernameId() + 1).ToString();
                    File.WriteAllLines("idSeeder", new string[] { id });
                }
            }
            catch (NoConnectionException)
            {
                MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            catch (IOException)
            {
                MessageBox.Show("Loading Data Failure, please restart", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 6
0
        private void btnGetProductStatistics_Click(object sender, EventArgs e)
        {
            lbStatistics.Items.Clear();
            if (cbProductCategories.SelectedIndex > -1)
            {
                int    categoryName       = cbProductCategories.SelectedIndex;
                double avgPrice           = 0;
                int    productsInCategory = 0;
                int    restocks           = 0;

                //int[] categories = new int[9];
                //DatabaseFunctions.GetAllProductsByCategory((ProductCategory)categoryName);
                DatabaseFunctions.GetAllProducts();
                Product mostRestocked = new Product("Bom", ProductCategory.COMPUTER, 2.2, 8, false);
                foreach (Product product in Products.products)
                {
                    if (product.Category == (ProductCategory)categoryName)
                    {
                        if (product.Quantity > restocks)
                        {
                            mostRestocked.Name     = product.Name;
                            mostRestocked.Category = product.Category;
                            mostRestocked.Price    = product.Price;
                            mostRestocked.Quantity = product.Quantity;
                            restocks = product.Quantity;
                        }
                        productsInCategory++;
                        avgPrice += product.Price;
                        //lbStatistics.Items.Add(product.ToString());
                    }
                }
                if (productsInCategory == 0)
                {
                    lbStatistics.Items.Add($"There are {productsInCategory} products in this category.");
                }
                else
                {
                    lbStatistics.Items.Add($"There are {productsInCategory} products in this category with average price of {(avgPrice / productsInCategory).ToString("C2", CultureInfo.CurrentCulture)}");
                    lbStatistics.Items.Add($"The most restocked product is: {mostRestocked.Name} Price: {mostRestocked.Price} Quantity: {mostRestocked.Quantity}");
                }
            }
            else
            {
                double  avgPrice       = 0;
                double  mostExpensive  = 0;
                Product mostExpensiveP = new Product("Test", ProductCategory.COMPUTER, 2.2, 8, false);
                DatabaseFunctions.GetAllProducts();

                foreach (Product product in Products.products)
                {
                    if (product.Price > mostExpensive)
                    {
                        mostExpensiveP.Name     = product.Name;
                        mostExpensiveP.Category = product.Category;
                        mostExpensiveP.Price    = product.Price;
                        mostExpensiveP.Quantity = product.Quantity;

                        mostExpensive = product.Price;
                    }
                    avgPrice += product.Price;
                }
                lbStatistics.Items.Add($"There are {Products.products.Count} products in total. The average price is {(avgPrice / Products.products.Count).ToString("C2", CultureInfo.CurrentCulture)}");
                lbStatistics.Items.Add($"The most expensive product is: {mostExpensiveP.Name} Price: {mostExpensiveP.Price} Quantity: {mostExpensiveP.Quantity}");
            }
        }