using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using DSWeb.Areas.TruckMng.DAL.MsWlTruck; using DSWeb.Areas.TruckMng.Models; using DSWeb.Areas.TruckMng.Models.MsWlTruck; using DSWeb.Areas.TruckMng.Models.Card; using DSWeb.TruckMng.Comm.Cookie; using DSWeb.TruckMng.Helper; using DSWeb.TruckMng.Helper.Repository; using HcUtility.Comm; using HcUtility.Core; using System.Web; using System.IO; using System.Globalization; using System.Web.Script.Serialization; namespace DSWeb.Areas.TruckMng.Controllers { [JsonRequestBehavior] public class MsWlTruckController : Controller { // // GET: /TruckMng/MsWlTruck public ActionResult Index() { return View(); } // // GET: /TruckMng/MsWlTruck/Edit public ActionResult Edit() { return View(); } // // GET:/TruckMng/MsWlTruck/GetDataList public ContentResult GetDataList(int start, int limit, string sort, string condition) { var dataList = MsWlTruckDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request),sort); var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = list.ToList() }); return new ContentResult() { Content = json }; } // // GET:/TruckMng/MsWlTruck/GetData/ public ContentResult GetData(string handle, string condition) { MsWlTruck head = null; if (handle == "edit") { var list = MsWlTruckDAL.GetDataList(condition, Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); if (list.Count > 0) head = list[0]; } if (head == null) { head = new MsWlTruck(); } var json = JsonConvert.Serialize( new { Success = true, Message = "查询成功", data = head }); return new ContentResult() { Content = json }; } // // GET:/TruckMng/MsWlTruck/Save public ContentResult Save ( string opstatus, string data, string body, string delbody, string Cardbody, string Carddelbody, string TruckMonthbody, string TruckMonthdelbody ) { MsWlTruck head = JsonConvert.Deserialize(data); var bodyList = JsonConvert.Deserialize>(body); var bodyDelList = JsonConvert.Deserialize>(delbody); var CardbodyList = JsonConvert.Deserialize>(Cardbody); var CardbodyDelList = JsonConvert.Deserialize>(Carddelbody); var TruckMonthList = JsonConvert.Deserialize>(TruckMonthbody); var TruckMonthDelList = JsonConvert.Deserialize>(TruckMonthdelbody); if (opstatus == "add") { head.DbOperationType = DbOperationType.DbotIns; head.ModelUIStatus = "I"; head.OrgCode = CookieConfig.GetCookie_OrgCode(Request); } else if (opstatus == "edit") { head.DbOperationType = DbOperationType.DbotUpd; head.ModelUIStatus = "E"; } else { head.DbOperationType = DbOperationType.DbotDel; } var modb = new ModelObjectRepository(); DBResult result = modb.Save(head, ModelObjectConvert.ToModelObjectList(bodyList), ModelObjectConvert.ToModelObjectList(bodyDelList), ModelObjectConvert.ToModelObjectList(CardbodyList), ModelObjectConvert.ToModelObjectList(CardbodyDelList), ModelObjectConvert.ToModelObjectList(TruckMonthList), ModelObjectConvert.ToModelObjectList(TruckMonthDelList) ); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message, Data = MsWlTruckDAL.GetData("TruckNo='" + head.TruckNo + "'", Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)) }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult Delete(string data) { var head = JsonConvert.Deserialize(data); var modb = new ModelObjectDB(); DBResult result = modb.Delete(head); var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message }; return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) }; } public ContentResult GetBodyList(string billno) { var condition = " TruckNo='" + billno + "' "; List list = MsWlTruckDAL.GetBodyList(condition); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() }); return new ContentResult() { Content = json }; } #region 参照部分 public ContentResult GetDrvCodeList() { var list = MsWlTruckDAL.GetDrvCodeList(Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request)); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = list.ToList() }); return new ContentResult() { Content = json }; } #endregion // public ContentResult GetTruckMonthList ( string condition ) { var dataList = MsWlTruckDAL.GetTruckMonthList(condition); //var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } /// /// 获取车辆证件信息 /// /// /// public ContentResult GetTruckCertList ( string TruckNo ) { var dataList = MsWlTruckDAL.GetTruckCertList(TruckNo); //var list = dataList.Skip(start).Take(limit); var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = dataList.Count, data = dataList.ToList() }); return new ContentResult() { Content = json }; } /// /// 上传证件照片 /// /// public ContentResult CertUpload () { 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 imgFile = Request.Files["file"]; var truckNo = Request.Form["TruckNo"].ToString().Trim(); var Cert_Type = Request.Form["Cert_Type"].ToString().Trim(); String strPath = "/Areas/TruckMng/CertImages/"+truckNo+"/"; String dirPath = System.Web.HttpContext.Current.Server.MapPath(strPath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } String fileExt = Path.GetExtension(imgFile.FileName).ToLower(); String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt; String filePath = dirPath + newFileName; imgFile.SaveAs(filePath); //写入数据库 MsWlTruckCert model = new MsWlTruckCert(); model.GID = Guid.NewGuid().ToString(); model.TruckNo = truckNo; model.Pic_Type = Convert.ToInt32(Cert_Type); model.Pic_Name = newFileName; model.Pic_Path = filePath; model.CreateTime = DateTime.Now.ToShortDateString(); model.Operator = Session["USERID"]!=null?Session["USERID"].ToString():""; string msg = ""; bool success= MsWlTruckDAL.SaveTruckCert(model, 0,out msg); jsonRespose.Success = success; jsonRespose.Message = msg; var json = JsonConvert.Serialize(new { success = success, Message = "上传成功", filePath = filePath }); return new ContentResult() { Content = json }; } public ContentResult CertDel ( string TruckNo ) { var data = Request["data"]; JavaScriptSerializer json = new JavaScriptSerializer(); List cert = json.Deserialize>(data); DBResult result = null; string msg = ""; bool rst = false; if (cert != null) { rst=MsWlTruckDAL.DelTruckCert(cert,out msg); } var jsonstr = JsonConvert.Serialize(new { Success = rst, Message = rst ? "删除成功" : msg }); return new ContentResult() { Content = jsonstr }; } } }