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 { /// /// 单车运输明细 /// public class MsRptDjTransController : 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 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.Weight) as Weight"); strSql.Append(",sum(M.RatedFuel) as RatedFuel,sum(M.TonMil) as TonMil,sum(f.Amount) 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.Weight) as Weight"); strSql.Append(",sum(b.RatedFuel) as RatedFuel,sum(b.TonMil) as TonMil "); strSql.Append(" from tMsWlDjPound b group by b.BillNo) as M left join tMsWlPcHead p on (p.Gid=M.BillNo)"); strSql.Append(" left join vPcFeeSum f on (f.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 SetData(StringBuilder strSql) { var headList = new List(); 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.Weight = Convert.ToDecimal(reader["Weight"]); data.TonMil = Convert.ToDecimal(reader["TonMil"]); if (reader["TransTotal"] != DBNull.Value) data.TransTotal = Convert.ToDecimal(reader["TransTotal"]); #endregion headList.Add(data); } reader.Close(); } return headList; } } }