using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.TruckMng.DAL.MsWlDjPc;
using DSWeb.Areas.TruckMng.Models.Comm;
using DSWeb.Areas.TruckMng.Models.MsWlDjPc;
using DSWeb.TruckMng.Comm.Cookie;
using DSWeb.TruckMng.Helper;
using DSWeb.TruckMng.Helper.Repository;
using HcUtility.Comm;
using HcUtility.Core;
using DSWeb.SoftMng.Filter;
namespace DSWeb.Areas.TruckMng.Controllers
{
///
/// 配件申领单
///
[JsonRequestBehavior]
public class MsWlDjPcController : Controller
{
//
// GET: /TruckMng/MsWlDjPc/
public ActionResult Index()
{
return View();
}
//
// GET: /TruckMng/MsWlDjPc/Edit
public ActionResult Edit()
{
return View();
}
//
// GET:/TruckMng/MsWlDjPc/GetDataList
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var sqlwhere = condition;
if (!string.IsNullOrEmpty(condition))
sqlwhere += " and ";
sqlwhere += " PcBillType='2'";
var dataList = MsWlDjPcDAL.GetDataList(sqlwhere,Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
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/MsWlDjPc/GetData/
[SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器
public ContentResult GetData(string handle, string condition)
{
MsWlPcHead headData = null;
if (handle == "edit")
{
var list = MsWlDjPcDAL.GetDataList(condition,Convert.ToString(Session["USERID"]), CookieConfig.GetCookie_UserCode(Request), CookieConfig.GetCookie_OrgCode(Request));
if (list.Count > 0)
headData = list[0];
}
if (headData == null)
{
headData = new MsWlPcHead();
}
var json = JsonConvert.Serialize(
new { Success = true, Message = "查询成功", data = headData });
return new ContentResult() { Content = json };
}
public ContentResult GetBodyList(string billno)
{
var condition = " BillNo='" + billno + "' ";
List list = MsWlDjPcDAL.GetBodyList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
public ContentResult GetFeeFixBodyList(string billno)
{
var condition = " BillNo='" + billno + "'";
List list = MsWlDjPcDAL.GetFixBodyList(condition);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", totalCount = list.Count, data = list.ToList() });
return new ContentResult() { Content = json };
}
//
// GET:/TruckMng/MsWlDjPc/Save
public ContentResult Save(string opstatus, string data, string poundbody, string pounddelbody,
string fixbody, string fixdelbody, string chfeebody, string chfeedelbody)
{
var head = JsonConvert.Deserialize(data);
var poundBodyList = JsonConvert.Deserialize>(poundbody);
var poundBodyDelList = JsonConvert.Deserialize>(pounddelbody);
var fixBodyList = JsonConvert.Deserialize>(fixbody);
var fixBodyDelList = JsonConvert.Deserialize>(fixdelbody);
var chfeeBodyList = JsonConvert.Deserialize>(chfeebody);
var chfeeBodyDelList = JsonConvert.Deserialize>(chfeedelbody);
head.TotalMil = head.NoLoadMil + head.OverLoadMil;
if (opstatus == "add")
{
head.BillNo = PubSysDAL.GetBillNo("0111");
head.DbOperationType = DbOperationType.DbotIns;
head.ModelUIStatus = "I";
head.UserCode = CookieConfig.GetCookie_UserCode(Request);
head.UserName = CookieConfig.GetCookie_UserName(Request);
head.OrgCode = CookieConfig.GetCookie_OrgCode(Request);
head.OrgName = CookieConfig.GetCookie_OrgName(Request);
head.LrDate = DateTime.Now;
}
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(poundBodyList),
ModelObjectConvert.ToModelObjectList(poundBodyDelList)
);
*/
DBResult result = modb.Save(head,
ModelObjectConvert.ToModelObjectList(poundBodyList),
ModelObjectConvert.ToModelObjectList(poundBodyDelList),
ModelObjectConvert.ToModelObjectList(fixBodyList),
ModelObjectConvert.ToModelObjectList(fixBodyDelList),
ModelObjectConvert.ToModelObjectList(chfeeBodyList),
ModelObjectConvert.ToModelObjectList(chfeeBodyDelList));
var jsonRespose = new JsonResponse
{
Success = result.Success,
Message = result.Message,
Data = MsWlDjPcDAL.GetHeadDataByBillNo(head.BillNo, 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 ModelObjectDBBill();
DBResult result = modb.Delete(head,
"delete from tMsWlDjPound where BillNo='" + head.BillNo + "'",
"delete from tMsWlBsFixed where BillNo='" + head.BillNo + "'",
"delete from ch_fee where BsNo='" + head.GId + "'");
var jsonRespose = new JsonResponse { Success = result.Success, Message = result.Message };
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
#region 参照部分
public ContentResult GetTruckNoList(string condition)
{
var list = MsWlDjPcDAL.GetTruckNoList(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 };
}
public ContentResult GetDrvNameList(string condition)
{
var list = MsWlDjPcDAL.GetDrvNameList(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 };
}
public ContentResult GetDjBillNoList(string condition)
{
var list = MsWlDjPcDAL.GetDjBillNoList(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 };
}
public ContentResult GetTruckFuel(string truckNo, string loadType, decimal ton, decimal mil)
{
var fuel = MsWlDjPcDAL.GetTruckFuel(truckNo, loadType, ton, mil);
var json = JsonConvert.Serialize(new { Success = true, Message = "查询成功", data = fuel });
return new ContentResult() { Content = json };
}
#endregion
}
}