wtt
2025-07-01 e7ef7f02094dbfc44950cb5bb363b95f0c77c57a
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
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 PM_ProjectBill_WorkController : ApiController
    {
 
        private json objJsonResult = new json();
        public DataSet ds = new DataSet();
        public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
 
        #region 反射构建更新SQL语句
        private string generateModifyStrReflection(Object model,string tableName, params string[] keys)
        {
            try
            {
                string sql = "update " + tableName + " Set ";
                string[] excludeNames = keys;
                foreach (var fInfo in model.GetType().GetProperties()
                   .Where(property => !excludeNames.Contains(property.Name))
                   .ToArray())
                {
                    string propName = fInfo.Name;
                    var propValue = fInfo.GetValue(model);
 
                    if (propValue != null)
                    {
                        sql += (propName + "='" + propValue.ToString() + "',");
                    }
                }
                sql = sql.Substring(0, sql.Length - 1);
                sql += " where 1 = 1 ";
                foreach (var key in keys)
                {
                    sql += "and " + key + " = " + model.GetType().GetProperty(key).GetValue(model);
                }
 
                //LogService.Write(sql);
                return sql;
            }catch(Exception e)
            {
                throw new ArgumentException(e.ToString());
            }
            
        }
        #endregion
 
        #region 工程项目 查询
        /// <summary>
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("PM_ProjectBill_Work/list")]
        [HttpGet]
        public object getProjectBill(string sWhere, string user, string stage)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                //if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
 
                if(string.IsNullOrWhiteSpace(sWhere) == false)
                {
                    sWhere = sWhere.Replace("'", "''");
                }
                
                //LogService.Write("exec h_p_PM_ProjectBill_StepsList '" + stage + "','" + sWhere + "'");
                ds = oCN.RunProcReturn("exec h_p_PM_ProjectBill_StepsList '" + stage + "','" + sWhere + "'", "h_p_PM_ProjectBill_StepsList");
 
                //添加列名
                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 工程项目 修改
        [Route("PM_ProjectBill_Work/ModifyByID")]
        [HttpPost]
        public object EditProjectBill([FromBody] JObject msg)
        {
            try
            {
                var _value = msg["oMainStr"].ToString();
                //LogService.Write(_value);
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0]; // 表单主体
                string msg3 = sArray[1]; // 所在阶段
                string msg4 = sArray[2]; // 操作用户
                //LogService.Write(msg2);
                //LogService.Write(msg3);
                //LogService.Write(msg4);
                msg2 = "[" + msg2 + "]";
                List<ClsPM_ProjectBill_Work> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsPM_ProjectBill_Work>>(msg2);
                //LogService.Write(list);
                if (string.Equals(msg3, "jiaodi", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HJiaodiSaveFlag = 1;
                }else if (string.Equals(msg3, "shigong", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HShigongSaveFlag = 1;
                }else if(string.Equals(msg3, "jungong", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HJungongSaveFlag = 1;
                }
 
                string sql = generateModifyStrReflection(list[0], "PM_ProjectBillMain", "HInterID");
 
                oCN.BeginTran();
 
                oCN.RunProcReturn(sql, "PM_ProjectBillMain");
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存成功!";
                objJsonResult.data = 1;
                return objJsonResult;
 
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        #region 工程费用 查询
        /// <summary>
        /// 返回项目阶段列表
        ///参数:string sql。
        ///返回值:object。
        /// </summary>
        [Route("PM_ProjectBill_WorkFee/list")]
        [HttpGet]
        public object getPM_ProjectBill_WorkFee(string sWhere, string user, string stage)
        {
            try
            {
                List<object> columnNameList = new List<object>();
                //查看权限
                //if (!DBUtility.ClsPub.Security_Log("Gy_ProjectStage_Query", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
 
                if (string.IsNullOrWhiteSpace(sWhere) == false)
                {
                    sWhere = sWhere.Replace("'", "''");
                }
 
                //LogService.Write("exec h_p_PM_ProjectBill_FeeList '" + stage + "','" + sWhere + "'");
                ds = oCN.RunProcReturn("exec h_p_PM_ProjectBill_FeeList '" + stage + "','" + sWhere + "'", "h_p_PM_ProjectBill_FeeList");
 
                //添加列名
                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 工程费用 修改
        [Route("PM_ProjectBill_WorkFee/ModifyByID")]
        [HttpPost]
        public object EditPM_ProjectBill_WorkFee([FromBody] JObject msg)
        {
            try
            {
                var _value = msg["oMainStr"].ToString();
                //LogService.Write(_value);
                string msg1 = _value.ToString();
                string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
                string msg2 = sArray[0]; // 表单主体
                string msg3 = sArray[1]; // 所在阶段
                string msg4 = sArray[2]; // 操作用户
                msg2 = "[" + msg2 + "]";
                List<ClsPM_ProjectBill_WorkFee> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ClsPM_ProjectBill_WorkFee>>(msg2);
                //LogService.Write(list);
                if (string.Equals(msg3, "workFeeEntry", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HGongfeiluruSaveFlag = 1;
                }
                else if (string.Equals(msg3, "SporadicProjectsEntry", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HLingxinluruSaveFlag = 1;
                }
                else if (string.Equals(msg3, "ProjectFeeSettleEntry", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HGongchengjiesuanSaveFlag = 1;
                }
                else if (string.Equals(msg3, "WorkFeeCheck", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HGongfeiCheckSaveFlag = 1;
                }
                else if(string.Equals(msg3, "ProjectFeeCheck", StringComparison.InvariantCultureIgnoreCase))
                {
                    list[0].HGongchengzaojiaCheckSaveFlag = 1;
                }
 
                string sql = generateModifyStrReflection(list[0], "PM_ProjectBillMain", "HInterID");
 
                oCN.BeginTran();
 
                oCN.RunProcReturn(sql, "PM_ProjectBillMain");
 
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "保存成功!";
                objJsonResult.data = 1;
                return objJsonResult;
 
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.Message;
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}