using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; using WalkingTec.Mvvm.Core; using WalkingTec.Mvvm.Core.Extensions; using HHWMS.Web; using HHWMS.Web.Models; using Microsoft.AspNetCore.Mvc; using Z.EntityFramework.Plus; namespace HHWMS.Web { public partial class ShipmentHeaderVM : BaseCRUDVM { public ShipmentDetailListVM Details = new ShipmentDetailListVM(); public List ShipTypes { get; set; } public ShipmentHeaderVM() { } protected override void InitVM() { Details.CopyContext(this); Details.Searcher.HeaderId = Entity.ID; var CurrentCulture = Wtm.CurrentCulture; var dictDatas = DC.Set().ToList(); ShipTypes = dictDatas.Where(x => x.DictType == "ShipType").Select(x => new ComboSelectListItem { Text = CurrentCulture == "zh" ? x.DictLabel : x.DictLabelUs, Value = x.DictValue }).ToList(); } public override void DoAdd() { base.DoAdd(); } public override void DoEdit(bool updateAllFields = false) { base.DoEdit(updateAllFields); } public override void DoDelete() { // 先删除该出库单下的明细,避免表头删除后残留明细导致后续单据下发报错 var details = DC.Set().Where(x => x.HeaderId == Entity.ID).ToList(); if (details.Count > 0) { DC.Set().RemoveRange(details); } // base.DoDelete 内部会统一 SaveChanges,明细与表头一并删除 base.DoDelete(); } } }