Exemplo n.º 1
0
        private void callbackPanel_Callback(object sender, CallbackEventArgsBase e)
        {
            if (e.Parameter == "add")
            {
                var newObject = (XPBaseObject)_objectSpace.CreateObject(Model.ModelClass.TypeInfo.Type);
                _collectionSource.Add(newObject);

                BindDataSource();

                object itemOid = newObject.GetMemberValue(Model.ModelClass.KeyProperty); // newObject.Oid;
                try{
                    var firstOrDefault = Model.Columns.Where(t => t.Index.HasValue && t.Index.Value >= 0)
                                         .OrderBy(t => t.Index.Value)
                                         .FirstOrDefault();
                    if (firstOrDefault != null)
                    {
                        _controlsPerObjectInList[itemOid][
                            firstOrDefault
                            .PropertyName].Focus();
                    }
                }
                catch {
                }
            }
            else if (e.Parameter != null && e.Parameter.StartsWith("changed_"))
            {
                string[] split        = e.Parameter.Split('_');
                string   itemOid      = split[2];
                string   propertyName = split[1];
                BindDataSource();
                try{
                    object key = _controlsPerObjectInList.Keys.FirstOrDefault(item => item.ToString() == itemOid);

                    if (key != null && _controlsPerObjectInList.ContainsKey(key))
                    {
                        _controlsPerObjectInList[key][propertyName].Focus();
                    }
                }
                catch {
                }
            }
            else if (e.Parameter != null && e.Parameter.StartsWith("rem_"))
            {
                string itemOid = e.Parameter.Replace("rem_", "");
                if (_dataSourceList == null)
                {
                    return;
                }
                XPBaseObject itemToBeDeleted = _dataSourceList.Cast <XPBaseObject>().FirstOrDefault(item => item.GetMemberValue(Model.ModelClass.KeyProperty).ToString() == itemOid);
                if (itemToBeDeleted != null)
                {
                    _collectionSource.Remove(itemToBeDeleted);
                    itemToBeDeleted.Delete();
                }
                if (_collectionSource.GetCount() == 0 && _btnAddFirst != null)
                {
                    _btnAddFirst.Visible = true;
                }

                BindDataSource();

                FocusCorrectControl();
            }
            ToggleHeadersVisibility();

            OnCallbackPerformed();
        }