private static void LoadPredictDetail(ProductNotice dmo) { if (dmo.Customer_ID == null) { throw new Exception("请先选择客户"); } if (dmo.Date == null) { throw new ArgumentException("请先选择日期"); } //var selectedList = new List<ProductNotice_Detail>(); var query = SaleForecastQuery((long)dmo.Customer_ID); using (var context = new TransactionContext()) { using (var reader = context.Session.ExecuteReader(query)) { while (reader.Read()) { var selectDmo = new ProductNotice_Detail(); selectDmo.DmoID = (long)reader[0]; selectDmo.DmoTypeID = B3FrameworksConsts.DmoTypeIDBases.B3Sale + 26; selectDmo.Goods_ID = (long)reader[1]; selectDmo.Number = (Money <decimal>?)reader[2]; selectDmo.Goods_MainUnit = reader[3].ToString(); selectDmo.Price = (Money <decimal>?)reader[4]; selectDmo.Money = (Money <金额>?)reader[5]; //selectedList.Add(selectDmo); dmo.Details.Add(selectDmo); } } } }
private static void UpdateDetail(ProductNotice dmo) { foreach (var detail in dmo.Details) { DmoUtil.RefreshDependency(detail, "Goods_ID"); } }
private static void BeforeSave(ProductNotice pro) { var noGoodsDetails = pro.Details.Where(x => x.Goods_ID == 0 || x.Number == null).ToList(); foreach (var item in noGoodsDetails) { pro.Details.Remove(item); } }
static void LoadDetail(ProductNotice dmo) { dmo.Details.Clear(); var query = new DQueryDom(new JoinAlias(typeof(ProductNotice_Detail))); query.Columns.Add(DQSelectColumn.Field("Goods_ID")); query.Columns.Add(DQSelectColumn.Field("Goods_Name")); query.Columns.Add(DQSelectColumn.Field("Goods_Code")); query.Where.Conditions.Add(DQCondition.EQ("ProductNotice_ID", dmo.ID)); var list = query.EExecuteList <long, string, string>().Select(x => new ProductNotice_Detail { ProductNotice_ID = dmo.ID, Goods_ID = x.Item1, Goods_Name = x.Item2, Goods_Code = x.Item3 }); var removeDetail = dmo.Details.Where(detail => list.All(x => x.Goods_ID != detail.Goods_ID)).ToList(); foreach (var remove in removeDetail) { dmo.Details.Remove(remove); } foreach (var add in list.Where(add => dmo.Details.All(x => x.Goods_ID != add.Goods_ID))) { dmo.Details.Add(add); } }
public static FormData FormActions(string action, FormData data) { var productInput = (ProductNotice)data.MainObject; var bl = BIFactory.Create <IProductNoticeBL>(); switch (action) { case FormActionNames.Load: var dom = bl.Load(productInput.ID); data.MainObject = dom; break; case FormActionNames.Save: BeforeSave(productInput); if (productInput.ID == 0) { bl.InitNewDmo(productInput); UpdateDetail(productInput); bl.Insert(productInput); data.MainObject = productInput; return(FormActions(FormActionNames.Load, data)); } UpdateDetail(productInput); bl.Update(productInput); return(FormActions(FormActionNames.Load, data)); case FormActionNames.Check: bl.Check(productInput); data.MainObject = productInput; break; case FormActionNames.New: var dmo = new ProductNotice(); data.MainObject = dmo; break; case FormActionNames.Prev: var prevDmo = GetPrevOrNext(productInput.ID); if (prevDmo == null) { throw new IndexOutOfRangeException("Current is first"); } data.MainObject = prevDmo; break; case FormActionNames.Next: var nextDmo = GetPrevOrNext(productInput.ID, false); if (nextDmo == null) { throw new IndexOutOfRangeException("Current is last"); } data.MainObject = nextDmo; break; case "LoadDetail": LoadDetail(productInput); break; case "ReferToCreate": data.MainObject = HippoUtil.ReferenceToCreate(productInput); break; case "Predict": LoadPredictDetail(productInput); UpdateDetail(productInput); break; default: throw new ArgumentException("Unknown action: " + action); } return(data); }