示例#1
0
 //********************************************************************************************//
 //  LOAD MODELS - DOUBLE CLICK PICTURE BOX EVENT
 //********************************************************************************************//
 //  TODO: Remove unwanted columns from each objects get all function.
 //  1. Category
 private void categoryPictureBox_DoubleClick(object sender, EventArgs e)
 {
     //Load all categories from the database to the main data grid view.
     modeStripStatusLabel.Text   = "CATEGORY MODE";
     mainDataGridView.DataSource = SqliteDACategory.GetAllCategories();
     SetDefaultLoadParameters();
     mainDataGridView.Columns["Id"].Visible = false;
 }
示例#2
0
 public CategoryNewOrEdit(int categoryId)
 {
     InitializeComponent();
     formTitleLabel.Text   = "Edit Category";
     saveButton.Text       = "Edit";
     this.existingCategory = SqliteDACategory.GetCategoryById(categoryId);
     this.newCategory      = false;
 }
示例#3
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);
         }
     }
 }
示例#4
0
        //Other Methods
        //******************************************************************************************************
        private void LoadMainCategoryComboBox()
        {
            //Add a none category instance to the list of main categories that are loaded to the combo box.
            //Create a category with no main category
            CategoryModel category = new CategoryModel();

            category.Id   = 0;
            category.Name = "<NONE>";
            //Get the list of main categories
            this.mainCategories = SqliteDACategory.GetMainCategoryOnly();
            //Add no main category to the start of the list
            this.mainCategories.Insert(0, category);
            //Wire up the main category combobox.
            mainCategoryComboBox.DataSource    = this.mainCategories;
            mainCategoryComboBox.DisplayMember = "Name";
            mainCategoryComboBox.ValueMember   = "Id";
        }
示例#5
0
 private void saveExistingCategoryInformationToDb()
 {
     if (SqliteDACategory.UpdateCategoryById(this.category))
     {
         DialogResult dialogResult = MessageBox.Show("Category updated successfully", "Category Edit",
                                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
         if (dialogResult == DialogResult.OK)
         {
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("Something went wrong. Category update could not be saved.\nCheck the error log for more information.", "Category Edit Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#6
0
 private void saveNewCategoryInformationToDb()
 {
     if (SqliteDACategory.SaveCategory(this.category))
     {
         DialogResult dialogResult = MessageBox.Show("New category created successfully", "New Category",
                                                     MessageBoxButtons.OK, MessageBoxIcon.Information);
         if (dialogResult == DialogResult.OK)
         {
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("Something went wrong. New category could not be saved.\nCheck the error log for more information.", "New Category Error",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#7
0
        private void LoadFindCategoryComboBox()
        {
            List <CategoryModel> categories = new List <CategoryModel>();

            //Combo box selection option. If the user wants to search for a product in all categories,
            //<ALL> can be chosen.
            CategoryModel category = new CategoryModel();

            category.Id   = 0;
            category.Name = "<ALL>";

            //Load Combo Boxes. Add <ALL> option at the beginning of list.
            categories = SqliteDACategory.GetSubcategoryOnly();
            categories.Insert(0, category);
            findCategoryComboBox.DataSource    = categories;
            findCategoryComboBox.ValueMember   = "Id";
            findCategoryComboBox.DisplayMember = "Name";

            //Default Selected Index
            findCategoryComboBox.SelectedIndex = 0;
            findCategoryComboBox.SelectedIndex = 0;
        }
示例#8
0
        //********************************************************************************************//
        //  DELETE MODELS - CLICK DELETE BUTTON EVENT
        //********************************************************************************************//
        private void deleteButton_Click(object sender, EventArgs e)
        {
            //1. Category
            if (modeStripStatusLabel.Text == "CATEGORY MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this category?" +
                                                                          "\nCategory Name: {0}\nMain Category: {1}", row.Cells["Name"].Value.ToString(), row.Cells["MainCategory"].Value.ToString()),
                                                            "Delete Category", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = SqliteDACategory.DeleteCategoryById(Convert.ToInt32(row.Cells["Id"].Value));
                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Category was successfully deleted.", "Delete Category", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDACategory.GetAllCategories();
                        mainDataGridView.AutoResizeColumns();
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Category could not be deleted.", "Delete Category Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
            //2. Store
            else if (modeStripStatusLabel.Text == "STORE MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this store?" +
                                                                          "\nStore Name: {0}\nLocation: {1}", row.Cells["Name"].Value.ToString(), row.Cells["Location"].Value.ToString()),
                                                            "Delete Store", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = SqliteDAStore.DeleteStoreById(Convert.ToInt32(row.Cells["Id"].Value));
                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Store was successfully deleted.", "Delete Store", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDAStore.GetAllStores();
                        mainDataGridView.AutoResizeColumns();
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Store could not be deleted.", "Delete Store Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
            //3. Product Link
            else if (modeStripStatusLabel.Text == "PRODUCT LINK MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product link?" +
                                                                          "\nProduct Link Name: {0}\nCategory Name: {1}", row.Cells["Name"].Value.ToString(), row.Cells["CategoryName"].Value.ToString()),
                                                            "Delete Product Link", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = SqliteDAProductLink.DeleteProductLinkById(Convert.ToInt32(row.Cells["Id"].Value));
                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Product Link was successfully deleted.", "Delete Product Link", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDAProductLink.GetAllProductLinks();
                        mainDataGridView.AutoResizeColumns();
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Product Link could not be deleted.", "Delete Product Link Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
            //4. Product
            else if (modeStripStatusLabel.Text == "PRODUCT MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product?" +
                                                                          "\nBrand Name: {0}\nProduct Description: {1}", row.Cells["BrandName"].Value.ToString(), row.Cells["Description"].Value.ToString()),
                                                            "Delete Product", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = SqliteDAProduct.DeleteProductById(Convert.ToInt32(row.Cells["Id"].Value));
                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Product was successfully deleted.", "Delete Product", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDAProduct.GetAllProducts();
                        mainDataGridView.AutoResizeColumns();
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Product could not be deleted.", "Delete Product Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
            //5. Invoice
            else if (modeStripStatusLabel.Text == "INVOICE MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this invoice?" +
                                                                          "\nInvoice Date: {0}\nInvoice Number: {1}", row.Cells["Date"].Value.ToString(), row.Cells["InvoiceNumber"].Value.ToString()),
                                                            "Delete Invoice", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = false;
                    if (row.Cells["Saved"].Value.ToString() == "Open")
                    {
                        //Invoices marked as open will be permanently deleted from the database
                        result = SqliteDAInvoice.DeleteOpenInvoiceById(Convert.ToInt32(row.Cells["Id"].Value));
                    }
                    else if (row.Cells["Saved"].Value.ToString() == "Saved")
                    {
                        //Invoices marked as saved will be archived (marked as deleted, but still kept in the database).
                        result = SqliteDAInvoice.DeleteSavedInvoiceById(Convert.ToInt32(row.Cells["Id"].Value));
                    }

                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Invoice was successfully deleted.", "Delete Invoice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDAInvoice.GetAllInvoices();
                        mainDataGridView.AutoResizeColumns();
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Invoice could not be deleted.", "Delete Invoice Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
            //6. Invoice Product
            else if (modeStripStatusLabel.Text == "INVOICE PRODUCT MODE")
            {
                DialogResult dialogResult = MessageBox.Show(string.Format("Are you sure you want to delete this product from the invoice?" +
                                                                          "\nProduct Name: {0}", row.Cells["ProductName"].Value.ToString()),
                                                            "Delete Invoice Product", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    bool result = SqliteDAInvoiceProduct.DeleteInvoiceProductById(Convert.ToInt32(row.Cells["Id"].Value));
                    if (result == true)
                    {
                        DialogResult dialog = MessageBox.Show("Product was successfully deleted from invoice.", "Delete Invoice Product", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        mainDataGridView.DataSource = SqliteDAInvoiceProduct.GetAllInvoiceProductsByInvoiceId(Convert.ToInt32(invoiceNumberStripStatusLabel.Text));
                        mainDataGridView.AutoResizeColumns();
                        mainDataGridView.Columns["ProductId"].Visible = false;
                        mainDataGridView.Columns["InvoiceId"].Visible = false;
                        toggleClickFirstButtons(false);
                    }
                    else
                    {
                        DialogResult dialog = MessageBox.Show("Something went wrong. Product could not be deleted from invoice.", "Delete Invoice Product Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    toggleClickFirstButtons(false);
                }
            }
        }
示例#9
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)));
            }
        }
示例#10
0
 private void LoadNewCategoryComboBox()
 {
     newCategoryComboBox.DataSource    = SqliteDACategory.GetSubcategoryOnly();
     newCategoryComboBox.DisplayMember = "Name";
     newCategoryComboBox.ValueMember   = "Id";
 }