Example #1
0
 //********************************************************************************************//
 //  SAVE MODELS - CLICK NEW BUTTON EVENT
 //********************************************************************************************//
 //  There is just one click new button event method. Check in which mode the app is in to
 //  determine which class to act on.
 private void newButton_Click(object sender, EventArgs e)
 {
     //1. Category
     if (modeStripStatusLabel.Text == "CATEGORY MODE")
     {
         CategoryNewOrEdit categoryForm = new CategoryNewOrEdit();
         categoryForm.ShowDialog();
         mainDataGridView.DataSource = SqliteDACategory.GetAllCategories();
         SetDefaultLoadParameters();
     }
     //2. Store
     else if (modeStripStatusLabel.Text == "STORE MODE")
     {
         StoreNewOrEdit storeForm = new StoreNewOrEdit();
         storeForm.ShowDialog();
         mainDataGridView.DataSource = SqliteDAStore.GetAllStores();
         SetDefaultLoadParameters();
     }
     //3. Product Link
     else if (modeStripStatusLabel.Text == "PRODUCT LINK MODE")
     {
         ProductLinkNewOrEdit productLinkForm = new ProductLinkNewOrEdit();
         productLinkForm.ShowDialog();
         mainDataGridView.DataSource = SqliteDAProductLink.GetAllProductLinks();
         SetDefaultLoadParameters();
     }
     //4. Product
     else if (modeStripStatusLabel.Text == "PRODUCT MODE")
     {
         ProductNewOrEdit productForm = new ProductNewOrEdit();
         productForm.ShowDialog();
         mainDataGridView.DataSource = SqliteDAProduct.GetAllProducts();
         SetDefaultLoadParameters();
     }
     //5. Invoice
     else if (modeStripStatusLabel.Text == "INVOICE MODE")
     {
         InvoiceNewOrEdit invoiceForm = new InvoiceNewOrEdit();
         invoiceForm.ShowDialog();
         //  Check if user clicked the save button.
         //  TODO: What happens if the user doesn't click the save button in the next form?
         if (invoiceForm.userClickedSaveButton)
         {
             SetDefaultLoadParametersForInvoiceBarcodeMode(invoiceForm.invoice);
         }
     }
 }
Example #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)));
            }
        }