Exemplo n.º 1
0
        /// <summary>
        /// Button to assign a SKU number.
        /// </summary>
        private void btnAssignSku_Click(object sender, EventArgs e)
        {
            // Declare and initialize new stockKeeper object
            StockKeeper stock = new StockKeeper();

            // Attempt to get department number from textbox
            int.TryParse(txtDepartmentNumber.Text, out int departmentNumber);

            // If the department number doesn't equal 0
            if (departmentNumber != 0)
            {
                // Generate new SKU and place in textbox
                txtSku.Text = stock.GenerateSKU(departmentNumber, _inventory).ToString();
            }
            else
            {
                // Let user know how to fix issue.
                MessageBox.Show(this, "Please select correct department number.");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Event if the user tries to change the department name
        /// </summary>
        private void cmbDepartment_SelectionChangeCommitted(object sender, EventArgs e)
        {
            // If the combo box changes and does not match the original index number...
            if (cmbDepartment.SelectedIndex != comboIndex)
            {
                // Let the user know that changing the box will change important information
                DialogResult result = MessageBox.Show(this, "You are about to change a value that will require updating the SKU assignment.\n\nAre you sure you want to continue?", "WARNING", MessageBoxButtons.OKCancel);

                // If they cancel...
                if (result == DialogResult.Cancel)
                {
                    // Set the index of the combobox back to origin
                    cmbDepartment.SelectedIndex = comboIndex;
                }
                // Otherwise...
                else if (result == DialogResult.OK)
                {
                    // Go through department list...
                    foreach (KeyValuePair <int, string> kvp in departments.DepartmentList)
                    {
                        // If the value equals the item string...
                        if (kvp.Value == cmbDepartment.SelectedItem.ToString())
                        {
                            // set the textbox to the new number
                            txtDepartmentNumber.Text = kvp.Key.ToString();
                        }
                    }

                    // Declare and initialize SKU object
                    StockKeeper stock = new StockKeeper();

                    // Get the department number
                    int.TryParse(txtDepartmentNumber.Text, out int departmentNumber);

                    // Generate a new SKU based on the new department chosen
                    txtSku.Text = (stock.GenerateSKU(departmentNumber, _inventory)).ToString();
                }
            }
        }