冯 海

一个程序新人菜鸟的日记,希望大家多多关照。QQ:32316131

bootstrap adminlte教程11:打造内部邮件系统 -收件箱管理

收件箱是相当复杂的。功能多,就不一一介绍了,全用代码说明一切。

1.index 的方法

// GET: Emails
		public  ActionResult  Index(string emailState, string SearchString, int? page)
        {			
			///初始化分页
			if (!string.IsNullOrEmpty(emailState) && !string.IsNullOrEmpty(SearchString))
			{
				page = 1;
			}
			//赋值回传
			ViewBag.emailState = emailState;
			ViewBag.SearchString = SearchString;
			//默认情况下是只显示未阅读的。同时按creattime降序
			var emalilist = db.Emails.Where(c => c.EmailState == "0").OrderByDescending(z => z.CreatTime);
			//开始if进行分析
			if (!string.IsNullOrEmpty(emailState))     //这是不为空,表示点了已阅,需在搜索已阅
			{
				emalilist = db.Emails.Where(c => c.EmailState == "1").OrderByDescending(z => z.CreatTime);
				
			}
			 
				if (!string.IsNullOrEmpty(SearchString))  //表示有字段
				{
				 
				emalilist = db.Emails.Where(c => c.Title.Contains(SearchString)).OrderByDescending(z => z.CreatTime);
		     	}


			int pageNumber = page ?? 1;
			int pageSize =10;
			//通过ToPagedList扩展方法进行分页
			//IPagedList<CmsContent> pagedList = seachindex.ToPagedList(pageNumber, pageSize);


			return View(emalilist.ToPagedList(pageNumber, pageSize));



		}

 同时有一个批量删除的方法

 

//	批量删除文件功能

		public ActionResult DelEmails(FormCollection form)
		{
			//var cmscontents = db.CmsContents;
			//db.MenuRoles.RemoveRange(menuroles);
			var winnars = from x in form.AllKeys
						  where form[x] != "false"
						  select x;
			foreach (var id2 in winnars)

			{
				if (id2 != "selectAll")   //全选的那个不算数。那个checkbox值要去掉
				{
					var emailContents = db.Emails.Find(id2);
					if (emailContents != null)
					{
						db.Emails.Remove(emailContents);
					}
				}

			}

			db.SaveChanges();
			return RedirectToAction("index", "Emails");
		}

  

 

2.视图

视图中加了分页。

 @model PagedList.IPagedList<jsdhh2.Models.Email>
@using PagedList.Mvc;
<link href="~/Content/PagedList.css" rel="stylesheet" />

@{
    ViewBag.Title = "Index";
} 
<div class="dhhheight1 col-md-12 col-xs-12"></div>
	<!--start 左 -->
<div class="col-md-3 hidden-xs">
	<div class="box box-solid">
		<div class="box-header with-border">
			<h3 class="box-title">内部邮箱</h3>

			<div class="box-tools">
				<button type="button" class="btn btn-box-tool" data-widget="collapse">
					<i class="fa fa-minus"></i>
				</button>
			</div>
		</div>
		<div class="box-body no-padding" style="display: block;">
			<ul class="nav nav-pills nav-stacked">
				<li class="active">
					<a href="~/Emails/Index">
						<i class="fa fa-inbox"></i> 收件箱
						<span class="label label-primary pull-right">12</span>
					</a>
				</li>
				<li><a href="#"><i class="fa fa-envelope-o"></i> 已发邮箱</a></li>
				<li><a href="~/Emails/Create"><i class="fa fa-file-text-o"></i> 发邮件</a></li>
			 
			</ul>
		</div>
		<!-- /.box-body -->
	</div>



</div>

	<!--start 右 -->
<div class="col-md-9 col-xs-12 pull-right">
	

	<!-- Content Header (Page header) -->
	<section class="content-header">
		 
		<h1>
			邮件清单
			<small>请不要乱发邮件哟~</small>
		</h1>
		<ol class="breadcrumb">
			<li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
			<li class="active">Here</li>
		</ol>

	</section>
	<!--end Content Header (Page header) -->

	<!--start button -->
	<h2></h2>
	<div class="col-md-4 col-xs-6">
	
		@using (Html.BeginForm("index", "Emails", new { @class = "form-inline" }, FormMethod.Post))
			{

			<div class="form-inline">

				<div class="form-group">
					<div class="input-group">
						@Html.TextBox("SearchString", "", new { @class = "form-control", @Style = "display:inline" })
						<span class="input-group-btn ">
							<input id="btnSearch" class="btn btn btn-primary" type="submit" value="搜索">
						</span>
					</div>
				</div>
			</div>
			}
	</div>
	<h2></h2>

@using (Html.BeginForm("DelEmails", "Emails", new { @class = "form-inline" }, FormMethod.Post))
{
	<div class="btn-group text-left col-md-8 col-xs-6" role="group" aria-label="...">

		<input type="submit" class="btn btn-warning" value="删除" />
		<a class="btn btn-default" href="/Emails/Index?emailState=1" role="button">已阅</a>

	</div>

	<div class="dhhheight1"></div>

	<h2> </h2>



	<table class="table  table-hover"  style="table-layout:fixed">
		<tr>
			<th width="40px">
				<input id="selectAll" name="selectAll" type="checkbox" value="true" onclick="changeState(this.checked)" /><input name="selectAll" type="hidden" value="false" />
			 
			</th>

			<th width="50%">
				标题
			</th>
			<th>
				发表时间
			</th>
			 			 
			<th>
				发件人
			</th>
			 
			 
		 
			<th></th>
		</tr>

		@foreach (var item in Model)
		{
			<tr>
				<td>

					@Html.CheckBox(item.Id, false)
				</td>
				<td style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">
					<small>
						@if (item.EmailState == "1")
						{ <span class="label label-success">阅</span>
						}
						else
						{<span class="label label-warning">未</span>
						}

					</small>		<a href="~/Emails/Details?id=@Html.DisplayFor(modelItem => item.Id)">@Html.DisplayFor(modelItem => item.Title)</a>
				</td>
				<td>
					@Html.DisplayFor(modelItem => item.CreatTime, "DateTimeTemplate")
				</td>
				 	 
				<td>
					@Html.DisplayFor(modelItem => item.CreatUser)
				</td>
				<td>
					 
			 
					@Html.ActionLink("Del", "Delete", new { id = item.Id }, new { @class = "btn btn-warning btn-xs" })
				</td>
			</tr>
		}

	</table>




}
	<hr />
	<!-- Main content -->
	Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
	@Html.PagedListPager(Model, page => Url.Action("Index",
  new { page, emailState = ViewBag.emailState, SearchString = ViewBag.SearchString }))


</div>



@section Scripts {
	 	<script type="text/javascript">
		function changeState(isChecked) {
			var chk_list = document.getElementsByTagName("input");
			for (var i = 0; i < chk_list.length; i++) {
				if (chk_list[i].type == "checkbox") {
					chk_list[i].checked = isChecked;
				}
			}
		}
	</script>
}

  

3.效果。

posted @ 2017-06-05 00:44  秋天来了哟  阅读(254)  评论(0编辑  收藏  举报
认识就是缘份,愿天下人都快乐!
QQ: 32316131
Email: 32316131@qq.com