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/MvcShipping/Controllers/MsRptHcTotalController.cs

356 lines
13 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.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.MvcShipping.Helper;
using DSWeb.MvcShipping.Comm.Cookie;
using DSWeb.Areas.CommMng.DAL;
using DSWeb.Areas.RptMng.Comm;
using HcUtility.Comm;
using HcUtility.Core;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using DSWeb.MvcShipping.DAL.MsSysParamSet;
namespace DSWeb.MvcShipping.Controllers
{
/// <summary>
///
/// </summary>
[JsonRequestBehavior]
public class MsRptHcTotalController : Controller
{
//
// GET: /MvcShipping/MsRptOpProfit
public ActionResult Index()
{
return View();
}
//
// GET/RptMng/MsRptPcHeadQry/QryData
public ContentResult CtnListData(int start, int limit, string bgnetd,string endetd,string sort,string printstr,string sortstr)
{
var condition = " B.ETD>='" + bgnetd + "' AND B.ETD<='" + endetd + "'";
var strSql = new StringBuilder();
strSql.Append("SELECT B.OPLBNAME, B.SALE, B.CUSTOMERNAME,COUNT(B.BSNO) AS BLCOUNT,SUM(CASE WHEN B.OPTYPE='更改单' THEN 1 ELSE 0 END) AMENDCOUNT");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' AND C.SIZE='20' THEN 1 ELSE 0 END) CTN20 ");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' AND C.SIZE='40' THEN 1 ELSE 0 END) CTN40 ");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' AND C.SIZE='45' THEN 1 ELSE 0 END) CTN45 ");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' AND B.BLTYPE='拼箱单票' OR B.BLTYPE='拼箱分票' THEN B.CBM ELSE 0 END) CBM ");
strSql.Append(",SUM(CASE WHEN B.OPTYPE='普通货' AND B.OPLBNAME='空运出口' OR B.OPLBNAME='空运进口' THEN B.KGS ELSE 0 END) KGS ");
strSql.Append(",dbo.GetOpCount(B.OPLBNAME,B.SALE,B.CUSTOMERNAME,'" + bgnetd + "','" + endetd + "') OPTTLSTR ");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN OP_CTN C ON (C.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" GROUP BY B.OPLBNAME, B.SALE,B.CUSTOMERNAME");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.OPLBNAME,B.CUSTOMERNAME,B.SALE ");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = condition,
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.OPLBNAME,B.CUSTOMERNAME,B.SALE");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult OpListData(int start, int limit, string condition, string sort, string printstr,string sortstr)
{
var strSql = new StringBuilder();
strSql.Append("SELECT B.OP");
strSql.Append(",sum(case when SERVICECONTRACTNO='1' and (substring(CUSTNO,1,1)='H' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) LOCAL1 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0.5' and (substring(CUSTNO,1,1)='H' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) LOCAL05 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0.2' and (substring(CUSTNO,1,1)='H' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) LOCAL02 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0' and (substring(CUSTNO,1,1)='H' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) LOCAL0 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='1' and (substring(CUSTNO,1,1)='N' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) OTHER1 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0.5' and (substring(CUSTNO,1,1)='N' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) OTHER05 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0.2' and (substring(CUSTNO,1,1)='N' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) OTHER02 ");
strSql.Append(",sum(case when SERVICECONTRACTNO='0' and (substring(CUSTNO,1,1)='N' or substring(CUSTNO,1,1)='T' ) then 1 else 0.0 end) OTHER0 ");
strSql.Append(" FROM V_OP_BILL B ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" GROUP BY B.OP");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.OP");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.OP ");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public ContentResult TruckCustomListData(int start, int limit, string condition, string sort, string printstr, string sortstr)
{
var strSql = new StringBuilder();
strSql.Append("SELECT CASE WHEN substring(CUSTNO,1,1)='N' THEN '宁波' ELSE '青岛' END PORT,B.OPLBNAME, F.CUSTOMERNAME, SUM(F.AMOUNT) AMOUNT,SUM(B.TEU) TEU");
strSql.Append(",(SELECT SUM(TEU) FROM V_OP_BS b LEFT JOIN V_TRUCKCUSTOMFEE F ON (F.BSNO=b.BSNO) WHERE substring(b.CUSTNO,1,1)<>'N' AND " + condition + ") TTLTEUQ ");
strSql.Append(",(SELECT SUM(TEU) FROM V_OP_BS b LEFT JOIN V_TRUCKCUSTOMFEE F ON (F.BSNO=b.BSNO) WHERE substring(b.CUSTNO,1,1)='N' AND " + condition + ") TTLTEUN ");
strSql.Append(" FROM V_OP_BILL B ");
strSql.Append("LEFT JOIN V_TRUCKCUSTOMFEE F ON (F.BSNO=B.BSNO) ");
if (!string.IsNullOrEmpty(condition))
{
strSql.Append(" Where " + condition);
}
strSql.Append(" Group by CASE WHEN substring(CUSTNO,1,1)='N' THEN '宁波' ELSE '青岛' END,B.OPLBNAME, F.CUSTOMERNAME ");
if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true"))
{
if (!string.IsNullOrEmpty(sortstr))
{
strSql.Append(" order by " + sortstr);
}
else
{
strSql.Append(" order by B.OPLBNAME, F.CUSTOMERNAME");
}
var jsonRespose = new JsonResponse
{
Success = true,
Message = "完成",
Data = strSql.ToString()
};
return new ContentResult() { Content = JsonConvert.Serialize(jsonRespose) };
}
else
{
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by B.OPLBNAME, F.CUSTOMERNAME");
}
var dbparams = new List<CustomDbParamter>();
var paramps_sSQL = new CustomDbParamter();
paramps_sSQL.ParameterName = "@sSQL";
paramps_sSQL.DbType = DbType.String;
paramps_sSQL.Direction = ParameterDirection.Input;
paramps_sSQL.Value = strSql.ToString();
dbparams.Add(paramps_sSQL);
var dbRptResult = PubSysDAL.GetMsSqlPrcDataSet("sMsExesqlQry", dbparams, "Result_Set");
var json = RptHelper.GetRptJsonResult(start, limit, dbRptResult, "Result_Set", true);
return new ContentResult() { Content = json };
}
}
public static string GetRangDAStr(string tb, string userid, string usercode, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" VISIBLERANGE,OPERATERANGE ");
strSql.Append(" from VW_User_Authority ");
strSql.Append(" where [NAME]='modProfitreportRange' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = "1=2";
}
else if (visiblerange == "3")
{
str = " (B.OP='" + usercode + "' OR B.SALE='" + usercode + "')";
}
else if (visiblerange == "2")
{
if (tb == "index")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
var userstr = new StringBuilder();
userstr.Append(" select SHOWNAME from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
str = str + " or B.OP='" + Convert.ToString(reader["SHOWNAME"]) + "' OR B.SALE='" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
str =str+ ")";
reader.Close();
}
}
else
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
}
else if (visiblerange == "1")
{
str = " UPPER(B.Corpid)='" + companyid + "'";
}
return str;
}
#region 参照部分
#endregion
}
}