Example #1
0
        private async void button_add_Click(object sender, EventArgs e)
        {
            if (controller != null)
            {
                try
                {
                    // prepare the data
                    float price;
                    float.TryParse(textBox_price.Text, out price);
                    int quantity;
                    Int32.TryParse(textBox_quantity.Text, out quantity);
                    string id          = textBox_ID.Text;
                    string description = textBox_description.Text;
                    Model.ObjectModel.Product newProduct = new Model.ObjectModel.Product();
                    newProduct.price       = price;
                    newProduct.Quantity    = quantity;
                    newProduct.ProductID   = Convert.ToInt64(id);
                    newProduct.Description = description;

                    // log it
                    logger.Info("Adding new product record: ");
                    logger.Info("ID: " + id);
                    logger.Info("Description: " + description);
                    logger.Info("Quantity: " + quantity);
                    logger.Info("Price: " + price);

                    // run this task in a separate thread
                    await Task.Run(() =>
                    {
                        controller.addProduct(newProduct);
                    });
                }
                catch (Exception ex)
                {
                    // error adding new product
                    // tell the user and the logger
                    string errorMessage = "Error adding new product: " + ex.Message;
                    logger.Error(ex, errorMessage);
                    MessageBox.Show(errorMessage, "Retail POS", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // nothing more we can do
                    return;
                }

                // success
                // inform the user and the logger
                string successMessage = "Successfully added new product";
                MessageBox.Show(successMessage, "Retail POS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                logger.Info(successMessage);

                // clean up UI
                textBox_ID.Text          = string.Empty;
                textBox_description.Text = string.Empty;
                textBox_price.Text       = string.Empty;
                textBox_quantity.Text    = string.Empty;
            }
        }
Example #2
0
        private async void button_add_Click(object sender, EventArgs e)
        {
            if (controller != null)
            {
                try
                {
                    // use busy cursor
                    this.UseWaitCursor = true;

                    // update the status bar
                    labelProgressBar1.setColourAndText(Configuration.ProgressBarColours.TASK_IN_PROGRESS_COLOUR, "Adding new product");
                    labelProgressBar1.Value = 100;

                    // prepare the data
                    float price;
                    float.TryParse(textBox_price.Text, out price);
                    int quantity;
                    Int32.TryParse(textBox_quantity.Text, out quantity);
                    string id          = textBox_ID.Text;
                    string description = textBox_description.Text;
                    Model.ObjectModel.Product newProduct = new Model.ObjectModel.Product();
                    newProduct.price       = price;
                    newProduct.Quantity    = quantity;
                    newProduct.ProductID   = Convert.ToInt64(id);
                    newProduct.Description = description;

                    // log it
                    logger.Info("Adding new product record: ");
                    logger.Info("ID: " + id);
                    logger.Info("Description: " + description);
                    logger.Info("Quantity: " + quantity);
                    logger.Info("Price: " + price);

                    // run this task in a separate thread
                    await Task.Run(() =>
                    {
                        controller.addProduct(newProduct);
                    });
                }
                catch (Exception ex)
                {
                    // error adding new product
                    // tell the user and the logger
                    string errorMessage = "Error adding new product: " + ex.Message;
                    logger.Error(ex, errorMessage);
                    labelProgressBar1.setColourAndText(Configuration.ProgressBarColours.TASK_FAILED_COLOUR, "Error adding new product");
                    labelProgressBar1.Value = 100;
                    this.UseWaitCursor      = false;
                    MessageBox.Show(errorMessage, "Retail POS", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    // nothing more we can do
                    return;
                }

                // success
                // inform the user and the logger
                string successMessage = "Successfully added new product";
                labelProgressBar1.setColourAndText(Configuration.ProgressBarColours.IDLE_COLOUR, "Ready");
                labelProgressBar1.Value = 100;
                this.UseWaitCursor      = false;
                MessageBox.Show(successMessage, "Retail POS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                logger.Info(successMessage);

                // clean up UI
                textBox_ID.Text          = string.Empty;
                textBox_description.Text = string.Empty;
                textBox_price.Text       = string.Empty;
                textBox_quantity.Text    = string.Empty;
            }
        }