app开发者平台在数字化时代的重要性与发展趋势解析
711
2022-09-16
适合小白的Demo_easyui+core3第五章用户数据操作
1、用户列表页面
@{
Layout = Layout = null;
}
url="/userlist/getuserlist"
toolbar="#toolbaruser"
rownumbers="true" fitColumns="true" singleSelect="true">
主键 登录名 昵称 手机号 微信号 邮箱 创建人 创建时间 状态
@*-----------------------------------------------编辑-------------------------------------------------------------------------------*@
@*-----------------------------------------------编辑-------------------------------------------------------------------------------*@
function adduser() {
$('#dlguser').dialog('open').dialog('center').dialog('setTitle', 'New User');
$('#fmuser').form('clear');
}
function editUser() {
var row = $('#datalistuser').datagrid('getSelected');
if (row) {
$('#dlguser').dialog('open').dialog('center').dialog('setTitle', 'Edit User');
$('#fmuser').form('load', row);
url = '/userlist/edituse?id=' + row.id;
}
}
function saveuser() {
$('#fmuser').form('submit', {
url: '/userlist/saveuser',
onSubmit: function () {
return $(this).form('validate');
},
success: function (result) {
if (result == "OK") {
$('#dlguser').dialog('close');
$('#datalistuser').datagrid('reload');
$.messager.show({
title: 'Success',
msg: "添加成功"
});
}
else {
$.messager.show({
title: 'Error',
msg: "添加失败"
});
}
}
});
}
function removeuser() {
var row = $('#datalistuser').datagrid('getSelected');
if (row) {
$.messager.confirm('删除', '确定要删除这条数据?', function (r) {
if (r) {
$.post('/userlist/removeuser', { id: row.id }, function (result) {
if (result.success) {
$('#datalistuser').datagrid('reload');
$.messager.show({
title: 'Success',
msg: "删除成功"
});
} else {
$.messager.show({
title: 'Error',
msg: "添加失败"
});
}
}, 'json');
}
});
}
}
function emailuser() {
var row = $('#datalistuser').datagrid('getSelected');
if (row) {
$.messager.confirm('邮件', '确定要发邮件?', function (r) {
if (r) {
$.post('/userlist/emailuser', { id: row.id }, function (result) {
if (result == "OK") {
$('#datalistuser').datagrid('reload');
$.messager.show({
title: 'Success',
msg: "发送成功"
});
} else {
$.messager.show({
title: 'Error',
msg: "发送失败"
});
}
}, 'json');
}
});
}
}
function printuser() {
$('#dlguser').printThis();
}
function onloaduser() {
var myDate = new Date();
var rows = getdownloaduser("/userlist/downloaduser");
$('#datalistuser').datagrid('toExcel', { filename: '用户信息-' + myDate.getFullYear() + myDate.getMonth() + myDate.getDate() + '.xls', rows: rows })
}
function getdownloaduser(url) {
$.ajax({
url: url,
type: "post",
dataType: "json",
async: false,
cache: false,
success: function (data) {
rows = data.rows;
},
error: function () {
layer.msg("数据查询错误!");
return;
}
});
return rows;
}
2、后台对应的操作
#region operation 增删改查
public JsonResult getuserlist() {
List
us = db.hr_user.Where(x => x.State == "Y").OrderByDescending(x => x.Createtime).ToList();
return Json(us);
}
public JsonResult edituse(int id) {
user u = db.hr_user.Find(id);
return Json(u);
}
public ContentResult saveuser(user u) {
user user = new user();
var result = "NO";
try {
if ( u.Id != 0 ) {
user = db.hr_user.Find(u.Id);
user.Updatetime = DateTime.Now;
user.Updateuser = CurrentUsers.UserId;
db.Update(user);
result = "OK";
}
else {
user.Password = "88888888";
user.Createtime = DateTime.Now;
user.Createuser = CurrentUsers.UserId;
db.Add(user);
result = db.hr_user.Where(x => x.Username == u.Username).Count() == 0 ? "OK" : "NO";
}
if ( result == "OK" ) {
user.Nickname = u.Nickname;
user.Phone = u.Phone;
user.State = "Y";
user.Username = u.Username;
user.Wchart = u.Wchart;
user.Email = u.Email;
db.SaveChanges();
return Content(result);
}
else {
return Content(result);
}
}
catch ( Exception ex ) {
return Content(result);
}
}
public ContentResult removeuser(int id) {
try {
var u = db.hr_user.Find(id);
u.State = "N";
u.Updateuser = CurrentUsers.UserId;
u.Updatetime = DateTime.Now;
db.Update(u);
db.SaveChanges();
return Content("OK");
}
catch ( Exception ex ) {
return Content("NO");
}
}
#endregion
3、邮件发送和-处理
//邮件
public ContentResult emailuser(int id) {
try {
var u = db.hr_user.Find(id);
_sendMail.acceptmail = u.Email;
send_email.get_send_email(_sendMail, "邮件", "请登录您账户");
u.Updateuser = CurrentUsers.UserId;
u.Updatetime = DateTime.Now;
db.Update(u);
db.SaveChanges();
return Content("OK");
}
catch ( Exception ex ) {
return Content("NO");
}
}
//-
public ActionResult downloaduser() {
List
return Json(users);
}
效果如下图
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~