private async void olvDetails_CellEditFinishing(object sender, CellEditEventArgs e) { if (e.Cancel) { return; } if (e.RowObject is MachineDetailsVm row) { if (e.Column == olvPieces) { row.Qty = (int)e.NewValue; if (row.Qty < 0) { row.Qty = 0; } _dmr.SetQuantity(row); } else if (e.Column == olvMaterial) { var detail = await _dr.GetByIdAsync(row.DetailId); detail.Material = e.NewValue.ToString(); await _dr.UpdateAsync(detail); } else if (e.Column == olvPrice) { var detail = await _dr.GetByIdAsync(row.DetailId); detail.Price = (decimal)(string.IsNullOrWhiteSpace(e.NewValue.ToString()) ? 0m : e.NewValue); await _dr.UpdateAsync(detail); } else if (e.Column == olvRemark) { var detail = await _dr.GetByIdAsync(row.DetailId); detail.Remark = e.NewValue.ToString(); await _dr.UpdateAsync(detail); } FillOlv(row.MachineId); } }
private async void olvDetails_CellEditFinishing(object sender, CellEditEventArgs e) { if (e.Cancel) { return; } var model = e.RowObject as Detail; if (model == null) { throw new Exception("Cast is not possible.Wrong model"); } if (e.NewValue.Equals(e.Value)) { e.Cancel = true; olvDetails.RemoveObjects(olvDetails.Objects.Cast <Detail>().Where(c => c.Id == 0).ToArray()); return; } if (e.Column == olvName) { model.Name = e.NewValue.ToString(); } else if (e.Column == olvPartNumber) { if (string.IsNullOrEmpty(e.NewValue.ToString())) { e.Cancel = true; } else { model.PartNumber = e.NewValue.ToString(); } } else if (e.Column == olvPrice) { model.Price = (decimal)(string.IsNullOrWhiteSpace(e.NewValue.ToString()) ? 0m : e.NewValue); } else if (e.Column == olvRemark) { model.Remark = e.NewValue.ToString(); } else if (e.Column == olvMaterial) { model.Material = e.NewValue.ToString(); _materials.Add(model.Material); } else if (e.Column == olvLength) { model.Length = Math.Round((double)(decimal)e.NewValue, 2); } if (model.Id != 0) { await _detailsRepo.UpdateAsync(model); } else { await _detailsRepo.InsertAsync(model); } }