using DBUtility;
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;
using SyntacticSugar.constant;
namespace WebAPI.Controllers
{
public class PM_WorkTaskWeekBillController : 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.ClsPM_WorkTaskWeekBill BillNew0 = new DAL.ClsPM_WorkTaskWeekBill(); //工作周计划对应单据类
public DAL.ClsPM_WorkTaskWeekBill BillOld0 = new DAL.ClsPM_WorkTaskWeekBill(); //工作周计划对应单据类
public DAL.ClsPM_WorkReportWeekBillMain BillNew = new DAL.ClsPM_WorkReportWeekBillMain(); //工作周总结对应单据类
public DAL.ClsPM_WorkReportWeekBillMain BillOld = new DAL.ClsPM_WorkReportWeekBillMain(); //工作周总结对应单据类
#region 工作周计划 子表2-待排计划 数据获取
[Route("PM_WorkTaskWeekBill/getSub2Data")]
[HttpGet]
public object getSub2Data(string user)
{
try
{
string sql = @"select
HProjectID
,项目代码 AS HProNumber
,项目名称 AS HProName
,HProjectStageID
,项目阶段 AS HProjectStageName
,任务名称 AS HName
,任务描述 AS HTaskNote
,评估工时 AS HPlanTimes
,已耗用工时 AS HReportTimes
,HInterID AS HSourceInterID
,HEntryID AS HSourceEntryID
,单据号 AS HSourceBillNo
,单据类型 AS HSourceBillType
from h_v_PM_WorkTaskBillList
where 单据状态 = '已审核'
and 接单人 = '" + user + "'";
ds = oCn.RunProcReturn(sql, "h_v_PM_WorkTaskBillList");
//if (ds.Tables[0].Rows.Count != 0 || ds != null)
//{
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "Sucess!";
objJsonResult.data = ds.Tables[0];
return objJsonResult;
//}
//else
//{
//objJsonResult.code = "0";
//objJsonResult.count = 0;
//objJsonResult.Message = "无数据";
//objJsonResult.data = null;
//return objJsonResult;
//}
}
catch (Exception ex)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "没有返回任何记录!" + ex.ToString();
objJsonResult.data = null;
return objJsonResult;
}
}
#endregion
#region 工作周计划保存/编辑
///
/// 保存生产领料单
///
///
///
[Route("PM_WorkTaskWeekBill/SavePM_WorkTaskWeekBill")]
[HttpPost]
public object SavePM_WorkTaskWeekBill([FromBody] JObject msg)
{
var _value = msg["msg"].ToString();
string msg1 = _value.ToString();
string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
string msg2 = sArray[0].ToString(); //表头数据
string msg3 = sArray[1].ToString(); //子表1数据
string refSav = sArray[2].ToString(); //操作方式
string msg4 = sArray[3].ToString(); //用户
DBUtility.ClsPub.CurUserName = msg4;
string UserName = "";
string s = "";
ListModels oListModels = new ListModels();
try
{
//编辑权限
if (!DBUtility.ClsPub.Security_Log_second("PM_WorkTaskWeekBill_Edit", 1, false, msg4))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "无保存权限!";
objJsonResult.data = null;
return objJsonResult;
}
DAL.ClsPM_WorkTaskWeekBill oBill = new DAL.ClsPM_WorkTaskWeekBill();
List lsmain = new List();
msg2 = msg2.Replace("\\", "");
msg2 = msg2.Replace("\n", ""); //\n
lsmain = oListModels.getObjectByJson_PM_WorkTaskWeekBillMain(msg2);
foreach (Model.ClsPM_WorkTaskWeekBillMain oItem in lsmain)
{
if (refSav == "Add")
{
//单据号是否重复
if (BillNew0.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld0.omodel.HInterID))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "单据号重复!不允许保存!";
objJsonResult.data = 1;
return objJsonResult;
}
}
if (refSav == "Update")
{
if (BillOld0.ShowBill(oItem.HInterID, ref s) == false)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "此单据有误!";
objJsonResult.data = 1;
return objJsonResult;
}
//判断是否可编辑
if (BillOld0.omodel.HChecker != "" && BillOld0.omodel.HChecker != null)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "此单据已经被审核,不允许修改!";
objJsonResult.data = 1;
return objJsonResult;
}
if (BillOld0.omodel.HBillStatus > 1)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "此单据处于不可编辑状态,不允许修改!";
objJsonResult.data = 1;
return objJsonResult;
}
if (!DBUtility.Xt_BaseBillFun.Fun_AllowEditBill(BillOld0, ref s))
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = s + ",不允许修改";
objJsonResult.data = 1;
return objJsonResult;
}
}
UserName = oItem.HMaker; //制单人
oItem.HBillType = "4756";
oItem.HBillSubType = "4756";
//oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year);
oItem.HPeriod = DBUtility.ClsPub.isLong(DateTime.Now.Month);
oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd"));
if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "")
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "保存失败!没有单据日期,无法保存!";
objJsonResult.data = 1;
return objJsonResult;
}
oBill.omodel = oItem;
}
//表体数据
//按 },{来拆分数组 //去掉【和】
msg3 = msg3.Substring(1, msg3.Length - 2);
msg3 = msg3.Replace("\\", "");
msg3 = msg3.Replace("\n", ""); //\n
//msg2 = msg2.Replace("'", "’");
List ls = new List();
ls = oListModels.getObjectByJson_PM_WorkTaskWeekBillSub(msg3);
int i = 0;
foreach (Model.ClsPM_WorkTaskWeekBillSub oItemSub in ls)
{
i++;
oItemSub.HEntryID = i;
//oItemSub.HCloseMan = ""; //行关闭
oItemSub.HEntryCloseDate = DBUtility.ClsPub.isDate(DateTime.Now);
oItemSub.HCloseType = false; //关闭类型
//oItemSub.HRemark = ""; //备注
//oItemSub.HSourceInterID = 0; // 源单主内码
//oItemSub.HSourceEntryID = 0; //源单子内码
//oItemSub.HSourceBillNo = ""; //源单单号
//oItemSub.HSourceBillType = ""; //源单类型
//oItemSub.HRelationQty = 0; //关联数量
//oItemSub.HRelationMoney = 0; //关联金额
oBill.DetailColl.Add(oItemSub);
}
//保存
//保存完毕后处理
bool bResult;
if (refSav == "Add")
{
// bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo);
}
else if (refSav == "Update")
{
bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo);
}
else
{
bResult = false;
}
if (bResult)
{
objJsonResult.code = "0";
objJsonResult.count = 1;
objJsonResult.Message = "保存成功!";
//WebAPIController.Add_Log("送货单下推", UserName, "生成送货单");
objJsonResult.data = 1;
return objJsonResult;
}
else
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo;
objJsonResult.data = 1;
return objJsonResult;
}
}
catch (Exception e)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "保存失败!" + e.ToString();
objJsonResult.data = 1;
return objJsonResult;
}
}
#endregion
#region 工作周计划编辑时获取表头数据
[Route("PM_WorkTaskWeekBill/PM_WorkTaskWeekBillgetEditMainData")]
[HttpGet]
public object PM_WorkTaskWeekBillgetEditMainData(Int64 HInterID)
{
try
{
string sql = @" select
a.HInterID,a.HBillNo,a.HYear,a.HWeek,a.HBeginDate,a.HEndDate,a.HPlanEmpID,e1.HName HPlanEmpName,a.HDate,a.HRemark,a.HOrgID,a.HMaker
,a.HMakeDate,a.HUpDater,a.HUpDateDate,a.HChecker,a.HCheckDate,a.HCloseMan,a.HCloseDate,a.HDeleteMan,a.HDeleteDate,a.HBacker,a.HBackDate
from PM_WorkTaskWeekBillMain AS a
LEFT OUTER JOIN Gy_Employee AS e1 on a.HPlanEmpID = e1.HItemID
where HInterID = " + HInterID;
ds = oCn.RunProcReturn(sql, "PM_WorkTaskWeekBillMain");
if (ds == null || ds.Tables[0].Rows.Count == 0)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "未获取到相关数据!";
objJsonResult.data = null;
}
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "查询成功!";
objJsonResult.data = ds.Tables[0];
}
catch (Exception e)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "没有返回任何记录!" + e.ToString();
objJsonResult.data = null;
}
return objJsonResult;
}
#endregion
#region 工作周计划获取表体数据
[Route("PM_WorkTaskWeekBill/PM_WorkTaskWeekBillgetEditSubData")]
[HttpGet]
public object PM_WorkTaskWeekBillgetEditSubData(Int64 HInterID)
{
try
{
string sql = @"select a.HInterID,a.HEntryID,a.HSno,a.HProjectID,p1.HProNumber,p1.HProName,a.HProjectStageID,g1.HName HProjectStageName,p2.HName,p2.HTaskNote
,a.HPlanTimes,p3.已耗用工时 HReportTimes,a.HWeekDay,a.HSourceInterID,a.HSourceEntryID,a.HSourceBillNo,a.HSourceBillType
from PM_WorkTaskWeekBillSub AS a
LEFT OUTER JOIN PM_ProjectBillMain AS p1 on a.HProjectID = p1.HInterID
LEFT OUTER JOIN Gy_ProjectStage AS g1 on a.HProjectStageID = g1.HItemID
LEFT OUTER JOIN PM_WorkTaskBillMain AS p2 on a.HSourceInterID = p2.HInterID
LEFT OUTER JOIN h_v_PM_WorkTaskBillList AS p3 on a.HSourceInterID = p3.HInterID and a.HSourceEntryID = p3.HEntryID
where a.HInterID = " + HInterID +
" order by a.HEntryID asc";
ds = oCn.RunProcReturn(sql, "PM_WorkTaskWeekBillSub");
if (ds == null || ds.Tables[0].Rows.Count == 0)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "未获取到周计划相关数据!";
objJsonResult.data = null;
}
objJsonResult.code = "1";
objJsonResult.count = 1;
objJsonResult.Message = "查询成功!";
objJsonResult.data = ds.Tables[0];
}
catch (Exception e)
{
objJsonResult.code = "0";
objJsonResult.count = 0;
objJsonResult.Message = "没有返回任何记录!" + e.ToString();
objJsonResult.data = null;
}
return objJsonResult;
}
#endregion
#region 工作周计划列表 查询
///
/// 返回项目阶段列表
///参数:string sql。
///返回值:object。
///
[Route("PM_WorkTaskWeekBill/list")]
[HttpGet]
public object getWorkTaskWeekBill(string sWhere, string user)
{
try
{
List