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; using Newtonsoft.Json; using DBUtility; namespace WebAPI.Controllers.SCGL { public class JIT_Cg_PODemandPlanBillController : ApiController { private json objJsonResult = new json(); public DataSet ds = new DataSet(); public WebServer webserver = new WebServer(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); JIT_Cg_PODemandPlanBillMain omdelMian = new JIT_Cg_PODemandPlanBillMain(); List omodelsub = new List(); public DAL.ClsSc_ICMOBill BillOld = new DAL.ClsSc_ICMOBill(); #region 提料计划单 列表 [Route("JIT_Cg_PODemandPlanBill/JIT_Cg_PODemandPlanBillList")] [HttpGet] public object Cg_PODemandPlanBillList(string sWhere, string user) { try { List a = new List(); //查看权限 if (!DBUtility.ClsPub.Security_Log("JIT_Cg_PODemandPlanBill_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_Cg_PODemandPlanBillList where 1=1" + sWhere + "order by hmainid desc ", "h_v_JIT_Cg_PODemandPlanBillList"); foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 { Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接 // 将列名和数据类型信息拼接成一个JSON格式的字符串 a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = a; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 提料计划单 添加/修改 [Route("JIT_Cg_PODemandPlanBill/AddPODemandPlanBillList")] [HttpPost] public object AddPODemandPlanBillList([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("JIT_Cg_PODemandPlanBill_Edit", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无保存权限!"; objJsonResult.data = null; return objJsonResult; } omdelMian = Newtonsoft.Json.JsonConvert.DeserializeObject(msg2); string BillType = "4608"; ds = ds = oCN.RunProcReturn($"select * from h_v_JIT_Cg_PODemandPlanBillList where hmainid={omdelMian.HInterID} and 单据号='{omdelMian.HBillNo}'", "h_v_JIT_Cg_PODemandPlanBillList"); if (ds.Tables[0].Rows.Count > 0) { OperationType = 3; } if (OperationType == 1)//新增 { //主表 oCN.RunProc("insert into JIT_Cg_PODemandPlanBillMain(HInterID,HBillNo,HYear,HPeriod,HBillType" + ",HBillSubType,HDate,HBillStatus,HMaker,HMakeDate" + ",HSubORGID ,HAddress,HPURCHASEORGID,HSupplierID ,HSettleCurrId" + ",HRemark,HExplanation)" + $"values({omdelMian.HInterID}, '{omdelMian.HBillNo}', {DateTime.Now.Year}, {DateTime.Now.Month}, '{BillType}'" + $", '{BillType}','{omdelMian.HDate}',1, '{omdelMian.HMaker}',GETDATE()," + $"{omdelMian.HSubORGID},'{omdelMian.HAddress}',{omdelMian.HPURCHASEORGID}, {omdelMian.HSupplierID}, {omdelMian.HSettleCurrId}" + $",'{omdelMian.HRemark}','{omdelMian.HExplanation}')"); } else if (OperationType == 3) { //修改 oCN.RunProc($"update JIT_Cg_PODemandPlanBillMain set HDate='{omdelMian.HDate}',HUpDater='{omdelMian.HMaker}',HUpDateDate=GETDATE()" + $",HSubORGID={omdelMian.HSubORGID},HAddress='{omdelMian.HAddress}',HPURCHASEORGID={omdelMian.HPURCHASEORGID}" + $",HSupplierID={omdelMian.HSupplierID},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 JIT_Cg_PODemandPlanBillSub where HInterID='" + omdelMian.HInterID.ToString() + "'"); omodelsub = Newtonsoft.Json.JsonConvert.DeserializeObject>(msg3); int i = 1; //插入子表 foreach (Models.JIT_Cg_PODemandPlanBillSub oSub in omodelsub) { oCN.RunProc("insert into JIT_Cg_PODemandPlanBillSub(HInterID,HEntryID,HLaterReason,HMaterID,HMaterName" + ", HMaterModel, HUnitID, HErpClsID, HQty, HRemark" + ", HPURCHASEORGID, HStatus, HFixleadTime, HDayPlanBillNo, HSourceInterID" + ", HSourceEntryID, HSourceBillNo, HSourceBillType, HWorkShopID, HDayPlanDate" + ", HRelationQty1, HPOOrderInterID, HPOOrderEntryID, HPOOrderBillNo, HPOOrderBillSEQ" + ", HWWOrderInterID, HWWOrderEntryID, HWWOrderBillNo, HPurchaseDeptID, HCloseTypeSub" + ", HCloseMan, HEntryCloseDate, HSendQty, HReciveQty, HCloseStatus" + ", HRemoveQty, HSeOrderBillNo, HUnReciveQty, HPOOrderBillDate, HPOOrderBillDeliveryDate" + ", HPOOrderBillRemark, HPOOrderBillNote)" + $"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.HPURCHASEORGID == null ? 0 : oSub.HPURCHASEORGID)}, '{oSub.HStatus}', {(oSub.HFixleadTime == null ? 0 : oSub.HFixleadTime)}, '{oSub.HDayPlanBillNo}', {oSub.HSourceInterID}" + $", {oSub.HSourceEntryID}, '{oSub.HSourceBillNo}', '{oSub.HSourceBillType}', {(oSub.HWorkShopID == null ? 0 : oSub.HWorkShopID)}, '{oSub.HDayPlanDate}'" + $", {(oSub.HRelationQty1 == null ? 0 : oSub.HRelationQty1)}, {(oSub.HPOOrderInterID == null ? 0 : oSub.HPOOrderInterID)},{(oSub.HPOOrderEntryID == null ? 0 : oSub.HPOOrderEntryID)}, '{oSub.HPOOrderBillNo}',{(oSub.HPOOrderBillSEQ == null ? 0 : oSub.HPOOrderBillSEQ)}" + $",{(oSub.HWWOrderInterID == null ? 0 : oSub.HWWOrderInterID)},{(oSub.HWWOrderEntryID == null ? 0 : oSub.HWWOrderEntryID)}, '{oSub.HWWOrderBillNo}',{(oSub.HPurchaseDeptID == null ? 0 : oSub.HPurchaseDeptID)}, '{(oSub.HCloseTypeSub == true ? 1 : 0)}'" + $", '{oSub.HCloseMan}','{oSub.HEntryCloseDate}',{(oSub.HSendQty == null ? 0 : oSub.HSendQty)},{(oSub.HReciveQty == null ? 0 : oSub.HReciveQty)}, '{(oSub.HCloseStatus == true ? 1 : 0)}'" + $",{(oSub.HRemoveQty == null ? 0 : oSub.HRemoveQty)}, '{oSub.HSeOrderBillNo}',{(oSub.HUnReciveQty == null ? 0 : oSub.HUnReciveQty)}, '{oSub.HPOOrderBillDate}', '{oSub.HPOOrderBillDeliveryDate}'" + $", '{oSub.HPOOrderBillRemark}', '{oSub.HPOOrderBillNote}')"); i++; } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = null; objJsonResult.data = null; return objJsonResult; } #endregion #region 提料计划单 删除 [Route("JIT_Cg_PODemandPlanBill/DelPODemandPlanBillList")] [HttpGet] public object DelPODemandPlanBillList(string HInterID, string HEntryID, string User) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_Cg_PODemandPlanBill_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_Cg_PODemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Cg_PODemandPlanBillList"); 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 JIT_Cg_PODemandPlanBillMain where HInterID={HInterID}"); } oCN.RunProc($"delete from JIT_Cg_PODemandPlanBillSub 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("JIT_Cg_PODemandPlanBill/CheckPODemandPlanBillList")] [HttpGet] public object CheckPODemandPlanBillList(string HInterID, int Type, string user) { try { //判断是否有删除权限 if (!DBUtility.ClsPub.Security_Log("Gy_RoutingBill_Check", 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 = "JIT_Cg_PODemandPlanBillMain"; 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]["HChecker"] != null && ds.Tables[0].Rows[0]["HChecker"].ToString() != "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已审核!不需要再审核!"; objJsonResult.data = null; return objJsonResult; } } //审核单据 if (!BillOld.CheckBill(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]["HChecker"] == null || ds.Tables[0].Rows[0]["HChecker"].ToString() == "") { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "单据已反审核!不需要再反审核!"; objJsonResult.data = null; return objJsonResult; } } //反审核单据 if (BillOld.AbandonCheck(Int64.Parse(HInterID), ref ClsPub.sExeReturnInfo)) { } else { 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("JIT_Cg_PODemandPlanBill/ClosePODemandPlanBillList")] [HttpGet] public object ClosePODemandPlanBillList(string HInterID, string User) { try { //关闭权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_Cg_PODemandPlanBill_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_Cg_PODemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Cg_PODemandPlanBillList"); 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 JIT_Cg_PODemandPlanBillMain 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("JIT_Cg_PODemandPlanBill/CancelClosePODemandPlanBillList")] [HttpGet] public object CancelClosePODemandPlanBillList(string HInterID, string User) { try { //关闭权限 if (!DBUtility.ClsPub.Security_Log_second("JIT_Cg_PODemandPlanBill_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_Cg_PODemandPlanBillList where 1=1 and hmainid=" + HInterID, "h_v_JIT_Cg_PODemandPlanBillList"); 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 JIT_Cg_PODemandPlanBillMain 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 ReportPODemandPlanBill { public int? HORGID; public DateTime HBEGINDATE; public DateTime HENDDATE; public int? HMATERIALID; public int? HSUPPLIERID; public string HXQD; public string HPURORDERNO; } [Route("JIT_Cg_PODemandPlanBill/ReportPODemandPlanBillList")] [HttpGet] public object ReportPODemandPlanBillList(string sWhere, string user) { try { List a = new List(); //查看权限 if (!DBUtility.ClsPub.Security_Log("JIT_ReportPODemandPlanBillList_S", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } //查看供应商权限 if (DBUtility.ClsPub.Security_Log("JIT_ReportPODemandPlanBillList_AllSup", 1, false, user)) { user = "0"; } ReportPODemandPlanBill Report = JsonConvert.DeserializeObject(sWhere); ds = oCN.RunProcReturn($"exec h_p_JIT_PODemandPlanBill_ReportList {Report.HORGID},'{Report.HBEGINDATE}','{Report.HENDDATE}',{Report.HMATERIALID},{Report.HSUPPLIERID},'{Report.HXQD}','{Report.HPURORDERNO}','{user}' ", "h_p_JIT_PODemandPlanBill_ReportList"); foreach (DataColumn col in ds.Tables[0].Columns)//遍历ds中第一个表(Tables[0])的所有列(Columns)每次循环中,col变量会持有当前列的引用 { Type dataType = col.DataType; //获取当前数据类型传入 自定义变量datadataType string ColmString = "{\"ColmCols\":\"" + col.ColumnName + "\",\"ColmType\":\"" + dataType.Name + "\"}"; //字符串拼接 // 将列名和数据类型信息拼接成一个JSON格式的字符串 a.Add(JsonConvert.DeserializeObject(ColmString));//获取到DataColumn列对象的列名 } objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = ds.Tables[0]; objJsonResult.list = a; return objJsonResult; } catch (Exception e) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "Exception!" + e.ToString(); objJsonResult.data = null; return objJsonResult; } } #endregion #region 提料计划单 提料计划报表 [Route("JIT_Cg_PODemandPlanBill/ReportPODemandPlanBillList_S")] [HttpGet] public object ReportPODemandPlanBillList_S(string sWhere, string user,string HBEGINDATE,string HENDDATE) { try { //查看权限 if (!DBUtility.ClsPub.Security_Log("JIT_ReportPODemandPlanBillList_S", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } //查看供应商权限 if (DBUtility.ClsPub.Security_Log("JIT_ReportPODemandPlanBillList_AllSup", 1, false, user)) { user = "0"; } ds = oCN.RunProcReturn($"exec h_p_JIT_PODemandPlanBill_S_ReportList '{sWhere.ToString()}','{HBEGINDATE}','{HENDDATE}','{user}' ", "h_p_JIT_PODemandPlanBill_S_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 } }