• mvc+dwz第七天


    SysUserInfoController代码

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Xiaowu.Model;
    using Xiaowu.BLL;
    using System.Linq.Expressions;
    using System.Transactions;
    namespace MySQLMVCTest.Controllers
    {
    //https://blog.csdn.net/qq_28218253/article/details/82909203;条件
    //https://www.cnblogs.com/qiuguochao/p/6838946.html

    //EF+lambda表达式 实现LIKE模糊查询
    //复制代码
    //1 s => s.XianWID.StartsWith(str)
    //2 匹配以str开头的
    //3 s => s.XianWID.EndsWith(str)
    //4 匹配以str结尾的
    //5 s => s.XianWID.Contains(str)
    //6 匹配包含str的
    public class SysUserInfoController : Controller
    {
    //
    // GET: /SysUserInfo/
    wu_userBLL userbll = new wu_userBLL();
    StudentDBContext db = new StudentDBContext();
    public ActionResult Index(int? pageNum, int? numPerPage, string username)
    {

    int pageIndex = pageNum.HasValue ? pageNum.Value : 1;
    int pageSize = numPerPage.HasValue && numPerPage.Value > 0 ? numPerPage.Value : 20;
    int recordCount = 0;
    //(q) => q.id,排序的字段
    Expression<Func<w_user, bool>> wherelambad = u => 1 == 1;//查询条件;
    if (username!=null&&username != "")
    {
    //wherelambad = wherelambad = u => u.wu_username == username;
    wherelambad = wherelambad = u => u.wu_username.Contains(username);//模糊查找
    }


    var data = userbll.GetPageEntities<int>(pageIndex, pageSize, out recordCount, wherelambad, (q) => q.id, false);
    ViewData["pageIndex"] = pageIndex;
    ViewData["pageSize"] = pageSize;
    ViewData["recordCount"] = recordCount;
    ViewData["username"] = username;
    var list = data.ToList();
    return View(list);
    }
    public ActionResult AddUserInfo(int ? OID)
    {
    var data = userbll.GetEntitysByStrwhere(u=>u.id==OID);
    var list = data.ToList();
    ViewData["OID"] = OID.HasValue ? OID : 0;
    ViewData["wu_username"] = list!=null&&list.Count>0?list[0].wu_username:"";
    ViewData["wu_nickName"] = list!=null&&list.Count>0? list[0].wu_nickName:"";
    return View();
    }

    public void checkAddUserInfo(w_user userinfo)
    {

    string otype = userinfo!=null&&userinfo.id == 0 ? "add" : "update";
    var result = 0;
    if (otype == "add")
    {
    userinfo.createtime = userinfo.updatetime= DateTime.Now;
    userinfo.createuser = userinfo.updateuser = 10000;
    result = userbll.AddUser(userinfo);
    }
    else
    {
    userinfo.updatetime = DateTime.Now;
    result = userbll.UpdateUser(userinfo);
    }
    if (result != 0)
    {
    string msg = SuccessAlert(200, "操作成功 ! ", "SysUserInfoList", callbackType: "closeCurrent");
    Response.Write(msg);
    }
    else
    {
    Response.Write(ErrorAlert(300, "操作失败"));
    }
    }

    /// <summary>
    /// 详情
    /// </summary>
    /// <param name="OID"></param>
    /// <returns></returns>
    public ActionResult UserInfoDetail(int? OID)
    {
    var data = userbll.GetEntitysByStrwhere(u => u.id == OID);
    var list = data.ToList();
    return View(list);
    }
    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="OID"></param>
    public void DeleteUserInfo(int? OID)
    {
    var id = OID.HasValue ? OID : 0;
    var result = 0;
    var data = userbll.GetEntitysByStrwhere(u => u.id == OID).ToList(); ;
    if (data != null)
    {
    w_user w_user = data[0];
    w_user.wu_state = 1;
    w_user.id = Convert.ToInt32(id);
    result = userbll.UpdateUser(w_user);
    }

    if (result != 0)
    {
    string msg = SuccessAlert(200, "删除成功", "SysUserInfoList");
    Response.Write(msg);
    }
    else
    {
    Response.Write(ErrorAlert(300, "操作失败"));
    }

    }

    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="OID"></param>
    public void DeleteUserInfoByIds(string ids)
    {
    //https://blog.csdn.net/iiithsoul/article/details/35257031
    //selectedTodo,,,关键代码在dwz.database.js中:
    if (string.IsNullOrWhiteSpace(ids))
    {
    Response.Write(ErrorAlert(300, "请选择数据"));
    return;
    }
    var result = 0;
    result = db.Database.ExecuteSqlCommand(string.Format("update w_user set wu_state=1,updatetime=now() where id in(" + ids + ")"));
    if (result != 0)
    {
    string msg = SuccessAlert(200, "删除成功", "SysUserInfoList");
    Response.Write(msg);
    }
    else
    {
    Response.Write(ErrorAlert(300, "操作失败"));
    }

    }

    /// <summary>
    /// 商品启用
    /// </summary>
    /// <param name="OID"></param>
    public void RecoverUserInfo(int? OID)
    {
    var id = OID.HasValue ? OID : 0;
    var result = 0;
    var data = userbll.GetEntitysByStrwhere(u => u.id == OID).ToList(); ;
    if (data != null)
    {
    w_user w_user = data[0];
    w_user.wu_state = 0;
    w_user.id = Convert.ToInt32(id);
    result = userbll.UpdateUser(w_user);
    }
    if (result != 0)
    {
    string msg = SuccessAlert(200, "启用成功", "SysUserInfoList");
    Response.Write(msg);
    }
    else
    {
    Response.Write(ErrorAlert(300, "操作失败"));
    }
    }


    /// <summary>
    /// 批量启用
    /// </summary>
    /// <param name="OID"></param>
    public void RecoverUserInfoByIds(string ids)
    {
    //https://blog.csdn.net/iiithsoul/article/details/35257031
    //selectedTodo,,,关键代码在dwz.database.js中:
    if (string.IsNullOrWhiteSpace(ids))
    {
    Response.Write(ErrorAlert(300, "请选择数据"));
    return;
    }
    var result = 0;
    result = db.Database.ExecuteSqlCommand(string.Format("update w_user set wu_state=0,updatetime=now() where id in(" + ids + ")"));
    if (result != 0)
    {
    string msg = SuccessAlert(200, "启用成功", "SysUserInfoList");
    Response.Write(msg);
    }
    else
    {
    Response.Write(ErrorAlert(300, "操作失败"));
    }

    }

    public static string SuccessAlert(int statusCode, string message, string navTabId = "", string rel = "", string callbackType = "", string forwardUrl = "", string strOther = "")
    {
    return string.Format("{7}"statusCode":"{0}", "message":"{1}","navTabId":"{2}","rel":"{3}","callbackType":"{4}","forwardUrl":"{5}"{6}{8}", statusCode, message, navTabId, rel, callbackType, forwardUrl, strOther, "{", "}");
    }
    public static string ErrorAlert(int statusCode, string message)
    {
    return string.Format("{2}"statusCode":"{0}", "message":"{1}"{3}", statusCode, message, "{", "}");
    }
    }
    }

    Index视图:

    @{
    ViewBag.Title = "系统用户列表";
    }
    @model List<Xiaowu.Model.w_user>
    <form id="pagerForm" method="post" action="@Url.Action("Index")">
    <input type="hidden" name="pageNum" value="@ViewData["pageIndex"]" />
    <input type="hidden" name="numPerPage" value="@ViewData["pageSize"]" />
    <input name="username" type="hidden" value="@ViewData["username"]" />
    </form>
    <div class="pageHeader">
    <form onsubmit="return navTabSearch(this);" action="@Url.Action("Index")" method="post">
    <div class="searchBar">
    <ul class="searchContent">
    <li>
    <label>
    用户名:
    </label>
    <input name="username" type="text" value="@ViewData["username"]" />
    </li>
    </ul>
    <div class="subBar">
    <ul>
    <li>
    <div class="buttonActive">
    <div class="buttonContent">
    <button type="submit">
    检索
    </button>
    </div>
    </div>
    </li>
    </ul>
    </div>
    </div>
    </form>
    </div>
    <div class="pageContent">
    <div class="panelBar">
    <ul class="toolBar">
    <li><a class="add" href="/SysUserInfo/AddUserInfo" mask="false" width="800" height="250" target="dialog" rel="SysUserInfo"><span>添加用户</span></a></li>
    <li>
    <a class="delete" href="/SysUserInfo/DeleteUserInfoByIds" rel="ids" target="selectedTodo" posttype="string"
    title="确定要删除吗?"><span>批量删除</span></a>
    </li>
    <li>
    <a class="delete" href="/SysUserInfo/RecoverUserInfoByIds" rel="ids" target="selectedTodo" posttype="string"
    title="确定要启用吗?"><span>批量启用</span></a>
    </li>
    <li class="line">line</li>
    </ul>
    </div>
    <table class="table" width="100%" layouth="138">
    <thead>
    <tr>
    <th width="40">
    <input type="checkbox" group="ids" class="checkboxCtrl">
    </th>
    <th>
    编号
    </th>
    <th>
    用户名
    </th>
    <th>
    昵称
    </th>
    <th>
    状态
    </th>
    <th width="120">
    操作
    </th>
    </tr>
    </thead>
    <tbody>
    @foreach(var item in Model)
    {
    <tr>
    <td>
    <input name="ids" type="checkbox" value="@item.id" />
    </td>
    <td>@item.id</td>
    <td>@item.wu_username</td>
    <td>@item.wu_nickName</td>
    <td>@(item.wu_state==0?"正常":"删除")</td>
    <td width="120">
    <a title="查看" target="dialog" class="btnInfo">详情</a>
    <a title="编辑" target="dialog" href="/SysUserInfo/AddUserInfo?OID=@item.id" class="btnEdit" mask="false" width="800" height="250"> 编辑</a>
    @if (item.wu_state == 0)
    {
    <a title="确定要删除吗?" target="ajaxTodo" href="/SysUserInfo/DeleteUserInfo?OID=@item.id" class="btnDel">
    删除
    </a>
    }
    else
    {
    <a title="确定要启用吗?" target="ajaxTodo" href="/SysUserInfo/RecoverUserInfo?OID=@item.id" class="btnSelect">
    启用
    </a>
    }
    </td>

    </tr>
    }
    </tbody>
    </table>
    <div class="panelBar">
    <div class="pages">
    <span>每页20条,共 @ViewData["recordCount"] 条</span>
    </div>
    <div class="pagination" targettype="navTab" totalcount="@ViewData["recordCount"]" numperpage="@ViewData["pageSize"]" pagenumshown="10"
    currentpage="@ViewData["pageIndex"]">
    </div>
    </div>
    </div>

     新增用户视图:

    @{
    ViewBag.Title = "新增系统用户";
    }


    <html>
    <head>
    <title></title>
    </head>
    <body>
    <div class="pageContent">
    <form method="post" action="/SysUserInfo/checkAddUserInfo" class="pageForm required-validate" onsubmit="return iframeCallback(this, dialogAjaxDone);">
    <div class="pageFormContent nowrap" layouth="97">
    <dl>
    <dt>用户名:</dt>
    <dd>
    <input type="text" name="wu_username" maxlength="20" class="required" alt="请输入您的用户名" value="@ViewData["wu_username"]" />
    <input type="hidden" name="id" value="@ViewData["OID"]" />
    </dd>
    </dl>
    <dl>
    <dt>昵称:</dt>
    <dd>
    <input type="text" name="wu_nickName" class="required " alt="请输入您的昵称" value="@ViewData["wu_nickName"]" />
    </dd>
    </dl>
    @*<div class="divider"></div>
    <p>自定义扩展请参照:dwz.validate.method.js</p>
    <p>错误提示信息国际化请参照:dwz.regional.zh.js</p>*@
    </div>
    <div class="formBar">
    <ul>
    <li><div class="buttonActive"><div class="buttonContent"><button type="submit">提交</button></div></div></li>
    <li><div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div></li>
    </ul>
    </div>
    </form>

    </div>
    </body>
    </html>

  • 相关阅读:
    clearfix
    css浮动
    css常识
    给数组排序方法2
    定时器
    数组
    redhat 7.6 iptables 配置
    redhat 7.6 流量监控命令、软件(3)nethogs 监控进程实时流量
    redhat 7.6 流量监控命令、软件(2) iftop 监控网络IP实时流量
    redhat 7.6 流量监控命令、软件(1) ethstatus
  • 原文地址:https://www.cnblogs.com/wugh8726254/p/14002622.html
Copyright © 2020-2023  润新知