Beispiel #1
0
        //********************************************************************************************//
        //  SAVE MODELS - BARCODE PANEL CONTROLS
        //********************************************************************************************//
        //  SAVE MODELS - BARCODE PRESS ENTER IN TEXT BOX EVENT
        //  Add invoice products to the invoice by either searching for the product by barcode,
        //  or by using the product search form.
        private void barcodeTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ProductModel product = new ProductModel();
                //1. Does the user have a barcode to scan or type in?
                //1.1 NO - Press Enter on empty text box
                if (barcodeTextBox.Text == "")
                {
                    //Get back a product from the product search form.
                    //If product search form is closed without selecting a product, e.g. closing the form
                    //Then exit process and wait for the user to type/scan a barcode or try to search again.
                    product = searchForProduct();
                }
                //1.2 YES - Enter barcode and press enter to search for product
                else
                {
                    //Search for product with barcode provided by the user
                    product = SqliteDAProduct.GetProductByBarcode(barcodeTextBox.Text);

                    //2. Did the search return a product that matches the barcode?
                    //NO?
                    if (product == null)
                    {
                        DialogResult result = MessageBox.Show("Barcode not found.\nAdd it to a new or existing product.", "Barcode Not Found", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        if (result == DialogResult.OK)
                        {
                            product = searchForProduct();
                        }
                    }
                }
                //Find Full Product Details with product Id
                //Check whether the user selected a product in the product search form
                if (product.Id != 0)
                {
                    product = SqliteDAProduct.GetProductById(product.Id);
                    //Add Invoice Product Details
                    InvoiceProductNewOrEdit invoiceProductForm = new InvoiceProductNewOrEdit(product, Convert.ToInt32(invoiceNumberStripStatusLabel.Text));
                    invoiceProductForm.ShowDialog();
                    mainDataGridView.DataSource = SqliteDAInvoiceProduct.GetAllInvoiceProductsByInvoiceId(Convert.ToInt32(invoiceNumberStripStatusLabel.Text));
                    mainDataGridView.AutoResizeColumns();
                    mainDataGridView.ClearSelection();
                    barCodeSearchPanel.Visible = true;
                    mainDataGridView.Columns["ProductId"].Visible = false;
                    mainDataGridView.Columns["InvoiceId"].Visible = false;
                    calculateInvoiceTotals(SqliteDAInvoice.GetInvoiceById(Convert.ToInt32(invoiceNumberStripStatusLabel.Text)));
                    barcodeTextBox.ResetText();
                    this.ActiveControl = barcodeTextBox;
                }
            }
        }
Beispiel #2
0
        //********************************************************************************************//
        //  EDIT MODELS - CLICK EDIT BUTTON EVENT
        //********************************************************************************************//
        private void editButton_Click(object sender, EventArgs e)
        {
            //  The user first has to select an item from the data grid view, click the edit button and
            //  then the edit form for the respective object should open.
            //  All the object properties are collected from the selected datagridview row and sent to
            //  the edit form. There the user will edit the object properties and update the database.
            //  The datagridview reloads and gets all objects and turns off the view/edit/delete buttons.
            //  1. Category
            if (modeStripStatusLabel.Text == "CATEGORY MODE")
            {
                //Create object
                int categoryId = Convert.ToInt32(row.Cells["Id"].Value);
                //Send to edit form
                CategoryNewOrEdit categoryForm = new CategoryNewOrEdit(categoryId);
                categoryForm.ShowDialog();
                //Reload data grid view
                mainDataGridView.DataSource = SqliteDACategory.GetAllCategories();
                SetDefaultLoadParameters();
            }
            //  2. Store
            else if (modeStripStatusLabel.Text == "STORE MODE")
            {
                int            storeId   = Convert.ToInt32(row.Cells["Id"].Value);
                StoreNewOrEdit storeForm = new StoreNewOrEdit(storeId);
                storeForm.ShowDialog();
                mainDataGridView.DataSource = SqliteDAStore.GetAllStores();
                SetDefaultLoadParameters();
            }
            //  3. Product Link
            else if (modeStripStatusLabel.Text == "PRODUCT LINK MODE")
            {
                int productLinkId = Convert.ToInt32(row.Cells["Id"].Value);
                ProductLinkNewOrEdit productLinkForm = new ProductLinkNewOrEdit(productLinkId);
                productLinkForm.ShowDialog();
                mainDataGridView.DataSource = SqliteDAProductLink.GetAllProductLinks();
                SetDefaultLoadParameters();
            }
            //  4. Product
            else if (modeStripStatusLabel.Text == "PRODUCT MODE")
            {
                int productId = Convert.ToInt32(row.Cells["Id"].Value);
                ProductNewOrEdit productForm = new ProductNewOrEdit(productId);
                productForm.ShowDialog();
                mainDataGridView.DataSource = SqliteDAProduct.GetAllProducts();
                SetDefaultLoadParameters();
            }
            //  5. Invoice
            else if (modeStripStatusLabel.Text == "INVOICE MODE")
            {
                int invoiceId = Convert.ToInt32(row.Cells["Id"].Value);
                InvoiceNewOrEdit invoiceForm = new InvoiceNewOrEdit(invoiceId);
                invoiceForm.ShowDialog();
                SetDefaultLoadParametersForInvoiceBarcodeMode(invoiceForm.invoice);
            }
            //  6. Invoice Product
            else if (modeStripStatusLabel.Text == "INVOICE PRODUCT MODE")
            {
                int invoiceProductId = Convert.ToInt32(row.Cells["Id"].Value);
                InvoiceProductNewOrEdit invoiceProductForm = new InvoiceProductNewOrEdit(invoiceProductId);
                invoiceProductForm.ShowDialog();
                barCodeSearchPanel.Visible  = true;
                this.ActiveControl          = barcodeTextBox;
                mainDataGridView.DataSource = SqliteDAInvoiceProduct.GetAllInvoiceProductsByInvoiceId(Convert.ToInt32(invoiceNumberStripStatusLabel.Text));
                mainDataGridView.AutoResizeColumns();
                mainDataGridView.ClearSelection();
                mainDataGridView.Columns["ProductId"].Visible = false;
                mainDataGridView.Columns["InvoiceId"].Visible = false;
                mainDataGridView.Columns["TotalPrice"].DefaultCellStyle.Format = "0.00##";

                calculateInvoiceTotals(SqliteDAInvoice.GetInvoiceById(Convert.ToInt32(invoiceNumberStripStatusLabel.Text)));
            }
        }