using MSXML2; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Dapper; namespace NX.ERP.U8.Store { /// /// 领料申请 /// public class MaterialAppDAL : VoucherBase { public MaterialAppDAL() : base("64", "U8API/AppVouchs") { } public string AddVoucher(object param) { VoucherParameter voucherParameter = new VoucherParameter { VoucherType = this.VoucherID, DomHead = new DOMDocumentClass(), DomBody = new DOMDocumentClass() }; DOMDocument domHead = voucherParameter.DomHead; DOMDocument domBody = voucherParameter.DomBody; voucherParameter.DomHead.loadXML(HeadTemplate); voucherParameter.DomBody.loadXML(BodyTemplate); return ""; } /// /// /// /// /// /// public IEnumerable GetList(string strWhere = "", object Params = null) { var strSQL = @"SELECT a.ID, a.cCode AS Code, a.dDate AS Date, a.cMaker AS PreparedBy, b.AutoID AS id , b.AutoID AS MaterialAppDtlId, b.ID AS MaterialAppId, b.cInvCode AS MaterialCode, b.iQuantity AS Quantit, b.imoseq AS Pesodid , b.cmocode AS MoCode, b.iMpoIds AS AllocateId, b.fOutQuantity AS OutQuantity, b.imoseq AS Moseq, b.crejectcode AS RejectCode , b.iOMoMID AS OmomId, b.iopseq AS OpSeq, b.copdesc AS OpDesc, b.cMoLotCode AS MoLotCode, b.cmocode AS Mocode , b.iMPoIds AS MPoIds, b.comcode AS OmCode, b.iOMoDID AS OMoDId, b.cciqbookcode AS ciqBookCode, b.cmworkcentercode AS mWorkCenterCode , b.cservicecode AS servicecode, b.isotype AS SoType, b.csocode AS SoCode, b.isodid AS SodId, b.isoseq AS SoSeq , b.iordertype AS ordertype, b.iordercode AS OrderCode, b.iorderdid AS OrderdId, b.iorderseq AS OrderSeq, b.ipesotype AS PesoType , b.cpesocode AS PesoCode, b.ipesodid AS PesodId, b.ipesoseq AS PesoSeq,b.cdepCode as DeptCode,cdepName as DeptName,b.cinvcode as ProductNo,b.imquantity as MoQuantity FROM MaterialAppVouch a LEFT JOIN KCMATERIALAPPLIST b ON a.id = b.id"; if (!string.IsNullOrEmpty(strWhere)) { strSQL += $" where {strWhere} "; } using (var conn = U8LoginContext.Instance.Connection) { var lookup = new Dictionary(); conn.Query(strSQL, (head, body) => { if (!lookup.TryGetValue(head.Id, out var _head)) { lookup.Add(head.Id, head); } else { head = _head; } head.MaterialAppVouchsLst.Add(body); return head; }, Params, null, true, "id", 10, System.Data.CommandType.Text); ; return lookup.Values; } } /// /// 查询等待未完成可出库的单子 /// /// public IEnumerable GetPendingList() { return this.GetList(" b.cDefine22='是' and iQuantity<>ISNULL( fOutQuantity,0)"); } /// /// 获取 /// /// /// public Model.Response.Store.MaterialApp GetModel(string Code) { return this.GetList(" a.cCode=@Code", new { Code }).FirstOrDefault(); } /// /// /// /// /// /// public IEnumerable GetListByMoCode(string MoCode, int MoDetailId) { return this.GetList(@" b.cmocode=@MoCode and b.iMPoIds in ( select AllocateId from mom_moallocate where MoDId = @MoDetailId) ", new { MoCode, MoDetailId }); } public IEnumerable GetDetailByMoCode(string MoCode, int MoDetailId) { var models = this.GetListByMoCode(MoCode, MoDetailId); var reslut = new List(); foreach (var items in models) { reslut.AddRange(items.MaterialAppVouchsLst); } return reslut; } public bool Provide(NX.ERP.Model.Request.MaterialAppProvide provide) { using (var conn = U8LoginContext.Instance.Connection) { var strSql = @"update MaterialAppVouchs set dDueDate=@DueDate,cDefine22='是',cDefine23=@SN,cDefine24=@WorkCenter"; if (provide.Detail.Count() != 0) { var mappDetails = this.GetDetailByMoCode(provide.OrderCode, provide.OrderDetailId).ToDictionary(m => m.AllocateId); foreach (var item in provide.Detail) { if (mappDetails.TryGetValue(item.AllocateId, out var _mappDetails)) { } else { throw new Exception("未找到"); } } return false; } else //整单发出 { strSql = @"update MaterialAppVouchs set dDueDate=@DueDate,cDefine22='是',cDefine23=@SN,cDefine24=@WorkCenter where cmocode = @MoCode and iMPoIds in ( select AllocateId from mom_moallocate where MoDId = @OrderDetailId )"; var info = conn.Execute(strSql, new { DueDate = provide.DueDate, SN = "", WorkCenter = provide.WorkCenter, MoCode = provide.OrderCode, OrderDetailId = provide.OrderDetailId }); if (info == 0) { throw new Exception("未找到相应的物料"); } return true; } } } } }