public Manutencao(Predio p, DateTime data, string titulo, string Descricao = "", int id = 0, string tipo = "", Outros_Pagamentos op = null) : base(p.ID, data, titulo, Descricao, id) { this.p = p; this.tipo = tipo; this.op = op; }
public static List <Manutencao> get_Manutencoes(Predio p, DateTime final, DateTime initial) { List <Manutencao> Rs = new List <Manutencao>(); SqlCommand cmd = new SqlCommand(@"SELECT * FROM getAllManutencoesAndPaymentsOfBuilding(@ID_Predio, @InitialDate, @FinalDate);", Database_Connection.cn); cmd.Parameters.AddWithValue("@ID_Predio", p.ID); cmd.Parameters.AddWithValue("@InitialDate", initial); cmd.Parameters.AddWithValue("@FinalDate", final); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Sujeito_Fiscal sj; Outros_Pagamentos op = null; if (DBNull.Value != reader["Id_Outros_Pagamentos"]) { string Morada = ""; string Email = ""; string NIF = reader["NIF"].ToString(); string Nome = reader["Nome"].ToString(); if (reader["Morada"] != DBNull.Value) { Morada = reader["Morada"].ToString(); } if (reader["e_mail"] != DBNull.Value) { Email = reader["e_mail"].ToString(); } sj = new Sujeito_Fiscal(NIF, Nome, Email, Morada); int id_outros_pag = int.Parse(reader["Id_Outros_Pagamentos"].ToString()); DateTime OData = DateTime.Parse(reader["OData"].ToString()); double balanco = double.Parse(reader["Balanco"].ToString()); string ODescricao = ""; if (DBNull.Value != reader["ODescricao"]) { ODescricao = reader["ODescricao"].ToString(); } op = new Outros_Pagamentos(OData, balanco, p, sj, ODescricao, id_outros_pag); } DateTime dt = DateTime.Parse(reader["MData"].ToString()); string titulo = reader["Titulo"].ToString(); string desc = ""; string tipo = ""; if (DBNull.Value != reader["MDescricao"]) { desc = reader["MDescricao"].ToString(); } if (DBNull.Value != reader["Tipo"]) { tipo = reader["Tipo"].ToString(); } int id = int.Parse(reader["MID"].ToString()); Rs.Add(new Manutencao(p, dt, titulo, desc, id, tipo, op)); } reader.Close(); Database_Connection.cn.Close(); return(Rs); }