Ejemplo n.º 1
0
        private void UpdatePart()
        {
            Console.WriteLine("Update Part");
            AddPartWindow partWindow = new AddPartWindow(selectedPart);

            partWindow.ShowDialog();

            //If the database gets updated in the update part call will need to read
            ReadDataBase();
        }
Ejemplo n.º 2
0
        private void AddPart()
        {
            AddPartWindow partWindow = new AddPartWindow(partsList);

            //partWindow.Show();
            partWindow.ShowDialog();

            //Now that it's back returning part may have a part to add
            if (returningPart != null)
            {
                if (Part.isPartInPartsList(partsList, returningPart) == false)
                {
                    //need to add to the database and then read the table
                    Console.WriteLine($"Part should be added as it's not in the list\n{returningPart.ToString()}");
                    using (SQLiteConnection connection = new SQLiteConnection(App.dataBasePath))
                    {
                        var tempPart = new Part();
                        tempPart.ModelName       = returningPart.ModelName;
                        tempPart.PartNumber      = returningPart.PartNumber;
                        tempPart.PartDescription = returningPart.PartDescription;
                        tempPart.Comments        = returningPart.Comments;
                        //by using the using statement no need to close the database connection
                        connection.CreateTable <Part>();
                        //Once inserted into the database is where it will pickup the Id field.
                        connection.Insert(tempPart);

                        MessageBox.Show($"The {tempPart.PartDescription} was added to the database.");
                    }

                    ReadDataBase();
                }
                else
                {
                    //Console.WriteLine($"Part is already in the database\n{returningPart.ToString()}");
                    MessageBox.Show($"The Part is already in the database, or has an empty part number or model number.\n{returningPart.ToString()}");
                }
            }

            //if so can i set it back to null?
            returningPart = null;
        }