示例#1
0
        public bool AddMessage(Messages message, Member member, Member friend)
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {

                int x = 0;
                SqlCommand cmd = new SqlCommand("AddMessage", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@MemberID", member.MemberId);
                cmd.Parameters.AddWithValue("@FriendID", friend.MemberId);
                cmd.Parameters.AddWithValue("@MessageText", message.MessageText);

                try
                {
                    con.Open();

                     x = cmd.ExecuteNonQuery();

                }
                catch (Exception e)
                {
                    e.ToString();
                }

                if (x < 0)
                { return true; }
                else { return false; }

            }
        }
示例#2
0
        public bool DeleteMessage(Messages message)
        {
            int countRow = 0;
                 using (SqlConnection con = new SqlConnection(ConnectionString))
            {

                SqlCommand cmd = new SqlCommand("uspDeleteMessage", con);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.AddWithValue("@MessageID", message.MessageId);

                da = new SqlDataAdapter(cmd);

                    try
                    {
                        con.Open();

                        countRow = cmd.ExecuteNonQuery();

                    }
                    catch (SqlException)
                    {
                        throw new ApplicationException("Error connection to database");

                    }

                }
                 if (countRow > 0)
                 {

                     return true;
                 }
                 else { return false; }
        }
示例#3
0
        public DataTable GetPreviousMessage(Messages message, Member member)
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {

                SqlCommand cmd = new SqlCommand("uspGetPreviousMessage", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MessageID", message.MessageId);
                cmd.Parameters.AddWithValue("@MemberID", member.MemberId);

                DataTable aMessage = new DataTable();

                try
                {
                    con.Open();

                    da = new SqlDataAdapter(cmd);
                    da.Fill(aMessage);

                }
                catch (SqlException)
                {
                    throw new ApplicationException("Error connection to database");

                }
                return aMessage;

            }
        }
示例#4
0
        public int[] GetMessageIndex(Messages message, Member member)
        {
            using (SqlConnection con = new SqlConnection(ConnectionString))
            {

                int[] index =  new int[2];
                SqlCommand cmd = new SqlCommand("uspGetMessageIndex", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@MessageID", message.MessageId);
                cmd.Parameters.AddWithValue("@MemberID", member.MemberId);

                DataTable aMessage = new DataTable();

                try
                {
                    con.Open();

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        index[0] = int.Parse(reader["IndexCount"].ToString());
                        index[1] = int.Parse(reader["InboxCount"].ToString());

                    }//End while
                    reader.Close();

                }
                catch (SqlException)
                {
                    throw new ApplicationException("Error connection to database");

                }
                return index;

            }
        }