Exemplo n.º 1
0
        /// <summary>
        ///     Deletes a receipt line from the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (receiptLineIdInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input the text box.");
                    receiptLineIdInput.Focus();
                    return;
                }
                else if (!Regex.IsMatch(receiptLineIdInput.Text, "^[0-9]*$"))
                {
                    MessageBox.Show("Please input only numerical characters into the text box.");
                    receiptLineIdInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            ReceiptLineObject receiptLine = businessLogicLayer.CheckReceiptLinesByID(int.Parse(receiptLineIdInput.Text));

            try
            {
                if (!int.Parse(receiptLineIdInput.Text).Equals(receiptLine.receipt_line_id))
                {
                    MessageBox.Show("The Receipt Line provided does not Exist.");
                    receiptLineIdInput.Focus();
                    return;
                }
                else
                {
                    receiptLine = businessLogicLayer.DeleteCurrentReceiptLine(int.Parse(receiptLineIdInput.Text));
                    MessageBox.Show("The provided Receipt Line has been deleted from the system.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Edits a receipt line in the database.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (currentReceiptLineIdInput.Text.Equals("") || newReceiptIdInput.Text.Equals("") || newProductIdInput.Text.Equals("") || newQuantityInput.Text.Equals(""))
                {
                    MessageBox.Show("Please input all text boxes.");
                    currentReceiptLineIdInput.Focus();
                    return;
                }
                else if ((!Regex.IsMatch(currentReceiptLineIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newReceiptIdInput.Text, "^[0-9]*$")) ||
                         (!Regex.IsMatch(newProductIdInput.Text, "^[0-9]*$")) || (!Regex.IsMatch(newQuantityInput.Text, "^[0-9]*$")))
                {
                    MessageBox.Show("Please input only numerical characters into all text boxes.");
                    currentReceiptLineIdInput.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }

            ReceiptLineObject receiptLine;
            ReceiptLineObject receiptLineCurrent = businessLogicLayer.CheckReceiptLinesByID(int.Parse(currentReceiptLineIdInput.Text));
            ReceiptObject     receipt            = businessLogicLayer.CheckReceiptsByID(int.Parse(newReceiptIdInput.Text));
            ProductObject     product            = businessLogicLayer.CheckProductsByID(int.Parse(newProductIdInput.Text));

            try
            {
                if (!int.Parse(currentReceiptLineIdInput.Text).Equals(receiptLineCurrent.receipt_line_id))
                {
                    MessageBox.Show("The Current Receipt Line ID provided does not exist.");
                    newProductIdInput.Focus();
                    return;
                }
                if (!int.Parse(newReceiptIdInput.Text).Equals(receipt.receipt_id))
                {
                    MessageBox.Show("The New Receipt ID provided does not exist.");
                    newReceiptIdInput.Focus();
                    return;
                }
                else if (!int.Parse(newProductIdInput.Text).Equals(product.product_id))
                {
                    MessageBox.Show("The New Product ID provided does not exist.");
                    newProductIdInput.Focus();
                    return;
                }
                else
                {
                    receiptLine = businessLogicLayer.EditCurrentReceiptLine(int.Parse(newReceiptIdInput.Text), int.Parse(newProductIdInput.Text), int.Parse(newQuantityInput.Text),
                                                                            int.Parse(currentReceiptLineIdInput.Text));
                    MessageBox.Show("The provided Receipt Line has been updated.");
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error has occurred, please contact your administrator." + "\n\n" + "The error message is: " + "\n\n" + ex.ToString());
            }
        }