using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Web; using System.Web.Mvc; using System.Web.Services; using DSWeb.Areas.CommMng.DAL; using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.RptMng.Comm; using DSWeb.EntityDA; using DSWeb.MvcShipping.Controllers; using DSWeb.MvcShipping.Helper; using HcUtility.Comm; using Newtonsoft.Json; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWebMobileService.Common; namespace DSWebMobileService { /// /// MsRptOpProfitMonth 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。 // [System.Web.Script.Services.ScriptService] public class MsRptOpProfitMonth : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] public static ContentResult SaleListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); /*strSql.AppendLine("SELECT B.SALE"); foreach (var enumValue in monthlist) { strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE end) as ZL" + enumValue.MONTHNO.ToString() + "TTL "); } strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD "); strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB "); strSql.Append(",sum((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE) as ZLTTLTTL ");*/ strSql.AppendLine("select B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.AppendLine("FROM CH_FEE F "); strSql.AppendLine("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.AppendLine(" Where " + condition); } strSql.AppendLine(" Group by B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstring); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE"); } List saleInquData = SetSaleData(strSql); string jsonStr = ""; foreach (SaleModule data in saleInquData) { jsonStr += "{"; jsonStr += "\"SALE\":\"" + data.Sale + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } [WebMethod] public static ContentResult SaleListDataByCondition(string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); /*strSql.AppendLine("SELECT B.SALE"); foreach (var enumValue in monthlist) { strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE end) as ZL" + enumValue.MONTHNO.ToString() + "TTL "); } strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD "); strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB "); strSql.Append(",sum((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE) as ZLTTLTTL ");*/ strSql.AppendLine("select B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.AppendLine("FROM CH_FEE F "); strSql.AppendLine("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.AppendLine(" Where " + condition); } strSql.AppendLine(" Group by B.SALE,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstring); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE"); } List saleInquData = SetSaleData(strSql); string jsonStr = ""; foreach (SaleModule data in saleInquData) { jsonStr += "{"; jsonStr += "\"SALE\":\"" + data.Sale + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } private static List SetSaleData(StringBuilder sql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString())) { while (reader.Read()) { SaleModule data = new SaleModule(); #region Set DB data to Object data.Sale = Convert.ToString(reader["SALE"]); data.OPDate = Convert.ToString(reader["OPDATE"]); data.ZLUsd = Convert.ToString(reader["ZLUSD"]); data.ZLRmb = Convert.ToString(reader["ZLRMB"]); data.ZLTtl = Convert.ToString(reader["ZLTTL"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } [WebMethod] public static ContentResult CustListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); /*strSql.Append("SELECT F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME "); foreach (var enumValue in monthlist) { strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE end) as ZL" + enumValue.MONTHNO.ToString() + "TTL "); } strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD "); strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB "); strSql.Append(",sum((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE) as ZLTTLTTL ");*/ strSql.AppendLine("select F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.Append("FROM CH_FEE F "); strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); //strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),F.CUSTOMERNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstring); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),F.CUSTOMERNAME"); } List custInquData = SetCustData(strSql); string jsonStr = ""; foreach (CustModulle data in custInquData) { jsonStr += "{"; jsonStr += "\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } [WebMethod] public static ContentResult CustListDataByCondition(string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); strSql.AppendLine("select F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.Append("FROM CH_FEE F "); strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),F.CUSTOMERNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstring); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),F.CUSTOMERNAME"); } List custInquData = SetCustData(strSql); string jsonStr=""; foreach (CustModulle data in custInquData) { jsonStr += "{"; jsonStr += "\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } private static List SetCustData(StringBuilder sql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString())) { while (reader.Read()) { CustModulle data = new CustModulle(); #region Set DB data to Object data.CustName = Convert.ToString(reader["CUSTNAME"]); data.OPDate = Convert.ToString(reader["OPDATE"]); data.ZLUsd = Convert.ToString(reader["ZLUSD"]); data.ZLRmb = Convert.ToString(reader["ZLRMB"]); data.ZLTtl = Convert.ToString(reader["ZLTTL"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } [WebMethod] public static ContentResult SaleCustListData(int start, int limit, string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); /*strSql.Append("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME "); foreach (var enumValue in monthlist) { strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE end) as ZL" + enumValue.MONTHNO.ToString() + "TTL "); } strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD "); strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB "); strSql.Append(",sum((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE) as ZLTTLTTL ");*/ strSql.AppendLine("select B.SALE,F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.Append("FROM CH_FEE F "); strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); //strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by B.SALE,F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE,F.CUSTOMERNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.SALE,F.CUSTOMERNAME"); } List saleCustInquData = SetSaleCustData(strSql); string jsonStr = ""; foreach (SaleCustModule data in saleCustInquData) { jsonStr += "{"; jsonStr += "\"SALE\":\"" + data.Sale + "\",\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } [WebMethod] public static ContentResult SaleCustListDataByCondition(string condition, string sort, string printstr, string sortstr, string startmonth, string endmonth) { var strDa = GetRangDAStr("index", Convert.ToString(SessionUtil.Session["USERID"]), Convert.ToString(SessionUtil.Session["SHOWNAME"]), Convert.ToString(SessionUtil.Session["COMPANYID"])); if (!string.IsNullOrEmpty(strDa)) { if (!string.IsNullOrEmpty(condition)) { condition = condition + " and " + strDa; } else { condition = strDa; } } //var monthlist = MsRptOpProfitMonthController.GetMonthList(startmonth, endmonth); var strSql = new StringBuilder(); /*strSql.Append("SELECT B.SALE,F.CUSTOMERNAME AS CUSTNAME "); strSql.Append(",C.[DESCRIPTION] AS CUSTFULLNAME "); foreach (var enumValue in monthlist) { strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "USD "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) else 0 end) as ZL" + enumValue.MONTHNO.ToString() + "RMB "); strSql.Append(",sum(case when SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)='" + enumValue.MONTHFIELDNAME + "' then (F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE end) as ZL" + enumValue.MONTHNO.ToString() + "TTL "); } strSql.Append(",sum(case F.CURRENCY when 'USD' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLUSD "); strSql.Append(",sum(case F.CURRENCY when 'RMB' then (F.AMOUNT-F.SETTLEMENT) else 0 end) as ZLTTLRMB "); strSql.Append(",sum((F.AMOUNT-F.SETTLEMENT)*F.EXCHANGERATE) as ZLTTLTTL ");*/ strSql.AppendLine("select B.SALE,F.CUSTOMERNAME AS CUSTNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) as OPDATE, "); strSql.AppendLine("sum(case F.currency when'USD' then (F.amount-F.settlement) else 0 end) as ZLUSD, "); strSql.AppendLine("sum(case F.currency when'RMB' then (F.amount-F.settlement) else 0 end) as ZLRMB, "); strSql.AppendLine("sum((F.amount-F.settlement)*F.exchangerate) as ZLTTL "); strSql.Append("FROM CH_FEE F "); strSql.Append("INNER JOIN V_OP_BILL B ON (F.BSNO=B.BSNO) "); //strSql.Append(" LEFT JOIN info_client C ON (C.SHORTNAME=F.CUSTOMERNAME) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" Where " + condition); } strSql.Append(" Group by B.SALE,F.CUSTOMERNAME,SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7) "); if ((!string.IsNullOrEmpty(printstr)) && (printstr == "true")) { if (!string.IsNullOrEmpty(sortstr)) { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7)," + sortstr); } else { strSql.Append(" order by SUBSTRING(CONVERT(char(15), B.OPDATE, 111), 1, 7),B.SALE,F.CUSTOMERNAME"); } var jsonRespose = new JsonResponse { Success = true, Message = "完成", Data = strSql.ToString() }; return new ContentResult() { Content = DSWeb.MvcShipping.Helper.JsonConvert.Serialize(jsonRespose) }; } else { var sortstring = DatasetSort.Getsortstring(sort); if (!string.IsNullOrEmpty(sortstring)) { strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by B.SALE,F.CUSTOMERNAME"); } List saleCustInquData = SetSaleCustData(strSql); string jsonStr = ""; foreach (SaleCustModule data in saleCustInquData) { jsonStr += "{"; jsonStr += "\"SALE\":\"" + data.Sale + "\",\"CUSTNAME\":\"" + data.CustName + "\",\"OPDATE\":\"" + data.OPDate + "\",\"ZLRMB\":\"" + data.ZLRmb + "\",\"ZLUSD\":\"" + data.ZLUsd + "\",\"ZLTTL\":\"" + data.ZLTtl + "\""; jsonStr += "},"; } if (jsonStr.Length > 0) { jsonStr = jsonStr.Substring(0, jsonStr.Length - 1); } string result = "[" + jsonStr + "]"; return new ContentResult() { Content = result }; } } private static List SetSaleCustData(StringBuilder sql) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, sql.ToString())) { while (reader.Read()) { SaleCustModule data = new SaleCustModule(); #region Set DB data to Object data.Sale = Convert.ToString(reader["SALE"]); data.CustName = Convert.ToString(reader["CUSTNAME"]); data.OPDate = Convert.ToString(reader["OPDATE"]); data.ZLUsd = Convert.ToString(reader["ZLUSD"]); data.ZLRmb = Convert.ToString(reader["ZLRMB"]); data.ZLTtl = Convert.ToString(reader["ZLTTL"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } private 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]='modMonthProfitreportRange' 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; } } }