").html(data).evalScripts();
+ }
+ if (type == "text")
+ data = r.responseText;
+ return data;
+ },
+
+ handleError:function(s, xhr, status, e )
+ {
+ // If a local callback was specified, fire it
+ if ( s.error ) {
+ s.error.call( s.context || s, xhr, status, e );
+ }
+
+ // Fire the global callback
+ if ( s.global ) {
+ (s.context ? jQuery(s.context) : jQuery.event).trigger( "ajaxError", [xhr, s, e] );
+ }
+ }
+});
diff --git a/Bootstrap.Admin/Controllers/InfosController.cs b/Bootstrap.Admin/Controllers/InfosController.cs
new file mode 100644
index 00000000..027cc90b
--- /dev/null
+++ b/Bootstrap.Admin/Controllers/InfosController.cs
@@ -0,0 +1,55 @@
+锘縰sing System.IO;
+using System.Web;
+using Bootstrap.DataAccess;
+using System.Web.Script.Serialization;
+using System.Web.Http;
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+
+namespace Bootstrap.Admin.Controllers
+{
+ public class InfosController : ApiController
+ {
+ [HttpPost]
+ public string Post()
+ {
+ bool ret = false;
+ var msg = new { Result = ret, img_str = "" };
+
+ var files = HttpContext.Current.Request.Files;
+ if (files.Count > 0)
+ {
+ string userName = HttpContext.Current.User.Identity.Name;
+ if (userName.ToLower() != "argo" && userName.ToLower() != "test")
+ {
+ string iconUrl = HttpContext.Current.Server.MapPath("~/Content/images/uploader/");
+ using (Stream inputStream = files[0].InputStream)
+ {
+ MemoryStream memoryStream = inputStream as MemoryStream;
+ if (memoryStream == null)
+ {
+ memoryStream = new MemoryStream();
+ inputStream.CopyTo(memoryStream);
+ }
+ Bitmap bmp = new Bitmap(memoryStream);
+ if (!Directory.Exists(iconUrl))
+ Directory.CreateDirectory(iconUrl);
+ string fileName = DateTime.Now.ToShortDateString().Replace("/", "") + DateTime.Now.Hour.ToString()
+ + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString()
+ + DateTime.Now.Millisecond.ToString() + userName + ".jpg"; //鍥剧墖鍚嶇О
+
+ bmp.Save(iconUrl + fileName, ImageFormat.Jpeg); //淇濆瓨鍥剧墖
+
+ string headImg = DictHelper.RetrieveUrl() + fileName;
+ ret = UserHelper.SaveUserHeadImgByName(headImg, userName);
+ msg = new { Result = ret, img_str = headImg };
+ }
+ }
+ }
+
+ JavaScriptSerializer serializer = new JavaScriptSerializer();
+ return serializer.Serialize(msg);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs
index 581a05ee..acf2ae47 100644
--- a/Bootstrap.Admin/Models/HeaderBarModel.cs
+++ b/Bootstrap.Admin/Models/HeaderBarModel.cs
@@ -13,6 +13,7 @@ namespace Bootstrap.Admin.Models
public HeaderBarModel()
{
var user = UserHelper.RetrieveUsersByName(HttpContext.Current.User.Identity.Name);
+ HeadImg = user.HeadImg;
DisplayName = user.DisplayName;
UserName = user.UserName;
UserID = user.ID;
@@ -68,6 +69,10 @@ namespace Bootstrap.Admin.Models
/// 鑾峰緱/璁剧疆 娑堟伅鍒楄〃
///
public IEnumerable
MessageList { get; set; }
+ ///
+ ///
+ ///
+ public string HeadImg { get; set; }
}
}
\ No newline at end of file
diff --git a/Bootstrap.Admin/Scripts/Infos.js b/Bootstrap.Admin/Scripts/Infos.js
new file mode 100644
index 00000000..23ce3968
--- /dev/null
+++ b/Bootstrap.Admin/Scripts/Infos.js
@@ -0,0 +1,46 @@
+锘$(function () {
+ bindImageSelectListener();
+
+ $('#btn_img').click(function () {
+ $.ajaxFileUpload({
+ url: '../api/Infos/',
+ secureuri: false,
+ fileElementId: 'uploadImg', //涓婁紶鏂囦欢鐨凬ame灞炴
+ dataType: 'json',
+ type: 'POST',
+ success: function (data, status) {
+ if (data.Result === true) {
+ swal("鎴愬姛", "淇敼澶村儚", "success");
+ //鍒锋柊澶村儚
+ changeHeaderIcon(data.img_str);
+ } else if (data.Result === false) {
+ swal("澶辫触", "缃戠珯绠$悊鍛樹笉鍏佽淇敼澶村儚", "error");
+ }
+ bindImageSelectListener();
+ },
+ error: function (data, status, e) {
+ swal("澶辫触", "淇敼澶村儚", "error");
+ bindImageSelectListener();
+ }
+ });
+
+ return false;
+ })
+})
+
+function changeHeaderIcon(img_str) {
+ $("#header_img").attr("src", img_str);
+}
+
+function bindImageSelectListener() {
+ $('#uploadImg').on("change", function () {
+ var file = this.files[0];
+ if (this.files && file) {
+ var reader = new FileReader();
+ reader.onload = function (e) {
+ $('#headImg').attr("src", e.target.result);
+ }
+ reader.readAsDataURL(file);
+ }
+ })
+}
\ No newline at end of file
diff --git a/Bootstrap.Admin/Views/Admin/Infos.cshtml b/Bootstrap.Admin/Views/Admin/Infos.cshtml
index 41b97a98..b5b7fa19 100644
--- a/Bootstrap.Admin/Views/Admin/Infos.cshtml
+++ b/Bootstrap.Admin/Views/Admin/Infos.cshtml
@@ -3,7 +3,13 @@
ViewBag.Title = "涓汉涓績";
Layout = "~/Views/Shared/_Admin.cshtml";
}
+@section Javascript {
+
+
+
+}
@section css {
+
}
@section header {
@@ -18,24 +24,12 @@
@@ -71,18 +65,18 @@
diff --git a/Bootstrap.Admin/Views/Shared/Header.cshtml b/Bootstrap.Admin/Views/Shared/Header.cshtml
index 16e8fb8a..d1ef02ea 100644
--- a/Bootstrap.Admin/Views/Shared/Header.cshtml
+++ b/Bootstrap.Admin/Views/Shared/Header.cshtml
@@ -190,7 +190,14 @@
-
+ @if (Model.HeadImg == null)
+ {
+
+ }
+ else
+ {
+
+ }
@Model.DisplayName
diff --git a/Bootstrap.DataAccess/DictHelper.cs b/Bootstrap.DataAccess/DictHelper.cs
index 725f3a3b..ed1bcb94 100644
--- a/Bootstrap.DataAccess/DictHelper.cs
+++ b/Bootstrap.DataAccess/DictHelper.cs
@@ -185,5 +185,15 @@ namespace Bootstrap.DataAccess
}
return ret;
}
+ ///
+ /// 鑾峰彇澶村儚璺緞
+ ///
+ ///
+ public static string RetrieveUrl()
+ {
+ var urls = DictHelper.RetrieveDicts(16);
+ var url = urls.FirstOrDefault(d => d.Name == "澶村儚璺緞");
+ return url.Code;
+ }
}
}
diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs
index db956bd4..a806e165 100644
--- a/Bootstrap.DataAccess/User.cs
+++ b/Bootstrap.DataAccess/User.cs
@@ -59,5 +59,9 @@ namespace Bootstrap.DataAccess
/// 鑾峰緱/璁剧疆 鎷掔粷鏃跺埢
///
public string RejectedTime { get; set; }
+ ///
+ /// 鑾峰彇/璁剧疆 鐢ㄦ埛澶村儚
+ ///
+ public string HeadImg { get; set; }
}
}
diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs
index 9b834a4e..b383e741 100644
--- a/Bootstrap.DataAccess/UserHelper.cs
+++ b/Bootstrap.DataAccess/UserHelper.cs
@@ -70,7 +70,7 @@ namespace Bootstrap.DataAccess
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
{
User user = null;
- string sql = "select ID, UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime from Users where ApprovedTime is not null and UserName = @UserName";
+ string sql = "select ID, UserName, [Password], PassSalt, DisplayName, RegisterTime, ApprovedTime, HeadImg from Users where ApprovedTime is not null and UserName = @UserName";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
@@ -87,7 +87,8 @@ namespace Bootstrap.DataAccess
PassSalt = (string)reader[3],
DisplayName = (string)reader[4],
RegisterTime = (DateTime)reader[5],
- ApprovedTime = (DateTime)reader[6]
+ ApprovedTime = (DateTime)reader[6],
+ HeadImg = (string)reader[7]
};
}
}
@@ -361,5 +362,31 @@ namespace Bootstrap.DataAccess
}
return ret;
}
+ ///
+ /// 鏍规嵁鐢ㄦ埛鍚嶄慨鏀圭敤鎴峰ご鍍
+ ///
+ ///
+ ///
+ ///
+ public static bool SaveUserHeadImgByName(string headImg, string userName)
+ {
+ bool ret = false;
+ try
+ {
+ string sql = "Update Users set HeadImg=@HeadImg where UserName=@UserName";
+ using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
+ {
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@HeadImg", headImg, ParameterDirection.Input));
+ cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName, ParameterDirection.Input));
+ DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
+ ret = true;
+ }
+ }
+ catch (Exception ex)
+ {
+ ExceptionManager.Publish(ex);
+ }
+ return ret;
+ }
}
}
\ No newline at end of file
diff --git a/DatabaseScripts/InitData.sql b/DatabaseScripts/InitData.sql
index 907b63e7..9947b3d1 100644
--- a/DatabaseScripts/InitData.sql
+++ b/DatabaseScripts/InitData.sql
@@ -3,7 +3,7 @@ GO
DELETE From Users where ID = 1
SET IDENTITY_INSERT [dbo].[Users] ON
-insert into Users (ID, UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime,ApprovedBy, [Description]) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', GetDate(), GetDate(), 'system', N'绯荤粺榛樿鍒涘缓')
+insert into Users (ID, UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedTime,ApprovedBy, [Description],HeadImg) values (1, 'Admin', 'Es7WVgNsJuELwWK8daCqufUBknCsSC0IYDphQZAiGOo=', 'W5vpBEOYRGHkQXatN0t+ECM/U8cHDuEgrq56+zZBk4J481xH', 'Administrator', GetDate(), GetDate(), 'system', N'绯荤粺榛樿鍒涘缓','http://118.244.234.207:85/Content/images/logo6.jpg')
SET IDENTITY_INSERT [dbo].[Users] OFF
DELETE From Dicts
@@ -23,7 +23,7 @@ INSERT [dbo].[Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (12, N'
INSERT [dbo].[Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (13, N'娑堟伅鐘舵', N'宸茶', N'1', 0)
INSERT [dbo].[Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (14, N'娑堟伅鏍囩', N'涓鑸', N'0', 0)
INSERT [dbo].[Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (15, N'娑堟伅鏍囩', N'绱ц', N'1', 0)
-
+INSERT [dbo].[Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (16, N'涓婁紶鏂囦欢鍦板潃', N'澶村儚璺緞', N'http://118.244.234.207:85/Content/images/uploader/', 0)
SET IDENTITY_INSERT [dbo].[Dicts] OFF
DELETE FROM Navigations
diff --git a/DatabaseScripts/Install.sql b/DatabaseScripts/Install.sql
index 173a871c..115873d3 100644
--- a/DatabaseScripts/Install.sql
+++ b/DatabaseScripts/Install.sql
@@ -28,6 +28,7 @@ CREATE TABLE [dbo].[Users](
[RejectedBy] [varchar](50) NULL,
[RejectedTime] [datetime] NULL,
[RejectedReason] [nvarchar](50) NULL,
+ [HeadImg] [varchar](500) NULL,
CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED
(
[ID] ASC