Ejemplo n.º 1
0
        private static void CurrentDataGrid_CurrentCellEndEdit(object sender, CurrentCellEndEditEventArgs e)
        {
            SfDataGrid dataGrid = sender as SfDataGrid;

            if (dataGrid != null)
            {
                IDictionary <string, object> objectName = new Dictionary <string, object>();
                var command = dataGrid.GetValue(ItemChangedCommandProperty) as ICommand;
                if (command != null)
                {
                    /*
                     *
                     * objectName["DataObject"] = GetDataSource(dataGrid);
                     * objectName["DataSourcePath"] = GetDataSourcePath(dataGrid);
                     * objectName["ChangedValue"] = dataGrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex);
                     * objectName["PreviousValue"] = lastChangedRow;
                     * objectName["Operation"] = ControlExt.GridOp.Update;
                     * objectName["DeletedItems"] = false;
                     * objectName["LastRowId"] = dataGrid.GetLastRowIndex();
                     * lastChangedRow = dataGrid.GetRecordAtRowIndex(e.RowColumnIndex.RowIndex);
                     * command.Execute(objectName);
                     */
                }
            }
        }
Ejemplo n.º 2
0
        private static void CurrentDataGrid_AddNewRowInitiating(object sender, AddNewRowInitiatingEventArgs e)
        {
            SfDataGrid dataGrid = sender as SfDataGrid;
            var        command  = dataGrid?.GetValue(ItemChangedCommandProperty) as ICommand;

            if ((command != null) && (dataGrid != null))
            {
                DependencyObject dependencyObject = sender as DependencyObject;
                SetGridOperation(dependencyObject, GridOp.Insert);
            }
        }
Ejemplo n.º 3
0
        private static void CurrentDataGrid_RecordDeleted(object sender, RecordDeletedEventArgs e)
        {
            SfDataGrid    dataGrid = sender as SfDataGrid;
            List <object> value    = new List <object>();

            if (dataGrid != null)
            {
                IDictionary <string, object> objectName = new Dictionary <string, object>();
                var command = dataGrid.GetValue(ItemChangedCommandProperty) as ICommand;
                if (command != null)
                {
                    var items = e.Items;
                    foreach (var item in items)
                    {
                        BaseDto dto = item as BaseDto;
                        dto.IsDeleted = true;
                    }
                    var collection = dataGrid.View.SourceCollection;
                    foreach (var c in collection)
                    {
                        BaseDto v = c as BaseDto;
                        if (v.IsNew)
                        {
                            value.Add(c);
                        }
                        else if (v.IsDirty)
                        {
                            value.Add(c);
                        }
                        else if (v.IsDeleted)
                        {
                            value.Add(c);
                        }
                    }


                    IEnumerable <object> currentValues = value.Union(items);

                    objectName["DataObject"]     = GetDataSource(dataGrid);
                    objectName["DataSourcePath"] = GetDataSourcePath(dataGrid);
                    objectName["ChangedValue"]   = currentValues;
                    objectName["DeletedItems"]   = true;
                    objectName["Operation"]      = ControlExt.GridOp.Delete;
                    objectName["DeletedItems"]   = false;
                    objectName["LastRowId"]      = dataGrid.GetLastRowIndex();
                    command.Execute(objectName);
                }
            }
        }
Ejemplo n.º 4
0
        /**
         *  The grid insertion or adding, we need to move between two states:
         *  When it gets the event add new row,
         *  we get the new row event and move the grid operation to insert,
         *  later when we are in a validation row, we validate the row and that's it.
         */


        private static void CurrentDataGrid_RowValidated(object sender, RowValidatedEventArgs e)
        {
            SfDataGrid       dataGrid         = sender as SfDataGrid;
            DependencyObject dependencyObject = sender as DependencyObject;
            var           command             = dataGrid?.GetValue(ItemChangedCommandProperty) as ICommand;
            List <object> value = new List <object>();

            if ((command != null) && (dataGrid != null))
            {
                var dataValue = dataGrid.GetRecordAtRowIndex(e.RowIndex);
                var rowState  = GetGridOperation(dependencyObject);
                if (dataValue != null)
                {
                    BaseDto dto = dataValue as BaseDto;
                    if (dto != null)
                    {
                        dto.LastModification = DateTime.Now.ToLongTimeString();
                        dto.IsNew            = (rowState == GridOp.Insert) ? true : false;
                        dto.IsDirty          = true;
                    }
                }

                var collection = dataGrid.View.SourceCollection;
                if (collection is IEnumerable <BaseDto> dtoArray)
                {
                    if (dtoArray.Count() == 0)
                    {
                        return;
                    }
                }
                foreach (var c in collection)
                {
                    BaseDto v = c as BaseDto;
                    if (v != null)
                    {
                        if (v.IsNew)
                        {
                            value.Add(c);
                        }
                        else if (v.IsDirty)
                        {
                            value.Add(c);
                        }
                        else if (v.IsDeleted)
                        {
                            value.Add(c);
                        }
                    }
                }

                IDictionary <string, object> objectName = new Dictionary <string, object>();
                value.Add(dataValue);
                objectName["DataObject"]     = GetDataSource(dataGrid);
                objectName["DataSourcePath"] = GetDataSourcePath(dataGrid);
                objectName["ChangedValue"]   = value;
                objectName["PreviousValue"]  = _lastChangedRow;
                objectName["Operation"]      = rowState;
                objectName["DeletedItems"]   = false;
                objectName["LastRowId"]      = dataGrid.GetLastRowIndex();
                _lastChangedRow = dataGrid.GetRecordAtRowIndex(e.RowIndex);
                command.Execute(objectName);
                SwitchToUpdate(dependencyObject, rowState);
            }
        }