public List <SmartDetention> GetSmartDetentionsByDetaineeID(int id) { const string storedProcedureName = Constants.GetSmartDetentionsByDetaineeID; using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString)) { SqlCommand command = new SqlCommand(storedProcedureName, connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(Constants.DetaineeID, SqlDbType.Int); command.Parameters[Constants.DetaineeID].Value = id; connection.Open(); SqlDataReader reader = command.ExecuteReader(); SmartDetention detention = null; List <SmartDetention> detentions_list = new List <SmartDetention>(); while (reader.Read()) { detention = new SmartDetention { DetentionID = Convert.ToInt32(reader.GetValue(0)) }; if (reader.GetValue(1) == DBNull.Value) { detention.DetentionDate = null; } else { detention.DetentionDate = Convert.ToDateTime(reader.GetValue(1)); } detention.EmployeeFullName = reader.GetValue(2).ToString(); detention.ReleaseStatus = reader.GetValue(3) == DBNull.Value ? "Не освобожден" : "Освобожден"; detention.DeliveryStatus = reader.GetValue(4) == DBNull.Value ? "Не доставлен" : "Доставлен"; detentions_list.Add(detention); } connection.Close(); return(detentions_list); } }
public List <SmartDetention> GetDetentionsByDate(DateTime date) { const string storedProcedureName = Constants.GetSmartDetentionsByDate; using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString)) { SqlCommand command = new SqlCommand(storedProcedureName, connection); command.CommandType = CommandType.StoredProcedure; connection.Open(); command.Parameters.Add(Constants.DetentionDate, SqlDbType.DateTime); command.Parameters[Constants.DetentionDate].Value = date; SqlDataReader reader = command.ExecuteReader(); SmartDetention detention = null; List <SmartDetention> detentions_list = new List <SmartDetention>(); while (reader.Read()) { detention = new SmartDetention { DetentionID = Convert.ToInt32(reader.GetValue(0)) }; if (reader.GetValue(1) == DBNull.Value) { detention.DetentionDate = null; } else { detention.DetentionDate = Convert.ToDateTime(reader.GetValue(1)); } detention.EmployeeFullName = reader.GetValue(2).ToString(); detentions_list.Add(detention); } connection.Close(); return(detentions_list); } }