using Newtonsoft.Json.Linq; using Pub_Class; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Web.Http; using WebAPI.Models; using Newtonsoft.Json; using DBUtility; namespace WebAPI.Controllers.SCGL { public class Sc_ComplementGoodsController : ApiController { private json objJsonResult = new json(); public DataSet ds = new DataSet(); public WebServer webserver = new WebServer(); SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); #region 拣料配送单列表 public class ComplementGoods { public string MaterialNumber { get; set; }//物料代码 public string MaterialName { get; set; }//物料名称 public string MaterialModel { get; set; }//规格型号 public string HGD { get; set; }//工段 public string HWHName { get; set; }//仓库 public string Organization { get; set; }//组织 public DateTime HBeginDate { get; set; }//开始时间 public DateTime HEndDate { get; set; }//结束时间 public string HDeptName { get; set; }//部门 public string HJLStatus { get; set; }//拣料状态 public string user { get; set; }//制单人 } [Route("Sc_ComplementGoods/ComplementGoodsList")] [HttpGet] public object ComplementGoodBillList(string sWhere, string user) { try { //查看权限 if (!DBUtility.ClsPub.Security_Log("Cj_ComplementGoodsBill_Query", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无查看权限!"; objJsonResult.data = null; return objJsonResult; } if (sWhere == null || sWhere.Equals("")) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = new DataTable(); return objJsonResult; } //反序列化传递的值 ComplementGoods com = JsonConvert.DeserializeObject(sWhere.ToString()); ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoodsBillList_Query '{com.MaterialNumber}','{com.MaterialName}','{com.MaterialModel}','{com.HGD}'," + $"'{com.HWHName}','{com.HDeptName}','{com.Organization}','{com.user}','{com.HJLStatus}','{com.HBeginDate}','{com.HEndDate}'" ,"h_p_JIT_ComplementGoodsBillList_Query"); 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_ComplementGoods/DelComplementGoodsList")] [HttpGet] public object DelComplementGoodsList(string HInterID, string HEntryID,string HOrgID, string user) { try { //删除权限 if (!DBUtility.ClsPub.Security_Log("Cj_ComplementGoodsBill_Drop", 1, false, user)) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "无删除权限!"; objJsonResult.data = null; return objJsonResult; } ds = oCN.RunProcReturn($"select HISCheck from JIT_SendGoodsBillMain where HMainSourceInterID={HInterID} ", "JIT_SendGoodsBillMain"); if (ds.Tables[0].Rows.Count>0) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "当前单据已配送,不能删除!"; objJsonResult.data = null; return objJsonResult; } oCN.RunProc($"exec Del_ComplementGoodsBillInfo {HInterID},{HEntryID},{HOrgID}"); objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "删除成功!"; 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 配料单列表 [Route("Sc_ComplementGoods/ComplementGoodsBill")] [HttpGet] public object ComplementGoodsBill(string sWhere) { try { if (sWhere == null || sWhere.Equals("")) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = new DataTable(); return objJsonResult; } ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoods_Load '{sWhere}'", "h_p_JIT_ComplementGoods_Load"); 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_ComplementGoods/ComplementGoodsBill_C")] [HttpGet] public object ComplementGoodsBill_C(string sWhere) { try { if (sWhere == null || sWhere.Equals("")) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "Sucess!"; objJsonResult.data = new DataTable(); return objJsonResult; } oCN.RunProc($"exec h_p_JIT_ComplementGoodsBill_C_Add '{sWhere}'"); ds = oCN.RunProcReturn("exec h_p_JIT_GetComplementGoodsBill_C " + sWhere, "h_p_JIT_GetComplementGoodsBill_C"); 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 仓库发料 //参数 public class SendGoodsBill { public int? 未拣料数量 = 0; public int? 最大拣料数量 = 0; public int? 本次拣料数量 = 0; public int? HEntryID = 0; public int? HMaterID = 0; public int? HWHID = 0; public int? HSPID = 0; } [Route("Sc_ComplementGoods/JIT_SendGoodsBill")] [HttpPost] public object JIT_SendGoodsBill([FromBody] JObject msg) { var _value = msg["msg"].ToString(); string[] sArray = _value.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); string msg2 = sArray[0].ToString(); string user = sArray[1].ToString(); string SourceInterID = sArray[2].ToString(); string SourceBillNo = sArray[3].ToString(); try { msg2 = msg2.Replace("\\", ""); msg2 = msg2.Replace("\n", ""); List listCa = new List(); //获取表格数据集合 listCa = JsonConvert.DeserializeObject>(msg2.ToString()); for (int i = 0; i < listCa.Count; i++) { if (listCa[i].本次拣料数量 > listCa[i].最大拣料数量) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "本次拣料数量超过最大拣料数量!"; objJsonResult.data = null; return objJsonResult; } if (listCa[i].本次拣料数量 > listCa[i].未拣料数量) { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "本次拣料数量超过未拣料数量!"; objJsonResult.data = null; return objJsonResult; } } bool flag = false; flag = AddSendGoodsBill(listCa, SourceInterID, SourceBillNo, user, ref DBUtility.ClsPub.sExeReturnInfo); if (flag) { objJsonResult.code = "1"; objJsonResult.count = 1; objJsonResult.Message = "配送成功!"; objJsonResult.data = null; return objJsonResult; } else { objJsonResult.code = "0"; objJsonResult.count = 0; objJsonResult.Message = "配送失败!"; 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 bool AddSendGoodsBill(List listCa, string SourceInterID, string SourceBillNo, string user, ref string sReturn) { try { oCN.BeginTran(); oCN.RunProc($"delete from JIT_SendGoodsBillMain where HMainSourceInterID={SourceInterID} and HMainSourceBillNo='{SourceBillNo}'"); oCN.RunProc($"delete from JIT_SendGoodsBillSub where HInterID in (select HInterID from JIT_SendGoodsBillMain where HMainSourceInterID={SourceInterID} and HMainSourceBillNo='{SourceBillNo}')"); for (int i = 0; i < listCa.Count; i++) { long InterID = DBUtility.ClsPub.CreateBillID_Prod("460201", ref DBUtility.ClsPub.sExeReturnInfo); string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod("460201", ref DBUtility.ClsPub.sExeReturnInfo, true); //添加主表数据 oCN.RunProc("insert into JIT_SendGoodsBillMain(HYear,HPeriod,HBillType,HBillSubType,HInterID,HDate" + ",HBillNo,HBillStatus,HMaker,HMakeDate,HISCheck, HMainSourceInterID, HMainSourceEntryID" + ", HMainSourceBillNo, HMainSourceBillType)" + $"values({DateTime.Now.Year},{DateTime.Now.Month},'460201','460201',{InterID}, GETDATE(), '{HBillNo}'," + $" 0,'{user}', GETDATE(), 0, {SourceInterID}, {listCa[i].HEntryID}, '{SourceBillNo}', '4602')"); //添加子表数据 oCN.RunProc("insert into JIT_SendGoodsBillSub(HInterID,HBillNo_bak,HEntryID" + ",HMaterID,HQty,HWHID,HSPID,HISCheck,HCheckSubMan,HCheckSubDate)" + $"values({InterID},'{HBillNo}',{i}, {listCa[i].HMaterID},{listCa[i].本次拣料数量}," + $" {listCa[i].HWHID},{listCa[i].HSPID},0,'{user}', GETDATE())"); //修改调拨数量 oCN.RunProc($"update JIT_ComplementGoodsBillSub_LK set HSendQTY={listCa[i].本次拣料数量} where HMaterID={listCa[i].HMaterID} " + $" and HSourceInterID=(select top 1 HSourceInterID from JIT_ComplementGoodsBillSub_LK " + $"where HMaterID={listCa[i].HMaterID} order by HSourceInterID ) and HInterID={SourceInterID}"); } sReturn = "新增单据成功!"; oCN.Commit(); return true; } catch (Exception e) { sReturn = e.Message; throw (e); } } #endregion #region 上查 [Route("Sc_ComplementGoods/ComplementGoodsList_Sc")] [HttpGet] public object ComplementGoodsList_Sc(string HInterID,string HEntryID) { try { ds = oCN.RunProcReturn($"exec h_p_JIT_ComplementGoodsBillList_UpQuery '{HInterID}',{HEntryID}", "h_p_JIT_ComplementGoodsBillList_UpQuery"); 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 } }