Esempio n. 1
0
        public Bil OpretBil()
        {
            try
            {
                Console.WriteLine("Indtast venligst registreringsnummer");
                string regnr = Console.ReadLine();
                Console.WriteLine("Indtast venligst mærke");
                string mærke = Console.ReadLine();
                Console.WriteLine("Indtast venligst model");
                string model = Console.ReadLine();
                Console.WriteLine("Indtast venligst årgang");
                int årgang = int.Parse(Console.ReadLine());
                Console.WriteLine("Indtast venligst antal kørte kilometer");
                int km = int.Parse(Console.ReadLine());
                Console.WriteLine("Indtast venligst brændstoftype (ID)");
                Brændstof brændstof = (Brændstof)int.Parse(Console.ReadLine());
                Console.WriteLine("Indtast venligst kundeID");
                int kundeid = int.Parse(Console.ReadLine());

                bil = new Bil(regnr, mærke, model, årgang, km, brændstof, kundeid);
                bil.Insert();
            }
            catch (FormatException)
            {
                Console.WriteLine("Forkert input. Tryk på en vilkårlig tast for at vende tilbage til hovedmenuen.");
                Console.ReadKey();
            }
            catch (Exception)
            {
                Console.WriteLine("Det var en upser! Smut pomfrit");
                Console.ReadKey();
            }
            return(bil);
        }
Esempio n. 2
0
 public Bil(string registreringsnummer, string mærke, string model, int årgang, int km, Brændstof brændstof, int kundeId)
 {
     Registreringsnummer = registreringsnummer;
     Mærke          = mærke;
     Model          = model;
     Årgang         = årgang;
     Km             = km;
     this.brændstof = brændstof;
     KundeId        = kundeId;
 }
Esempio n. 3
0
File: Bil.cs Progetto: Anoobiz/MMO
        public void opretBil()
        {
            Console.Clear();
            Forside.DisplayTop();
            Console.WriteLine("Indtast KundeID: ");
            Console.WriteLine("Indtast Mærke: ");
            Console.WriteLine("Indtast Model: ");
            Console.WriteLine("Indtast Årgang: ");
            Console.WriteLine("Indtast KmKørt: ");
            Console.WriteLine("Indtast Brændstof: ");
            Console.WriteLine("Indtast RegistreringsNr: ");
            Console.SetCursorPosition(50, 7);
            bool loop     = true;
            int  idFindes = 0;

            while (loop)
            {
                try
                {
                    KundeId = Convert.ToInt32(Console.ReadLine());
                    foreach (DataRow item in SQL.Liste("Select KundeId from Kunder").Rows)
                    {
                        if (KundeId == Convert.ToInt32(item["KundeId"]))
                        {
                            idFindes = Convert.ToInt32(item["KundeId"]);
                        }
                    }
                    if (KundeId == idFindes)
                    {
                        loop = false;
                    }
                    else
                    {
                        Console.SetCursorPosition(0, 7);
                        Console.Write("                                                                                            ");
                        Console.SetCursorPosition(0, 7);
                        Console.WriteLine("Ugyldigt kundeId, prøv igen:");
                        Console.SetCursorPosition(50, 7);
                    }
                }
                catch (FormatException)
                {
                    Console.SetCursorPosition(0, 7);
                    Console.Write("                                                                                            ");
                    Console.SetCursorPosition(0, 7);
                    Console.WriteLine("KundeId skal være et tal:");
                    Console.SetCursorPosition(50, 7);
                }
                catch (OverflowException)
                {
                    Console.SetCursorPosition(0, 7);
                    Console.Write("                                                                                            ");
                    Console.SetCursorPosition(0, 7);
                    Console.WriteLine("Tallet er for stort, prøv igen:");
                    Console.SetCursorPosition(50, 7);
                }
            }
            Console.SetCursorPosition(0, 7);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 7);
            Console.WriteLine("KundeId:");
            Console.SetCursorPosition(50, 7);
            Console.WriteLine(KundeId);
            Console.SetCursorPosition(50, 8);
            Mærke = Console.ReadLine();
            Console.SetCursorPosition(0, 8);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 8);
            Console.WriteLine("Mærke:");
            Console.SetCursorPosition(50, 8);
            Console.WriteLine(Mærke);
            Console.SetCursorPosition(50, 9);
            Model = Console.ReadLine();
            Console.SetCursorPosition(0, 9);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 9);
            Console.WriteLine("Model:");
            Console.SetCursorPosition(50, 9);
            Console.WriteLine(Model);
            Console.SetCursorPosition(50, 10);
            while (Årgang == 0)
            {
                try
                {
                    Årgang = Convert.ToInt32(Console.ReadLine());
                    if (Årgang < 1900 || Årgang > 2019)
                    {
                        Console.SetCursorPosition(0, 10);
                        Console.Write("                                                                                            ");
                        Console.SetCursorPosition(0, 10);
                        Console.WriteLine("Indtast en gyldig årgang:");
                        Console.SetCursorPosition(50, 10);
                        Årgang = 0;
                    }
                }
                catch (FormatException)
                {
                    Console.SetCursorPosition(0, 10);
                    Console.Write("                                                                                            ");
                    Console.SetCursorPosition(0, 10);
                    Console.WriteLine("En årgang indeholder kun tal, prøv igen:");
                    Console.SetCursorPosition(50, 10);
                    Console.ReadKey(true);
                }
            }
            Console.SetCursorPosition(0, 10);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 10);
            Console.WriteLine("Årgang:");
            Console.SetCursorPosition(50, 10);
            Console.WriteLine(Årgang);
            Console.SetCursorPosition(50, 11);
            while (KmKørt == 0)
            {
                try
                {
                    KmKørt = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException)
                {
                    Console.SetCursorPosition(0, 11);
                    Console.Write("                                                                                            ");
                    Console.SetCursorPosition(0, 11);
                    Console.WriteLine("Km kørt skal være et tal, prøv igen:");
                    Console.SetCursorPosition(50, 11);
                }
            }
            Console.SetCursorPosition(0, 11);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 11);
            Console.WriteLine("Kilometer kørt:");
            Console.SetCursorPosition(50, 11);
            Console.WriteLine(KmKørt);
            Console.SetCursorPosition(50, 12);
            Brændstof = Console.ReadLine();
            while (Brændstof.ToLower() != "benzin" && Brændstof.ToLower() != "diesel")
            {
                Console.SetCursorPosition(0, 12);
                Console.Write("                                                                                            ");
                Console.SetCursorPosition(0, 12);
                Console.WriteLine("Benzin eller diesel:");
                Console.SetCursorPosition(50, 12);
                Brændstof = Console.ReadLine();
            }
            Console.SetCursorPosition(0, 12);
            Console.Write("                                                                                            ");
            Console.SetCursorPosition(0, 12);
            Console.WriteLine("Brændstof:");
            Console.SetCursorPosition(50, 12);
            Console.WriteLine(Brændstof);
            Console.SetCursorPosition(50, 13);
            RegNr     = Console.ReadLine();
            OpretDato = DateTime.Now.ToString("d");
            SQL.Change("insert into Bil values(" + KundeId + ",'" + Mærke + "', '" + Model + "', " + Årgang + ", " + KmKørt + ", '" + Brændstof + "', '" + RegNr + "', '" + OpretDato + "')");
            biler.Add(new Bil(Mærke, Model, Årgang, KmKørt, Brændstof, OpretDato, RegNr, KundeId));
        }