private void AcceptInput(object sender, RoutedEventArgs e)
        {
            if (!inputCorrect)
            {
                MessageBox.Show("Description field can't be empty.", "Invalid description input", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                // create new tool instance
                ToolModel updateTool = new ToolModel();


                if (SqliteDataAcces.SearchDataByText("ToolID", "Tools", "ToolID", toolID).ToList().Count == 0)
                {
                    MessageBox.Show("Tool not found in database.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                else
                {
                    // Assign info to updateTool
                    updateTool.ToolID          = Convert.ToInt32(toolID);
                    updateTool.Storage         = StorageTextBox.Text;
                    updateTool.Location        = LocationTextBox.Text;
                    updateTool.Description     = DescriptionTextBox.Text;
                    updateTool.HolderVendor    = HolderVendorComboBox.Text;
                    updateTool.HolderArt       = HolderArtTextBox.Text;
                    updateTool.ExtensionVendor = ExtensionVendorComboBox.Text;
                    updateTool.ExtensionArt    = ExtensionArtTextBox.Text;
                    updateTool.ToolVendor      = ToolVendorComboBox.Text;
                    updateTool.ToolArt         = ToolArtTextBox.Text;



                    // Write new tool to Database and check if succesfull
                    bool writingSuccesFull = SqliteDataAcces.UpdateToolRecord(updateTool);

                    if (writingSuccesFull)
                    {
                        MessageBox.Show($"Changes succesfully written to database.", "Succesfull", MessageBoxButton.OK, MessageBoxImage.Information);

                        //Close window
                        raiseClosingEvent = false;
                        Close();

                        //Refresh data grid
                        ((MainWindow)Owner).SetDataGrid();
                    }
                    else
                    {
                        MessageBox.Show($"Failed update tool!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
            }
        }
Esempio n. 2
0
        //
        // ---Create new tool when accepting input---
        //
        private void AcceptInput(object sender, RoutedEventArgs e)
        {
            bool userInputOK = CheckUserInput();

            if (userInputOK == false)
            {
                MessageBox.Show("Invalid input", "Invalid input", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
            else
            {
                // create new tool instance
                ToolModel newTool = new ToolModel();

                // Create new toolID
                string toolID = CreateToolID();

                if (SqliteDataAcces.SearchDataByText("ToolID", "Tools", "ToolID", toolID).ToList().Count > 0)
                {
                    ToolModel existingTool = SqliteDataAcces.SearchDataByText("Description", "Tools", "ToolID", toolID)[0];
                    MessageBox.Show($"Tool already exists!\n\nToolID: {existingTool.ToolID}\nDescription: {existingTool.Description}", "Existing tool", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                }
                else
                {
                    // Assign info to newTool
                    newTool.ToolID          = Convert.ToInt32(toolID);
                    newTool.Description     = DescriptionTextBox.Text;
                    newTool.Type            = TypeComboBox.Text;
                    newTool.Function        = FunctionComboBox.Text;
                    newTool.Diameter        = Convert.ToDouble(DiameterTextBox.Text);
                    newTool.Length          = Convert.ToDouble(LengthTextBox.Text);
                    newTool.Holder          = HolderComboBox.Text;
                    newTool.Machine         = MachineComboBox.Text;
                    newTool.Storage         = StorageTextBox.Text;
                    newTool.HolderVendor    = HolderVendorComboBox.Text;
                    newTool.HolderArt       = HolderArtTextBox.Text;
                    newTool.ExtensionVendor = ExtensionVendorComboBox.Text;
                    newTool.ExtensionArt    = ExtensionArtTextBox.Text;
                    newTool.ToolVendor      = ToolVendorComboBox.Text;
                    newTool.ToolArt         = ToolArtTextBox.Text;

                    // Write new tool to Database and check if succesfull
                    bool writingSuccesFull = SqliteDataAcces.NewToolRecord(newTool);

                    if (writingSuccesFull)
                    {
                        MessageBox.Show($"Succesfully created new tool.", "Succesfull", MessageBoxButton.OK, MessageBoxImage.Information);

                        // Close window
                        raiseClosingEvent = false;
                        Close();

                        //Refresh data grid
                        ((MainWindow)Owner).SetDataGrid();
                    }
                    else
                    {
                        MessageBox.Show($"Failed to create new tool!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                    }
                }
            }
        }