Beispiel #1
0
        //updates the data of an ITEM in the database it also displays the current ITEMS in the database so you can provide a ID for updating
        //using the Insert Method in the SQLconnection Class
        static private void UpdateData(Firma P)
        {
            Console.Clear();
            string    selectquery = $"SELECT id, navn FROM Vare";
            DataTable dataTable   = new DataTable();

            dataTable = Select(selectquery);
            foreach (DataRow row in dataTable.Rows)
            {
                string updatestring = string.Format("ID: {0} | Navn: {1}", row.ItemArray);
                Console.WriteLine(updatestring);
            }
            Console.WriteLine("Write the ID number of the item you want updated");
            string userinput  = Console.ReadLine();
            bool   errorCheck = int.TryParse(userinput, out int result);

            if (errorCheck)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    if (Convert.ToInt32(row.ItemArray[0]) == result)
                    {
                        Console.Clear();
                        Console.WriteLine(" _______________________________ ");
                        Console.WriteLine("| Navn:                         |");
                        Console.WriteLine("| Pris:                         |");
                        Console.WriteLine("| Antal:                        |");
                        Console.WriteLine("|_______________________________|");
                        Console.SetCursorPosition(8, 1);
                        string varenavn = Console.ReadLine();
                        Console.SetCursorPosition(8, 2);
                        double pris = Convert.ToDouble(Console.ReadLine());
                        Console.SetCursorPosition(9, 3);
                        int antal = Convert.ToInt32(Console.ReadLine());
                        Insert($"UPDATE Vare SET navn ='{varenavn}', pris = '{pris}', stock = '{antal}' WHERE id = {result}");
                        break;
                    }
                }
            }
            Menu(P);
        }
Beispiel #2
0
        //Adds a placement for an item in the database
        static private void AddPlacering(Firma P)
        {
            Console.Clear();
            string    selectquery = $"SELECT id, navn FROM Vare";
            DataTable dataTable   = new DataTable();

            dataTable = Select(selectquery);
            foreach (DataRow row in dataTable.Rows)
            {
                string placeringstring = string.Format("ID: {0} | Navn: {1}", row.ItemArray);
                Console.WriteLine(placeringstring);
            }
            string userinput  = Console.ReadLine();
            bool   errorCheck = int.TryParse(userinput, out int result);

            if (errorCheck)
            {
                foreach (DataRow row in dataTable.Rows)
                {
                    if (Convert.ToInt32(row.ItemArray[0]) == result)
                    {
                        Console.Clear();
                        Console.WriteLine(" _______________________________ ");
                        Console.WriteLine("| Hylde:                        |");
                        Console.WriteLine("| Plads:                        |");
                        Console.WriteLine("|_______________________________|");
                        Console.SetCursorPosition(9, 1);
                        string hylde = Console.ReadLine();
                        Console.SetCursorPosition(9, 2);
                        double plads = Convert.ToDouble(Console.ReadLine());
                        Insert($"INSERT INTO Placering (hylde, plads, vare) VALUES ('{hylde}','{plads}','{result}')");
                        break;
                    }
                }
            }
            Menu(P);
        }