个性化维护显示和保存功能实现

This commit is contained in:
liuchun_0206@163.com 2016-11-08 15:35:14 +08:00
parent 4f5483f1ea
commit 539528fdcb
6 changed files with 153 additions and 5 deletions

View File

@ -212,6 +212,7 @@
<Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\LogsController.cs" />
<Compile Include="Controllers\MenusController.cs" />
<Compile Include="Controllers\ProfilesController.cs" />
<Compile Include="Controllers\RolesController.cs" />
<Compile Include="Controllers\UsersController.cs" />
<Compile Include="Global.asax.cs">

View File

@ -0,0 +1,41 @@
using Bootstrap.DataAccess;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
namespace Bootstrap.Admin.Controllers
{
public class ProfilesController : ApiController
{
// GET api/<controller>
public IEnumerable<string> Get()
{
string sysName = DictHelper.RetrieveWebTitle();
string footer = DictHelper.RetrieveWebFooter();
return new string[] { sysName, footer };
}
// POST api/<controller>
public bool Post([FromBody]JObject value)
{
//保存个性化设置
dynamic json = value;
return DictHelper.SaveProfiles((string)json.type, (string)json.dvalue);
}
// PUT api/<controller>/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/<controller>/5
public void Delete(int id)
{
}
}
}

View File

@ -1,4 +1,55 @@
$(function () {
var url = "../api/Profiles";
$.ajax({
url: url,
type: 'GET',
success: function (result) {
if (result) {
$('#sysNameSet').val(result[0]);
$('#footSet').val(result[1]);
}
else {
swal("失败", "加载数据失败", "error");
}
}
});
$('#sysSave').click(function () {
var dvalue = $('#sysNameSet').val();
$.ajax({
url: url,
data: { "type": "sysName", "dvalue": dvalue },
type: 'POST',
success: function (result) {
if (result) {
swal("成功", "设置网站标题成功", "success");
}
else {
swal("失败", "设置网站标题失败", "error");
}
}
});
});
$('#footSave').click(function () {
var dvalue = $('#footSet').val();
$.ajax({
url: url,
data: { "type": "foot", "dvalue": dvalue },
type: 'POST',
success: function (result) {
if (result) {
swal("成功", "设置网站页脚成功", "success");
}
else {
swal("失败", "设置网站页脚失败", "error");
}
}
});
});
var html = '<li class="list-primary"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp">{2}</span><span class="badge badge-sm label-success">{0}</span><div class="task-wrapper"><span class="task-value tooltips" data-placement="top" data-original-title="{3}">{3}</span></div><div class="pull-right hidden-phone"><button class="btn btn-danger btn-xs fa fa-trash-o tooltips" data-key="{1}" data-placement="left" data-original-title="{1}"></button></div></div></li>';
function listCache(options) {
@ -31,4 +82,8 @@
listCache({ url: '../../CacheList.axd' });
$('a.fa-refresh').click(function () { listCache({ url: '../../CacheList.axd' }); });
});
})

View File

@ -4,6 +4,7 @@
Layout = "~/Views/Shared/_Admin.cshtml";
}
@section Javascript {
<script src="~/Content/js/sweetalert.js"></script>
<script src="~/Scripts/Profiles.js"></script>
}
@section css {
@ -15,13 +16,14 @@
@section navigator {
@Html.Partial("Navigator", Model)
}
<div class="panel panel-default">
<div class="panel-heading">系统名称设置</div>
<div class="panel-body">
<div class="input-group">
<input type="text" class="form-control">
<input type="text" class="form-control" id="sysNameSet">
<span class="input-group-btn">
<button class="btn btn-default" type="button">保存</button>
<button class="btn btn-default" type="button" id="sysSave">保存</button>
</span>
</div>
</div>
@ -30,9 +32,9 @@
<div class="panel-heading">页脚设置</div>
<div class="panel-body">
<div class="input-group">
<input type="text" class="form-control">
<input type="text" class="form-control" id="footSet">
<span class="input-group-btn">
<button class="btn btn-default" type="button">保存</button>
<button class="btn btn-default" type="button" id="footSave">保存</button>
</span>
</div>
</div>

View File

@ -4,8 +4,11 @@
<package id="Microsoft.AspNet.Razor" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client.zh-Hans" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core.zh-Hans" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost.zh-Hans" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebPages" version="3.2.3" targetFramework="net45" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net45" />
<package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net45" developmentDependency="true" />

View File

@ -156,5 +156,51 @@ namespace Bootstrap.DataAccess
var settings = DictHelper.RetrieveWebSettings();
return (settings.FirstOrDefault(d => d.Name == "网站页脚") ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code;
}
/// <summary>
/// 保存网站个性化设置
/// 2016-11-8
/// </summary>
/// <returns></returns>
public static bool SaveProfiles(string type, string value)
{
string name="";
string category="网站设置";
switch(type)
{
case "sysName": name = "网站标题"; break;
case "foot": name = "网站页脚"; break;
}
var settings = DictHelper.RetrieveWebSettings();
var p = from ps in settings
where ps.Name.Equals(name)
select new
{
ID=ps.ID
};
var ret = false;
string sql = "Update Dicts set Code = @Code where Category =@Category and Name=@Name";
try
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Code", value, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Name", name, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
ret = true;
foreach(var px in p)
CacheCleanUtility.ClearCache(dictIds:px.ID.ToString());
}
catch (DbException ex)
{
ExceptionManager.Publish(ex);
}
return ret;
}
}
}