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 { /// /// 利润报表查询 /// [JsonRequestBehavior] public class MsRptOpHdProfitController : Controller { // // GET: /MvcShipping/MsRptOpProfit public ActionResult Index() { return View(); } // // GET:/RptMng/MsRptPcHeadQry/QryData public ContentResult BsListData(int start, int limit, string condition,string sort,string printstr,string sortstr,string amendstr="false") { var strDa = GetRangDAStr("index", Convert.ToString(Session["USERID"]), Convert.ToString(Session["SHOWNAME"]), Convert.ToString(Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } var strSql = new StringBuilder(); if (amendstr == "true") { strSql.Append("SELECT B.BSNO, B.OPLB,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,"); strSql.Append("B.ETD,B.PKGS,B.CBM,B.NETWEIGHT,B.BLFRT"); strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.TRADETERM,B.CONSIGNEE,B.DESTINATION,B.MBLFRT,B.CNTRSEALNO,B.VESSEL2N,B.VOYNO2N,B.ETA"); strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF"); strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.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BCR) RMBPROFIT,(G.USDDR-G.USDCR) USDPROFIT,(G.RMBCR-G.RMBDZFCR-G.RMBDCDL1CR-G.RMBDCDL2CR-G.RMBDCDL3CR-G.RMBBGF1CR-G.RMBBGF2CR-G.RMBLYF1CR-G.RMBLYF2CR-G.RMBLYF3CR-G.RMBCD1CR-G.RMBCD2CR-G.RMBCD3CR-G.RMBBXFCR-G.RMBCZF1CR-G.RMBCZF2CR-G.RMBCZF3CR-G.RMBCCCR) RMBOTCR"); strSql.Append(" FROM v_op_SEA B "); // strSql.Append("LEFT JOIN V_OP_BILL A ON (A.PARENTID=B.BSNO) "); strSql.Append("LEFT JOIN v_op_gain_BLHD G ON (G.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } } else { strSql.Append("SELECT B.BSNO, B.OPLB,B.OPTYPE,B.OPLBNAME, B.BSTYPE,B.CUSTOMERNAME, B.CUSTNO, B.MBLNO, B.HBLNO,B.VESSEL, B.VOYNO, B.INPUTBY, B.CREATETIME, B.BSSTATUS, B.SALE, B.OP, B.DOC,"); strSql.Append("B.ETD,B.PKGS,B.CBM,B.NETWEIGHT,B.BLFRT"); strSql.Append(",B.OPDATE,B.ENTERP,B.REMARK,B.TRADETERM,B.CONSIGNEE,B.DESTINATION,B.MBLFRT,B.CNTRSEALNO,B.VESSEL2N,B.VOYNO2N,B.ETA"); strSql.Append(",case B.FEESTATUS when 1 then '锁定' else '未锁定' end as FEESTATUSREF"); strSql.Append(",B.CUSTSERVICE, B.PORTLOAD, B.PORTDISCHARGE, B.CUSTOMNO, B.ACCDATE,B.CARRIER, B.BSSOURCE, B.LANE, B.FORWARDER,B.CNTRTOTAL,B.CORPID"); strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR1 ELSE 0 END) CNTR1,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR2 ELSE 0 END) CNTR2,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR3 ELSE 0 END) CNTR3"); strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR4 ELSE 0 END) CNTR4,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR5 ELSE 0 END) CNTR5,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR6 ELSE 0 END) CNTR6"); strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR7 ELSE 0 END) CNTR7,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR8 ELSE 0 END) CNTR8,(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR9 ELSE 0 END) CNTR9"); strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.CNTR10 ELSE 0 END) CNTR10,(CASE WHEN B.OPTYPE='普通货' THEN B.OTCNTR ELSE 0 END) OTCNTR"); strSql.Append(",(CASE WHEN B.OPTYPE='普通货' THEN B.NETWEIGHT ELSE 0 END) NETWEIGHT,(CASE WHEN B.OPTYPE='普通货' THEN B.KGS ELSE 0 END) KGS,(CASE WHEN B.OPTYPE='普通货' THEN B.TEU ELSE 0 END) TEU"); strSql.Append(",B.TRADETYPE,B.GOODSNAME,B.FEESTATUS"); strSql.Append(",G.USDHYFDR,G.USDHYFCCDR,G.USDDR,G.RMBGZDR,G.RMBLYFDR,G.RMBCCDR,G.RMBCCCR,G.RMBDR,G.USDDCDL1CROBJ,G.USDDCDL1CR,G.USDDCDL2CROBJ,G.USDDCDL2CR,G.USDHYFCCCR,G.USDKODAICR,G.USDDZFCR,G.RMBDZFCR,G.RMBDCDL1CROBJ,G.RMBDCDL1CR"); strSql.Append(",G.RMBDCDL2CROBJ,G.RMBDCDL2CR,G.RMBDCDL3CROBJ,G.RMBDCDL3CR,G.RMBCZF1CROBJ,G.RMBCZF1CR,G.RMBCZF2CROBJ,G.RMBCZF2CR,G.RMBCZF3CROBJ,G.RMBCZF3CR,RMBBGF1CR,RMBBGF1CROBJ,RMBBGF2CR,RMBBGF2CROBJ"); strSql.Append(",G.RMBLYF1CROBJ,G.RMBLYF1CR,G.RMBLYF2CROBJ,G.RMBLYF2CR,G.RMBLYF3CROBJ,G.RMBLYF3CR,G.RMBCD1CROBJ,G.RMBCD1CR,G.RMBCD2CROBJ,G.RMBCD2CR,G.RMBCD3CROBJ,G.RMBCD3CR,G.RMBBXFCR,G.RMBBXFCROBJ,G.RMBCR,G.USDCR"); strSql.Append(",(G.RMBDZFCR+G.RMBDCDL1CR+G.RMBDCDL2CR+G.RMBDCDL3CR+G.RMBBGF1CR+G.RMBBGF2CR+G.RMBLYF1CR+G.RMBLYF2CR+G.RMBLYF3CR+G.RMBCD1CR+G.RMBCD2CR+G.RMBCD3CR+G.RMBBXFCR+G.RMBCZF1CR+G.RMBCZF2CR+G.RMBCZF3CR+G.RMBCCCR) RMBSUBTTLCR"); strSql.Append(",(G.RMBDR-G.RMBCR) RMBPROFIT,(G.USDDR-G.USDCR) USDPROFIT,(G.RMBCR-G.RMBDZFCR-G.RMBDCDL1CR-G.RMBDCDL2CR-G.RMBDCDL3CR-G.RMBBGF1CR-G.RMBBGF2CR-G.RMBLYF1CR-G.RMBLYF2CR-G.RMBLYF3CR-G.RMBCD1CR-G.RMBCD2CR-G.RMBCD3CR-G.RMBBXFCR-G.RMBCZF1CR-G.RMBCZF2CR-G.RMBCZF3CR-G.RMBCCCR) RMBOTCR"); strSql.Append(" FROM v_op_SEA B "); strSql.Append("LEFT JOIN v_op_gain_HD G ON (G.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } } if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by " + sortstr); } else { strSql.Append(" order by B.ETD DESC,B.MBLNO,B.OPTYPE DESC"); } 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.ETD DESC,B.MBLNO,B.OPTYPE DESC"); } var dbparams = new List(); 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 } }