public override void OnValueChanged(SourceGrid.CellContext sender, EventArgs e) { base.OnValueChanged(sender, e); SuplementsGrid grid1 = (SuplementsGrid)sender.Grid; SuplementItemDTO entry = null; var row = grid1.Rows[sender.Position.Row]; if (row == null) { return; } if (row.Tag == null) { entry = new SuplementItemDTO(); row.Tag = entry; suplementEntry.AddItem(entry); parent.AddEmptyRow(); if (SuplementsSettings.Default.SetCurrentTime) { entry.Time = DateTime.Now; entry.Time = DateHelper.MoveToNewDate(entry.Time, suplementEntry.TrainingDay.TrainingDate); } } else { entry = (SuplementItemDTO)row.Tag; } entry.SuplementId = (Guid)sender.Value; //grid1[row.Index, SuplementsGrid.DosageTypeColumn].Value = DosageType.Grams; var selectedItem = from t in ((SourceGrid.Cells.Editors.ComboBox)grid1[row.Index, SuplementsGrid.DosageTypeColumn].Editor).Control.Items.Cast <ComboBoxItem>() where (DosageType)t.Tag == DosageType.Grams select t; grid1[row.Index, SuplementsGrid.DosageTypeColumn].Value = selectedItem.SingleOrDefault(); grid1[row.Index, SuplementsGrid.SuplementTypeColumn].View.ForeColor = Color.Black; grid1[row.Index, SuplementsGrid.TimeColumn].Value = entry.Time; grid1[row.Index, SuplementsGrid.DosageColumn].Value = entry.Dosage; parent.UpdateCellsReadOnlyMode(row); if (!parent.ReadOnly && !(grid1[row.Index, SuplementsGrid.DeleteButtonColumn] is SourceGrid.Cells.Button)) { var bnCol1 = new SourceGrid.Cells.Button(null); bnCol1.Image = SuplementsResources.Delete; bnCol1.ToolTipText = SuplementsEntryStrings.DeleteThisEntryTip; var ctrButton1 = new SourceGrid.Cells.Controllers.Button(); ctrButton1.Executed += new EventHandler(deleteRowBtn_Execute); bnCol1.View = new SourceGrid.Cells.Views.Button(); bnCol1.AddController(ctrButton1); grid1[row.Index, SuplementsGrid.DeleteButtonColumn] = bnCol1; } }
public SupplementItemViewModel AddSupplementItem(SuplementDTO supplement = null) { var item = new SuplementItemDTO(); item.Suplement = supplement; item.Time.DateTime = DateTime.Now; item.SuplementsEntry = Entry; Entry.Items.Add(item); var viewModel = new SupplementItemViewModel(item); _supplements.Add(viewModel); return(viewModel); }
public SuplementItemDTO GetItem() { if (item == null) { item = new SuplementItemDTO(); } item.Comment = Comment; item.Name = Name; item.Suplement = Supplement; item.Time.DateTime = Time; item.Dosage = Dosage; item.DosageType = DosageType; return(item); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); StateHelper stateHelper = new StateHelper(this.State); var item = stateHelper.GetValue <Guid>("SelectedItemId", Guid.Empty); if (item != Guid.Empty && (SelectedItem == null || SelectedItem.InstanceId == item)) { //SelectedItem = ApplicationState.Current.TrainingDay.TrainingDay.Supplements.GetItem(item); SelectedItem = Entry.GetItem(item); } viewModel = new SupplementItemViewModel(SelectedItem); DataContext = viewModel; }
public void EnsureNewRowAdded() { if (readOnly) {//in readonly mode we don't need an empty row return; } foreach (var model in Items) { if (model.IsNew) { return; } } var i = new SuplementItemDTO(); //entry.AddItem(i); Items.Add(new SupplementItemViewModel(i, readOnly)); //UpdateReadOnly(); }
public List <SuplementItemDTO> GetSuplementItems() { List <SuplementItemDTO> entries = new List <SuplementItemDTO>(); foreach (var gridViewRow in Rows) { if (gridViewRow.Tag == null) { continue; } SuplementItemDTO entry = (SuplementItemDTO)gridViewRow.Tag; Cell cell = (Cell)GetCell(gridViewRow.Index, SuplementTypeColumn); entry.SuplementId = (Guid)cell.Value; //entry.SuplementId = ((SuplementDTO)((LookupEditEditor)cell.Editor).SelectedItem).SuplementId; cell = (Cell)GetCell(gridViewRow.Index, InfoColumn); entry.Comment = (string)cell.Value; cell = (Cell)GetCell(gridViewRow.Index, SuplementNameColumn); entry.Name = (string)cell.Value; cell = (Cell)GetCell(gridViewRow.Index, DosageColumn); double tempDosage = 0; if (cell.Value != null && double.TryParse(cell.Value.ToString(), out tempDosage)) { } entry.Dosage = tempDosage; cell = (Cell)GetCell(gridViewRow.Index, DosageTypeColumn); entry.DosageType = (DosageType)((ComboBoxItem)cell.Value).Tag; cell = (Cell)GetCell(gridViewRow.Index, TimeColumn); if (cell.Value != null) { entry.Time = DateHelper.MoveToNewDate((DateTime)cell.Value, this.entry.TrainingDay.TrainingDate); } else { entry.Time = this.entry.TrainingDay.TrainingDate.Date; } entries.Add(entry); } return(entries); }
public SupplementItemViewModel(SuplementItemDTO item) { this.item = item; }
public SupplementItemViewModel(SuplementItemDTO item, bool readOnly) { this.item = item; this.readOnly = readOnly; }