C# 报表接口样例,简单实用
阅读原文时间:2023年07月08日阅读:1

//连接视图名称,视图在数据库写好
<%@ WebHandler Language="C#" Class="GetwmsReport" %>

using System;
using System.Drawing;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Web;
using System.Text;
using CloudSaaS.DAL;
using CloudSaaS.Model;
using Newtonsoft.Json;
using CloudSaaS.Common;
using CloudSaaS.DB.Handler;
using Newtonsoft.Json.Linq;

public class GetwmsReport : IHttpHandler
{

public void ProcessRequest(HttpContext context)  
{

    var json = string.Empty;  
      var req = context.Request\["req"\].Trim();  
    string tenantId = HttpContext.Current.Request.Cookies\["tenantID"\].Value;  
    switch(req){  
        case "GetDeliverSum":  
        json = GetDeliverSum(tenantId, context);//当日发货汇总  
        break;  
        case "GetDeliverDetail":  
        json = GetDeliverDetail(tenantId, context);//当日发货明细  
        break;  
        case "GetReceiptSum":  
        json = GetReceiptSum(tenantId, context);//当日收获汇总  
        break;  
        case "GetReceiptDetail":  
        json = GetReceiptDetail(tenantId, context);//当日收货明细  
        break;

    }  
    context.Response.ContentType = "text/json";  
    context.Response.Write(json);  
    context.Response.End();  
    context.Response.Close();

}  

/*--当日收货明细:UV_SYSWMSREPORT_1 --当日发货明细:UV_SYSWMSREPORT_2 --当日收货汇总:UV_SYSWMSREPORT_3 --当日发货汇总:UV_SYSWMSREPORT_4*/
///

///当日发货汇总 ///
///
/// 当日发货汇总
public string GetDeliverSum(string tenantId, HttpContext context)
{
DataTable dt = new DataTable();
StringBuilder strSql = new StringBuilder();
string hetong = context.Request["hetong"]; //摘要
string product = context.Request["product"]; //文件名称
string project = context.Request["project"];
strSql.Append("select * from UV_SYSWMSREPORT_4 where 1=1 ");

    DataSet ds = CloudSaaS.DB.Handler.CloudDB.GetHandler(tenantId).Query(strSql.ToString());  
    if (ds.Tables.Count > 0)  
    {  
        dt = ds.Tables\[0\];  
       // obj.code = "200";  
      //  obj.msg = "操作成功!";  
    }  
    return Newtonsoft.Json.JsonConvert.SerializeObject(dt);  
}

///

///当日发货明细 ///
///
/// 当日发货明细
public string GetDeliverDetail(string tenantId, HttpContext context)
{
DataTable dt = new DataTable();
StringBuilder strSql = new StringBuilder();
string hetong = context.Request["hetong"]; //摘要
string product = context.Request["product"]; //文件名称
string project = context.Request["project"];
strSql.Append("select * from UV_SYSWMSREPORT_2 where 1=1 ");

    DataSet ds = CloudSaaS.DB.Handler.CloudDB.GetHandler(tenantId).Query(strSql.ToString());  
    if (ds.Tables.Count > 0)  
    {  
        dt = ds.Tables\[0\];  
       // obj.code = "200";  
        //obj.msg = "操作成功!";  
    }  
    return Newtonsoft.Json.JsonConvert.SerializeObject(dt);  
}  

///

///当日收货汇总 ///
///
/// 当日收货汇总
public string GetReceiptSum(string tenantId, HttpContext context)
{
DataTable dt = new DataTable();
StringBuilder strSql = new StringBuilder();
string hetong = context.Request["hetong"]; //摘要
string product = context.Request["product"]; //文件名称
string project = context.Request["project"];
strSql.Append("select * from UV_SYSWMSREPORT_3 where 1=1 ");

    DataSet ds = CloudSaaS.DB.Handler.CloudDB.GetHandler(tenantId).Query(strSql.ToString());  
    if (ds.Tables.Count > 0)  
    {  
        dt = ds.Tables\[0\];  
       // obj.code = "200";  
       // obj.msg = "操作成功!";  
    }  
    return Newtonsoft.Json.JsonConvert.SerializeObject(dt);  
}  

///

///当日收货明细 ///
///
/// 当日收货明细
public string GetReceiptDetail(string tenantId, HttpContext context)
{
dynamic obj = new System.Dynamic.ExpandoObject();
obj.code = "1000";
obj.msg="提交时出现错误!";
try {
// DataTable dt = new DataTable();
// dalSYSWMSInputBillHead dal = new dalSYSWMSInputBillHead(tenantId);
StringBuilder strSql = new StringBuilder();
string hetong = context.Request["hetong"]; //摘要
string product = context.Request["product"]; //文件名称
string project = context.Request["project"];
strSql.Append("select * from UV_SYSWMSREPORT_1 where 1=1 ");
/* if (!string.IsNullOrEmpty(hetong))
{
strSql.AppendFormat(" and 合同编号 like '%{0}%'",hetong);
}
// strSql.AppendFormat(" order by 序号 desc");
*/
DataSet ds = CloudSaaS.DB.Handler.CloudDB.GetHandler(tenantId).Query(strSql.ToString());
if (ds.Tables.Count > 0)
{
obj.data = ds.Tables[0];
obj.code = "200";
obj.msg = "操作成功!";
}
}
catch (Exception ex)
{
string strMsg = string.Format("提交时出现错误{0}", ex.Message);
obj.code = "1000";
obj.msg = strMsg;
}
// return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
return JsonConvert.SerializeObject(obj);
}

public bool IsReusable  
{  
    get  
    {  
        return false;  
    }  
}

}