Пример #1
0
        public UiBase AddNew()
        {
            // update current, if necessary
            SelectionChanged(null);

            // add new item
            IUiBase newItem = null;

            try {
                newItem = service.Create();
            } catch (Exception ex) {
                Trace.TraceError("Add new item : " + ex.Message);
            }

            if (newItem == null)
            {
                view.ShowMessage("Add Item", "Could not create a new line", MessageActions.Ok);
                return(null);
            }

            // select the new item
            var newIndex = service.GetIndex(newItem);

            Debug.Assert(newIndex >= 0);
            RefreshData();

            //SetDetailDataSourceIndex(newIndex);
            view.SelectedItem = newItem;
            return(newItem as UiBase);
        }
Пример #2
0
        public virtual void SelectionChanged(IUiBase item)
        {
            if (service.SelectedItem == item)
            {
                return;                                 // re-selected the same item
            }
            var oldSelection = service.SelectedItem;

            if (oldSelection != null)
            {
                oldSelection.PropertyChanged -= Selection_PropertyChanged;
                if (oldSelection.IsDirty)
                {
                    if (!oldSelection.Update())
                    {
                        view.ShowMessage("Delete", "Could not update the line", MessageActions.Ok);
                        // move selection back to it
                        view.SetSelection(item);
                        return;
                    }
                }

                view.SetRowStatus(service.GetIndex(oldSelection), oldSelection.IsLocked ? RowStatus.Locked : RowStatus.Normal);
            }

            // set new selection
            service.SelectedItem = item;

            if (item == null)
            {
                view.DetailSelection = null;
                return;
            }

            // TODO pass the object, not the index
            //var index = service.GetIndex(item);
            //view.DetailDataSourceIndex = index;
            item.PropertyChanged += Selection_PropertyChanged;
            view.GridReadOnly     = item.IsLocked;
        }