예제 #1
0
        public static void SaveMessageRecipient(MessageRecipient recipient)
        {
            try
            {
                string query = "UPDATE MessageRecipient SET [Site] = " + (recipient.IsRead ? "'" + MACHINE_NAME + "', ReadDate = '" + recipient.ReadDate + "'" : "NULL, ReadDate = NULL ") +
                    " WHERE MessageID = " + recipient.MessageID + " AND [UserID] = '" + recipient.User.UserID + "'";

                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand(query, connection);
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception ex)
            {
                string errmsg = "Fehler beim Speichern des Nachrichtenempfängers (" + recipient.MessageID + ").\n\n";
                errmsg += "DatabaseHandler.SaveMessageRecipient(recipient): " + ex.ToString();
                throw new Exception(errmsg);
            }
        }
예제 #2
0
 public static void RemoveMessageRecipient(MessageRecipient recipient)
 {
     try
     {
         string query = "DELETE MessageRecipient WHERE MessageID = " + recipient.MessageID + " AND UserID = " + recipient.User.UserID;
         SqlConnection connection = new SqlConnection(ConnectionString);
         SqlCommand cmd = new SqlCommand(query, connection);
         connection.Open();
         cmd.ExecuteNonQuery();
         connection.Close();
     }
     catch (Exception ex)
     {
         string errmsg = "Fehler beim Löschen des Nachrichtenempfängers (" + recipient.MessageID + ").\n\n";
         errmsg += "DatabaseHandler.RemoveMessageRecipient(recipient): " + ex.ToString();
         throw new Exception(errmsg);
     }
 }
예제 #3
0
        private static ReadOnlyCollection<MessageRecipient> GetMessageRecipients(int messageId)
        {
            List<MessageRecipient> targets = new List<MessageRecipient>();

            try
            {
                SqlConnection connection = new SqlConnection(ConnectionString);
                SqlCommand cmd = new SqlCommand("SELECT * FROM MessageRecipient WHERE MessageID = " + messageId, connection);
                connection.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    MessageRecipient t = new MessageRecipient();
                    t.MessageRecipientID = Convert.ToInt32(reader["MessageRecipientID"]);
                    t.MessageID = messageId;
                    if (reader["Site"] == DBNull.Value || reader["ReadDate"] == DBNull.Value)
                        t.IsRead = false;
                    else
                        t.IsRead = true;
                    t.User = GetUser(Convert.ToInt32(reader["UserID"]));
                    if (t.IsRead)
                    {
                        t.Site = reader["Site"].ToString();
                        t.ReadDate = Convert.ToDateTime(reader["ReadDate"]);
                    }
                    targets.Add(t);
                }
                connection.Close();

            }
            catch (Exception ex)
            {
                string errmsg = "Fehler beim Abrufen der Nachrichtenempfänger (" + messageId + ").\n\n";
                errmsg += "DatabaseHandler.GetMessageRecipients(messageId): " + ex.ToString();
                throw new Exception(errmsg);
            }

            return new ReadOnlyCollection<MessageRecipient>(targets);
        }