コード例 #1
0
ファイル: BookController.cs プロジェクト: polsani/BookRental
        public static List <Book> ConvertFileToList()
        {
            List <Book> books = new List <Book>();
            FileHandler file  = new FileHandler();

            string[] fileContent;

            file.FileName = "LIVRO.csv";

            fileContent = FileHandlerController.ReadFile(file);

            if (fileContent != null)
            {
                foreach (var lineContent in fileContent)
                {
                    string[] lineBook = lineContent.Split(';');

                    Book book = new Book
                    {
                        TumbleNumber    = long.Parse(lineBook[0]),
                        ISBN            = lineBook[1],
                        Title           = lineBook[2],
                        Genre           = lineBook[3],
                        PublicationDate = Convert.ToDateTime(lineBook[4]),
                        Author          = lineBook[5]
                    };

                    books.Add(book);
                }
            }

            return(books);
        }
コード例 #2
0
        private static bool BookAvailable(long bookTumbleNumber)
        {
            bool available = true;

            FileHandler file = new FileHandler();

            file.FileName = "EMPRESTIMO.csv";

            if (FileHandlerController.CreateDirectoryAndFile(file))
            {
                available = true;
            }
            else
            {
                List <BookLoan> loanedsBooks = ConvertFileToList();
                if (loanedsBooks.Count > 0)
                {
                    for (int i = (loanedsBooks.Count - 1); i >= 0; i--)
                    {
                        if (loanedsBooks[i].TumbleNumber == bookTumbleNumber)
                        {
                            if (loanedsBooks[i].LoanStatus == 1)
                            {
                                available = false;
                                break;
                            }
                        }
                    }
                }
            }

            return(available);
        }
コード例 #3
0
        private static List <BookLoan> ConvertFileToList()
        {
            List <BookLoan> loanedsBooks = new List <BookLoan>();
            FileHandler     file         = new FileHandler();

            string[] fileContent;

            file.FileName = "EMPRESTIMO.csv";

            fileContent = FileHandlerController.ReadFile(file);

            if (fileContent != null)
            {
                foreach (var lineContent in fileContent)
                {
                    string[] lineLoan = lineContent.Split(';');

                    BookLoan bookLoan = new BookLoan
                    {
                        IdCustomer     = long.Parse(lineLoan[0]),
                        TumbleNumber   = long.Parse(lineLoan[1]),
                        LoanDate       = Convert.ToDateTime(lineLoan[2]),
                        DevolutionDate = Convert.ToDateTime(lineLoan[3]),
                        LoanStatus     = int.Parse(lineLoan[4])
                    };

                    loanedsBooks.Add(bookLoan);
                }
            }

            return(loanedsBooks);
        }
コード例 #4
0
ファイル: BookController.cs プロジェクト: polsani/BookRental
        public static bool BookExists(long bookTumbleNumber)
        {
            bool exists = false;

            FileHandler file = new FileHandler();

            file.FileName = "LIVRO.csv";

            if (FileHandlerController.CreateDirectoryAndFile(file))
            {
                exists = false;
            }
            else
            {
                List <Book> books = ConvertFileToList();
                for (int i = 0; i < books.Count; i++)
                {
                    if (books[i].TumbleNumber == bookTumbleNumber)
                    {
                        exists = true;
                        break;
                    }
                }
            }

            return(exists);
        }
コード例 #5
0
ファイル: BookController.cs プロジェクト: polsani/BookRental
        private static bool BookExists(string bookISBN)
        {
            bool exists = false;

            FileHandler file = new FileHandler();

            file.FileName = "LIVRO.csv";

            if (FileHandlerController.CreateDirectoryAndFile(file))
            {
                exists = false;
            }
            else
            {
                List <Book> books = ConvertFileToList();
                for (int i = 0; i < books.Count; i++)
                {
                    if (books[i].ISBN.Equals(bookISBN))
                    {
                        exists = true;
                        break;
                    }
                }
            }

            return(exists);
        }
コード例 #6
0
        private static bool CustomerExists(string customerCpf)
        {
            bool exists = false;

            FileHandler file = new FileHandler();

            file.FileName = "CLIENTE.csv";

            if (FileHandlerController.CreateDirectoryAndFile(file))
            {
                exists = false;
            }
            else
            {
                List <Customer> customers = ConvertFileToList();
                for (int i = 0; i < customers.Count; i++)
                {
                    if (customers[i].Cpf.Equals(customerCpf))
                    {
                        exists = true;
                        break;
                    }
                }
            }

            return(exists);
        }
コード例 #7
0
        public static long CustomerExistsAndReturnId(string customerCpf)
        {
            long idCustomer = 0;

            FileHandler file = new FileHandler();

            file.FileName = "CLIENTE.csv";

            if (FileHandlerController.CreateDirectoryAndFile(file))
            {
                idCustomer = 0;
            }
            else
            {
                List <Customer> customers = ConvertFileToList();
                for (int i = 0; i < customers.Count; i++)
                {
                    if (customers[i].Cpf.Equals(customerCpf))
                    {
                        idCustomer = customers[i].IdCustomer;
                        break;
                    }
                }
            }

            return(idCustomer);
        }
コード例 #8
0
ファイル: BookController.cs プロジェクト: polsani/BookRental
        private static void ConvertListForWriteFile(Book book)
        {
            List <Book> books = ConvertFileToList();
            FileHandler file  = new FileHandler();

            file.FileName = "LIVRO.csv";
            books.Add(book);

            StringBuilder bookSb = new StringBuilder();

            foreach (var sbBook in books)
            {
                bookSb.Append(sbBook.ToStringForWriteFile());
                bookSb.AppendLine();
            }

            string[] booksForWrite = bookSb.ToString().Split('\n');

            FileHandlerController.WriteInFile(file, booksForWrite);
        }
コード例 #9
0
        private static void ConvertListForWriteFile(Customer customer)
        {
            List <Customer> customers = ConvertFileToList();
            FileHandler     file      = new FileHandler();

            file.FileName = "CLIENTE.csv";
            customers.Add(customer);

            StringBuilder customerSb = new StringBuilder();

            foreach (var sbCustomer in customers)
            {
                customerSb.Append(sbCustomer.ToStringForWriteFile());
                customerSb.AppendLine();
            }

            string[] customersForWrite = customerSb.ToString().Split('\n');

            FileHandlerController.WriteInFile(file, customersForWrite);
        }
コード例 #10
0
        private static void ConvertListForWriteFile(BookLoan bookLoan, bool update = false)
        {
            List <BookLoan> loanedsBooks = ConvertFileToList();
            FileHandler     file         = new FileHandler();

            file.FileName = "EMPRESTIMO.csv";

            if (!update)
            {
                loanedsBooks.Add(bookLoan);
            }
            else
            {
                for (int i = (loanedsBooks.Count - 1); i >= 0; i--)
                {
                    if (loanedsBooks[i].TumbleNumber == bookLoan.TumbleNumber)
                    {
                        if (loanedsBooks[i].LoanStatus == 1)
                        {
                            loanedsBooks[i].LoanStatus = 2;
                            break;
                        }
                    }
                }
            }

            StringBuilder bookLoanSb = new StringBuilder();

            foreach (var sbBookLoan in loanedsBooks)
            {
                bookLoanSb.Append(sbBookLoan.ToStringForWriteFile());
                bookLoanSb.AppendLine();
            }

            string[] booksLoanForWrite = bookLoanSb.ToString().Split('\n');

            FileHandlerController.WriteInFile(file, booksLoanForWrite);
        }
コード例 #11
0
        public static List <Customer> ConvertFileToList()
        {
            List <Customer> customers = new List <Customer>();
            FileHandler     file      = new FileHandler();

            string[] fileContent;

            file.FileName = "CLIENTE.csv";

            fileContent = FileHandlerController.ReadFile(file);

            if (fileContent != null)
            {
                foreach (var lineContent in fileContent)
                {
                    string[] lineCustomer = lineContent.Split(';');

                    Customer customer = new Customer {
                        IdCustomer    = long.Parse(lineCustomer[0]),
                        Cpf           = lineCustomer[1],
                        Name          = lineCustomer[2],
                        DateOfBorning = Convert.ToDateTime(lineCustomer[3]),
                        Telephone     = lineCustomer[4],
                        PublicPlace   = lineCustomer[5],
                        Neighborhood  = lineCustomer[6],
                        City          = lineCustomer[7],
                        State         = lineCustomer[8],
                        ZipCode       = lineCustomer[9]
                    };

                    customers.Add(customer);
                }
            }

            return(customers);
        }