using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using DSWeb.MvcShipping.Helper; using DSWeb.MvcShipping.Models.MsOpMailLog; using DSWeb.Areas.MvcShipping.DAL; using HcUtility.Comm; using System.IO; using HcUtility.Core; using DSWeb.SoftMng.Filter; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsOpMailLogController : Controller { public ActionResult Index() { return View(); } public ActionResult PiLiang() { return View(); } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 public ContentResult GetDataList(int start, int limit, string sort, string condition) { var dataList = MsOpMailLogDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"]), sort); var list = dataList.Skip(start).Take(limit).ToList(); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list });//list.ToList() return new ContentResult() { Content = json }; } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 public ContentResult GetData(string condition) { OpMailLog head = null; head = MsOpMailLogDAL.GetData(condition); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } public ContentResult Delete(string bsno, string data) { if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "") { var jsonRespose2 = new JsonResponse { Success = false, Message = "登录超时,请退出系统重新登录!" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } // var bodyList = JsonConvert.Deserialize>(data); var result = new DBResult(); if (bodyList != null) { result = MsOpMailLogDAL.DeleteMailLog(bodyList); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } [HttpPost] public ContentResult UpMailLog() { var jsonRespose = new JsonResponse { Success = false, Message = "" }; if (Request.Files.Count != 1) { jsonRespose.Success = false; jsonRespose.Message = "请选择上传的文件"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } var file = Request.Files["filename"]; if (file == null) { jsonRespose.Success = false; jsonRespose.Message = "上传文件发生未知错误,请重新上传"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } if (Convert.ToString(Session["COMPANYID"]).ToString().Trim() == "" || Convert.ToString(Session["USERID"]).ToString().Trim() == "" || Convert.ToString(Session["CODENAME"]).ToString().Trim() == "" || Convert.ToString(Session["SHOWNAME"]).ToString().Trim() == "" || Convert.ToString(Session["DEPTNAME"]).ToString().Trim() == "") { jsonRespose.Success = false; jsonRespose.Message = "请重新登陆"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } string ext = Path.GetExtension(file.FileName).ToLower(); if (ext == ".asp" || ext == ".aspx") { jsonRespose.Success = false; jsonRespose.Message = "不允许上传ASP或ASPX文件"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } var path = Server.MapPath("../../UploadFiles/MailLog"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var size = file.ContentLength; var name = Path.GetFileName(file.FileName); var Mailid = Request.Form["Mailid"]; var usercode = Convert.ToString(Session["CODENAME"]).ToString().Trim(); string filenamepath = usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name; string filename = path + "\\" + filenamepath; if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } file.SaveAs(filename); filenamepath = "../../UploadFiles/MailLog/"+filenamepath; var OpMailSend = MsOpMailLogDAL.GetSendData("GID='"+ Mailid + "'"); var OpMailLog = new OpMailLog(); OpMailLog.BSNO = OpMailSend.BSNO; OpMailLog.BLTYPE = OpMailSend.BLTYPE; OpMailLog.SUBJECT = OpMailSend.SUBJECT; OpMailLog.DESCRIPTION = OpMailSend.DESCRIPTION; OpMailLog.SENDER = OpMailSend.SENDER; OpMailLog.RECEIVER = OpMailSend.RECEIVER; OpMailLog.ATTACHMENT = filenamepath; OpMailLog.SENDTIME = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); OpMailLog.SENDUSER = Convert.ToString(Session["USERID"]).ToString().Trim(); OpMailLog.DbOperationType = DbOperationType.DbotIns; var modb = new ModelObjectDB(); modb.Save(OpMailLog); var jsonRespose2 = new JsonResponse { Success = true, Message ="" }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose2) }; } } }