예제 #1
0
        // [VortexPrincipalPermissionAttribute(SecurityAction.Demand, Role = Security.Roles.data_exchange_view_can_update_record)]
#endif
        private void Update()
        {
            var a = ((dynamic)DataExchange)._data.CreatePlainerType();

            a.CopyShadowToPlain(((dynamic)DataExchange)._data);
            string info = $"{this.DataExchange.Symbol} {a._EntityId}";

            Vortex.Presentation.Wpf.ActionRunner.Runner.Execute(() =>
            {
                CrudDataObject?.ChangeTracker.SaveObservedChanges(a);
                var validationErrrors = new StringBuilder();
                var validations       = DataBrowser.UpdateRecord(a);
                var validationFailed  = false;
                foreach (DataItemValidation validationItem in validations)
                {
                    if (validationItem.Failed)
                    {
                        validationErrrors.AppendLine($"{validationItem.Error}");
                        validationFailed = true;
                    }
                }

                if (validationFailed)
                {
                    MessageBox.Show($"Some data is not valid: {validationErrrors}", "Data validation", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                FillObservableRecords();
                this.Mode = ViewMode.Display;
            }, info,
                                                                () => MessageBox.Show($"{strings.WouldYouLikeToUpdateRecord} '{a._EntityId}'?", "Data", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes);
        }
예제 #2
0
 internal void FillObservableRecords()
 {
     ObservableRecords.Clear();
     DataBrowser.Filter(this.FilterByID, this.Limit, this.page * this.Limit);
     foreach (var item in DataBrowser.Records)
     {
         ObservableRecords.Add(item);
     }
 }
예제 #3
0
        public PageHandler( DataBrowser owner, Uri url, object obj )
        {
            if( owner == null )
                throw new ArgumentNullException( "owner" );
            if( url == null )
                throw new ArgumentNullException( "uri" );
            if( obj == null )
                throw new ArgumentNullException( "obj" );

            this.owner = owner;
            this.url = url;
            this.obj = obj;
        }
예제 #4
0
 private void CreateNew()
 {
     Vortex.Presentation.Wpf.ActionRunner.Runner.Execute(() =>
     {
         var plainer       = ((dynamic)DataExchange)._data.CreatePlainerType();
         plainer._EntityId = RecordIdentifier;
         DataBrowser.AddRecord(plainer);
         var plain = DataBrowser.FindById(plainer._EntityId);
         ((dynamic)DataExchange)._data.CopyPlainToShadow(plain);
         FillObservableRecords();
         SelectedRecord = plain;
         this.Mode      = ViewMode.Edit;
     });
 }
예제 #5
0
 void LoadFromPlc()
 {
     Vortex.Presentation.Wpf.ActionRunner.Runner.Execute(() =>
     {
         var plainer = ((dynamic)DataExchange)._data.CreatePlainerType();
         ((dynamic)DataExchange)._data.FlushOnlineToPlain(plainer);
         plainer._EntityId = $"{DataHelpers.CreateUid().ToString()}";
         DataBrowser.AddRecord(plainer);
         var plain = DataBrowser.FindById(plainer._EntityId);
         ((dynamic)DataExchange)._data.CopyPlainToShadow(plain);
         FillObservableRecords();
         SelectedRecord = plain;
         this.Mode      = ViewMode.Edit;
     }, "", () => MessageBox.Show($"{strings.WouldYouLikeToGetFromPLC}", "Data", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes);
 }
예제 #6
0
        // [VortexPrincipalPermissionAttribute(SecurityAction.Demand, Role = Security.Roles.data_exchange_view_can_user_delete_record)]
#endif
        private void Delete()
        {
            var a = ((dynamic)DataExchange)._data.CreatePlainerType();

            a.CopyShadowToPlain(((dynamic)DataExchange)._data);
            string id = $"{DataExchange.Symbol}.{a._EntityId}";

            Vortex.Presentation.Wpf.ActionRunner.Runner.Execute(() =>
            {
                DataBrowser.Delete(a);
                this.FilterByID = "";
                FillObservableRecords();
                this.SelectedRecord = this.ObservableRecords.FirstOrDefault();
            },
                                                                id,
                                                                () => MessageBox.Show($"{strings.WouldYouLikeToDeleteRecord}: '{a._EntityId}'?", "Data", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes);
        }
예제 #7
0
 public ModelScorePageHandler( DataBrowser owner, Uri url, Audit.ModelScore obj )
     : base(owner, url, obj)
 {
 }
        /// <summary>
        /// Method to create a DataTable to be visualized
        /// </summary>
        /// <param name="list"></param>
        /// <param name="history">history as breadcrumbs to jump back. root objects don't need one</param>
        /// <returns></returns>
        private DataTable CreateDataTableFromList(String title, System.Collections.IList list, List <HistoryElement> history = null)
        {
            if (list.Count == 0)
            {
                return(null);
            }

            var dataTable = new DataTable();

            // root object? init history
            if (history == null)
            {
                history = new List <HistoryElement>();
            }


            bool addBackButton = history != null && history.Count > 0;

            // fake-headers-row:
            List <DataCellObject> header = new List <DataCellObject>();

            dataTable.rows.Add(header);
            for (int rowNr = 0; rowNr < list.Count; rowNr++)
            {
                var rowObject = list[rowNr];
                // try to convert this object if there is an converter registered(e.g. UID)
                rowObject = devui.DataBrowserConvertObject(rowObject);
                List <DataCellObject> rowDataList = new List <DataCellObject>();

                Action <object, List <DataCellObject> > traverseObj = null;
                traverseObj = (rowObj, rowData) => {
                    DataBrowser.Traverse(rowObj, (varName, varObj, type, meta) => {
                        Debug.Log(varName + " : " + varObj);
                        if (rowNr == 0)
                        {
                            // define the columns in the first row
                            var headerElement = new ColumnDefinition()
                            {
                                width   = meta == null ? 100.0f : meta.width,
                                colName = (meta == null || meta.visualName == null) ? varName : meta.visualName
                            };

                            dataTable.columnDef.Add(headerElement);

                            // --------fake headers------------
                            header.Add(new DataCellObject()
                            {
                                value    = headerElement.colName,
                                cellType = DataCellObject.CellType.Header,
                                callback = (st) => { Debug.Log("Pressed the header:" + headerElement.colName); }
                            });
                            // --------------------------------
                        }

                        // traverse another list and add the whole data in one DataCellObject

                        /*if (meta!=null && meta.type == DataBrowser.UIDBInclude.Type.subdata) {
                         *  if (type == MemoryBrowser.ElementType.listType) {
                         *      var subList = (IList)varObj;
                         *      List<List<DataCellObject>> subdata = new List<List<DataCellObject>>();
                         *      for (int i = 0; i < subList.Count; i++) {
                         *          var subListElem = subList[i];
                         *          List<DataCellObject> subRowData = new List<DataCellObject>();
                         *          traverseObj(subListElem, subRowData);
                         *          subdata.Add(subRowData);
                         *      }
                         *      var rowElem = new DataCellObject() {
                         *          cellType = DataCellObject.CellType.Subdata,
                         *          value = subdata
                         *      };
                         *      rowData.Add(rowElem);
                         *  }
                         * }
                         * else */
                        if (varObj == null || MemoryBrowser.IsSimple(varObj.GetType()) || varObj is Vector2 || varObj is Vector3)
                        {
                            // SIMPLE TYPE-HANDLING (int,string,enums,bool,...)
                            var rowElem = new DataCellObject()
                            {
                                value    = varObj,
                                callback = (newVal) => {
                                    if (newVal == null)
                                    {
                                        // selection of readonly-cell
                                        return;
                                    }
                                    // try to set the value of this field/property
                                    bool successful = DataBrowser.SetValue(rowObj, varName, newVal);
                                    Debug.Log("Setting var " + varName + " to new Value:" + newVal + " [" + (successful ? "success" : "fail") + "]");
                                }
                            };

                            var onlyread = varObj == null || (meta != null && meta.type == DataBrowser.UIDBInclude.Type.onlyread);

                            if (onlyread)
                            {
                                rowElem.cellType = DataCellObject.CellType.Output;
                            }
                            else
                            {
                                if (varObj is Enum)
                                {
                                    rowElem.cellType       = DataCellObject.CellType.Dropdown;
                                    rowElem.dropdownValues = new List <string>(Enum.GetNames(varObj.GetType()));
                                    rowElem.value          = (int)varObj;
                                }
                                else if (varObj.GetType() == typeof(bool))
                                {
                                    rowElem.cellType       = DataCellObject.CellType.Dropdown;
                                    rowElem.dropdownValues = new List <string> {
                                        "false", "true"
                                    };
                                    rowElem.value = ((bool)varObj) ? 1 : 0;
                                }
                                else
                                {
                                    rowElem.cellType = DataCellObject.CellType.EditableOutput;
                                }
                            }
                            rowData.Add(rowElem);
                        }
                        else
                        {
                            // NOT SIMPLE TYPES ( Object-Instances, List, Dict...)
                            if (type == MemoryBrowser.ElementType.objectType || type == MemoryBrowser.ElementType.dictType)
                            {
                                // REFERENCE - LINK : OBJECT
                                string cellTitle = (meta != null && meta.type == DataBrowser.UIDBInclude.Type.subdata)
                                                ? "( " + (varObj.ToString()) + " )"
                                                : "LINK";
                                var rowElem = new DataCellObject()
                                {
                                    value    = cellTitle,
                                    callback = (newVal) => {
                                        var objList = new ArrayList()
                                        {
                                            varObj
                                        };
                                        Debug.Log("Go to REF:" + varObj.ToString());
                                        history.Add(new HistoryElement()
                                        {
                                            historyTitle = title, objectList = list
                                        });
                                        _eventService.Publish(new Service.DevUIService.Events.NewDataTable()
                                        {
                                            // since this is a single object and the DataBrowser is meant for lists, wrap the object in a list
                                            objectList = objList,
                                            history    = history,
                                            tableTitle = varName + ":" + varObj.GetType().Name
                                        });
                                        return;
                                    },
                                    cellType = DataCellObject.CellType.Button
                                };
                                rowData.Add(rowElem);
                            }
                            else if (type == MemoryBrowser.ElementType.listType)
                            {
                                // REFERENCE-LINK: LIST
                                var theList = (IList)varObj;



                                string cellTitle = (meta != null && meta.type == DataBrowser.UIDBInclude.Type.subdata)
                                                ? "( " + (OutputListAsStrings(theList)) + " )"
                                                : "List[" + theList.Count + "]";


                                var rowElem = new DataCellObject()
                                {
                                    value    = cellTitle,
                                    callback = (newVal) => {
                                        Debug.Log("Cannot go into empty lists");

                                        if (theList.Count == 0)
                                        {
                                            //
                                            return;
                                        }
                                        history.Add(new HistoryElement()
                                        {
                                            historyTitle = title, objectList = list
                                        });
                                        _eventService.Publish(new Service.DevUIService.Events.NewDataTable()
                                        {
                                            // since this is a single object and the DataBrowser is meant for lists, wrap the object in a list
                                            objectList = (IList)varObj,
                                            history    = history,
                                            tableTitle = varName + ":" + varObj.GetType().Name
                                        });
                                        return;
                                    },
                                    cellType = DataCellObject.CellType.Button
                                };
                                rowData.Add(rowElem);
                            }
                        }
                    });
                };
                traverseObj(rowObject, rowDataList);

                Func <int, List <DataCellObject> > CreateEmptyLine = (amount) => {
                    var result = new List <DataCellObject>(amount);
                    for (int i = 0; i < amount; i++)
                    {
                        result.Add(new DataCellObject()
                        {
                            cellType = DataCellObject.CellType.Empty
                        });
                    }
                    return(result);
                };


                dataTable.rows.Add(rowDataList);
            }
            return(dataTable);
        }