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
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Pub_Class;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebAPI.Models;
namespace WebAPI.Controllers
{
    public class ZWDBController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更)
        public SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public WebServer webserver = new WebServer();
        // GET: ZWDB
        [Route("ZWDBController/GetLIST")]
        public object GetLIST(string user,int OrgIDs)
        {
            List<object> columnNameList = new List<object>();
            try
            {
                DataSet ds = oCn.RunProcReturn("select  * from h_v_ZWDB where 1=1 order by HItemID desc", "h_v_ZWDB");
                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 ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
        [Route("ZWDBController/insertTODOS")]
        [HttpGet]
        public object insertTODOS(string contents, string user)
        {
            List<object> columnNameList = new List<object>();
            try
            {
                oCn.BeginTran();
                if (contents == "" || contents == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查询数据异常,请与管理员联系!" ;
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCn.RunProc($"INSERT INTO [Gy_ZWDB] ( [HDate], [HMaker], [HMakeDate], [contents], [IsBan], [IsUsed], [IsEdit], [HUSEORGID]) VALUES ( '{DateTime.Now}', '{user}', '{DateTime.Now}', '{contents}', 0, 1, 1, 100038);");
 
                oCn.Commit();
                DataSet ds = oCn.RunProcReturn("select MAX(HItemID) HItemID from Gy_ZWDB   ", "Gy_ZWDB");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
 
        [Route("ZWDBController/deleteTODOS")]
        [HttpGet]
        public object deleteTODOS( string user,int HID)
        {
            List<object> columnNameList = new List<object>();
            try
            {
                oCn.BeginTran();
                if ( HID == null)
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "查询数据异常,请与管理员联系!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
                oCn.RunProc($"UPDATE Gy_ZWDB set IsUsed=0 where HItemID='{HID}'");
                oCn.Commit();
                DataSet ds = oCn.RunProcReturn("select MAX(HItemID) HItemID from Gy_ZWDB   ", "Gy_ZWDB");
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                objJsonResult.list = columnNameList;
                return objJsonResult;
            }
            catch (Exception ex)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "查询数据异常,请与管理员联系!" + ex.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
    }
}