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.Import.Models.RptProfit; using DSWeb.TruckMng.Helper; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.Areas.CommMng.Models; using DSWeb.SoftMng.Filter; namespace DSWeb.Areas.Import.Controllers { /// /// 应收/实收 应付/实付 列表 /// public class RptProfitController : Controller { // // GET: /Import/RptFeeTotal/ public ActionResult Index() { return View(); } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 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 }; } [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 private static List GetDataList(string strCondition,string sort) { var strSql = new StringBuilder(); strSql.Append(" select m.HTH,t1.* into #t from ( "); strSql.Append(" select gid,bsno ContractNo,customername,feetype,feename, "); strSql.Append(" case feetype when 1 then convert(numeric(18,2),amount*c.exchangerate) else 0 end ys, "); strSql.Append(" case feetype when 2 then amount*c.exchangerate else 0 end yf, "); strSql.Append(" 0 y, "); strSql.Append(" case feetype when 1 then convert(numeric(18,2),settlement*c.exchangerate) else 0 end ss, "); strSql.Append(" case feetype when 2 then settlement*c.exchangerate else 0 end sf, "); strSql.Append(" 0 s, "); strSql.Append(" case feetype when 1 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end ys_ref, "); strSql.Append(" case feetype when 2 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end yf_ref,'' y_ref, "); strSql.Append(" case feetype when 1 then convert(varchar,convert(numeric(18,2),settlement*c.exchangerate)) else '' end ss_ref, "); strSql.Append(" case feetype when 2 then convert(varchar,convert(numeric(18,2),settlement*c.exchangerate)) else '' end sf_ref, "); strSql.Append(" '' s_ref, "); strSql.Append(" dbo.trimdate(enterdate) [feedate],c.remark,Currency from ch_fee c "); strSql.Append(" left join import_main m on m.contractno=c.bsno "); strSql.Append(" where feestatus in(0,1,2,8,9) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" union all select gid,bsno ContractNo,customername,feetype,feename, "); strSql.Append(" case feetype when 1 then convert(numeric(18,2),amount*c.exchangerate) else 0 end ys, "); strSql.Append(" case feetype when 2 then amount*c.exchangerate else 0 end yf, "); strSql.Append(" 0 y, "); strSql.Append(" case feetype when 1 then convert(numeric(18,2),settlement*c.exchangerate) else 0 end ss, "); strSql.Append(" case feetype when 2 then settlement*c.exchangerate else 0 end sf, "); strSql.Append(" 0 s, "); strSql.Append(" case feetype when 1 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end ys_ref, "); strSql.Append(" case feetype when 2 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end yf_ref,'' y_ref, "); strSql.Append(" case feetype when 1 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end ss_ref, "); strSql.Append(" case feetype when 2 then convert(varchar,convert(numeric(18,2),amount*c.exchangerate)) else '' end sf_ref, "); strSql.Append(" '' s_ref, "); strSql.Append(" dbo.trimdate(enterdate) [feedate],c.remark,Currency from ch_fee c "); strSql.Append(" left join import_main m on m.contractno=c.bsno "); strSql.Append(" where feestatus in(10,11) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } strSql.Append(" ) t1 left join import_main m on m.contractno=t1.ContractNo "); strSql.Append(" order by t1.ContractNo ,t1.[feedate] "); strSql.Append(" select gid,ContractNo,hth,customername,feetype,feename,ys,yf,y,ss,sf,s,ys_ref,yf_ref,y_ref "); strSql.Append(" ,ss_ref,sf_ref,s_ref,feedate,remark,'' ZJY from #t union all "); strSql.Append(" select '','y',#T.hth,'到港日'+dbo.trimdate(m.ArrivalDate) [ArrivalDate],3,'小计' feename, "); strSql.Append(" 0,0,0,0,0,0,convert(varchar,convert(numeric(18,2),sum(ys))),convert(varchar,convert(numeric(18,2),sum(yf))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(ys)-sum(yf)))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),sum(ss))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),sum(sf))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(ss)-sum(sf)))), "); strSql.Append(" '应收节余:'+convert(varchar,convert(numeric(18,2),(sum(ys)-sum(ss)))), "); strSql.Append(" '应付节余:'+convert(varchar,convert(numeric(18,2),(sum(yf)-sum(sf)))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(isnull(ys,0))-sum(isnull(ss,0))))-convert(numeric(18,2),(sum(isnull(yf,0))-sum(isnull(sf,0))))) "); strSql.Append(" from #t left join import_main m on m.contractno=#t.ContractNo "); strSql.Append(" group by #t.hth,creattime,arrivaldate union all "); strSql.Append(" select '','z','总计','',4,'' feename, "); strSql.Append(" 0,0,0,0,0,0,convert(varchar,convert(numeric(18,2),sum(ys))),convert(varchar,convert(numeric(18,2),sum(yf))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(ys)-sum(yf)) ) ), "); strSql.Append(" convert(varchar,convert(numeric(18,2),sum(ss))), convert(varchar,convert(numeric(18,2),sum(sf))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(ss)-sum(sf)))), "); strSql.Append(" '应收节余:'+convert(varchar,convert(numeric(18,2),(sum(ys)-sum(ss)))), "); strSql.Append(" '应付节余:'+convert(varchar,convert(numeric(18,2),(sum(yf)-sum(sf)))), "); strSql.Append(" convert(varchar,convert(numeric(18,2),(sum(isnull(ys,0))-sum(isnull(ss,0))))-convert(numeric(18,2),(sum(isnull(yf,0))-sum(isnull(sf,0))))) "); strSql.Append(" from #t left join import_main m on m.contractno=#t.ContractNo "); var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { if (sortstring != " HTH ASC") { strSql.Append(" order by HTH," + sortstring); } else { strSql.Append(" order by HTH,contractno,customername,feename,FeeDate "); } }else{ strSql.Append(" order by HTH,contractno,customername,feename,FeeDate "); } strSql.Append(" drop table #t "); 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 RptProfitmb(); #region Set DB data to Object data.gid = Convert.ToString(reader["gid"]); data.ContractNo = Convert.ToString(reader["ContractNo"]); data.HTH = Convert.ToString(reader["HTH"]); data.CustomerName = Convert.ToString(reader["CustomerName"]); data.FeeType = Convert.ToString(reader["FeeType"]); data.FeeName = Convert.ToString(reader["FeeName"]); data.ys_ref = Convert.ToString(reader["ys_ref"]); data.yf_ref = Convert.ToString(reader["yf_ref"]); data.y_ref = Convert.ToString(reader["y_ref"]); data.ss_ref = Convert.ToString(reader["ss_ref"]); data.sf_ref = Convert.ToString(reader["sf_ref"]); data.s_ref = Convert.ToString(reader["s_ref"]); data.FeeDate = Convert.ToString(reader["FeeDate"]); //data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]); data.Remark = Convert.ToString(reader["Remark"]); data.ZJY = Convert.ToString(reader["ZJY"]); #endregion headList.Add(data); } reader.Close(); } return headList; } } }