duhe
2024-02-26 334e9d99031f076b5379a0b3215b4db264358e49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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;
using System.IO;
using System.Web;
using WebAPI.Controllers.SCGL.日计划管理;
 
namespace WebAPI.Controllers
{
    //客户余额查询报表Controller
    public class Xs_CusBalanceReportController : ApiController
    {
        //获取系统参数
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
 
        #region 客户余额查询报表 查询
        /// <summary>
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("Xs_CusBalanceReport/list")]
        [HttpGet]
        public object getXs_CusBalanceReport(string sWhere, string user)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                ////查看权限
                if (!DBUtility.ClsPub.Security_Log("Xs_CusBalanceReport_Query", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无查看权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                //获取客户
                if (sWhere == null || sWhere.Equals(""))
                {
                    string sql = "select a.HItemID HCusID,a.HNumber HCusNumber,a.HName HCusName,b.HItemID HCurID,b.HName HCurName " +
                        " from Gy_Customer as a " +
                        " left join Gy_Currency as b on a.HCurID = b.HItemID " +
                        " order by a.HNumber ";
                    ds = oCN.RunProcReturn(sql, "Gy_Customer");
                }
                else
                {
                    string sql1 = "select a.HItemID HCusID,a.HNumber HCusNumber,a.HName HCusName,b.HItemID HCurID,b.HName HCurName " +
                        " from Gy_Customer as a " +
                        " inner join Gy_Currency as b on a.HCurID = b.HItemID " +
                        " where 1=1  ";
                    string sql = sql1 + sWhere + " order by a.HNumber ";
                    ds = oCN.RunProcReturn(sql, "Gy_Customer");
                }
 
                //创建临时表
                DataTable tb2 = new DataTable("dt2");
                //模板缺少列 但需要从数据库中查询出来显示在页面的字段
                tb2.Columns.Add("客户内码", typeof(string));
                tb2.Columns.Add("客户代码", typeof(string));
                tb2.Columns.Add("客户名称", typeof(string));
                tb2.Columns.Add("币别内码", typeof(string));
                tb2.Columns.Add("币别名称", typeof(string));
                tb2.Columns.Add("客户余额", typeof(string));
                tb2.Columns.Add("占用额度", typeof(string));
                tb2.Columns.Add("可用额度", typeof(string));
 
                for(int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    string HCusID = ds.Tables[0].Rows[i]["HCusID"].ToString();
                    string HCusNumber = ds.Tables[0].Rows[i]["HCusNumber"].ToString();
                    string HCusName = ds.Tables[0].Rows[i]["HCusName"].ToString();
                    string HCurID = ds.Tables[0].Rows[i]["HCurID"].ToString();
                    string HCurName = ds.Tables[0].Rows[i]["HCurName"].ToString();
 
                    //获取对应客户的客户余额、信用额度、可用余额
                    string sql = "exec Xs_CusBalanceReport_Query " + HCusID;
                    DataSet ds2 = oCN.RunProcReturn(sql, "Xs_CusBalanceReport_Query");
                    if (ds2 == null||ds2.Tables.Count==0)
                    {
                        objJsonResult.code = "0";
                        objJsonResult.count = 0;
                        objJsonResult.Message = "Exception!未获取到对应客户[" + HCusNumber + "][" + HCusName + "]的余额信息!!";
                        objJsonResult.data = null;
                        return objJsonResult;
                    }
 
                    if (Double.Parse(ds2.Tables[0].Rows[0]["HCusBalance"].ToString()) <= 0)
                    {
                        continue;
                    }
 
                    //向临时表插入数据
                    DataRow row = tb2.NewRow();
                    row[0] = HCusID;
                    row[1] = HCusNumber;
                    row[2] = HCusName;
                    row[3] = HCurID;
                    row[4] = HCurName;
                    row[5] = ds2.Tables[0].Rows[0]["HCusBalance"].ToString();
                    row[6] = Double.Parse(ds2.Tables[0].Rows[0]["HCusBalance"].ToString()) + Double.Parse(ds2.Tables[0].Rows[0]["HCreditRating_Now"].ToString()) - Double.Parse(ds2.Tables[0].Rows[0]["HAvailableBalance"].ToString());
                    row[7] = ds2.Tables[0].Rows[0]["HAvailableBalance"].ToString();
                    tb2.Rows.Add(row);
                }
 
                //添加列名
                foreach (DataColumn col in tb2.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 = tb2;
                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
    }
}