using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    //销售报表Controller
    public class Xs_SeReportController : ApiController
    {
        //销售报表
        
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        #region 销售毛利估算分析报表 查询
        /// 
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        ///  
        [Route("Xs_SeReport/Xs_SeOrderBillProfitReportList")]
        [HttpGet]
        public object Xs_SeOrderBillProfitReportList(string sWhere, string user)
        {
            try
            {
                List columnNameList = new List();
                ds = oCN.RunProcReturn("exec  h_p_Xs_SeOrderBillProfitReport   '" + sWhere + "',''", "h_p_Xs_SeOrderBillProfitReport");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 销售出库汇总报表 查询
        /// 
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        ///  
        [Route("Xs_SeReport/Xs_SellOutStockSumReportList")]
        [HttpGet]
        public object Xs_SellOutStockSumReportList(string sWhere, string user)
        {
            try
            {
                List columnNameList = new List();
                ds = oCN.RunProcReturn("exec  h_p_Xs_SellOutStockSumReport   '" + sWhere + "',''  ", "h_p_Xs_SellOutStockSumReport");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 销售订单执行汇总报表 查询
        /// 
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        ///  
        [Route("Xs_SeReport/Xs_SeOrderBillProcessSumReportList")]
        [HttpGet]
        public object Xs_SeOrderBillProcessSumReportList(string sWhere, string user)
        {
            try
            {
                List columnNameList = new List();
                ds = oCN.RunProcReturn("exec  h_p_Xs_SeOrderBillProcessSumReport    '" + sWhere + "','',''", "h_p_Xs_SeOrderBillProcessSumReport");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
        #region 客户发货及时率报表 查询
        /// 
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        ///  
        [Route("Xs_SeReport/Xs_SeOrderSendDaySumReportList")]
        [HttpGet]
        public object Xs_SeOrderSendDaySumReportList(string sWhere, string user)
        {
            try
            {
                List columnNameList = new List();
                ds = oCN.RunProcReturn("exec  h_p_Xs_SeOrderSendDaySumReport    '" + sWhere + "','',''", "h_p_Xs_SeOrderSendDaySumReport");
                //添加列名
                foreach (DataColumn col in ds.Tables[0].Columns)
                {
                    Type dataType = col.DataType;
                    string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}";
                    columnNameList.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名
                }
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}