private void CompleteSaleButton_Click(object sender, EventArgs e)
        {
            if (SystemProtocols.ApplyCartManagementProtocol(1, null, 0, null, 0).Count > 0)
            {
                // Requesting the creation of a new transaction
                String message = SystemProtocols.ApplySalesTransactionProtocols(1, CreateSalesObject());

                if (message == "SUCCESS")
                {
                    MessageBox.Show("This transaction has been completed successfully!");

                    // Updating grids
                    PopulateProductDataGrid();
                    UpdateCartSummaryDataGrid();
                }
                else
                {
                    MessageBox.Show("FATEL ERROR!"); // TODO: manage errors and exceptions
                }
            }
            else
            {
                MessageBox.Show("Please add items to complete a purchase.");
            }
        }
        /// <summary>
        /// Funtion to add one or more selected products into the cart
        /// </summary>
        private void AddItemsToCart()
        {
            // Capturing the data of multiple selected products
            foreach (DataGridViewRow row in productDataGridView.SelectedRows)
            {
                if (FormatToInt(row.Cells[10].Value.ToString()) > 0)                                                // only works if the product in the inventory has atleast 1 unit in existence
                {
                    Product product = new Product();                                                                // creating new product

                    product.Id        = row.Cells[0].Value.ToString();                                              // getting the selected product's id
                    product.Name      = row.Cells[2].Value.ToString();                                              // getting the selected product's name
                    product.Brand     = row.Cells[3].Value.ToString();                                              // getting the selected product's brand
                    product.Unit      = row.Cells[5].Value.ToString();                                              // getting the selected product's unit
                    product.UnitPrice = FormatToDecimal(row.Cells[9].Value.ToString());                             // getting the selected product's price
                    product.Quantity  = quantityNumericUpDown.Value < FormatToInt(row.Cells[10].Value.ToString()) ? // getting the desired quantity of the selected product
                                        (int)quantityNumericUpDown.Value :                                          // the client desires less units than the limit in existence
                                        FormatToInt(row.Cells[10].Value.ToString());                                // the client wants all units in existence

                    // Adding product to cart or updating the amount of units of already added product
                    SystemProtocols.ApplyCartManagementProtocol(2, null, 0, product, FormatToInt(row.Cells[10].Value.ToString()));
                }
            }

            // Updating numeric up down
            quantityNumericUpDown.Value   = 1;
            quantityNumericUpDown.Maximum = 2;

            UpdateCartSummaryDataGrid(); // updating the cart summary
        }
        /// <summary>
        /// Function to populate the cart summary data grid
        /// </summary>
        private void UpdateCartSummaryDataGrid()
        {
            // Code needed to refresh the cart summary
            cartSummaryDataGridView.DataSource = new List <Product>();                                 // reseting the datasource as a clean and empty list
            cartSummaryDataGridView.Refresh();                                                         // refreshing the data grid to clean any old information an update it with the new one

            List <Product> summary = SystemProtocols.ApplyCartManagementProtocol(1, null, 0, null, 0); // fetching the cart

            if (summary.Count() > 0)
            {
                cartSummaryDataGridView.DataSource = summary; // feeding the grid view with the new information on the cart summary
                cartSummaryDataGridView.Refresh();            // refreshing the data grid to clean any old information an update it with the new one

                // Hidding unnecessary fields
                cartSummaryDataGridView.Columns["Id"].Visible               = false;
                cartSummaryDataGridView.Columns["Key"].Visible              = false;
                cartSummaryDataGridView.Columns["Brand"].Visible            = false;
                cartSummaryDataGridView.Columns["Supplier"].Visible         = false;
                cartSummaryDataGridView.Columns["Category"].Visible         = false;
                cartSummaryDataGridView.Columns["Type"].Visible             = false;
                cartSummaryDataGridView.Columns["UnitCost"].Visible         = false;
                cartSummaryDataGridView.Columns["MinimumQuantity"].Visible  = false;
                cartSummaryDataGridView.Columns["MaximumQuantity"].Visible  = false;
                cartSummaryDataGridView.Columns["RegisteredBy"].Visible     = false;
                cartSummaryDataGridView.Columns["RegistrationDate"].Visible = false;
                cartSummaryDataGridView.Columns["ModifiedBy"].Visible       = false;
                cartSummaryDataGridView.Columns["ModificationDate"].Visible = false;
                cartSummaryDataGridView.Columns["Discontinued"].Visible     = false;
                cartSummaryDataGridView.Columns["Total"].Visible            = false;

                // Formationg columns
                cartSummaryDataGridView.Columns["Name"].Width      = 180;
                cartSummaryDataGridView.Columns["Unit"].Width      = 50;
                cartSummaryDataGridView.Columns["UnitPrice"].Width = 70;
                cartSummaryDataGridView.Columns["Quantity"].Width  = 80;

                int     quantity = 0; // variable to track the amount of items requested
                decimal total    = 0; // variable to track the total of the entire purchase
                foreach (Product item in summary)
                {
                    quantity += item.Quantity;  // counting how many products are in the cart
                    total    += item.UnitPrice; // calculating the total price
                }

                // publishing the purchase information of a full cart
                numberLabel.Text = "Number of Item: " + quantity;
                totalLabel.Text  = "Total: $" + total.ToString("0.00");
            }
            else
            {
                // publishing the purchase information of an empty cart
                numberLabel.Text = "Number of Item: 0";
                totalLabel.Text  = "Total: $0.00";
            }
        }
Пример #4
0
        private void LogOutLabel_Click(object sender, EventArgs e)
        {
            // Executing correct log out processes
            SystemProtocols.ApplyLogOutProtocols();
            FormsMenuList.loginForm.Show();

            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart before logging out

            // Closing form while freeing system resources
            FormsMenuList.registerNewProduct.Dispose();
        }
        private void RemoveOneButton_Click(object sender, EventArgs e)
        {
            // Capturing the data of multiple selected products
            foreach (DataGridViewRow row in cartSummaryDataGridView.SelectedRows)
            {
                // Removing one unit from a product in the cart
                SystemProtocols.ApplyCartManagementProtocol(5, row.Cells[0].Value.ToString(), FormatToDecimal(row.Cells[9].Value.ToString()) / FormatToInt(row.Cells[10].Value.ToString()), null, 0);
            }

            UpdateCartSummaryDataGrid(); // updating the cart summary
        }
        private void RemoveItemButton_Click(object sender, EventArgs e)
        {
            // Capturing the data of multiple selected products
            foreach (DataGridViewRow row in cartSummaryDataGridView.SelectedRows)
            {
                // Adding product to cart or updating the amount of units of already added product
                SystemProtocols.ApplyCartManagementProtocol(4, row.Cells[0].Value.ToString(), 0, null, 0);
            }

            UpdateCartSummaryDataGrid(); // updating the cart summary
        }
Пример #7
0
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            // Executing correct log out processes
            SystemProtocols.ApplyLogOutProtocols();
            FormsMenuList.loginForm.Show();

            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart before logging out

            // Closing form while freeing system resources
            FormsMenuList.registerNewProduct.Dispose();
        }
        private void LogOutLabel_Click(object sender, EventArgs e)
        {
            // Executing correct log out processes
            SystemProtocols.ApplyLogOutProtocols();
            FormsMenuList.loginForm.Show();

            if (userInformationForm != null)
            {
                userInformationForm.Dispose();                                // Closing Child
            }
            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart before logging out

            // Closing form while freeing system resources
            FormsMenuList.usersRegistryForm.Dispose();
        }
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            // Executing correct log out processes
            SystemProtocols.ApplyLogOutProtocols();
            FormsMenuList.loginForm.Show();

            if (userInformationForm != null)
            {
                userInformationForm.Dispose();                                // Closing Child
            }
            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart before logging out

            // Closing form while freeing system resources
            FormsMenuList.usersRegistryForm.Dispose();
        }
Пример #10
0
        private void LogOutLabel_Click(object sender, EventArgs e)
        {
            // Executing correct log out processes
            SystemProtocols.ApplyLogOutProtocols();
            FormsMenuList.loginForm.Show();

            if (timesheetChild != null)
            {
                timesheetChild.Dispose(); // disposing of child timesheet if open
            }
            if (salesRecordChild != null)
            {
                salesRecordChild.Dispose();                                   // disposing of child sales record if open
            }
            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart before logging out

            // Closing form while freeing system resources
            FormsMenuList.reportsAnalyticsForm.Dispose();
        }
        private void ClearCartButton_Click(object sender, EventArgs e)
        {
            SystemProtocols.ApplyCartManagementProtocol(3, null, 0, null, 0); // clearing the cart

            UpdateCartSummaryDataGrid();                                      // updating the cart summary
        }