diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs
index 18841d5d..065e6c8c 100644
--- a/Bootstrap.Admin/Models/HeaderBarModel.cs
+++ b/Bootstrap.Admin/Models/HeaderBarModel.cs
@@ -21,7 +21,9 @@ namespace Bootstrap.Admin.Models
var notis = NotificationHelper.RetrieveNotifications();
NotifiCount = notis.Count();
Notifications = notis.Take(6);
- Messages = MessageHelper.RetrieveMessagesHeader(HttpContext.Current.User.Identity.Name);
+ var msgs = MessageHelper.RetrieveMessagesHeader(UserName);
+ MessageCount = msgs.Count();
+ Messages = msgs.Take(6);
}
public string UserName { get; protected set; }
///
@@ -53,9 +55,12 @@ namespace Bootstrap.Admin.Models
///
public int NotifiCount { get; set; }
///
- /// 或者/设置消息列表
+ /// 获得/设置 消息列表
///
public IEnumerable Messages { get; set; }
-
+ ///
+ /// 获得/设置 消息数量
+ ///
+ public int MessageCount { get; set; }
}
}
\ No newline at end of file
diff --git a/Bootstrap.Admin/Views/Shared/Header.cshtml b/Bootstrap.Admin/Views/Shared/Header.cshtml
index e22343df..bc62bc1a 100644
--- a/Bootstrap.Admin/Views/Shared/Header.cshtml
+++ b/Bootstrap.Admin/Views/Shared/Header.cshtml
@@ -108,42 +108,42 @@
- @if (Model.Messages.Count() > 0)
- {
-
- }
+ @if (Model.MessageCount > 0)
+ {
+
+
+
+ @Model.MessageCount
+
+
+
+ }
@if (Model.NotifiCount > 0)
{
-
@Model.NotifiCount
diff --git a/Bootstrap.DataAccess/MessageHelper.cs b/Bootstrap.DataAccess/MessageHelper.cs
index 16b7f594..06c22497 100644
--- a/Bootstrap.DataAccess/MessageHelper.cs
+++ b/Bootstrap.DataAccess/MessageHelper.cs
@@ -1,124 +1,118 @@
-using Longbow;
-using Longbow.Caching;
-using Longbow.Caching.Configuration;
-using Longbow.ExceptionManagement;
-using System;
-using System.Collections.Generic;
-using System.Data;
-using System.Data.Common;
-using System.Linq;
-
-namespace Bootstrap.DataAccess
-{
-
-
- public class MessageHelper
- {
- internal const string RetrieveMessageFromDataKey = "MessageHelper-RetrieveMessagesFromOthers";
- internal const string RetrieveMessageToDataKey = "MessageHelper-RetrieveMessagesToOthers";
-
- ///
- /// 获取其他人发送给自己的消息列表
- ///
- ///
- ///
- public static IEnumerable RetrieveMessagesFromOthers(string userName)
- {
- var messageRet = CacheManager.GetOrAdd(RetrieveMessageFromDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageFromDataKey), key =>
- {
- string sql = "select * from [Messages] where [To]=@UserName";
- List messages = new List();
- DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
- try
- {
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
- using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- messages.Add(new Message()
- {
- ID = (int)reader[0],
- Title = (string)reader[1],
- Content = (string)reader[2],
- From = (string)reader[3],
- To = (string)reader[4],
- SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
- Status = (string)reader[6]
-
- });
- }
- }
- }
- catch (Exception ex) { ExceptionManager.Publish(ex); }
- return messages;
-
- }, CacheSection.RetrieveDescByKey(RetrieveMessageFromDataKey));
-
- return messageRet.OrderByDescending(n => n.SendTime);
- }
-
- ///
- /// 自己获取发送给其他人的消息列表
- ///
- ///
- ///
- public static IEnumerable RetrieveMessagesToOthers(string userName)
- {
- var messageRet = CacheManager.GetOrAdd(RetrieveMessageToDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageToDataKey), key =>
- {
- string sql = "select * from [Messages] where [From]=@UserName";
- List messages = new List();
- DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
- try
- {
- cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
- using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
- {
- while (reader.Read())
- {
- messages.Add(new Message()
- {
- ID = (int)reader[0],
- Title = (string)reader[1],
- Content = (string)reader[2],
- From = (string)reader[3],
- To = (string)reader[4],
- SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
- Status = (string)reader[6]
-
- });
- }
- }
- }
- catch (Exception ex) { ExceptionManager.Publish(ex); }
- return messages;
-
- }, CacheSection.RetrieveDescByKey(RetrieveMessageToDataKey));
-
- return messageRet.OrderByDescending(n => n.SendTime);
- }
-
- ///
- /// 获取Header处显示的消息列表
- ///
- ///
- ///
- public static IEnumerable RetrieveMessagesHeader(string userName)
- {
-
- var messageRet = RetrieveMessagesFromOthers(userName);
-
- messageRet.AsParallel().ForAll(n =>
- {
- var ts = DateTime.Now - n.SendTime;
- if (ts.TotalMinutes < 5) n.Period = "刚刚";
- else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
- else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
- else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
- });
- return messageRet;
- }
-
- }
-}
+using Longbow;
+using Longbow.Caching;
+using Longbow.Caching.Configuration;
+using Longbow.ExceptionManagement;
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.Common;
+using System.Linq;
+
+namespace Bootstrap.DataAccess
+{
+ ///
+ ///
+ ///
+ public class MessageHelper
+ {
+ internal const string RetrieveMessageFromDataKey = "MessageHelper-RetrieveMessagesFromOthers";
+ internal const string RetrieveMessageToDataKey = "MessageHelper-RetrieveMessagesToOthers";
+
+ ///
+ /// 获取其他人发送给自己的消息列表
+ ///
+ ///
+ ///
+ public static IEnumerable RetrieveMessagesFromOthers(string userName)
+ {
+ var messageRet = CacheManager.GetOrAdd(RetrieveMessageFromDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageFromDataKey), key =>
+ {
+ string sql = "select * from [Messages] where [To]=@UserName";
+ List messages = new List();
+ DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
+ try
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
+ using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
+ {
+ while (reader.Read())
+ {
+ messages.Add(new Message()
+ {
+ ID = (int)reader[0],
+ Title = (string)reader[1],
+ Content = (string)reader[2],
+ From = (string)reader[3],
+ To = (string)reader[4],
+ SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
+ Status = (string)reader[6]
+
+ });
+ }
+ }
+ }
+ catch (Exception ex) { ExceptionManager.Publish(ex); }
+ return messages;
+
+ }, CacheSection.RetrieveDescByKey(RetrieveMessageFromDataKey));
+ return messageRet.OrderByDescending(n => n.SendTime);
+ }
+ ///
+ /// 自己获取发送给其他人的消息列表
+ ///
+ ///
+ ///
+ public static IEnumerable RetrieveMessagesToOthers(string userName)
+ {
+ var messageRet = CacheManager.GetOrAdd(RetrieveMessageToDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageToDataKey), key =>
+ {
+ string sql = "select * from [Messages] where [From]=@UserName";
+ List messages = new List();
+ DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
+ try
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
+ using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
+ {
+ while (reader.Read())
+ {
+ messages.Add(new Message()
+ {
+ ID = (int)reader[0],
+ Title = (string)reader[1],
+ Content = (string)reader[2],
+ From = (string)reader[3],
+ To = (string)reader[4],
+ SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
+ Status = (string)reader[6]
+
+ });
+ }
+ }
+ }
+ catch (Exception ex) { ExceptionManager.Publish(ex); }
+ return messages;
+
+ }, CacheSection.RetrieveDescByKey(RetrieveMessageToDataKey));
+ return messageRet.OrderByDescending(n => n.SendTime);
+ }
+ ///
+ /// 获取Header处显示的消息列表
+ ///
+ ///
+ ///
+ public static IEnumerable RetrieveMessagesHeader(string userName)
+ {
+ var messageRet = RetrieveMessagesFromOthers(userName);
+ messageRet.AsParallel().ForAll(n =>
+ {
+ var ts = DateTime.Now - n.SendTime;
+ if (ts.TotalMinutes < 5) n.Period = "刚刚";
+ else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
+ else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
+ else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
+ });
+ return messageRet;
+ }
+ }
+}
diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql
index ee82f14c..032f2d04 100644
--- a/DatabaseScripts/Install.sql
+++ b/DatabaseScripts/Install.sql
@@ -324,8 +324,8 @@ CREATE TABLE [dbo].[Messages](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Title] [nvarchar](50) NOT NULL,
[Content] [nvarchar](500) NOT NULL,
- [From] [nvarchar](50) NOT NULL,
- [To] [nvarchar](50) NOT NULL,
+ [From] [varchar](50) NOT NULL,
+ [To] [varchar](50) NOT NULL,
[SendTime] [datetime] NOT NULL,
[Status] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED