Ejemplo n.º 1
0
        public                CardFailes[] fileInit(string path)
        {
            try
            {
                int      temp  = 0;
                string[] lines = File.ReadAllLines(@path);
                if (lines.Length % 5 == 0)
                {
                    CardFailes[] cardFaileses = new CardFailes[lines.Length / 5];
                    Console.WriteLine(lines.Length % 5);


                    for (int i = 0; i < lines.Length / 5; i++)
                    {
                        cardFaileses[i].room      = Convert.ToInt32(lines[temp]);
                        cardFaileses[i].floor     = Convert.ToInt32(lines[temp + 1]);
                        cardFaileses[i].square    = (float)Convert.ToDouble(lines[temp + 2]);
                        cardFaileses[i].street    = lines[temp + 3];
                        cardFaileses[i].ownerName = lines[temp + 4];
                        temp += 5;
                    }
                    return(cardFaileses);
                }
                else
                {
                    Console.WriteLine("Error !");
                    return(null);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error!" + e);
                return(null);
            }
        }
Ejemplo n.º 2
0
        public                CardFailes[] manualInit(int count)
        {
            CardFailes[] cardFaileses = new CardFailes[count];

            for (int i = 0; i < count; i++)
            {
                cardFaileses[i].room      = writeInt("Count rooms: ");
                cardFaileses[i].floor     = writeInt("Floor: ");
                cardFaileses[i].square    = writeFloat("Square: ");
                cardFaileses[i].street    = writeString("Street: ");
                cardFaileses[i].ownerName = writeString("Owner: ");
            }

            return(cardFaileses);
        }
Ejemplo n.º 3
0
        public                CardFailes[] autoInit(int count)
        {
            CardFailes[] cardFaileses = new CardFailes[count];
            Random       r            = new Random();

            for (int i = 0; i < count; i++)
            {
                cardFaileses[i].room      = r.Next(1, 10);
                cardFaileses[i].floor     = r.Next(1, 30);
                cardFaileses[i].square    = (float)(r.NextDouble() * (maxSquare - minSquare) + minSquare);
                cardFaileses[i].street    = i + " East Edgefield Lane Mount Airy";
                cardFaileses[i].ownerName = "OwnerNumber " + i;
            }

            return(cardFaileses);
        }
Ejemplo n.º 4
0
        public void menu()
        {
            Console.WriteLine("1.Auto fill");
            Console.WriteLine("2.Manual fill");
            Console.WriteLine("3.Import from file");
            Console.WriteLine("4.Exit");

            CardFailes[] cardFaileses = null;
            CardFailes   c            = new CardFailes();
            int          a            = c.writeInt("Choose number ");

            switch (a)
            {
            case 1:
                int b = c.writeInt("Enter count: ");
                cardFaileses = c.autoInit(b);
                break;

            case 2:
                int bb = c.writeInt("Enter count: ");
                cardFaileses = c.manualInit(bb);
                break;

            case 3:
                string bbb = c.writeString("Entre path: ");
                cardFaileses = c.fileInit(bbb);
                if (cardFaileses == null)
                {
                    Console.WriteLine("Error!");
                    menu();
                    return;
                }

                break;

            case 4:
                Environment.Exit(1);
                break;

            default:
                Console.WriteLine("Error!");
                menu();
                return;
            }

            nextmenu(cardFaileses);
        }
Ejemplo n.º 5
0
        public void nextmenu(CardFailes[] a)
        {
            Console.WriteLine("1.Swap apartment");
            Console.WriteLine("2.OutInf");
            Console.WriteLine("3.Export to file");
            Console.WriteLine("4.Exit");

            CardFailes[] cardFaileses = a;
            CardFailes   c            = new CardFailes();

            int sk = c.writeInt("Choose number ");

            switch (sk)
            {
            case 1:
                Console.WriteLine("Describe your apartment");
                CardFailes temp = c.manualInit(1)[0];
                cardFaileses = c.swapApartment(cardFaileses, temp);
                break;

            case 2:
                c.outInf(cardFaileses);
                break;

            case 3:
                c.writeCardsToFile(cardFaileses);
                break;

            case 4:
                Environment.Exit(1);
                break;

            default:
                Console.WriteLine("Error!");
                nextmenu(a);
                return;
            }

            nextmenu(cardFaileses);
        }
Ejemplo n.º 6
0
        public                CardFailes[] swapApartment(CardFailes[] cardFaileses, CardFailes card)
        {
            for (int i = 0; i < cardFaileses.Length; i++)
            {
                if (cardFaileses[i].room == card.room && cardFaileses[i].floor == card.floor &&
                    compareSquare(cardFaileses[i].square, card.square))
                {
                    CardFailes[] newCardFaileses = new CardFailes[cardFaileses.Length - 1];
                    int          temp            = 0;

                    for (int j = 0; j < newCardFaileses.Length; j++)
                    {
                        if (i != j)
                        {
                            newCardFaileses[j] = cardFaileses[j + temp];
                        }
                        else
                        {
                            temp = 1;
                            newCardFaileses[j] = cardFaileses[j + temp];
                        }
                    }

                    Console.WriteLine("Apartment was changed!");
                    return(newCardFaileses);
                }
            }

            Console.WriteLine("Apartment not found !");
            CardFailes[] oldCardFaileses = new CardFailes[cardFaileses.Length + 1];
            for (int i = 0; i < cardFaileses.Length; i++)
            {
                oldCardFaileses[i] = cardFaileses[i];
            }

            oldCardFaileses[oldCardFaileses.Length - 1] = card;
            return(oldCardFaileses);
        }