Beispiel #1
0
        public string GetUpdateSql <T>(T obj, ConflictResolution extra, List <object> args)
        {
            if (PrimaryKey == null)
            {
                throw new NotSupportedException("Cannot update " + TableName + ": it has no primary keys");
            }

            if (!string.IsNullOrEmpty(_updateSql) && _updateExtra != extra)
            {
                _updateSql = string.Empty;
            }

            if (string.IsNullOrEmpty(_updateSql))
            {
                _updateExtra = extra;

                string col = string.Join(", ", EditableColumns.Select(c => string.Format(CultureInfo.InvariantCulture, "[{0}] = ?", c.Name)).ToArray());
                string pks = string.Join(" AND ", PrimaryKey.Columns.Select(c => string.Format(CultureInfo.InvariantCulture, "[{0}] = ?", c.Name)).ToArray());
                _updateSql = string.Format(CultureInfo.InvariantCulture, "UPDATE {3} [{0}] SET {1} WHERE {2}",
                                           TableName,
                                           col,
                                           pks,
                                           extra == ConflictResolution.Default
                                               ? string.Empty
                                               : string.Format(CultureInfo.InvariantCulture, "OR {0}", extra));
            }

            if (args != null)
            {
                args.AddRange(EditableColumns.Select(c => c.GetValue(obj)));
                args.AddRange(PrimaryKey.Columns.Select(c => c.GetValue(obj)));
            }

            return(_updateSql);
        }
Beispiel #2
0
        protected async Task OnSaveCommand()
        {
            if (Data == null)
            {
                return;
            }

            // get the list of edited values
            var editedCellValues = EditableColumns
                                   .Select(c => new { c.Field, editItemCellValues[c.ElementId].CellValue }).ToDictionary(x => x.Field, x => x.CellValue);

            var rowSavingHandler = editState == DataGridEditState.New ? RowInserting : RowUpdating;

            if (await IsSafeToProceed(rowSavingHandler, editItem, editedCellValues))
            {
                if (UseInternalEditing && editState == DataGridEditState.New && CanInsertNewItem && Data is ICollection <TItem> data)
                {
                    data.Add(editItem);
                }

                if (UseInternalEditing || editState == DataGridEditState.New)
                {
                    // apply edited cell values to the item
                    // for new items it must be always be set, while for editing items it can be set only if it's enabled
                    foreach (var column in EditableColumns)
                    {
                        column.SetValue(editItem, editItemCellValues[column.ElementId].CellValue);
                    }
                }

                if (editState == DataGridEditState.New)
                {
                    await RowInserted.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));

                    dirtyFilter = dirtyView = true;

                    // If a new item is added, the data should be refreshed
                    // to account for paging, sorting, and filtering
                    if (ManualReadMode)
                    {
                        await HandleReadData();
                    }
                }
                else
                {
                    await RowUpdated.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));
                }

                editState = DataGridEditState.None;

                if (EditMode == DataGridEditMode.Popup)
                {
                    PopupVisible = false;
                }
            }
        }
Beispiel #3
0
        protected async Task OnSaveCommand()
        {
            if (Data is ICollection <TItem> data)
            {
                // get the list of edited values
                var editedCellValues = EditableColumns
                                       .Select(c => new { c.Field, editItemCellValues[c.ElementId].CellValue }).ToDictionary(x => x.Field, x => x.CellValue);

                if (IsSafeToProceed(RowSaving, editItem, editedCellValues))
                {
                    if (UseInternalEditing && editState == DataGridEditState.New && CanInsertNewItem)
                    {
                        data.Add(editItem);
                    }

                    if (UseInternalEditing || editState == DataGridEditState.New)
                    {
                        // apply edited cell values to the item
                        // for new items it must be always be set, while for editing items it can be set only if it's enabled
                        foreach (var column in EditableColumns)
                        {
                            column.SetValue(editItem, editItemCellValues[column.ElementId].CellValue);
                        }
                    }

                    if (editState == DataGridEditState.New)
                    {
                        await RowInserted.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));

                        dirtyFilter = dirtyView = true;
                    }
                    else
                    {
                        await RowUpdated.InvokeAsync(new SavedRowItem <TItem, Dictionary <string, object> >(editItem, editedCellValues));
                    }

                    editState = DataGridEditState.None;

                    if (EditMode == DataGridEditMode.Popup)
                    {
                        PopupVisible = false;
                    }
                }
            }
        }