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<OrderInfo>
|
{
|
/// <summary>
|
/// 供货学期
|
/// </summary>
|
public List<ComboSelectListItem> AllSemesters { get; set; }
|
/// <summary>
|
/// 供应商
|
/// </summary>
|
public List<ComboSelectListItem> AllSuppliers { get; set; }
|
/// <summary>
|
/// 订单类别
|
/// </summary>
|
public List<ComboSelectListItem> AllBidTypes { get; set; }
|
/// <summary>
|
/// 封面纸张
|
/// </summary>
|
public List<ComboSelectListItem> AllCoverPaperTypes { get; set; }
|
/// <summary>
|
/// 内页纸张
|
/// </summary>
|
public List<ComboSelectListItem> AllInnerPaperTypes { get; set; }
|
|
/// <summary>
|
/// 内页颜色
|
/// </summary>
|
public List<ComboSelectListItem> AllColorTypes { get; set; }
|
/// <summary>
|
/// 装订方式
|
/// </summary>
|
public List<ComboSelectListItem> AllBindingTypes { get; set; }
|
|
/// <summary>
|
/// 印刷厂
|
/// </summary>
|
public List<ComboSelectListItem> AllManufacturers { get; set; }
|
/// <summary>
|
/// 页码
|
/// </summary>
|
public List<ComboSelectListItem> AllInnerPaperCodes { get; set; }
|
/// <summary>
|
/// 初始供货年份 为了除了date控件年份bug
|
/// </summary>
|
[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<Dictionary>().Include(x=>x.Parent).Where(x=>x.Parent.Key== "ghxq").GetSelectListItems(Wtm, y => y.Name);
|
AllSuppliers = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "zbgys").GetSelectListItems(Wtm, y => y.Name);
|
AllBidTypes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "ddlb").GetSelectListItems(Wtm, y => y.Name);
|
AllCoverPaperTypes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "fmzz").GetSelectListItems(Wtm, y => y.Name);
|
AllInnerPaperTypes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "nyzz").GetSelectListItems(Wtm, y => y.Name);
|
AllColorTypes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "nyys").GetSelectListItems(Wtm, y => y.Name);
|
AllBindingTypes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "zdfs").GetSelectListItems(Wtm, y => y.Name);
|
AllManufacturers = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "yscs").GetSelectListItems(Wtm, y => y.Name);
|
AllInnerPaperCodes = DC.Set<Dictionary>().Include(x => x.Parent).Where(x => x.Parent.Key == "nyym").GetSelectListItems(Wtm, y => y.Name);
|
|
if (string.IsNullOrEmpty(Entity.Title))
|
{
|
//是新建
|
//设置默认值
|
Entity.SemesterId = DC.Set<Dictionary>().Where(x => x.Key == "ghxqmrz").Select(x => x.ID).SingleOrDefault();
|
|
var WorkbookCoverPaperTypeId= DC.Set<Dictionary>().Where(x => x.Key == "fmzzmrz").Select(x => x.ID).SingleOrDefault();
|
Entity.WorkbookCoverPaperTypeId = WorkbookCoverPaperTypeId;
|
Entity.PictureBookCoverPaperTypeId = WorkbookCoverPaperTypeId;
|
Entity.LargeCharacterBookCoverPaperTypeId= WorkbookCoverPaperTypeId;
|
var WorkbookInnerPaperTypeId = DC.Set<Dictionary>().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<Dictionary>().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<Dictionary>().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<OrderProduction>(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<OrderProduction> CreatProduction(DateTime ProductionTime,Guid OderId)
|
//{
|
|
//}
|
}
|
}
|