public static void AddOperationMenu()
        {
            Console.Title = "RealEstate - Add Menu";

            RealEstate realEstate = new RealEstate();

            Console.WriteLine("Aby dodać nowy wpis do bazy danych, wypełnij wszystkie pola.");
            Console.WriteLine();

            UserSetEnum(realEstate);
            UserSetPrice(realEstate);
            UserSetArea(realEstate);
            UserSetRoomsAmount(realEstate);
            Console.WriteLine("Wpisz imię właściciela:");
            realEstate.OwnerName = FilterMenu.SetStringFromConsole();
            Console.WriteLine("Wpisz nazwisko właściciela:");
            realEstate.OwnerSurname = FilterMenu.SetStringFromConsole();
            Console.WriteLine("Wpisz nazwę miejscowości:");
            realEstate.City = FilterMenu.SetStringFromConsole();
            Console.WriteLine("Wpisz nazwę ulicy:");
            realEstate.Street = FilterMenu.SetStringFromConsole();
            Console.WriteLine("Wpisz nr domu, mieszkania:");
            realEstate.EstateAddress = FilterMenu.SetStringFromConsole();

            DatabaseContext.AddToDatabase(realEstate);

            //jakieś potwierdzenie trzeba napisać, np zwrócić z backendu ID wpisu
            //koniec funkcji
            //task 6
        }
        public static void UserSetEnum(RealEstate realEstate)
        {
            var isEnumSet = false;

            Console.WriteLine("Podaj typ nieruchomości:");
            Console.WriteLine();
            Console.WriteLine("0 - Dom,");
            Console.WriteLine("1 - Mieszkanie,");
            Console.WriteLine("2 - Działka,");
            Console.WriteLine("3 - Garaż,");
            Console.WriteLine("4 - Lokal usługowy");
            Console.WriteLine();

            while (!isEnumSet)
            {
                if (int.TryParse(Console.ReadLine(), out var realEstateTypeNumber) &&
                    Enum.IsDefined(typeof(RealEstate.TypeOfRealEstate), realEstateTypeNumber))
                {
                    realEstate.typeOfRealEstate = (RealEstate.TypeOfRealEstate)realEstateTypeNumber;
                    isEnumSet = true;
                }
                else
                {
                    Console.WriteLine("Wpisz jedną z podanych wartości.");
                }
            }
        }
示例#3
0
        public static void AddToDatabase(RealEstate realEstate)
        {
            //ID; TypeOfRealEstate; Price; Area; OwnerName; OwnerSurname; City; Street; EstateAddress; CreationDate; ModificationDate;
            //ID zostaje ustalony automatycznie
            //Data stworzenia wpisu zostaje ustalona automatycznie
            //funkcja przyjmuje obiekt RealEstate

            realEstate.CreationDate     = DateTime.Now;
            realEstate.ModificationDate = DateTime.Now;


            String path          = "..\\Files\\RealEstates.csv";
            string realativePath = DatabaseContext.bingPathToAppDir(path);

            var lastLine = File.ReadLines(realativePath).Last(); // z tego wyciągam  ID

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("");
            sb.Append(GetLastLineId(lastLine));          //Id
            sb.Append(";");
            sb.Append((int)realEstate.typeOfRealEstate); //TypeOfRealEstate
            sb.Append(";");
            sb.Append(realEstate.Price);
            sb.Append(";");
            sb.Append(realEstate.Area);
            sb.Append(";");
            sb.Append(realEstate.RoomsAmount);
            sb.Append(";");
            sb.Append(realEstate.OwnerName);
            sb.Append(";");
            sb.Append(realEstate.OwnerSurname);
            sb.Append(";");
            sb.Append(realEstate.City);
            sb.Append(";");
            sb.Append(realEstate.Street);
            sb.Append(";");
            sb.Append(realEstate.EstateAddress);
            sb.Append(";");
            sb.Append(realEstate.CreationDate);
            sb.Append(";");
            sb.Append(realEstate.ModificationDate);
            sb.Append(";");



            using (StreamWriter sw = File.AppendText(realativePath))
            {
                sw.Write(sb);
            }

            Console.Clear();
            Console.WriteLine("Record added to database.Press any key");
            Console.ReadLine();
            Log insertLog = new Log(0, DateTime.Now, "Insert of Real Estate: " + realEstate.typeOfRealEstate, "worker");

            Logger.AddLineToLog(insertLog);
        }
        public static void UserSetArea(RealEstate realEstate)
        {
            var area = 0;

            Console.WriteLine("Wpisz powierzchnię dodawanej nieruchomości (w m^2):");
            while (!int.TryParse(Console.ReadLine(), out area) || (area < 0))
            {
                Console.WriteLine("Wpisz poprawną liczbę.");
            }
            realEstate.Area = area;
        }
        public static void UserSetPrice(RealEstate realEstate)
        {
            var price = 0.0m;

            Console.WriteLine("Wpisz cenę dodawanej nieruchomości (w PLN):");
            while (!decimal.TryParse(Console.ReadLine(), out price) || (price < 0))
            {
                Console.WriteLine("Wpisz poprawną liczbę.");
            }

            realEstate.Price = price;
        }
 public static void UserSetRoomsAmount(RealEstate realEstate)
 {
     if (realEstate.typeOfRealEstate == RealEstate.TypeOfRealEstate.Dom ||
         realEstate.typeOfRealEstate == RealEstate.TypeOfRealEstate.Mieszkanie)
     {
         int roomsAmount;
         Console.WriteLine("Wpisz liczbę pokoi:");
         while (!int.TryParse(Console.ReadLine(), out roomsAmount) && roomsAmount < 0)
         {
             Console.WriteLine("Wpisz właściwą liczbę.");
         }
         realEstate.RoomsAmount = roomsAmount;
     }
     else
     {
         realEstate.RoomsAmount = 0;
     }
 }
示例#7
0
        public static void EditionOperationMenu()
        {
            var isEditionMenuRunning = true;

            Console.Title = "RealEstate - Edit Menu";

            Console.WriteLine("Podaj numer ID wpisu który chcesz edytować:");
            while (isEditionMenuRunning)
            {
                if (int.TryParse(Console.ReadLine(), out var choice))
                {
                    //todo:
                    //tutaj przekazywane jest ID do backendu który zwraca pojedynczy obiekt RealEstate o właściwym ID
                    //jeśli nie ma wpisu o takim ID ma być zwracana o tym informacja
                    //jeśli obiekt został zwrócony jest on tutaj wyświetlany
                    //tu zwrócony z backendu opbiekt RealEstate może być zmieniany, ale roboczo jest tu tworzony nowy obiekt realestate
                    var realEstate = new RealEstate();
                    while (isEditionMenuRunning)
                    {
                        Console.Clear();
                        Console.WriteLine("Które pole chcesz zmienić?");
                        Console.WriteLine();
                        Console.WriteLine("1. Kategorię nieruchomości.");
                        Console.WriteLine("2. Cenę.");
                        Console.WriteLine("3. Powierzchnię.");
                        Console.WriteLine("4. Liczbę pokoi.");
                        Console.WriteLine("5. Imię i nazwisko właściciela.");
                        Console.WriteLine("6. Miejscowość.");
                        Console.WriteLine("7. Nazwę ulicy.");
                        Console.WriteLine("8. Adres.");
                        Console.WriteLine("9. Zatwierdź zmiany.");
                        Console.WriteLine();
                        Console.WriteLine("0. Wróć do głównego menu.");

                        //tu powinien się wyświetlać bieżący stan obiektu realestate
                        if (int.TryParse(Console.ReadLine(), out var editchoice))
                        {
                            switch (editchoice)
                            {
                            case 1:
                                AddMenu.UserSetEnum(realEstate);
                                break;

                            case 2:
                                AddMenu.UserSetPrice(realEstate);
                                break;

                            case 3:
                                AddMenu.UserSetArea(realEstate);
                                break;

                            case 4:
                                AddMenu.UserSetRoomsAmount(realEstate);
                                break;

                            case 5:
                                Console.WriteLine("Wpisz imię właściciela:");
                                realEstate.OwnerName = FilterMenu.SetStringFromConsole();
                                Console.WriteLine("Wpisz nazwisko właściciela:");
                                realEstate.OwnerSurname = FilterMenu.SetStringFromConsole();
                                break;

                            case 6:
                                Console.WriteLine("Wpisz nazwę miejscowości:");
                                realEstate.City = FilterMenu.SetStringFromConsole();
                                break;

                            case 7:
                                Console.WriteLine("Wpisz nazwę ulicy:");
                                realEstate.Street = FilterMenu.SetStringFromConsole();
                                break;

                            case 8:
                                Console.WriteLine("Wpisz nr domu, mieszkania:");
                                realEstate.EstateAddress = FilterMenu.SetStringFromConsole();
                                break;

                            case 9:
                                string changedLine = DatabaseContext.EditRecordInDatabase(realEstate, choice);
                                if (!String.IsNullOrEmpty(changedLine))
                                {
                                    DatabaseContext.saveLine(choice, changedLine);
                                }

                                Log insertLog = new Log(0, DateTime.Now, "Edited record of Real Estate", "worker");
                                Logger.AddLineToLog(insertLog);


                                isEditionMenuRunning = false;
                                break;

                            case 0:
                                isEditionMenuRunning = false;
                                break;

                            default:
                                break;
                            }
                        }
                        else
                        {
                            Console.WriteLine("Wpisz właściwą wartość.");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Wpisz właściwą wartość.");
                }
            }
        }
示例#8
0
        public static string EditRecordInDatabase(RealEstate realEstate, int id)
        {
            //ID; TypeOfRealEstate; Price; Area; OwnerName; OwnerSurname; City; Street; EstateAddress; CreationDate; ModificationDate;
            //Data modyfikacji wpisu zostaje ustalona/nadpisana automatycznie
            //funkcja przyjmuje realEstate.ID
            //funkcja przyjmuje też pola RealEstate które użytkownik chce zmodyfikować
            //task 3
            String path     = "..\\Files\\RealEstates.csv";
            string fullPath = DatabaseContext.bingPathToAppDir(path);
            string line;
            string lineToChange = "";
            string s1           = String.Empty;

            using (StreamReader reader = new StreamReader(fullPath))
            {
                while ((line = reader.ReadLine()) != null)
                {
                    string[] columns = line.Split(";");
                    if (Convert.ToInt32(columns[0]) == id)
                    {
                        lineToChange = line;   // this is  line to modify
                    }
                }
            }



            if (String.IsNullOrEmpty(lineToChange))
            {
                Console.WriteLine("No RealEstate record in our database with this ID !");
                Console.ReadLine();
            }
            else
            {
                string[] columnsToChange = lineToChange.Split(";");


                if ((int)realEstate.typeOfRealEstate != 0)
                {
                    int type = (int)realEstate.typeOfRealEstate;
                    columnsToChange[1] = type.ToString();
                }


                if (realEstate.Price != 0)
                {
                    columnsToChange[2] = realEstate.Price.ToString();
                }


                if (realEstate.Area != 0)
                {
                    columnsToChange[3] = realEstate.Area.ToString();
                }

                if (realEstate.RoomsAmount != 0)
                {
                    columnsToChange[4] = realEstate.RoomsAmount.ToString();
                }

                if (!String.IsNullOrEmpty(realEstate.OwnerName))
                {
                    columnsToChange[5] = realEstate.OwnerName;
                }

                if (!String.IsNullOrEmpty(realEstate.OwnerSurname))
                {
                    columnsToChange[6] = realEstate.OwnerSurname;
                }

                if (!String.IsNullOrEmpty(realEstate.City))
                {
                    columnsToChange[7] = realEstate.City;
                }

                if (!String.IsNullOrEmpty(realEstate.Street))
                {
                    columnsToChange[8] = realEstate.Street;
                }

                if (!String.IsNullOrEmpty(realEstate.EstateAddress))
                {
                    columnsToChange[9] = realEstate.EstateAddress;
                }


                columnsToChange[11] = DateTime.Now.ToString();

                s1 = string.Join(";", columnsToChange);
            }


            return(s1);
        }