新增 编辑 新写法
using System.Linq; using System.Web.Mvc; using Common; using DoddleReport; using DoddleReport.Web; using IServices.ISysServices; using IServices.Infrastructure; using Web.Helper; using System; using Models.SysModels; using BootstrapSupport; using Models.Constraints; using Services; using IServices.IUserServices; using Models.UserModels; using Newtonsoft.Json; using System.Collections.Generic; using System.Text.RegularExpressions; namespace Web.Areas.Admin.Controllers { public class AtmCustomerEmailController : BaseController { private readonly IUnitOfWork _unitOfWork; private readonly IUserInfo _userInfo; private readonly ISysProjectService _sysProjectService; private readonly IAtmCustomerService _iAtmCustomerService; private readonly IAtmCustomerEmailService _iAtmCustomerEmailService; private readonly IVMDispatchService _ivmdispatchService; public AtmCustomerEmailController(IUnitOfWork unitOfWork, IUserInfo userInfo, ISysProjectService sysProjectService, IAtmCustomerService iAtmCustomerService, IAtmCustomerEmailService iAtmCustomerEmailService, IVMDispatchService ivmdispatchService) { _unitOfWork = unitOfWork; _userInfo = userInfo; _sysProjectService = sysProjectService; _iAtmCustomerService = iAtmCustomerService; _iAtmCustomerEmailService = iAtmCustomerEmailService; _ivmdispatchService = ivmdispatchService; } // GET: Admin/AtmCustomerEmail public ActionResult Index() { return View(); } /// <summary> /// 获取列表信息 /// </summary> /// <returns></returns> public string GetList() { int currentPage = Request["offset"] == null ? 1 : ConvertHelper.ToInt(Request["offset"]); // 每页行数 int showCount = Request["limit"] == null ? 10 : ConvertHelper.ToInt(Request["limit"]); if (currentPage != 0) {// 获取页数 currentPage = currentPage / showCount; } currentPage += 1; string search = Request["search"]; var model = _iAtmCustomerEmailService.GetAll().Select(a => new { a.Id, a.Recipients, CustomerName = a.AtmCustomer == null ? "" : a.AtmCustomer.Name, a.ProjectList, a.CreatedDate, a.EmailType, }).Search(search); string ordering = Request["sort"]; string order = Request["order"]; if (!string.IsNullOrEmpty(ordering)) { model = model.OrderBy(ordering + " " + order, null); } else { model = model.OrderBy(" CreatedDate desc ", null); } int count = model.Count(); var list = model.Skip((currentPage - 1) * showCount).Take(showCount).ToList(); List<AtmCustomerEmail> customerEmailList = new List<AtmCustomerEmail>(); if (count > 0) { AtmCustomerEmail customerEmail; foreach (var item in list) { customerEmail = new AtmCustomerEmail(); customerEmail.Id = item.Id; customerEmail.Recipients = item.Recipients; if ((int)item.EmailType == 1) { customerEmail.AtmCustomerName = ""; } else { customerEmail.AtmCustomerName = item.CustomerName; } customerEmail.ProjectList = item.ProjectList; customerEmail.ProjectNameList = ConvertProjectList(item.ProjectList); customerEmail.CreatedDate = item.CreatedDate; customerEmail.Remark = (int)item.EmailType != 0 ? ((int)item.EmailType == 1 ? LangResources.Resource.ATMPWDemailtype : LangResources.Resource.TransferemailType) : LangResources.Resource.Customeremailtype; customerEmailList.Add(customerEmail); } } string jsonDataTable = JsonConvert.SerializeObject( new { total = count, rows = customerEmailList }); return jsonDataTable; } /// <summary> /// 转换城市名称集合 /// </summary> /// <param name="projectlist">城市ID集合</param> /// <returns>城市名称集合</returns> private string ConvertProjectList(string projectlist) { List<SysProject> list = _sysProjectService.GetAll().ToList(); List<string> namelist = new List<string>(); Guid id = Guid.Empty; SysProject project = null; foreach (string str in projectlist.Split(',')) { if (!string.IsNullOrEmpty(str)) { id = Guid.Parse(str); project = list.Where(p => p.Id == id).FirstOrDefault(); if (project != null) { namelist.Add(project.Name); } } } return string.Join(",", namelist); } public ActionResult Create() { return RedirectToAction("Edit"); } public ActionResult Edit(Guid? id) { var item = new AtmCustomerEmail(); if (id.HasValue) { item = _iAtmCustomerEmailService.GetById(id.Value); } ViewBag.EmailType = new SelectList(EmailTypes.Customeremailtype.ToSelectListItem(), "Value", "Text", (int)item.EmailType); ViewBag.CustomerId = new SelectList(_iAtmCustomerService.GetAll().ToList(), "Id", "Name", item.CustomerId); ViewBag.ProjectList = new MultiSelectList(_sysProjectService.GetAll().ToList(), "Id", "Name" , (string.IsNullOrEmpty(item.ProjectList) ? null : item.ProjectList.Split(','))); return View(item); } public void Exportatm() { IAutoEmailATMPWD service = new AutoEmailATMPWD(null, null, null); service.RunExport(); } [HttpPost] public ActionResult Edit(Guid? id, AtmCustomerEmail collection, string changelog) { if (!ModelState.IsValid) { Edit(id); ViewBag.CustomerId = new SelectList(_iAtmCustomerService.GetAll().ToList(), "Id", "Name", collection.CustomerId); ViewBag.ProjectList = new MultiSelectList(_sysProjectService.GetAll().ToList(), "Id", "Name" , (string.IsNullOrEmpty(collection.ProjectList) ? null : collection.ProjectList.Split(','))); ViewBag.EmailType = new SelectList(EmailTypes.Customeremailtype.ToSelectListItem(), "Value", "Text", collection.EmailType); return View(collection); } //验证收件人格式是否正确 string[] emailList = collection.Recipients.Split(';'); foreach (string email in emailList) { if (!ValidateEmail(email)) { ModelState.AddModelError("Validate", LangResources.Resource.Recipients + "[" + email + "]" + LangResources.Resource.FormatError); ViewBag.CustomerId = new SelectList(_iAtmCustomerService.GetAll().ToList(), "Id", "Name", collection.CustomerId); ViewBag.ProjectList = new MultiSelectList(_sysProjectService.GetAll().ToList(), "Id", "Name" , (string.IsNullOrEmpty(collection.ProjectList) ? null : collection.ProjectList.Split(','))); return View(collection); } } if (id.HasValue) { _ivmdispatchService.Changedata(id.Value, 1, changelog, "T_ATM_CUSTOMER_EMAIL"); } else { _ivmdispatchService.Changedata(collection.Id, 0, changelog, "T_ATM_CUSTOMER_EMAIL"); } collection.ProjectList = Request.Form["ProjectList"]; _iAtmCustomerEmailService.Save(id, collection); _unitOfWork.Commit(); return RedirectToAction("Index"); } /// <summary> /// 验证邮箱格式是否正确 /// </summary> /// <param name="email"></param> /// <returns></returns> private bool ValidateEmail(string email) { string strRegex = @"^([a-z0-9A-Z_]+[-|\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\.)+[a-zA-Z]{2,}$"; Regex regex = new Regex(strRegex, RegexOptions.IgnoreCase); if (regex.IsMatch(email)) { return true; } else { return false; } } public ActionResult Delete(Guid id) { _ivmdispatchService.Changedata(id, 2,"Deleted", "T_ATM_CUSTOMER_EMAIL"); _iAtmCustomerEmailService.Delete(id); _unitOfWork.Commit(); return RedirectToAction("Index"); } } }
@{ Layout = "~/Views/Shared/_Layout.cshtml"; } <div class="row"> <div class="col-sm-12"> <div class="ibox float-e-margins"> @using (Html.BeginForm()) { <div class="ibox-title"> <h5> @if (ViewContext.RouteData.Values["Id"] == null) { <span>@LangResources.Resource.PageTitle_Create</span> } else { <span>@LangResources.Resource.PageTitle_Edit</span> } </h5> </div> <div class="ibox-content"> <div class="form-horizontal"> @Html.AntiForgeryToken() <div> @Html.Partial("_alerts") @Html.Partial("_validationSummary") </div> @foreach (var prop in ViewData.ModelMetadata.Properties.Where(pm => pm.ShowForEdit && !pm.ModelType.IsAbstract && !ViewData.TemplateInfo.Visited(pm)).OrderBy(a => a.Order)) { <input type="hidden" id="changelog" name="changelog"> if (prop.HideSurroundingHtml) { @Html.Hidden(prop.PropertyName) } else if (prop.PropertyName == "Recipients") { <div class="form-group row"> <label class="col-md-2 control-label" for="@prop.PropertyName">@(prop.IsRequired ? "*" : "") @prop.DisplayName</label> <div class="col-md-8"> @Html.Editor(prop.PropertyName) @LangResources.Resource.RecipientsDescription </div> <div class="col-md-2 "> <label class="control-label"> @Html.ValidationMessage(prop.PropertyName) </label> </div> </div> } else { <div class="form-group row"> <label class="col-md-2 control-label" for="@prop.PropertyName">@(prop.IsRequired ? "*" : "") @prop.DisplayName</label> <div class="col-md-8"> @Html.Editor(prop.PropertyName) @prop.Description </div> <div class="col-md-2 "> <label class="control-label"> @Html.ValidationMessage(prop.PropertyName) </label> </div> </div> } } @Html.Partial("Button_Submit") </div> </div> } </div> </div> </div> <script src="~/Scripts/base/Atmbase/BaseLog.js"></script> <script> (function ($) { var EmailType = $("#EmailType").val(); //if (EmailType == "1" || EmailType == "2") { document.getElementById("CustomerId").parentElement.parentElement.parentElement.style.display = "none"; $("#CustomerId_chosen").hide(); $("#CustomerId").val('5b5480c6-6460-4377-89b6-9ff1062d65f2'); //} //else { // document.getElementById("CustomerId").parentElement.parentElement.parentElement.style.display = "block"; // $("#CustomerId_chosen").show(); // //$("#CustomerId").val(''); //} //$("#CustomerId_chosen").css("width", "350px"); })(jQuery); $("#EmailType").change(function () { var EmailType = $("#EmailType").val(); //if (EmailType == "1") { document.getElementById("CustomerId").parentElement.parentElement.parentElement.style.display = "none"; $("#CustomerId_chosen").hide(); $("#CustomerId").val('5b5480c6-6460-4377-89b6-9ff1062d65f2'); //} //else { // document.getElementById("CustomerId").parentElement.parentElement.parentElement.style.display = "block"; // $("#CustomerId_chosen").show(); // $("#CustomerId_chosen").css("width", "350px"); // $("#CustomerId").val(''); //} }); </script>
@using System.Reflection @using Web.Helper @model System.Collections.IEnumerable @using BootstrapSupport @{ Layout = "~/Views/Shared/_Layout.cshtml"; var culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name.ToLowerInvariant(); } <div class="row"> <div class="col-sm-12"> <div class="ibox float-e-margins"> <div class="ibox-content"> <div class="btn-group hidden-xs" id="operateToolbar" role="group"> <div class="col-sm-6"> <a class="btn btn-w-m btn-info" href="@Url.Action("Create")" id="btnPerson">@LangResources.Resource.Create</a> </div> <div class="col-sm-6"> <button type="button" class="btn btn-info " onclick="Exportatm()">Send AtmPWD</button> </div> </div> <table id="dataTable" data-toggle="table" data-show-columns="true" data-mobile-responsive="true"></table> </div> </div> </div> </div> <script type="text/javascript"> (function ($) { $("#dataTable").bootstrapTable( { method: 'get', url: '/AtmCustomerEmail/GetList', sidePagination: 'server', search: !0, pagination: !0, showRefresh: !0, showToggle: !0, pageList: [15, 30, 50, 100], pageSize: 15, pageNumber: 1, showColumns: false, iconSize: "outline", toolbar: "#operateToolbar", columns: [{ field: 'Recipients', title: SetStr("Recipients"), valign: 'middle', sortable: true }, { field: 'AtmCustomerName', title: SetStr("AtmCustomer"), valign: 'middle', sortable: true }, { field: 'ProjectNameList', title: SetStr("ProjectIds"), valign: 'middle', sortable: true }, { field: 'Remark', title: SetStr("EmailType"), valign: 'middle', sortable: true }, { field: 'Id', title: SetStr("Btn_IndexClose"), width: '200', formatter: EditeOpt }], icons: { refresh: "glyphicon-repeat", toggle: "glyphicon-list-alt", columns: "glyphicon-list" } }); })(jQuery); function EditeOpt(obj, row) { var clrclass = 'class = "btn btn-info btn-xs" style="margin-top:5px;margin-left:5px;position:relative;" '; var linkedit = '<a ' + clrclass + ' id="' + row.Id + '" href="/Admin/AtmCustomerEmail/Edit/' + row.Id + '">' + SetStr("Btn_Edit") + '</a>'; var linkdel = '<a ' + clrclass + ' id="' + row.Id + '" href="/Admin/AtmCustomerEmail/Delete/' + row.Id + '">' + SetStr("Delete") + '</a>'; return linkedit + linkdel; } function Exportatm() { //var str = txtbgrq + "," + txtendrq + "," + txtjijubianhao + "," + txtCustomerName + "," + txtNumMin + "," + txtNumMax; var url = "/Admin/AtmCustomerEmail/Exportatm"; window.open(url); } </script>
没有新增页面