using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using DSWeb.MvcShipping.DAL.MsOpReceiptDAL; using DSWeb.MvcShipping.Models.MsOpReceipt; using DSWeb.MvcShipping.Models.MsOpAmend; using DSWeb.MvcShipping.Helper; using HcUtility.Comm; using HcUtility.Core; using System.IO; namespace DSWeb.MvcShipping.Controllers { [JsonRequestBehavior] public class MsOpReceiptController : Controller { public ActionResult Index() { return View(); } #region 查询列表 public ContentResult GetDataList(string billno, string optype) { var dataList = MsOpReceiptDAL.GetDataList("BSNO='" + billno + "'", optype, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetBLDataList(int start, int limit, string sort, string condition) { int total = 0; var dataList = MsOpReceiptDAL.GetBLDataList(condition, start, limit, out total, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = total, data = dataList.ToList() }); return new ContentResult() { Content = json }; } public ContentResult GetBLDataListStr(string sort, string condition) { int total = 0; var dataList = MsOpReceiptDAL.GetBLDataListStr(condition, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = total, data = dataList }); return new ContentResult() { Content = json }; } #endregion #region 插入、更新、删除 等 op_receipt 表的操作,并返回操作结果 public ContentResult Save(string BSNO, string OpReceiptbody) { int iResult = 0; var bodyList = JsonConvert.Deserialize>(OpReceiptbody); var result =new DBResult(); if (bodyList != null) { iResult = MsOpReceiptDAL.SaveUpdateReceipt(bodyList, BSNO, Convert.ToString(Session["USERID"]), Convert.ToString(Session["COMPANYID"])); } if (iResult == 1) { result.Success=true; result.Message = "更新成功!"; } else if (iResult == 0) { result.Success = false; result.Message = "出现错误,未更新!"; } else if (iResult == -1) { result.Success = false; result.Message = "有异常,插入失败!"; } else if (iResult == -2) { result.Success = false; result.Message = "插入异常,事务已回滚成功!"; } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult Delete(string BSNO,string data) { int iResult = 0; var bodyList = data; var result = new DBResult(); if (bodyList !="" ||bodyList != null) { iResult = MsOpReceiptDAL.DeleteReceipt(bodyList); } if (iResult == 1) { result.Success = true; result.Message = "删除成功!"; } else if (iResult == 0) { result.Success = false; result.Message = "出现错误,未删除!"; } else if (iResult == -1) { result.Success = false; result.Message = "有异常,删除失败!"; } else if (iResult == -2) { result.Success = false; result.Message = "删除异常,事务已回滚成功!"; } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion #region 单据确认,并返回操作结果 public ContentResult onSetRECEIPT(string strBSNO, string gids, string onSetType) { int iResult = 0; var bodyList = gids; var result = new DBResult(); if (bodyList !="" ||bodyList != null) { iResult = MsOpReceiptDAL.onSetRECEIPT(strBSNO, bodyList, onSetType, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); } if (iResult == 1) { result.Success = true; result.Message = "操作成功!"; } else if (iResult == 0) { result.Success = false; result.Message = "出现错误,未操作!"; } else if (iResult == -1) { result.Success = false; result.Message = "有异常,操作失败!"; } else if (iResult == -2) { result.Success = false; result.Message = "操作异常,事务已回滚成功!"; } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SongDan(string data,string formdata) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData = JsonConvert.Deserialize(formdata); if (headData.SEND_DATE == "") headData.SEND_DATE = null; var result = MsOpReceiptDAL.SongDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SongDanAll(string condition, string formdata) { int total = 0; var dataList = MsOpReceiptDAL.GetBLDataList(condition, 0,1000, out total, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var headData = JsonConvert.Deserialize(formdata); if (headData.SEND_DATE == "") headData.SEND_DATE = null; var result = MsOpReceiptDAL.SongDan(headData, dataList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CancelSongDan(string data) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData =new MsOpReceiptEntity(); headData.SEND_DATE = null; var result = MsOpReceiptDAL.SongDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult HuiDan(string data, string formdata) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData = JsonConvert.Deserialize(formdata); if (headData.REPEAT_DATE == "") headData.REPEAT_DATE = null; var result = MsOpReceiptDAL.HuiDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult HuiDanAll(string condition, string formdata) { int total = 0; var dataList = MsOpReceiptDAL.GetBLDataList(condition, 0, 1000, out total, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var headData = JsonConvert.Deserialize(formdata); if (headData.REPEAT_DATE == "") headData.REPEAT_DATE = null; var result = MsOpReceiptDAL.HuiDan(headData, dataList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CancelHuiDan(string data) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData = new MsOpReceiptEntity(); headData.REPEAT_DATE = null; var result = MsOpReceiptDAL.HuiDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult HuanDan(string data, string formdata) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData = JsonConvert.Deserialize(formdata); if (headData.RETURN_DATE == "") headData.RETURN_DATE = null; var result = MsOpReceiptDAL.HuanDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult HuanDanAll(string condition, string formdata) { int total = 0; var dataList = MsOpReceiptDAL.GetBLDataList(condition, 0, 1000, out total, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); var headData = JsonConvert.Deserialize(formdata); if (headData.RETURN_DATE == "") headData.RETURN_DATE = null; var result = MsOpReceiptDAL.HuanDan(headData, dataList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult CancelHuanDan(string data) { var MsOpReceiptEntityList = JsonConvert.Deserialize>(data); var headData = new MsOpReceiptEntity(); headData.RETURN_DATE = null; var result = MsOpReceiptDAL.HuanDan(headData, MsOpReceiptEntityList, Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"])); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #endregion [HttpPost] public ContentResult UploadFile() { 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["LoadFile"]; var CUSTNO = Request.Form["CUSTNO"]; var BSNO = Request.Form["BSNO"]; var TYPE = Request.Form["TYPE"]; var DOCUMENTATTACHEDCODE = Request.Form["DOCUMENTATTACHEDCODE"]; var DOCUMENTATTACHEDNO = Request.Form["DOCUMENTATTACHEDNO"]; if (file == null) { jsonRespose.Success = false; jsonRespose.Message = "上传文件发生未知错误,请重新上传"; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } var path = Server.MapPath("../../UploadFiles/MsOpFiles/" + CUSTNO); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var size = file.ContentLength; var name = Path.GetFileName(file.FileName); name = name.Replace("%","").Replace("&", "").Replace("@", "").Replace("'", "").Replace(" ", "").Replace("?", "").Replace("+", ""); var usercode = Convert.ToString(Session["USERCODE"]); var partname=usercode + DateTime.Now.ToString("yyyyMMddHHmmssfff") + name; string filename = path + "\\"+partname ; string filenameURL = "../../UploadFiles/MsOpFiles/" + CUSTNO + "/" + partname; if (System.IO.File.Exists(filename)) { System.IO.File.Delete(filename); } file.SaveAs(filename); if (!System.IO.File.Exists(filename)) { var json = JsonConvert.Serialize(new { success = false, Message = "上传文件发生未知错误,请重新上传" }); return new ContentResult() { Content = json }; } 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) }; } try { var message = string.Empty; var isSucess = MsOpReceiptDAL.UpdateFileData(filenameURL, name, BSNO, Convert.ToString(Session["USERID"]),TYPE,DOCUMENTATTACHEDCODE,DOCUMENTATTACHEDNO); var json = JsonConvert.Serialize(new { success = isSucess.Success, Message = isSucess.Message, data = filename }); return new ContentResult() { Content = json }; } catch (Exception) { var json = JsonConvert.Serialize(new { success = false, Message = "上传文件出错,请确认文件正确性" }); return new ContentResult() { Content = json }; } } public ContentResult DeleteUploadFile(string data) { int iResult = 0; var bodyList = data; var result = new DBResult(); if (bodyList != "" || bodyList != null) { iResult = MsOpReceiptDAL.DeleteUploadFile(bodyList); } if (iResult == 1) { result.Success = true; result.Message = "删除成功!"; } else if (iResult == 0) { result.Success = false; result.Message = "出现错误,未删除!"; } else if (iResult == -1) { result.Success = false; result.Message = "有异常,删除失败!"; } else if (iResult == -2) { result.Success = false; result.Message = "删除异常,事务已回滚成功!"; } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, // Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult SaveUploadFile(string data) { int iResult = 0; var bodyList = JsonConvert.Deserialize>(data); var result = new DBResult(); if (bodyList != null) { result = MsOpReceiptDAL.UpdateFileData(bodyList, Convert.ToString(Session["USERID"])); } var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, // Data = MsChFeeDAL.GetDataList(headData.BillNo, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } #region 权限设置 public ContentResult GetReceiptOpRang() { var list = MsOpReceiptDAL.GetReceiptOpRang(Convert.ToString(Session["USERID"])); var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = list.ToList() }); return new ContentResult() { Content = json }; } #endregion // } }