コード例 #1
0
        /// <summary>
        ///  ExecuteInsertAsync
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sender"></param>
        /// <returns></returns>
        public async Task ExecuteInsertAsync <T>(object sender) where T : class
        {
            IEnumerable <DtoType> dtoValues = sender as IEnumerable <DtoType>;
            var retValue = false;

            try
            {
                if (dtoValues != null)
                {
                    var newItems = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return(baseViewObject.IsNew == true);
                    }
                                                   );
                    if (newItems.Count() > 0)
                    {
                        retValue = await _helperDataServices.ExecuteBulkInsertAsync <DtoType, T>(newItems).ConfigureAwait(false);
                    }
                }
            } catch (Exception ex)
            {
                throw new DataLayerException(ex.Message, ex);
            }
        }
コード例 #2
0
ファイル: DataField.cs プロジェクト: skiwheelr/KarveCar
        private void DataField_LostFocus(object sender, RoutedEventArgs e)
        {
            TextBox textField = GetTemplateChild("PART_TextField") as TextBox;


            // here we put the validation logic using data annotations just for data objects
            if (IsReadOnly)
            {
                return;
            }
            if (DataObject != null)
            {
                BaseViewObject baseViewObject = null;
                if (DataObject is BaseViewObject)
                {
                    baseViewObject = DataObject as BaseViewObject;
                }
                else
                {
                    var dto = ComponentUtils.GetPropValue(DataObject, "Value");
                    baseViewObject = dto as BaseViewObject;
                }
                if (baseViewObject != null)
                {
                    var context = new ValidationContext(baseViewObject, serviceProvider: null, items: null);
                    var results = new List <System.ComponentModel.DataAnnotations.ValidationResult>();
                    var isValid = Validator.TryValidateObject(baseViewObject, context, results);
                    if (!isValid)
                    {
                        baseViewObject.IsValid = isValid;
                        ErrorText = results[0].ErrorMessage;
                    }
                }
            }

            if (textField?.Text.Length > 0 && (_textContentChanged))
            {
                DataFieldEventArgs ev = new DataFieldEventArgs(DataFieldChangedEvent)
                {
                    FieldData = textField.Text
                };

                var valueDictionary = InitValueDictionary(textField.Text, DataObject);
                ev.ChangedValuesObjects = valueDictionary;

                if (ItemChangedCommand != null)
                {
                    if (ItemChangedCommand.CanExecute(valueDictionary))
                    {
                        ItemChangedCommand.Execute(valueDictionary);
                    }
                }
                else
                {
                    RaiseEvent(ev);
                }
                _textContentChanged = false;
            }
        }
コード例 #3
0
        /*
         *
         * This method handles all the grid operations
         */
        protected async Task UpdateGridAsync <Dto, Entity>(DataPayLoad payLoad) where Dto : class
            where Entity : class
        {
            GridOperationHandler <Dto> gridOperationHandler = new GridOperationHandler <Dto>(DataServices);
            IEnumerable <Dto>          dtoValues            = payLoad.RelatedObject as IEnumerable <Dto>;

            // ok now we can see if it is an insert or a delete.
            try
            {
                if (dtoValues != null)
                {
                    var newItems = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return(baseViewObject.IsNew == true);
                    });
                    if (newItems.Any())
                    {
                        await gridOperationHandler.ExecuteInsertAsync <Entity>(newItems).ConfigureAwait(false);
                    }

                    var itemsToDelete = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return(baseViewObject.IsDeleted == true);
                    });
                    if (itemsToDelete.Count() > 0)
                    {
                        await gridOperationHandler.ExecuteDeleteAsync <Entity>(itemsToDelete).ConfigureAwait(false);
                    }
                    var updateItems = dtoValues.Where(x =>
                    {
                        BaseViewObject baseViewObject = x as BaseViewObject;
                        return((baseViewObject.IsDirty == true) && (baseViewObject.IsNew == false));
                    });
                    if (updateItems.Count() > 0)
                    {
                        await gridOperationHandler.ExecuteUpdateAsync <Entity>(updateItems).ConfigureAwait(false);
                    }
                    for (int i = 0; i < updateItems.Count(); ++i)
                    {
                        BaseViewObject baseViewObject = updateItems.ElementAt(i) as BaseViewObject;
                        if (baseViewObject != null)
                        {
                            baseViewObject.IsNew   = false;
                            baseViewObject.IsDirty = false;
                        }
                    }
                }
            } catch (Exception e)
            {
                /// FIXME: in case of exception happens that gets called twice.
                var msg = "UpdateGridException " + e.Message;
                throw new DataLayerException(msg);
            }
        }
コード例 #4
0
 private void OnItemSelected(object[] obj)
 {
     if (obj != null && obj.Count() > 0)
     {
         var current = obj.FirstOrDefault() as BaseViewObject;
         if (current != null)
         {
             this.SelectedItem = current;
         }
     }
 }
コード例 #5
0
ファイル: ControlExt.cs プロジェクト: skiwheelr/KarveCar
        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)
                    {
                        BaseViewObject viewObject = item as BaseViewObject;
                        viewObject.IsDeleted = true;
                    }
                    var collection = dataGrid.View.SourceCollection;
                    foreach (var c in collection)
                    {
                        BaseViewObject v = c as BaseViewObject;
                        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);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Execute the update async.
        /// </summary>
        /// <typeparam name="T">entity Type.</typeparam>
        /// <param name="sender"></param>
        /// <returns></returns>
        public async Task <bool> ExecuteUpdateAsync <T>(object sender) where T : class
        {
            IEnumerable <DtoType> dtoValues = sender as IEnumerable <DtoType>;
            bool retValue = false;

            if (dtoValues != null)
            {
                var newItems = dtoValues.Where(x =>
                {
                    BaseViewObject baseViewObject = x as BaseViewObject;
                    return((baseViewObject.IsDirty == true) && (!baseViewObject.IsNew));
                });
                if (dtoValues.Count() > 0)
                {
                    retValue = await _helperDataServices.ExecuteBulkUpdateAsync <DtoType, T>(newItems).ConfigureAwait(false);
                }
            }
            return(retValue);
        }
コード例 #7
0
        protected async Task <bool> DeleteGridAsync <Dto, Entity>(DataPayLoad payLoad) where Dto : class
            where Entity : class
        {
            bool retValue = false;
            GridOperationHandler <Dto> gridOperationHandler = new GridOperationHandler <Dto>(DataServices);
            IEnumerable <Dto>          dtoValues            = payLoad.RelatedObject as IEnumerable <Dto>;

            if (dtoValues != null)
            {
                var toBeDeleted = dtoValues.Where(x =>
                {
                    BaseViewObject baseViewObject = x as BaseViewObject;
                    return(baseViewObject.IsDeleted == true);
                });
                if (toBeDeleted.Count() > 0)
                {
                    retValue = await gridOperationHandler.ExecuteDeleteAsync <Dto>(toBeDeleted);
                }
            }
            return(retValue);
        }
コード例 #8
0
ファイル: ControlExt.cs プロジェクト: skiwheelr/KarveCar
        /**
         *  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;
            BaseViewObject   viewObject       = null;
            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)
                {
                    viewObject = dataValue as BaseViewObject;
                    if (viewObject != null)
                    {
                        viewObject.LastModification = DateTime.Now.ToLongTimeString();
                        viewObject.IsNew            = (rowState == GridOp.Insert) ? true : false;
                        viewObject.IsDirty          = true;
                    }
                }

                var collection = dataGrid.View.SourceCollection;

                /*
                 * if (collection is IEnumerable<BaseViewObject> dtoArray)
                 * {
                 *  if (viewObject != null)
                 *  {
                 *      if (dtoArray.Count() == 0)
                 *      {
                 *          dtoArray = dtoArray.Union(new List<BaseViewObject> { viewObject });
                 *          collection = dtoArray;
                 *         return;
                 *      }
                 *  }
                 * }*/

                foreach (var c in collection)
                {
                    BaseViewObject v = c as BaseViewObject;
                    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);
            }
        }
コード例 #9
0
ファイル: ControlExt.cs プロジェクト: skiwheelr/KarveCar
        private static void CurrentDataGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
        {
            object dataValue = null;

            if (e.Key == System.Windows.Input.Key.Enter)
            {
                if (sender is SfDataGrid dataGrid)
                {
                    DependencyObject dependencyObject = sender as DependencyObject;
                    var           command             = dataGrid?.GetValue(ItemChangedCommandProperty) as ICommand;
                    List <object> value = new List <object>();
                    if ((command != null) && (dataGrid != null))
                    {
                        dataValue = dataGrid.SelectedItem;
                        var rowState = GetGridOperation(dependencyObject);
                        if (dataValue != null)
                        {
                            BaseViewObject viewObject = dataValue as BaseViewObject;
                            if (viewObject != null)
                            {
                                viewObject.LastModification = DateTime.Now.ToLongTimeString();
                                if (!viewObject.IsNew)
                                {
                                    viewObject.IsNew = (rowState == GridOp.Insert) ? true : false;
                                }
                                viewObject.IsDirty = true;
                            }
                        }

                        var collection = dataGrid.View.SourceCollection;
                        if (collection is IEnumerable <BaseViewObject> dtoArray)
                        {
                            if (dtoArray.Count() == 0)
                            {
                                return;
                            }
                        }
                        foreach (var c in collection)
                        {
                            BaseViewObject v = c as BaseViewObject;
                            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 = dataValue;
                        command.Execute(objectName);
                        SwitchToUpdate(dependencyObject, rowState);
                    }
                }
            }
        }
コード例 #10
0
 public ItemSelectionViewModel()
 {
     this.SelectItemCommand = new DelegateCommand <object>(this.AcceptSelectedItem);
     this.CancelCommand     = new DelegateCommand(this.CancelInteraction);
     SelectedItem           = new BaseViewObject();
 }