Example #1
0
        //Ta bort en medlem
        public int taBortMedlem(Klubb klubb)
        {
            if (klubb.Medlemmar.Count <= 0)
            {
                Console.WriteLine("Det finns inga medlemmar att ta bort.");
                ContinueOnKeyPressed();
                return(0);
            }
            ListaMedlemmar(klubb, "kompakt");
            Console.Write("\nAnge vilken medlem du vill ta bort: ");
            string inData = Console.ReadLine();

            if (inData == "" || inData == null)
            {
                return(0);
            }
            int choice = int.Parse(inData);

            if (choice > klubb.Medlemmar.Count || choice < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            else if (choice == 0)
            {
                return(0);
            }
            else
            {
                Console.WriteLine("\n{0} har tagits bort från medlemslistan.\n", klubb.Medlemmar[choice - 1].Namn);
                //klubb.Medlemmar.RemoveAt(choice - 1);
                ContinueOnKeyPressed();
                return(choice);
            }
        }
Example #2
0
        //Lägga till båt
        public bool nyBat(Klubb klubb)
        {
            string[] nyBat = klubbInfo.nyBatInfo(klubb);
            if (nyBat == null)
            {
                return(false);
            }

            int mNummer = klubb.Medlemmar[int.Parse(nyBat[2]) - 1].Medlemsnummer;

            foreach (Medlem m in klubb.Medlemmar)
            {
                if (m.Medlemsnummer == mNummer)
                {
                    m.AntalBatar++;
                }
            }

            Bat bat = new Bat(nyBat[0], nyBat[1], mNummer);

            klubb.Batar.Add(bat);

            SparaAlltDB(klubb);

            return(true);
        }
Example #3
0
        //Ta bort en båt
        public int taBortBat(Klubb klubb)
        {
            if (klubb.Batar.Count <= 0)
            {
                Console.WriteLine("Det finns inga båtar att ta bort.");
                ContinueOnKeyPressed();
                return(0);
            }
            int number = 1;

            //for (int i = 0; i < klubb.Batar.Count; i++) {
            //    Console.WriteLine("{0}. {1} med längd {2}, ägs av medlemsnummer: {3}", number, klubb.Batar[i].Typ, klubb.Batar[i].Langd, klubb.Batar[i].Medlemsnummer);
            //    number++;
            //}
            ListaBatar(klubb);
            Console.Write("\nAnge vilken båt du vill ta bort: ");

            int choice = int.Parse(Console.ReadLine());

            if (choice > klubb.Batar.Count || choice < 0)
            {
                throw new ArgumentOutOfRangeException();
            }
            else if (choice == 0)
            {
                return(0);
            }
            else
            {
                Console.WriteLine("\n{0} har tagits bort från båtlistan.\n", klubb.Batar[choice - 1]);
                ContinueOnKeyPressed();
                return(choice);
            }
        }
Example #4
0
        //Visa medlemslistan, kompakt eller full
        public void ListaMedlemmar(Klubb klubb, string Listtyp = null)
        {
            int counter = 1;

            if (Listtyp == "kompakt")
            {
                foreach (Medlem medlem in klubb.Medlemmar)
                {
                    Console.WriteLine(counter + ". Namn: " + medlem.Namn + ". Medlemsnummer: " + medlem.Medlemsnummer + " Antal båtar: " + medlem.AntalBatar + ".");
                    counter++;
                }
            }
            else if (Listtyp == "full")
            {
                foreach (Medlem medlem in klubb.Medlemmar)
                {
                    Console.WriteLine(counter + ". Namn: " + medlem.Namn + " Personnummer: " + medlem.Personnummer + ". Medlemsnummer: " + medlem.Medlemsnummer + " båtar: ");

                    //foreach (Bat bat in klubb.Batar) {
                    //    if (bat.Medlemsnummer == medlem.Medlemsnummer)
                    //        Console.WriteLine(bat.ToString());
                    //}
                    ListaBatar(klubb, medlem.Medlemsnummer);
                    counter++;
                }
            }
            else
            {
                foreach (Medlem medlem in klubb.Medlemmar)
                {
                    Console.WriteLine(counter + ". " + medlem.ToString());
                    counter++;
                }
            }
        }
Example #5
0
        static void Main(string[] args)
        {
            Klubb  klubb = new Klubb("AHS", "hdhd", "hdhd", "jdjd");
            Medlem m1    = new Medlem();
            Medlem m2    = new Medlem();
            Medlem m3    = new Medlem();

            klubb.SetOrdförande(m1);

            klubb.NyMedlem(m2);
            klubb.NyMedlem(m3);

            Console.WriteLine(klubb.AntalMedlemmar());
            Console.ReadLine();
        }
Example #6
0
        //Redigera medlem
        public bool redigeraMedlem(Klubb klubb)
        {
            string[] redigeradMedlem = klubbInfo.redMedlemsInfo(klubb);
            if (redigeradMedlem[0] == null || redigeradMedlem[0] == "" || redigeradMedlem[1] == null || redigeradMedlem[1] == "")
            {
                return(false);
            }

            klubb.Medlemmar[int.Parse(redigeradMedlem[2]) - 1].Namn         = redigeradMedlem[0];
            klubb.Medlemmar[int.Parse(redigeradMedlem[2]) - 1].Personnummer = redigeradMedlem[1];

            SparaAlltDB(klubb);

            return(true);
        }
Example #7
0
        //Ta bort medlem
        public bool tabortMedlem(Klubb klubb)
        {
            int mIndex = klubbInfo.taBortMedlem(klubb);

            if (mIndex == 0)
            {
                return(false);
            }

            klubb.Medlemmar.RemoveAt(mIndex - 1);

            SparaAlltDB(klubb);

            return(true);
        }
Example #8
0
 //lista alla medlemmar, kompakt, full lista eller vanlig tostring(definieras i objektet)
 public void listaMedlemmar(Klubb klubb, string typ = null)
 {
     if (typ == "full")
     {
         klubbInfo.ListaMedlemmar(klubb, "full");
     }
     else if (typ == "kompakt")
     {
         klubbInfo.ListaMedlemmar(klubb, "kompakt");
     }
     else
     {
         klubbInfo.ListaMedlemmar(klubb);
     }
     klubbInfo.ContinueOnKeyPressed();
 }
Example #9
0
 //Spara all data till FIL
 public void SparaAlltDB(Klubb klubb)
 {
     using (StreamWriter sw = new StreamWriter(path_))
     {
         sw.WriteLine("[Medlemmar]");
         foreach (Medlem medlem in klubb.Medlemmar)
         {
             sw.WriteLine(medlem.Namn + ";" + medlem.Personnummer + ";" + medlem.Medlemsnummer + ";" + medlem.AntalBatar);
         }
         sw.WriteLine("[Batar]");
         foreach (Bat bat in klubb.Batar)
         {
             sw.WriteLine(bat.Typ + ";" + bat.Langd + ";" + bat.Medlemsnummer);
         }
     }
 }
Example #10
0
        public string[] redMedlemsInfo(Klubb klubb)
        {
            string[] medlem = new string[3];
            if (klubb.Medlemmar.Count <= 0)
            {
                Console.WriteLine("Det finns inga medlemmar att redigera.");
                ContinueOnKeyPressed();
            }
            else
            {
                ListaMedlemmar(klubb, "kompakt");
                Console.Write("\nAnge vilken medlem du vill redigera: ");
                medlem[2] = Console.ReadLine();
                int choice = int.Parse(medlem[2]);
                if (choice > klubb.Medlemmar.Count || choice < 0)
                {
                    throw new ArgumentOutOfRangeException();
                }
                else if (choice == 0)
                {
                    return(medlem);
                }
                else
                {
                    Console.Write("Förnamn: ");
                    medlem[0] = Console.ReadLine();
                    if (!verifInputBokstaver(medlem[0]))
                    {
                        return(medlem);
                    }

                    Console.Write("Personnummer i formatet(yymmddxxxx): ");
                    medlem[1] = Console.ReadLine();
                    if (!verifInputPn(medlem[1]))
                    {
                        return(medlem);
                    }

                    Console.WriteLine("Medlemsinformationen är nu uppdaterad.");
                    ContinueOnKeyPressed();
                    return(medlem);
                }
            }
            return(medlem);
        }
Example #11
0
        //Lägga till medlem
        public bool nyMedlem(Klubb klubb)
        {
            string[] nyMedlem = klubbInfo.nyMedlemsInfo();
            if (nyMedlem[0] == null || nyMedlem[0] == "" || nyMedlem[1] == null || nyMedlem[1] == "")
            {
                return(false);
            }
            Console.Write(nyMedlem[0]);
            Random rnd           = new Random();
            int    medlemsNummer = rnd.Next(1, 64395);

            Medlem medlem = new Medlem(nyMedlem[0], nyMedlem[1], medlemsNummer);

            klubb.Medlemmar.Add(medlem);

            SparaAlltDB(klubb);

            return(true);
        }
Example #12
0
        //Lista alla båtar
        public void ListaBatar(Klubb klubb, int medlemsNummer = 0)
        {
            int    counter = 1;
            string ret     = "";

            foreach (Bat bat in klubb.Batar)
            {
                switch (int.Parse(bat.Typ))
                {
                case 1:
                    ret = counter + ". Typ: Segelbåt Längd: " + bat.Langd + "m Medlemsnummer: " + bat.Medlemsnummer;
                    break;

                case 2:
                    ret = counter + ". Typ: Motorseglare Längd: " + bat.Langd + "m Medlemsnummer: " + bat.Medlemsnummer;
                    break;

                case 3:
                    ret = counter + ". Typ: Motorbåt Längd: " + bat.Langd + "m Medlemsnummer: " + bat.Medlemsnummer;
                    break;

                case 4:
                    ret = counter + ". Typ: Kanot Längd: " + bat.Langd + "m Medlemsnummer: " + bat.Medlemsnummer;
                    break;

                case 5:
                    ret = counter + ". Typ: Övrigt Längd: " + bat.Langd + "m Medlemsnummer: " + bat.Medlemsnummer;
                    break;

                default: break;
                }
                if (medlemsNummer == 0)
                {
                    Console.WriteLine(ret);
                }
                else if (bat.Medlemsnummer == medlemsNummer)
                {
                    Console.WriteLine(ret);
                }
                counter++;
            }
        }
Example #13
0
        //Skapa ny båt
        public string[] nyBatInfo(Klubb klubb)
        {
            string[] nyBat = new string[3];
            Console.Write("Ange båttyp. 1. Segelbåt, 2. Motorseglare, 3. Motorbåt, 4. Kajak/Kanot, 5. Övrigt (1-5): ");
            string batTyp = Console.ReadLine();

            if (!Regex.IsMatch(batTyp, @"^[1-5]+$") || string.IsNullOrEmpty(batTyp))
            {
                Console.WriteLine("Var vänlig ange ett nummer mellan 1-5. Tryck valfri knapp för att återgå till till huvudmenyn.");
                ContinueOnKeyPressed();
                return(null);
            }

            Console.Write("Längd på båten i meter (t.ex 1,5): ");
            string batLangd = Console.ReadLine();

            if (!Regex.IsMatch(batLangd, @"^[0-9,]+$") || string.IsNullOrEmpty(batLangd))
            {
                Console.WriteLine("Vänligen ange ett tal i meter med en decimal. Tryck valfri knapp för att återgå till till huvudmenyn.");
                ContinueOnKeyPressed();
                return(null);
            }

            ListaMedlemmar(klubb, "kompakt");
            Console.Write("Ange numret på ägaren: ");
            string medlemsIndex = Console.ReadLine();

            if (!Regex.IsMatch(medlemsIndex, @"^[1-" + (klubb.Medlemmar.Count) + "]+$") || string.IsNullOrEmpty(batLangd))
            {
                Console.WriteLine("Vänligen ange bara heltal som är listat. Tryck valfri knapp för att återgå till till huvudmenyn.");
                ContinueOnKeyPressed();
                return(null);
            }

            nyBat[0] = batTyp;
            nyBat[1] = batLangd;
            nyBat[2] = medlemsIndex;
            Console.WriteLine("\nBåten är nu tillagd i båtlistan i klubben.\n");
            ContinueOnKeyPressed();
            return(nyBat);
        }
Example #14
0
        //Ta bårt båt
        public bool tabortBat(Klubb klubb)
        {
            int batIndex = klubbInfo.taBortBat(klubb);

            if (batIndex == 0)
            {
                return(false);
            }

            foreach (Medlem m in klubb.Medlemmar)
            {
                if (m.Medlemsnummer == klubb.Batar[batIndex - 1].Medlemsnummer)
                {
                    m.AntalBatar--;
                }
            }

            klubb.Batar.RemoveAt(batIndex - 1);
            SparaAlltDB(klubb);

            return(true);
        }
Example #15
0
        //Ladda in från fil (path)
        //läs in varje rad och skapa nya objekt att stoppa in i klubbobjektet
        public Klubb LaddaAlltDB(Klubb klubb)
        {
            DBReadEnum status = DBReadEnum.None;

            using (StreamReader reader = new StreamReader(path_))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    if (line == "[Medlemmar]")
                    {
                        status = DBReadEnum.Medlem;
                    }
                    else if (line == "[Batar]")
                    {
                        status = DBReadEnum.Bat;
                    }
                    else
                    {
                        if (status == DBReadEnum.Medlem)
                        {
                            string[] medlem = line.Split(';');

                            if (medlem.Length != 4)
                            {
                                throw new ArgumentException("Fel vid inläsning av medlemmar.");
                            }

                            string Namn          = medlem[0];
                            string pn            = medlem[1];
                            int    Medlemsnummer = int.Parse(medlem[2]);
                            int    antalBatar    = int.Parse(medlem[3]);

                            Medlem nyMedlem = new Medlem(Namn, pn, Medlemsnummer, antalBatar);

                            klubb.Add(nyMedlem);
                        }
                        else if (status == DBReadEnum.Bat)
                        {
                            string[] bat = line.Split(';');

                            if (bat.Length != 3)
                            {
                                throw new ArgumentException("Fel vid inläsning av båtar.");
                            }

                            string Typ           = bat[0];
                            string Langd         = bat[1];
                            int    MedlemsNummer = int.Parse(bat[2]);

                            Bat baten = new Bat(Typ, Langd, MedlemsNummer);
                            klubb.Add(baten);
                        }
                        else
                        {
                            Console.WriteLine("Fel vid inläsning");
                        }
                    }
                }
                return(klubb);
            }
        }
Example #16
0
 //Kontruktorn som tillsätter klubbobjektet med parametern och laddar från fil
 public KlubbController(Klubb klubb)
 {
     klubben = klubb;
     klubben = klubbModell.LaddaAlltDB(klubben);
 }