using DBUtility; using Model; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Http; using System.Windows.Forms; using WebAPI.Models; namespace WebAPI.Controllers.项目管理.工作任务 { public class PM_WorkTaskBillController : ApiController { public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) private json objJsonResult = new json(); public DataSet ds = new DataSet(); public SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); string user_LongShan = ""; string HName_LongShan = ""; #region 工作任务 新增/编辑 #region 工作任务 表头数据 public class PM_WorkTaskBill_Main { public int HInterID; public string HBillNo; public string HProNumber; public string HProName; public int HProjectStageID; public string HProjectStageName; public string HName; public string HDate; public string HTaskNote; public double HPlanTimes; public double HSelfTimes; public string HLastDate; public string HSendEmp; public string HReceiveEmp; public string HType; public string HCopyEmp; public string HRemark; public int HOrgID; public string HMaker; public string HUpdater; public string HChecker; public string HMakerDate; public string HUpdaterDate; public string HCheckerDate; public string HCloseMan; public string HDeleteMan; public string HBacker; public string HCloseManDate; public string HDeleteManDate; public string HBackerDate; public string HBackRemark; } #endregion #region 工作任务 新增/编辑 /// /// 新增单据-保存按钮 ///参数:string sql。 ///返回值:object。 /// [Route("PM_WorkTaskBill/AddBill")] [HttpPost] public object AddBill([FromBody] JObject sMainSub) { //获取参数 var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); //开始事务 oCN.BeginTran(); //保存主表 objJsonResult = AddBillMain(msg1); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "新增单据成功!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } #endregion #region 添加 工作任务 主表 public json AddBillMain(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); int OperationType = int.Parse(sArray[1].ToString());//数据类型 1添加 3修改 2 复制 string user = sArray[2].ToString();//用户名 string HComputerName = SystemInformation.ComputerName; //设备名称 user_LongShan = sArray[2].ToString();//用户名 try { if(OperationType == 1) { //判断是否有新增权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_add", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无新增权限!"; objJsonResult.data = null; return objJsonResult; } } else if(OperationType == 3) { //判断是否有编辑权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_edit", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无编辑权限!"; objJsonResult.data = null; return objJsonResult; } } msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); int HYear = int.Parse(mainList[0].HDate.Split('-')[0]); int HPeriod = int.Parse(mainList[0].HDate.Split('-')[1]); string HBillType = "4753"; string HBillSubType = ""; int HInterID = mainList[0].HInterID; string HBillNo = mainList[0].HBillNo; string HProNumber = mainList[0].HProNumber; string HProName = mainList[0].HProName; int HProjectStageID = mainList[0].HProjectStageID; string HProjectStageName = mainList[0].HProjectStageName; string HName = mainList[0].HName; string HDate = mainList[0].HDate; string HTaskNote = mainList[0].HTaskNote; double HPlanTimes = mainList[0].HPlanTimes; double HSelfTimes = mainList[0].HSelfTimes; string HLastDate = mainList[0].HLastDate; string HSendEmp = mainList[0].HSendEmp; string HReceiveEmp = mainList[0].HReceiveEmp; string HType = mainList[0].HType; string HCopyEmp = mainList[0].HCopyEmp; string HRemark = mainList[0].HRemark; int HOrgID = mainList[0].HOrgID; string HMaker = mainList[0].HMaker; string HUpdater = mainList[0].HUpdater; string HChecker = mainList[0].HChecker; string HMakerDate = mainList[0].HMakerDate; string HUpdaterDate = mainList[0].HUpdaterDate; string HCheckerDate = mainList[0].HCheckerDate; string HCloseMan = mainList[0].HCloseMan; string HDeleteMan = mainList[0].HDeleteMan; string HBacker = mainList[0].HBacker; string HCloseManDate = mainList[0].HCloseManDate; string HDeleteManDate = mainList[0].HDeleteManDate; string HBackerDate = mainList[0].HBackerDate; string HBackRemark = mainList[0].HBackRemark; if (OperationType == 2) { ds = oCN.RunProcReturn("select * from PM_WorkTaskBillMain where HBillNo ='" + HBillNo + "'", "PM_WorkTaskBillMain"); if (ds.Tables[0].Rows.Count > 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据号重复,请重新输入!"; objJsonResult.data = null; return objJsonResult; } } ds = oCN.RunProcReturn("select * from PM_WorkTaskBillMain where HInterID = " + HInterID + " and HBillNo = '" + HBillNo + "'", "PM_WorkTaskBill"); if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增 { string sql = "insert into PM_WorkTaskBillMain" + "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HBillNo,HProNumber,HProjectStageID,HName,HDate,HTaskNote,HPlanTimes" + ",HSelfTimes,HLastDate,HSendEmp,HReceiveEmp,HType,HCopyEmp,HRemark,HOrgID,HMaker,HMakeDate)" + "values(" + "" + HYear + "," + HPeriod + ",'" + HBillType + "','" + HBillSubType + "'," + HInterID + ",'" + HBillNo + "','" + HProNumber + "'," + HProjectStageID + ",'" + HName + "','" + HDate + "','" + HTaskNote + "'," + HPlanTimes + "," + HSelfTimes + ",'" + HLastDate + "','" + HSendEmp + "','" + HReceiveEmp + "','" + HType + "','" + HCopyEmp + "','" + HRemark + "'," + HOrgID + ",'" + HMaker + "','" + HMakerDate + "')"; //主表 oCN.RunProc(sql); LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增工作任务:" + HBillNo); oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "新增工作任务:" + HBillNo + "','LMES-工作任务模块','" + DBUtility.ClsPub.IPAddress + "','新增单据'", ref DBUtility.ClsPub.sExeReturnInfo); } else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) //编辑 { string sql = "update PM_WorkTaskBillMain set " + "HYear = " + HYear + ",HPeriod = " + HPeriod + ",HBillType = '" + HBillType + "',HBillSubType = '" + HBillSubType + "',HBillNo = '" + HBillNo + "',HProNumber = '" + HProNumber + "',HProjectStageID = " + HProjectStageID + ",HName = '" + HName + "',HDate = '" + HDate + "',HTaskNote = '" + HTaskNote + "',HPlanTimes = " + HPlanTimes + ",HSelfTimes = " + HSelfTimes + ",HLastDate = '" + HLastDate + "',HSendEmp = '" + HSendEmp + "',HReceiveEmp = '" + HReceiveEmp + "',HType = '" + HType + "',HCopyEmp = '" + HCopyEmp + "',HRemark = '" + HRemark + "',HOrgID = " + HOrgID + ",HUpdater = '" + HUpdater + "',HUpdateDate = '" + HUpdaterDate + "' where HInterID = " + HInterID; oCN.RunProc(sql); //删除子表 oCN.RunProc("delete from PM_WorkTaskBillSub where HInterID='" + HInterID + "'"); //记录日志 LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",修改工作任务:" + HBillNo); oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "修改工作任务:" + HBillNo + "','LMES-工作任务模块','" + DBUtility.ClsPub.IPAddress + "','修改单据'", ref DBUtility.ClsPub.sExeReturnInfo); } //保存子表 objJsonResult = AddBillSub(HInterID, HBillNo, OperationType); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 添加工作任务 子表 public json AddBillSub(long HInterID, string HBillNo, int OperationType) { string sql = "insert into PM_WorkTaskBillSub" + "(HInterID,HEntryID,HBillNo_bak,HRemark) " + "values(" + "" + HInterID + "," + 1 + ",'" + HBillNo + "','" + "" + "')"; oCN.RunProc(sql); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #endregion #region 工作任务列表 查询 /// /// 返回项目阶段列表 ///参数:string sql。 ///返回值:object。 /// [Route("PM_WorkTaskBill/list")] [HttpGet] public object getWorkTaskBill(string sWhere, string user) { try { List columnNameList = new List(); //查看权限 //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 (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from PM_WorkTaskBillMain order by HBillNo ", "PM_WorkTaskBillMain"); } else { string sql1 = "select * from PM_WorkTaskBillMain where 1 = 1 "; string sql = sql1 + sWhere + " order by HBillNo "; ds = oCN.RunProcReturn(sql, "PM_WorkTaskBillMain"); } //添加列名 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 HInterID。 ///返回值:object。 /// [Route("PM_WorkTaskBill/editInit")] [HttpGet] public object getWorkTaskBilleditInit(string HInterID, string user) { try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_edit", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } if(HInterID == null || HInterID.Equals("")) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID不能为空!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskBill_EditInit " + HInterID, "h_p_PM_WorkTaskBill_EditInit"); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工作任务 删除 /// ///参数:string HInterID。 ///返回值:object。 /// [Route("PM_WorkTaskBill/delete")] [HttpGet] public object deleteWorkTaskBill(string HInterID, string user) { try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_delete", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限!"; objJsonResult.data = null; return objJsonResult; } if(HInterID == null || HInterID.Equals("")) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID不能为空!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); oCN.RunProc("delete from PM_WorkTaskBillMain where HInterID = " + HInterID); oCN.RunProc("delete from PM_WorkTaskBillSub where HInterID='" + HInterID + "'"); oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工作任务 审核/反审核 /// /// /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [Route("PM_WorkTaskBill/AuditPM_WorkTaskBill")] [HttpGet] public object AuditPM_WorkTaskBill(int HInterID, int IsAudit, string CurUserName) { try { //审核权限 if (!DBUtility.ClsPub.Security_Log_second("Pm_WorkTaskBill_Check", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败!无权限!"; objJsonResult.data = null; return objJsonResult; } var ds = oCN.RunProcReturn("select * from PM_WorkTaskBillMain where HInterID=" + HInterID, "PM_WorkTaskBillMain"); if (ds.Tables[0].Rows.Count > 0) { if (IsAudit == 0) //审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能再次审核!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未审核!不需要反审核!"; objJsonResult.data = null; return objJsonResult; } } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据不存在!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); if (IsAudit == 0) //审核判断 { oCN.RunProc("update PM_WorkTaskBillMain set HChecker='" + CurUserName + "',HCheckDate=getdate() where HInterID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核成功"; objJsonResult.data = null; } if (IsAudit == 1) //反审核判断 { oCN.RunProc("update PM_WorkTaskBillMain set HChecker='',HCheckDate=null where HInterID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反审核成功"; objJsonResult.data = null; } oCN.Commit(); return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工作任务 关闭/反关闭功能 [Route("PM_WorkTaskBill/ClosePM_WorkTaskBill")] [HttpGet] public object ClosePM_WorkTaskBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_Close", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限关闭!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "PM_WorkTaskBillMain"; oCN.BeginTran();//开始事务 //Type 1 关闭 2 反关闭 if (Type == 1) { //判断单据是否已经关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已关闭!不需要再关闭!"; objJsonResult.data = null; return objJsonResult; } } //关闭单据 if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反关闭!不需要再反关闭!"; objJsonResult.data = null; return objJsonResult; } } //反关闭单据 if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 工作任务 作废/反作废功能 [Route("PM_WorkTaskBill/DropPM_WorkTaskBill")] [HttpGet] public object DropPM_WorkTaskBill(string HInterID, int Type, string user) { try { //判断是否有作废权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskBill_Drop", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限作废!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "PM_WorkTaskBillMain"; oCN.BeginTran();//开始事务 //Type 1 作废 2 反作废 if (Type == 1) { //判断单据是否已经作废 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HDeleteMan"] != null && ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已作废!不需要再作废!"; objJsonResult.data = null; return objJsonResult; } } //作废单据 if (!BillOld.Cancelltion(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "作废失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反作废 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HDeleteMan"] == null || ds.Tables[0].Rows[0]["HDeleteMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反作废!不需要再反作废!"; objJsonResult.data = null; return objJsonResult; } } //反作废单据 if (!BillOld.AbandonCancelltion(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反作废失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 任务汇报 新增/编辑-保存 #region 任务汇报 表头数据 public class PM_WorkTaskReportBill_Main { public int HInterID; public string HBillNo; public string HDate; public string HRemark; public int HOrgID; public string HMaker; public string HUpdater; public string HChecker; public string HMakerDate; public string HUpdaterDate; public string HCheckerDate; public string HCloseMan; public string HDeleteMan; public string HBacker; public string HCloseManDate; public string HDeleteManDate; public string HBackerDate; public string HBackRemark; public int HReportEmpID; public string HReportEmpName; } #endregion #region 任务汇报 子表数据 public class PM_WorkTaskReportBill_Sub { public int RowID; public string HProNumber; public int HProjectStageID; public string HProjectStageName; public string HName; public string HTaskNote; public string HType; public double HRelTimes; public string HReportNote; public string HAdv; public string HRemarkSub; } #endregion #region 项目阶段清单 新增/编辑-保存 /// /// 新增单据-保存按钮 ///参数:string sql。 ///返回值:object。 /// [Route("PM_WorkTaskReportBill/AddBill")] [HttpPost] public object AddBill_WorkTaskReportBill([FromBody] JObject sMainSub) { //获取参数 var _value = sMainSub["sMainSub"].ToString(); string msg1 = _value.ToString(); //开始事务 oCN.BeginTran(); //保存主表 objJsonResult = AddBillMain_WorkTaskReportBill(msg1); if (objJsonResult.code == "0") { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "新增单据成功!"; objJsonResult.data = ds.Tables[0]; return objJsonResult; } #endregion #region 添加 项目阶段清单 主表 public json AddBillMain_WorkTaskReportBill(string msg1) { string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string msg3 = sArray[1].ToString(); int OperationType = int.Parse(sArray[2].ToString());//数据类型 1添加 3修改 2 复制 string user = sArray[3].ToString();//用户名 string HComputerName = SystemInformation.ComputerName; //设备名称 user_LongShan = sArray[3].ToString();//用户名 try { if (OperationType == 1) { //判断是否有编辑权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskReportBill_add", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无新增权限!"; objJsonResult.data = null; return objJsonResult; } } else if (OperationType == 3) { //判断是否有编辑权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskReportBill_edit", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无编辑权限!"; objJsonResult.data = null; return objJsonResult; } } msg2 = "[" + msg2.ToString() + "]"; List mainList = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg2); int HYear = int.Parse(mainList[0].HDate.Split('-')[0]); int HPeriod = int.Parse(mainList[0].HDate.Split('-')[1]); string HBillType = "4754"; string HBillSubType = ""; int HBillStatus = 1; int HInterID = mainList[0].HInterID; string HBillNo = mainList[0].HBillNo; string HDate = mainList[0].HDate; string HRemark = mainList[0].HRemark; int HOrgID = mainList[0].HOrgID; string HMaker = mainList[0].HMaker; string HMakerDate = mainList[0].HMakerDate; int HReportEmpID = mainList[0].HReportEmpID; string HReportEmpName = mainList[0].HReportEmpName; string HUpdater = mainList[0].HUpdater; string HUpdaterDate = mainList[0].HUpdaterDate; if (OperationType == 2) { ds = oCN.RunProcReturn("select * from PM_WorkTaskReportBillMain where HBillNo ='" + HBillNo + "'", "PM_WorkTaskReportBillMain"); if (ds.Tables[0].Rows.Count > 0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据号重复,请重新输入!"; objJsonResult.data = null; return objJsonResult; } } ds = oCN.RunProcReturn("select * from PM_WorkTaskReportBillMain where HInterID = " + HInterID + " and HBillNo = '" + HBillNo + "'", "PM_WorkTaskReportBillMain"); if ((OperationType == 1 || OperationType == 2) && ds.Tables[0].Rows.Count == 0)//新增 { string sql = "insert into PM_WorkTaskReportBillMain" + "(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate,HBillNo,HBillStatus,HRemark,HMaker,HMakeDate,HOrgID,HReportEmpID) " + "values(" + "" + HYear + "," + HPeriod + ",'" + HBillType + "','" + HBillSubType + "'," + HInterID + ",'" + HDate + "','" + HBillNo + "'," + HBillStatus + ",'" + HRemark + "','" + HMaker + "','" + HMakerDate + "'," + HOrgID + "," + HReportEmpID + ")"; //主表 oCN.RunProc(sql); LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",新增任务汇报:" + HBillNo); oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "新增任务汇报:" + HBillNo + "','LMES-任务汇报模块','" + DBUtility.ClsPub.IPAddress + "','新增单据'", ref DBUtility.ClsPub.sExeReturnInfo); } else if (OperationType == 3 || ds.Tables[0].Rows.Count != 0) //编辑 { string sql = "update PM_WorkTaskReportBillMain set " + "HYear = " + HYear + ",HPeriod = " + HPeriod + ",HBillType = '" + HBillType + "',HBillSubType = '" + HBillSubType + "',HDate = '" + HDate + "',HBillNo = '" + HBillNo + "',HBillStatus = " + HBillStatus + ",HRemark = '" + HRemark + "',HUpdater = '" + HUpdater + "',HUpdateDate = '" + HUpdaterDate + "',HOrgID = " + HOrgID + ",HReportEmpID = " + HReportEmpID + " where HInterID = " + HInterID; oCN.RunProc(sql); //删除子表 oCN.RunProc("delete from PM_WorkTaskReportBillSub where HInterID='" + HInterID + "'"); //记录日志 LogService.Write("用户:" + user + ",日期:" + DateTime.Now + ",修改项目阶段清单:" + HBillNo); oCN.RunProc("Insert into System_log (GeginDate, userid, WorkstationName, WorkList, SystemName, NetuserName, State) select GETDATE(),'" + user + "','" + HComputerName + "','" + "修改项目阶段清单:" + HBillNo + "','LMES-项目阶段清单模块','" + DBUtility.ClsPub.IPAddress + "','修改单据'", ref DBUtility.ClsPub.sExeReturnInfo); } //保存子表 objJsonResult = AddBillSub_WorkTaskReportBill(msg3, HInterID, HBillNo, OperationType); if (objJsonResult.code == "0") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = objJsonResult.Message; objJsonResult.data = null; return objJsonResult; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 添加项目阶段清单 子表 public json AddBillSub_WorkTaskReportBill(string msg3, long HInterID, string HBillNo, int OperationType) { List DetailColl = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg3); int i = 0; //作为子表内码 foreach (PM_WorkTaskReportBill_Sub oSub in DetailColl) { i++; //同一个主表下的子表的内码自增 int HEntryID = i; string HProNumber = oSub.HProNumber; int HProjectStageID = oSub.HProjectStageID; string HName = oSub.HName; string HTaskNote = oSub.HTaskNote; string HType = oSub.HType; double HRelTimes = oSub.HRelTimes; string HReportNote = oSub.HReportNote; string HAdv = oSub.HAdv; string HRemark = oSub.HRemarkSub; string sql = "insert into PM_WorkTaskReportBillSub" + "(HInterID,HBillNo_bak,HEntryID,HRemark,HProNumber,HProjectStageID,HName,HTaskNote,HType,HRelTimes,HReportNote,HAdv) " + "values(" + "" + HInterID + ",'" + HBillNo + "'," + HEntryID + ",'" + HRemark + "','" + HProNumber + "'," + HProjectStageID + ",'" + HName + "','" + HTaskNote + "','" + HType + "'," + HRelTimes + ",'" + HReportNote + "','" + HAdv + "')"; oCN.RunProc(sql); } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #endregion #region 任务汇报 查询 /// /// 返回项目阶段列表 ///参数:string sql。 ///返回值:object。 /// [Route("PM_WorkTaskReportBill/list")] [HttpGet] public object getWorkTaskReportBill(string sWhere, string user) { try { List columnNameList = new List(); //查看权限 //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 (sWhere == null || sWhere.Equals("")) { ds = oCN.RunProcReturn("select * from PM_WorkTaskReportBillMain order by HBillNo desc ", "PM_ProjectStageBillMain"); } else { string sql1 = "select * from PM_WorkTaskReportBillMain where 1 = 1 "; string sql = sql1 + sWhere + " order by HBillNo desc "; ds = oCN.RunProcReturn(sql, "PM_WorkTaskReportBillMain"); } //添加列名 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 HInterID。 ///返回值:object。 /// [Route("PM_WorkTaskReportBill/editInit")] [HttpGet] public object getWorkTaskReportBilleditInit(string HInterID, string user) { try { List tableList = new List(); //查看权限 //if (!DBUtility.ClsPub.Security_Log("Pm_ProjectStageBill_edit", 1, false, user)) //{ // objJsonResult.code = "0"; // objJsonResult.count = 0; // objJsonResult.Message = "无查看权限!"; // objJsonResult.data = null; // return objJsonResult; //} if (HInterID == null || HInterID.Equals("")) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID不能为空!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn("exec h_p_PM_WorkTaskReportBill_EditInit " + HInterID, "h_p_PM_WorkTaskReportBill_EditInit"); tableList.Add(ds.Tables[0]); tableList.Add(ds.Tables[1]); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = tableList; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 任务汇报 删除 /// ///参数:string HInterID。 ///返回值:object。 /// [Route("PM_WorkTaskReportBill/delete")] [HttpGet] public object deleteWorkTaskReportBill(string HInterID, string user) { try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskReportBill_delete", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限!"; objJsonResult.data = null; return objJsonResult; } if (HInterID == null || HInterID.Equals("")) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID不能为空!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); oCN.RunProc("delete from PM_WorkTaskReportBillMain where HInterID = " + HInterID); oCN.RunProc("delete from PM_WorkTaskReportBillSub where HInterID='" + HInterID + "'"); oCN.Commit(); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = null; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 任务汇报 审核/反审核 /// /// /// /// 单据ID /// 审核(0),反审核(1) /// 审核人 /// [Route("PM_WorkTaskReportBill/AuditPM_WorkTaskReportBill")] [HttpGet] public object AuditPM_WorkTaskReportBill(int HInterID, int IsAudit, string CurUserName) { try { //审核权限 if (!DBUtility.ClsPub.Security_Log_second("Pm_WorkTaskReportBill_Check", 1, false, CurUserName)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败!无权限!"; objJsonResult.data = null; return objJsonResult; } var ds = oCN.RunProcReturn("select * from PM_WorkTaskReportBillMain where HInterID=" + HInterID, "PM_WorkTaskReportBillMain"); if (ds.Tables[0].Rows.Count > 0) { if (IsAudit == 0) //审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不能再次审核!"; objJsonResult.data = null; return objJsonResult; } } if (IsAudit == 1) //反审核判断 { if (ds.Tables[0].Rows[0]["HChecker"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据未审核!不需要反审核!"; objJsonResult.data = null; return objJsonResult; } } } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据不存在!"; objJsonResult.data = null; return objJsonResult; } oCN.BeginTran(); if (IsAudit == 0) //审核判断 { oCN.RunProc("update PM_WorkTaskReportBillMain set HChecker='" + CurUserName + "',HCheckDate=getdate() where HInterID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "审核成功"; objJsonResult.data = null; } if (IsAudit == 1) //反审核判断 { oCN.RunProc("update PM_WorkTaskReportBillMain set HChecker='',HCheckDate=null where HInterID=" + HInterID); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "反审核成功"; objJsonResult.data = null; } oCN.Commit(); return objJsonResult; } catch (Exception e) { oCN.RollBack(); objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "审核失败或者反审核失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 任务汇报 关闭/反关闭功能 [Route("PM_WorkTaskReportBill/ClosePM_WorkTaskReportBill")] [HttpGet] public object ClosePM_WorkTaskReportBill(string HInterID, int Type, string user) { try { //判断是否有删除权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskReportBill_Close", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限关闭!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "PM_WorkTaskReportBillMain"; oCN.BeginTran();//开始事务 //Type 1 关闭 2 反关闭 if (Type == 1) { //判断单据是否已经关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] != null && ds.Tables[0].Rows[0]["HCloseMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已关闭!不需要再关闭!"; objJsonResult.data = null; return objJsonResult; } } //关闭单据 if (!BillOld.CloseBill(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反关闭 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HCloseMan"] == null || ds.Tables[0].Rows[0]["HCloseMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反关闭!不需要再反关闭!"; objJsonResult.data = null; return objJsonResult; } } //反关闭单据 if (!BillOld.CancelClose(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反关闭失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 任务汇报 作废/反作废功能 [Route("PM_WorkTaskReportBill/DropPM_WorkTaskReportBill")] [HttpGet] public object DropPM_WorkTaskReportBill(string HInterID, int Type, string user) { try { //判断是否有作废权限 if (!DBUtility.ClsPub.Security_Log("Pm_WorkTaskReportBill_Drop", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无权限作废!"; objJsonResult.data = null; return objJsonResult; } if (string.IsNullOrWhiteSpace(HInterID)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "HInterID为空!"; objJsonResult.data = null; return objJsonResult; } ClsPub.CurUserName = user; BillOld.MvarItemKey = "PM_WorkTaskReportBillMain"; oCN.BeginTran();//开始事务 //Type 1 作废 2 反作废 if (Type == 1) { //判断单据是否已经作废 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HDeleteMan"] != null && ds.Tables[0].Rows[0]["HDeleteMan"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已作废!不需要再作废!"; objJsonResult.data = null; return objJsonResult; } } //作废单据 if (!BillOld.Cancelltion(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "作废失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } else { //判断单据是否已经反作废 DataSet ds; string sql = "select * from " + BillOld.MvarItemKey + " where HinterID = " + HInterID; ds = oCN.RunProcReturn(sql, BillOld.MvarItemKey); if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["HDeleteMan"] == null || ds.Tables[0].Rows[0]["HDeleteMan"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反作废!不需要再反作废!"; objJsonResult.data = null; return objJsonResult; } } //反作废单据 if (!BillOld.AbandonCancelltion(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "反作废失败!原因:" + ClsPub.sExeReturnInfo; objJsonResult.data = null; return objJsonResult; } } oCN.Commit();//提交事务 objJsonResult.code = "0"; objJsonResult.count = 1; objJsonResult.Message = "执行成功!"; objJsonResult.data = null; return objJsonResult; ; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "执行失败!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion } }