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 cy_scdz.Model.Oder; using cy_scdz.Model.Set; using Microsoft.EntityFrameworkCore; using utils; using Microsoft.AspNetCore.Http; using System.Globalization; using NPOI.SS.Formula.Functions; namespace cy_scdz.ViewModel.BidOrder.OrderInfoVMs { public partial class OrderInfoVM : BaseCRUDVM { /// /// 供货学期 /// public List AllSemesters { get; set; } /// /// 供应商 /// public List AllSuppliers { get; set; } /// /// 订单类别 /// public List AllBidTypes { get; set; } /// /// 封面纸张 /// public List AllCoverPaperTypes { get; set; } /// /// 内页纸张 /// public List AllInnerPaperTypes { get; set; } /// /// 内页颜色 /// public List AllColorTypes { get; set; } /// /// 装订方式 /// public List AllBindingTypes { get; set; } /// /// 印刷厂 /// public List AllManufacturers { get; set; } /// /// 页码 /// public List AllInnerPaperCodes { get; set; } /// /// 初始供货年份 为了除了date控件年份bug /// [Display(Name ="初始供货")] [Required] public string InitialDeliveryTime { set; get; } public OrderInfoVM() { SetInclude(x => x.Semester); SetInclude(x => x.Supplier); SetInclude(x => x.BidType); SetInclude(x => x.WorkbookCoverPaperType); SetInclude(x => x.WorkbookInnerPaperType); SetInclude(x => x.WorkbookColorType); SetInclude(x => x.WorkbookBindingType); SetInclude(x => x.PictureBookCoverPaperType); SetInclude(x => x.PictureBookInnerPaperType); SetInclude(x => x.PictureBookColorType); SetInclude(x => x.PictureBookBindingType); SetInclude(x => x.LargeCharacterBookCoverPaperType); SetInclude(x => x.LargeCharacterBookInnerPaperType); SetInclude(x => x.LargeCharacterBookColorType); SetInclude(x => x.LargeCharacterBookBindingType); SetInclude(x => x.OrderReceivablesStatus); SetInclude(x => x.Sures); SetInclude(x => x.AdvancePayments); //SetInclude(x => x.LargeCharacterManufacturer); //SetInclude(x => x.Workbook16KManufacturer); //SetInclude(x => x.Workbook32KManufacturer); //SetInclude(x => x.PictureBook16KManufacturer); //SetInclude(x => x.PictureBook32KManufacturer); //SetInclude(x => x.PictureBookA4KManufacturer); } protected override void InitVM() { AllSemesters = DC.Set().Include(x=>x.Parent).Where(x=>x.Parent.Key== "ghxq").GetSelectListItems(Wtm, y => y.Name); AllSuppliers = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "zbgys").GetSelectListItems(Wtm, y => y.Name); AllBidTypes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "ddlb").GetSelectListItems(Wtm, y => y.Name); AllCoverPaperTypes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "fmzz").GetSelectListItems(Wtm, y => y.Name); AllInnerPaperTypes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "nyzz").GetSelectListItems(Wtm, y => y.Name); AllColorTypes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "nyys").GetSelectListItems(Wtm, y => y.Name); AllBindingTypes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "zdfs").GetSelectListItems(Wtm, y => y.Name); AllManufacturers = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "yscs").GetSelectListItems(Wtm, y => y.Name); AllInnerPaperCodes = DC.Set().Include(x => x.Parent).Where(x => x.Parent.Key == "nyym").GetSelectListItems(Wtm, y => y.Name); if (string.IsNullOrEmpty(Entity.Title)) { //是新建 //设置默认值 Entity.SemesterId = DC.Set().Where(x => x.Key == "ghxqmrz").Select(x => x.ID).SingleOrDefault(); var WorkbookCoverPaperTypeId= DC.Set().Where(x => x.Key == "fmzzmrz").Select(x => x.ID).SingleOrDefault(); Entity.WorkbookCoverPaperTypeId = WorkbookCoverPaperTypeId; Entity.PictureBookCoverPaperTypeId = WorkbookCoverPaperTypeId; Entity.LargeCharacterBookCoverPaperTypeId= WorkbookCoverPaperTypeId; var WorkbookInnerPaperTypeId = DC.Set().Where(x => x.Key == "nyzzmrz").Select(x => x.ID).SingleOrDefault(); Entity.WorkbookInnerPaperTypeId = WorkbookInnerPaperTypeId; Entity.PictureBookInnerPaperTypeId = WorkbookInnerPaperTypeId; Entity.LargeCharacterBookInnerPaperTypeId = WorkbookInnerPaperTypeId; InitialDeliveryTime = DateTime.Now.ToString("yyyy"); Entity.Chunqiuji = chunqiue.chun; //生产厂商 var ManufacturerId = DC.Set().Where(x => x.Key == "bchang").Select(x => x.ID).SingleOrDefault(); //Entity.Workbook32KManufacturerId = ManufacturerId; //Entity.Workbook16KManufacturerId = ManufacturerId; //Entity.PictureBook16KManufacturerId= ManufacturerId; //Entity.PictureBook32KManufacturerId= ManufacturerId; //Entity.PictureBookA4KManufacturerId = ManufacturerId; //Entity.LargeCharacterManufacturerId = ManufacturerId; } else { InitialDeliveryTime= Entity.InitialDeliveryTime.ToString("yyyy"); } } public override void DoAdd() { var data= DC.Set().Where(x => x.ID == Entity.SemesterId).Select(x => x.Value).SingleOrDefault(); var SemesterCount = data?.ToInt32(); int year = InitialDeliveryTime.ToInt32(); if(year<1000) { MSD.AddModelError("InitialDeliveryTime", "初始供货年份选择错误"); return; } Entity.InitialDeliveryTime = new DateTime(year, Entity.Chunqiuji == chunqiue.chun?1:7, 1); var ProductionTime = Entity.InitialDeliveryTime; using (var tr = DC.BeginTransaction()) { DC.AddEntity(Entity); ///创建订单 for (int i = 0; i < SemesterCount; i++) { var oder = new OrderProduction { CreateTime = DateTime.Now, CreateBy = Wtm.LoginUserInfo.ITCode, OderId = Entity.ID, DeliveryTime = ProductionTime, Chunqiuji = ProductionTime.Month >= 6 ? chunqiue.qiu : chunqiue.chun }; DC.AddEntity(oder); ProductionTime= ProductionTime.AddMonths(6); } DC.SaveChanges(); if(MSD.IsValid) { tr.Commit(); } else { tr.Rollback(); } } //base.DoAdd(); } public override void DoEdit(bool updateAllFields = false) { base.DoEdit(updateAllFields); } public override void DoDelete() { base.DoDelete(); } //private List CreatProduction(DateTime ProductionTime,Guid OderId) //{ //} } }