You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/TruckMng/Controllers/MsWlTruckController.cs

253 lines
9.7 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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<MsWlTruck>(data);
var bodyList = JsonConvert.Deserialize<List<MsWlTruckFuel>>(body);
var bodyDelList = JsonConvert.Deserialize<List<MsWlTruckFuel>>(delbody);
var CardbodyList = JsonConvert.Deserialize<List<CardHeadmb>>(Cardbody);
var CardbodyDelList = JsonConvert.Deserialize<List<CardHeadmb>>(Carddelbody);
var TruckMonthList = JsonConvert.Deserialize<List<TruckMonthmb>>(TruckMonthbody);
var TruckMonthDelList = JsonConvert.Deserialize<List<TruckMonthmb>>(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<MsWlTruckFuel>.ToModelObjectList(bodyList),
ModelObjectConvert<MsWlTruckFuel>.ToModelObjectList(bodyDelList),
ModelObjectConvert<CardHeadmb>.ToModelObjectList(CardbodyList),
ModelObjectConvert<CardHeadmb>.ToModelObjectList(CardbodyDelList),
ModelObjectConvert<TruckMonthmb>.ToModelObjectList(TruckMonthList),
ModelObjectConvert<TruckMonthmb>.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<MsWlTruck>(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<MsWlTruckFuel> 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 };
}
/// <summary>
/// 获取车辆证件信息
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
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 };
}
/// <summary>
/// 上传证件照片
/// </summary>
/// <returns></returns>
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<MsWlTruckCert> cert = json.Deserialize<List<MsWlTruckCert>>(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 };
}
}
}