private void btnSave_Click(object sender, RoutedEventArgs e) { var bill = _dataContext.Master; if (bill.OrganizationID == default(int)) { MessageBox.Show("未指定订货机构"); return; } if (bill.BrandID == default(int)) { MessageBox.Show("未指定订货品牌"); return; } if (!SysProcessView.UIHelper.CheckGridViewDataWithBrand <DistributionProductShow>(gvDatas, bill.BrandID)) { return; } bill.Status = (int)OrderStatusEnum.NotDelivered; var details = _dataContext.Details = new List <BillOrderDetails>(); foreach (var item in gvDatas.Items) { var product = (DistributionProductShow)item; if (product.Quantity != 0) { details.Add(new BillOrderDetails { ProductID = product.ProductID, Quantity = product.Quantity, QuaCancel = 0, QuaDelivered = 0, Status = (int)OrderStatusEnum.NotDelivered }); } } if (details.Count == 0) { MessageBox.Show("没有需要保存的数据"); return; } //if (!UIHelper.CheckDetailsWithBrand<BillOrderDetails>(details, bill.BrandID, gvDatas)) // return; var result = _dataContext.Save(); if (result.IsSucceed) { MessageBox.Show("保存成功"); InitDataContext(); } else { MessageBox.Show("保存失败\n失败原因:" + result.Message); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { StylePictureAlbum album = this.DataContext as StylePictureAlbum; DistributionCommonBillVM <BillOrder, BillOrderDetails> orderVM = new DistributionCommonBillVM <BillOrder, BillOrderDetails>(); var details = orderVM.Details = new List <BillOrderDetails>(); IEnumerable <int> sids = album.Styles.Select(o => o.ID).ToArray(); var products = VMGlobal.SysProcessQuery.LinqOP.Search <Product>(o => sids.Contains(o.StyleID)).ToList(); foreach (var table in _tables) { var dv = table.DefaultView; foreach (DataRowView row in dv) { ProSCPictureBO pic = (ProSCPictureBO)row[0]; for (int i = 1; i < dv.Table.Columns.Count; i++) { int qua = 0; int.TryParse(row[i].ToString(), out qua); if (qua > 0) { string sname = dv.Table.Columns[i].ColumnName; var sid = VMGlobal.Sizes.Find(o => o.Name == sname).ID; var pid = products.Find(o => o.StyleID == pic.StyleID && o.ColorID == pic.ColorID && o.SizeID == sid).ID; details.Add(new BillOrderDetails { ProductID = pid, Quantity = qua, QuaCancel = 0, QuaDelivered = 0, Status = (int)OrderStatusEnum.NotDelivered }); } } } } if (details.Count == 0) { MessageBox.Show("没有需要保存的数据"); return; } orderVM.Master.BrandID = album.BrandID; orderVM.Master.OrganizationID = VMGlobal.CurrentUser.OrganizationID; orderVM.Master.Remark = txtRemark.Text; orderVM.Master.Status = (int)OrderStatusEnum.NotDelivered; var result = orderVM.Save(); if (result.IsSucceed) { MessageBox.Show("保存成功"); foreach (var table in _tables) { var dv = table.DefaultView; foreach (DataRowView row in dv) { for (int i = 1; i < dv.Table.Columns.Count; i++) { int qua = 0; int.TryParse(row[i].ToString(), out qua); if (qua > 0) { row[i] = 0; } } } } } else { MessageBox.Show("保存失败\n失败原因:" + result.Message); } }