//Devolução public static void Devolucao(List <EmprestimoLivro> listaEmprestimo, List <StatusEmprestimo> listaStatus, List <Cliente> listaClient) { long numeroTombo; int encontradoNumeroTombo = 0; string cpf = ""; long id = 0; DateTime datual = DateTime.Now; DateTime ddevolucao = DateTime.Now; TimeSpan result; double multa; /*foreach (var elemento in listaEmprestimo) * { * Console.WriteLine(elemento.ToString()); * }*/ numeroTombo = LeiaNumeroTombo(); foreach (var elemento in listaEmprestimo) { if (elemento.StatusEmprestimo == 2) { break; } else if (elemento.NumeroTombo == numeroTombo) { encontradoNumeroTombo++; ddevolucao = elemento.DataDevolucao; } } if (encontradoNumeroTombo == 0) { Console.WriteLine("Livro não encontrado para devolução"); } else { result = datual - ddevolucao; if (result.Days > 0) { multa = (result.Days * 0.10); Console.WriteLine("O valor da Multa é R$:" + multa.ToString("N2")); for (int i = 0; i < listaEmprestimo.Count; i++) { if (listaEmprestimo[i].NumeroTombo == numeroTombo) { EmprestimoLivro el = new EmprestimoLivro(); el.IdCliente = listaEmprestimo[i].IdCliente; el.NumeroTombo = listaEmprestimo[i].NumeroTombo; el.DataEmprestimo = listaEmprestimo[i].DataEmprestimo; el.DataDevolucao = listaEmprestimo[i].DataDevolucao; el.StatusEmprestimo = 2; listaEmprestimo[i] = el; EscreverArquivo(listaEmprestimo); id = el.IdCliente; } } for (int i = 0; i < listaClient.Count; i++) { if (listaClient[i].IdCliente == id) { cpf = listaClient[i].Cpf; } } for (int i = 0; i < listaStatus.Count; i++) { if (listaStatus[i].Cpf == cpf) { StatusEmprestimo se = new StatusEmprestimo(); se.Cpf = listaStatus[i].Cpf; se.Titulo = listaStatus[i].Titulo; se.DataEmprestimo = listaStatus[i].DataEmprestimo; se.DataDevolucao = listaStatus[i].DataDevolucao; se.Status = 2; listaStatus[i] = se; } } } else { Console.WriteLine("Não há multa a se pagar"); for (int i = 0; i < listaEmprestimo.Count; i++) { if (listaEmprestimo[i].NumeroTombo == numeroTombo) { EmprestimoLivro el = new EmprestimoLivro(); el.IdCliente = listaEmprestimo[i].IdCliente; el.NumeroTombo = listaEmprestimo[i].NumeroTombo; el.DataEmprestimo = listaEmprestimo[i].DataEmprestimo; el.DataDevolucao = listaEmprestimo[i].DataDevolucao; el.StatusEmprestimo = 2; listaEmprestimo[i] = el; EscreverArquivo(listaEmprestimo); id = el.IdCliente; } } for (int i = 0; i < listaClient.Count; i++) { if (listaClient[i].IdCliente == id) { cpf = listaClient[i].Cpf; } } for (int i = 0; i < listaStatus.Count; i++) { if (listaStatus[i].Cpf == cpf) { StatusEmprestimo se = new StatusEmprestimo(); se.Cpf = listaStatus[i].Cpf; se.Titulo = listaStatus[i].Titulo; se.DataEmprestimo = listaStatus[i].DataEmprestimo; se.DataDevolucao = listaStatus[i].DataDevolucao; se.Status = 2; listaStatus[i] = se; } } } Console.WriteLine("Aperte qualquer tecla para retorar ao menu principal"); Console.ReadKey(); } }
public static void Registrar(List <EmprestimoLivro> listaEmprestimo, List <Livro> listaLivro, List <Cliente> listaCliente, List <StatusEmprestimo> listaStatus) { // VARIAVEIS string cpf; long idcliente = 0, numeroTombo; DateTime demprestimo, ddevolucao; int status = 0; int statusfim = 0; int encontradoNumeroTombo = 0; int encontradoCpf = 0; string nomelivro = ""; string cpfstatus = ""; do { numeroTombo = LeiaNumeroTombo(); foreach (var elemento in listaEmprestimo) { if (elemento.NumeroTombo == numeroTombo && elemento.StatusEmprestimo == 1) { Console.WriteLine("Livro emprestado, aguarde a sua devolução"); statusfim = 1; } } if (statusfim != 1) { foreach (var elemento in listaLivro) { if (elemento.NumeroTombo == numeroTombo) { encontradoNumeroTombo++; nomelivro = elemento.Titulo; } } if (encontradoNumeroTombo == 0) { Console.WriteLine("Livro não está disponivel para emprestimo"); } else { cpf = LerCpf(); foreach (var elemento in listaCliente) { if (elemento.Cpf.ToString() == cpf) { idcliente = elemento.IdCliente; encontradoCpf++; cpfstatus = elemento.Cpf; } } if (encontradoCpf == 0) { Console.WriteLine("Cliente não cadastrado"); } else { demprestimo = DateTime.Now; Console.Write("Data do Emprestimo: " + demprestimo + "\n"); ddevolucao = LeiaDevolucao(); status = 1; StatusEmprestimo novoStatus = new StatusEmprestimo() { Cpf = cpfstatus, Titulo = nomelivro, Status = status, DataEmprestimo = demprestimo, DataDevolucao = ddevolucao }; EmprestimoLivro novoEmprestimo = new EmprestimoLivro() { IdCliente = idcliente, NumeroTombo = numeroTombo, DataEmprestimo = demprestimo, DataDevolucao = ddevolucao, StatusEmprestimo = status }; listaStatus.Add(novoStatus); listaEmprestimo.Add(novoEmprestimo); listaEmprestimo = listaEmprestimo.OrderBy(x => x.IdCliente).ToList(); listaStatus = listaStatus.OrderBy(x => x.Cpf).ToList(); EscreverArquivo(listaEmprestimo); Console.Clear(); Console.WriteLine("Emprestimo Cadastrado"); Console.WriteLine("Aperte qualquer tecla para voltar ao menu principal"); Console.ReadKey(); Console.Clear(); } } } } while (encontradoCpf == 0 && statusfim != 1); }