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
|
}
|
}
|