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/Areas/RptMng/Controllers/MsRptBulkTransController.cs

103 lines
4.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.Areas.RptMng.Models;
using DSWeb.TruckMng.Helper;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.Areas.CommMng.Models;
namespace DSWeb.Areas.RptMng.Controllers
{
/// <summary>
/// 单车运输明细
/// </summary>
public class MsRptBulkTransController : Controller
{
//
// GET: /RptMng/MsRptBulkTrans/
public ActionResult Index()
{
return View();
}
public ContentResult GetDataList(int start, int limit, string sort, string condition)
{
var dataList = GetDataList(condition,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 };
}
private static List<MsRptBulkTrans> GetDataList(string strCondition,string sort=null)
{
var strSql = new StringBuilder();
strSql.Append("SELECT p.TruckNo,sum(p.FuelQty) as FuelQty, sum(M.RealMil) as RealMil ");
strSql.Append(",sum(M.OverLoadMil) as OverLoadMil,sum(M.NoLoadMil) as NoLoadMil ");
strSql.Append(",sum(M.LoadCount) as LoadCount,sum(M.UnLoadCount) as UnLoadCount,sum(M.Weight) as Weight");
strSql.Append(",sum(M.RatedFuel) as RatedFuel,sum(M.TonMil) as TonMil,sum(M.TransTotal) as TransTotal from ");
strSql.Append("(SELECT b.BillNo,sum(b.OverLoadMil+b.NoLoadMil) as RealMil ");
strSql.Append(",sum(b.OverLoadMil) as OverLoadMil,sum(b.NoLoadMil) as NoLoadMil");
strSql.Append(",sum(b.LoadCount) as LoadCount,sum(b.UnLoadCount) as UnLoadCount,sum(b.Weight) as Weight");
strSql.Append(",sum(b.RatedFuel) as RatedFuel,sum(b.TonMil) as TonMil,sum(b.TransTotal) as TransTotal ");
strSql.Append(" from tMsWlBulkPound b group by b.BillNo) as M left join tMsWlPcHead p on (p.BillNo=M.BillNo)");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(" group by p.TruckNo ");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
return SetData(strSql);
}
private static List<MsRptBulkTrans> SetData(StringBuilder strSql)
{
var headList = new List<MsRptBulkTrans>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
var data = new MsRptBulkTrans();
#region Set DB data to Object
data.TruckNo = Convert.ToString(reader["TruckNo"]);
// data.ExpDate = Convert.ToString(reader["ExpDate"]);
data.RealMil = Convert.ToDecimal(reader["RealMil"]);
data.OverLoadMil = Convert.ToDecimal(reader["OverLoadMil"]);
data.NoLoadMil = Convert.ToDecimal(reader["NoLoadMil"]);
data.RatedFuel = Convert.ToDecimal(reader["RatedFuel"]);
if (reader["FuelQty"] != DBNull.Value)
data.FuelQty = Convert.ToDecimal(reader["FuelQty"]);
data.LoadCount = Convert.ToDecimal(reader["LoadCount"]);
data.UnLoadCount = Convert.ToDecimal(reader["UnLoadCount"]);
data.Weight = Convert.ToDecimal(reader["Weight"]);
data.TonMil = Convert.ToDecimal(reader["TonMil"]);
data.TransTotal = Convert.ToDecimal(reader["TransTotal"]);
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
}
}