예제 #1
0
        public static List <UserMessage> GetUserMessageByUserID(int MainUserID, int SubUserID, int MessageCount, MessagesWay Way, DateTime?MessageDate = null)
        {
            List <UserMessage> xx  = new List <MainWPF.UserMessage>();
            SqlConnection      con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand         com = new SqlCommand("sp_Get_UserMessageByUserID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr1 = new SqlParameter("@MainUserID", MainUserID);
            SqlParameter pr2 = new SqlParameter("@SubUserID", SubUserID);
            SqlParameter pr3 = new SqlParameter("@MessageCount", MessageCount);
            SqlParameter pr4 = new SqlParameter("@Way", Way.ToString());

            com.Parameters.Add(pr1);
            com.Parameters.Add(pr2);
            com.Parameters.Add(pr3);
            com.Parameters.Add(pr4);

            if (MessageDate.HasValue)
            {
                com.Parameters.Add(new SqlParameter("@MessageDate", MessageDate));
            }
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    UserMessage x = new UserMessage();
                    if (!(rd["MessageID"] is DBNull))
                    {
                        x.MessageID = int.Parse(rd["MessageID"].ToString());
                    }
                    if (!(rd["SenderID"] is DBNull))
                    {
                        x.SenderID = int.Parse(rd["SenderID"].ToString());
                    }
                    if (!(rd["RecieverID"] is DBNull))
                    {
                        x.RecieverID = int.Parse(rd["RecieverID"].ToString());
                    }
                    x.Message = rd["Message"].ToString();
                    if (!(rd["Date"] is DBNull))
                    {
                        x.Date = DateTime.Parse(rd["Date"].ToString());
                    }
                    if (!(rd["IsReaded"] is DBNull))
                    {
                        x.IsReaded = bool.Parse(rd["IsReaded"].ToString());
                    }
                    if (!(rd["ReadDate"] is DBNull))
                    {
                        x.ReadDate = DateTime.Parse(rd["ReadDate"].ToString());
                    }
                    if (!(rd["IsReceived"] is DBNull))
                    {
                        x.IsReceived = bool.Parse(rd["IsReceived"].ToString());
                    }
                    if (!(rd["ReceiveDate"] is DBNull))
                    {
                        x.ReceiveDate = DateTime.Parse(rd["ReceiveDate"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
예제 #2
0
 public static bool DeleteData(UserMessage x)
 {
     return(BaseDataBase._StoredProcedure("sp_Delete_UserMessage"
                                          , new SqlParameter("@MessageID", x.MessageID)));
 }