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 WebAPI.Models;
|
|
|
namespace WebAPI.Controllers.SCGL.日计划管理
|
{
|
public class Sc_WorkDemandPlanBillController : ApiController
|
{
|
private json objJsonResult = new json();
|
public DataSet ds = new DataSet();
|
public WebServer webserver = new WebServer();
|
SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
|
Sc_WorkDemandPlanBillMain omdelMian = new Sc_WorkDemandPlanBillMain();
|
List<Sc_WorkDemandPlanBillSub> omodelsub = new List<Sc_WorkDemandPlanBillSub>();
|
|
#region 要料计划单 列表
|
[Route("Sc_WorkDemandPlanBill/Sc_WorkDemandPlanBillList")]
|
[HttpGet]
|
public object Sc_WorkDemandPlanBillList(string sWhere, string user)
|
{
|
try
|
{
|
//查看权限
|
if (!DBUtility.ClsPub.Security_Log("Sc_WorkDemandPlanBill_Query", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无查看权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkDemandPlanBillList where 1=1" + sWhere + "order by hmainid desc ", "h_v_JIT_Sc_WorkDemandPlanBillList");
|
|
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 要料计划单 添加/修改
|
[Route("Sc_WorkDemandPlanBill/AddWorkDemandPlanBillList")]
|
[HttpPost]
|
public object AddWorkDemandPlanBillList([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 = null;
|
return objJsonResult;
|
}
|
|
public json AddBillMain(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修改
|
string user = sArray[3].ToString();
|
try
|
{
|
if (!DBUtility.ClsPub.Security_Log("Sc_WorkDemandPlanBill_Edit", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无保存权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject<Sc_WorkDemandPlanBillMain>(msg2);
|
string BillType = "4609";
|
ds = ds = oCN.RunProcReturn($"select * from h_v_JIT_Sc_WorkDemandPlanBillList where hmainid={omdelMian.HInterID} and 单据号='{omdelMian.HBillNo}'", "h_v_JIT_Sc_WorkDemandPlanBillList");
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
OperationType = 3;
|
}
|
|
if (OperationType == 1)//新增
|
{
|
//主表
|
oCN.RunProc("insert into Sc_WorkDemandPlanBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType" +
|
", HBillSubType, HDate, HBillStatus, HMaker, HMakeDate" +
|
", HProdORGID, HAddress, HDeptID, HSettleCurrId" +
|
", HRemark, HExplanation)" +
|
$" values({omdelMian.HInterID}, '{omdelMian.HBillNo}', {DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}'" +
|
$", '{BillType}','{omdelMian.HDate}', 1, '{omdelMian.HMaker}', '{omdelMian.HMakeDate}'" +
|
$", {omdelMian.HProdORGID}, '{omdelMian.HAddress}', {omdelMian.HDeptID}, {omdelMian.HSettleCurrId}" +
|
$", '{omdelMian.HRemark}', '{omdelMian.HExplanation}')");
|
}
|
else if (OperationType == 3)
|
{
|
//修改
|
oCN.RunProc($"update Sc_WorkDemandPlanBillMain set HDate='{omdelMian.HDate}',HUpDater='{omdelMian.HMaker}',HUpDateDate=GETDATE()" +
|
$",HProdORGID={omdelMian.HProdORGID},HAddress='{omdelMian.HAddress}',HDeptID={omdelMian.HDeptID}" +
|
$",HSettleCurrId={omdelMian.HSettleCurrId},HRemark='{omdelMian.HRemark}',HExplanation='{omdelMian.HExplanation}'" +
|
$" where HInterID={omdelMian.HInterID}");
|
}
|
//保存子表
|
objJsonResult = AddBillSub(msg3);
|
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;
|
}
|
}
|
|
public json AddBillSub(string msg3)
|
{
|
//删除子表
|
oCN.RunProc("delete from Sc_WorkDemandPlanBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'");
|
|
omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Sc_WorkDemandPlanBillSub>>(msg3);
|
int i = 1;
|
//插入子表
|
foreach (Models.Sc_WorkDemandPlanBillSub oSub in omodelsub)
|
{
|
oCN.RunProc("insert into Sc_WorkDemandPlanBillSub(HInterID,HEntryID,HLaterReason,HMaterID,HMaterName" +
|
", HMaterModel, HUnitID, HErpClsID, HQty, HRemark" +
|
", HProdORGID, HStatus, HFixleadTime, HSourceInterID" +
|
", HSourceEntryID, HSourceBillNo, HSourceBillType, HDayPlanDate" +
|
", HRelationQty, HICMOInterID, HICMOEntryID, HICMOBillSEQ, HCloseMan" +
|
", HEntryCloseDate, HCloseTypeSub, HReciveQty, HCloseStatus, HRemoveQty" +
|
", HSeOrderBillNo, HUnReciveQty, HICMOBillDate, HICMOBillDeliveryDate, HICMOBillRemark" +
|
", HICMOBillNote,HICMOEmpID)" +
|
$"values({omdelMian.HInterID},'{i}','{oSub.HLaterReason}', {(oSub.HMaterID==null?0: oSub.HMaterID)}, '{oSub.HMaterName}'" +
|
$", '{oSub.HMaterModel}',{(oSub.HUnitID == null ? 0: oSub.HUnitID)}, '{oSub.HErpClsID}',{(oSub.HQty == null ? 0: oSub.HQty)}, '{oSub.HRemark}'" +
|
$",{(oSub.HProdORGID == null ? 0: oSub.HProdORGID)}, '{oSub.HStatus}',{(oSub.HFixleadTime == null ? 0: oSub.HFixleadTime)},{oSub.HSourceInterID}" +
|
$",{oSub.HSourceEntryID}, '{oSub.HSourceBillNo}', '{oSub.HSourceBillType}','{oSub.HDayPlanDate}'" +
|
$",{oSub.HRelationQty},{(oSub.HICMOInterID == null ? 0: oSub.HICMOInterID)},{(oSub.HICMOEntryID == null ? 0: oSub.HICMOEntryID)},{(oSub.HICMOBillSEQ == null ? 0: oSub.HICMOBillSEQ)}, '{oSub.HCloseMan}'" +
|
$", '{oSub.HEntryCloseDate}', '{(oSub.HCloseTypeSub == false ? 0 : 1)}',{(oSub.HReciveQty == null ? 0: oSub.HReciveQty)}, '{(oSub.HCloseStatus == false ? 0 : 1)}',{(oSub.HRemoveQty == null ? 0: oSub.HRemoveQty)}" +
|
$", '{oSub.HSeOrderBillNo}',{(oSub.HUnReciveQty == null ? 0: oSub.HUnReciveQty)}, '{oSub.HICMOBillDate}','{oSub.HICMOBillDeliveryDate}', '{oSub.HICMOBillRemark}', " +
|
$"'{oSub.HICMOBillNote}',{(oSub.HICMOEmpID == null ? 0 : oSub.HICMOEmpID)})");
|
i++;
|
}
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = null;
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
#endregion
|
|
#region 要料计划单 删除
|
[Route("Sc_WorkDemandPlanBill/DelWorkDemandPlanBillList")]
|
[HttpGet]
|
public object DelWorkDemandPlanBillList(string HInterID, string HEntryID, string User)
|
{
|
try
|
{
|
//删除权限
|
if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkDemandPlanBill_Drop", 1, false, User))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无权限删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkDemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkDemandPlanBillList");
|
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "1")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据不能删除!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();//开启事务
|
|
if (ds.Tables[0].Rows.Count == 1)
|
{
|
oCN.RunProc($"delete from Sc_WorkDemandPlanBillMain where HInterID={HInterID}");
|
}
|
oCN.RunProc($"delete from Sc_WorkDemandPlanBillSub where HInterID={HInterID} and HEntryID={HEntryID}");
|
|
oCN.Commit();//结束事务
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "删除成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据不存在,无法删除!";
|
objJsonResult.data = null;
|
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("Sc_WorkDemandPlanBill/CloseWorkDemandPlanBillList")]
|
[HttpGet]
|
public object CloseWorkDemandPlanBillList(string HInterID, string User)
|
{
|
try
|
{
|
//关闭权限
|
if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkDemandPlanBill_Close", 1, false, User))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无权限关闭!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkDemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkDemandPlanBillList");
|
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (ds.Tables[0].Rows[0]["单据状态"].ToString() == "3")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据已关闭!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();//开启事务
|
|
oCN.RunProc($"update Sc_WorkDemandPlanBillMain set HBillStatus=3,HCloseMan='{User}',HCloseDate=getdate() where HInterID={HInterID}");
|
|
oCN.Commit();//结束事务
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "关闭成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据不存在,无法关闭!";
|
objJsonResult.data = null;
|
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("Sc_WorkDemandPlanBill/CancelCloseWorkDemandPlanBillList")]
|
[HttpGet]
|
public object CancelCloseWorkDemandPlanBillList(string HInterID, string User)
|
{
|
try
|
{
|
//关闭权限
|
if (!DBUtility.ClsPub.Security_Log_second("Sc_WorkDemandPlanBill_Close", 1, false, User))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无权限关闭!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ds = oCN.RunProcReturn("select * from h_v_JIT_Sc_WorkDemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Sc_WorkDemandPlanBillList");
|
|
if (ds.Tables[0].Rows.Count > 0)
|
{
|
if (ds.Tables[0].Rows[0]["单据状态"].ToString() != "3")
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据没有处于关闭状态!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
oCN.BeginTran();//开启事务
|
|
string HBillStatus = ds.Tables[0].Rows[0]["审核人"].ToString() == "" ? "1" : "2";
|
oCN.RunProc($"update Sc_WorkDemandPlanBillMain set HBillStatus='{HBillStatus}',HCloseMan='',HCloseDate=null where HInterID={HInterID}");
|
|
oCN.Commit();//结束事务
|
|
objJsonResult.code = "1";
|
objJsonResult.count = 1;
|
objJsonResult.Message = "关闭成功!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "当前单据不存在,无法关闭!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
catch (Exception e)
|
{
|
oCN.RollBack();//回滚事务
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = e.ToString();
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
}
|
#endregion
|
|
#region 要料计划单 要料计划报表
|
public class ReportWorkDemandPlanBill
|
{
|
public int? HORGID;
|
public DateTime HBEGINDATE;
|
public DateTime HENDDATE;
|
public int? HMATERIALID;
|
public int? HDeptID;
|
}
|
[Route("Sc_WorkDemandPlanBill/ReportWorkDemandPlanBillList")]
|
[HttpGet]
|
public object ReportWorkDemandPlanBillList(string sWhere, string user)
|
{
|
try
|
{
|
//查看权限
|
if (!DBUtility.ClsPub.Security_Log("Sc_WorkDemandPlanBill_Query", 1, false, user))
|
{
|
objJsonResult.code = "0";
|
objJsonResult.count = 0;
|
objJsonResult.Message = "无查看权限!";
|
objJsonResult.data = null;
|
return objJsonResult;
|
}
|
|
ReportWorkDemandPlanBill Report = JsonConvert.DeserializeObject<ReportWorkDemandPlanBill>(sWhere);
|
|
ds = oCN.RunProcReturn($"exec h_p_JIT_Sc_WorkDemandPlanBill_ReportList {Report.HORGID},'{Report.HBEGINDATE}','{Report.HENDDATE}',{Report.HMATERIALID},{Report.HDeptID} ", "h_p_JIT_Sc_WorkDemandPlanBill_ReportList");
|
|
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
|
|
}
|
}
|