Пример #1
0
        public static List <Note> getNotes(int taskID, int subtaskID)
        {
            List <Note>   notes           = new List <Note>();
            string        selectStatement = "";
            SqlConnection connection      = DBConnection.GetConnection();

            if (subtaskID == -1)
            {
                selectStatement =
                    "SELECT * FROM note " +
                    "WHERE " +
                    "taskID = @taskID and " +
                    "subtaskID is null";
            }
            else
            {
                selectStatement =
                    "SELECT * FROM note " +
                    "WHERE " +
                    "taskID = @taskID and " +
                    "subtaskID = @stID";
            }

            SqlCommand selectCommand = new SqlCommand(selectStatement, connection);

            selectCommand.Parameters.AddWithValue("@taskID", taskID);
            selectCommand.Parameters.AddWithValue("@stID", subtaskID);

            try
            {
                connection.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    Note note = new Note();
                    note.taskID = Convert.ToInt32(reader["taskID"]);
                    if (reader["subtaskID"] == DBNull.Value)
                    {
                        note.subtaskID = 0;
                    }
                    else
                    {
                        note.subtaskID = Convert.ToInt32(reader["subtaskID"]);
                    }
                    note.noteID       = Convert.ToInt32(reader["noteID"]);
                    note.note_message = reader["note_message"].ToString();

                    notes.Add(note);
                }
                reader.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }

            return(notes);
        }