private void GridSpinEditColumn_Validate(object sender, GridCellValidationEventArgs e)
        {
            bool discontinued = ((Product)e.Row).Discontinued;

            if (discontinued)
            {
                double discount = 100 - (Convert.ToDouble(e.Value) * 100) /
                                  Convert.ToDouble(e.CellValue);
                if (!(discount > 0 && discount <= 30))
                {
                    e.Handled   = true;
                    e.IsValid   = false;
                    e.ErrorType = DevExpress.UI.Xaml.Editors.Native.ErrorType.Critical;
                    if (discount < 0)
                    {
                        e.ErrorContent = string.Format("The price cannot be greater than ${0}",
                                                       Convert.ToDouble(e.CellValue));
                        return;
                    }
                    e.ErrorContent = string.Format(
                        "The discount cannot be greater than 30% (${0}). Please correct the price.",
                        Convert.ToDouble(e.CellValue) * 0.7);
                    e.Handled = true;
                }
            }
        }
Пример #2
0
        private void colFreight_Validate(object sender, GridCellValidationEventArgs e)
        {
            if (e.Value == null)
            {
                e.IsValid      = false;
                e.ErrorContent = "Freight can't be empty";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Information;
                e.Handled      = true;
                return;
            }
            decimal freight;

            e.IsValid = decimal.TryParse(e.Value.ToString(), out freight);
            if (!e.IsValid)
            {
                e.ErrorContent = "Freight must be decimal";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Critical;
                e.Handled      = true;
            }
            if (freight <= 0)
            {
                e.IsValid      = false;
                e.ErrorContent = "Freight must be greater than 0";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Default;
                e.Handled      = true;
            }
        }
Пример #3
0
        private void executeValidateOrderType(GridCellValidationEventArgs eventArgs)
        {
            if (eventArgs.Value == null)
            {
                eventArgs.IsValid = false;
                eventArgs.SetError("Invalid item.");
                return;
            }
            string  value = eventArgs.Value.ToString();
            InvType item  = MarketTypes.SingleOrDefault(f => f.TypeName == value);

            if (item == null)
            {
                eventArgs.IsValid = false;
                eventArgs.SetError("Invalid item.");
            }
            else
            {
                if (Orders.SingleOrDefault(order => order.Order.TypeId == item.TypeId) != null)
                {
                    eventArgs.IsValid = false;
                    eventArgs.SetError("An order for this item already exists.");
                }
                else
                {
                    ((OrderVm)eventArgs.Row).Order.TypeId  = item.TypeId;
                    ((OrderVm)eventArgs.Row).Order.InvType = item;
                }
            }
        }
Пример #4
0
        void colCustomerID_Validate(object sender, GridCellValidationEventArgs e)
        {
            if (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))
            {
                e.ErrorContent = "Customer ID can't be empty";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Information;
                e.Handled      = true;
                e.IsValid      = false;
                return;
            }
            string id = e.Value.ToString();

            //if (id.Length != 5) {
            //    e.ErrorContent = "Customer ID must be 5-characters long";
            //    e.ErrorType = DevExpress.UI.Xaml.Editors.Native.ErrorType.Information;
            //    e.Handled = true;
            //    e.IsValid = false;
            //    return;
            //}
            if (id.ToUpper() != id)
            {
                e.ErrorContent = "Customer ID must contain only upper case letters";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Information;
                e.Handled      = true;
                e.IsValid      = false;
            }
        }
Пример #5
0
        private void colOrderIDValidate(object sender, GridCellValidationEventArgs e)
        {
            if (e.Value == null)
            {
                e.IsValid      = false;
                e.ErrorContent = "Order ID can't be empty";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Information;
                e.Handled      = true;
                return;
            }
            int id;

            e.IsValid = int.TryParse(e.Value.ToString(), out id);
            if (!e.IsValid)
            {
                e.ErrorContent = "Order ID must be integer";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Critical;
                e.Handled      = true;
            }
            if (id <= 0)
            {
                e.IsValid      = false;
                e.ErrorContent = "Order ID must be greater than 0";
                e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Default;
                e.Handled      = true;
            }
        }
Пример #6
0
        void colHoursActive_Validate(object sender, GridCellValidationEventArgs e)
        {
            double value = Convert.ToDouble(e.Value, e.Culture);

            if (value <= 0 || 1000 < value)
            {
                e.SetError("The Hours Active value must be greater than zero and less than or equal to 1000", ErrorType.Default);
            }
        }
        protected override void OnValidateCell(object sender, GridCellValidationEventArgs args)
        {
            GridItem item = (GridItem)this.gridControl.SelectedItem;

            if (item == null)
            {
                item = (GridItem)this.gridControl.CurrentItem;
            }
            if (item != null)
            {
                ColumnBase   col      = args.Column;
                GrilleColumn column   = this.Grille.GetColumn(col.FieldName);
                string       oldValue = item.Datas[column.position] != null ? item.Datas[column.position].ToString() : "";
                string       newValue = args.Value != null?args.Value.ToString() : "";

                if (!IsEditionValid(item, column, oldValue, newValue, args))
                {
                    args.Handled = true;
                    args.IsValid = false;
                    return;
                }

                GrilleEditedElement element = new GrilleEditedElement();
                element.column     = column;
                element.oid        = item.GetOid();
                element.value      = new Kernel.Domain.Browser.BrowserData();
                element.value.name = newValue;
                if (this.EditEventHandler != null)
                {
                    GrilleEditedResult result = EditEventHandler(element);
                    if (result.isError)
                    {
                        args.Handled      = true;
                        args.IsValid      = false;
                        args.ErrorContent = result.error;
                        return;
                    }
                    else
                    {
                        if (result.datas == null)
                        {
                            args.Handled = true;
                        }
                        else
                        {
                            item.Datas = result.datas;
                        }
                        Refresh();
                    }
                }
            }
        }
Пример #8
0
 private void ProductNameValidate(object sender, GridCellValidationEventArgs e)
 {
     if (e.Value == null || string.IsNullOrEmpty(e.Value.ToString()))
     {
         e.IsValid = false;
     }
     if (!e.IsValid)
     {
         e.Handled      = true;
         e.ErrorType    = DevExpress.UI.Xaml.Editors.Native.ErrorType.Warning;
         e.ErrorContent = "Product Name can't be empty";
     }
 }
Пример #9
0
        private bool EditProperty(B item, GridCellValidationEventArgs args)
        {
            String         header = args.Column.Header.ToString();
            Object         value  = args.Value;
            OperationState state  = EditProperty(item, header, value);

            if (state == OperationState.STOP)
            {
                args.Handled = false;
                return(false);
            }
            return(true);
        }
Пример #10
0
 public void SetWorkItem(GridCellValidationEventArgs e)
 {
     try
     {
         var detail = (DetailService)e.Row;
         detail.WorkItem = WorkItem;
         detail.UnitCost = WorkItem.EstimatedCost;
     }
     catch (Exception ex)
     {
         MessageBoxService.ShowMessage(GetStringValue(Next.Enums.Enums.MessageError.DataError) + ex.Message, ex.Message,
                                       MessageButton.OK, MessageIcon.Error);
     }
 }
Пример #11
0
        static void OnColumnValidate(object sender, GridCellValidationEventArgs e)
        {
            GridColumn column = (GridColumn)sender;

            foreach (ValidationRule rule in GetValidationRules(column))
            {
                ValidationResult result = rule.Validate(e.Value, CultureInfo.CurrentCulture);
                if (!result.IsValid)
                {
                    e.IsValid      = false;
                    e.ErrorContent = result.ErrorContent;
                    break;
                }
            }
        }
Пример #12
0
        void OnValidateCell(object sender, GridCellValidationEventArgs e)
        {
            if (e.Column.FieldName != nameof(Product.UnitPrice) || !((Product)e.Row).Discontinued)
            {
                return;
            }
            var cellValue = (double)e.CellValue;
            var discount  = 100 - Convert.ToDouble(e.Value) / cellValue * 100;

            if (discount > 0 && discount <= 30)
            {
                return;
            }

            e.IsValid      = false;
            e.ErrorType    = DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical;
            e.ErrorContent = discount < 0
                ? $"The price cannot be greater than {cellValue}"
                : $"The discount cannot be greater than 30% ({cellValue * 0.7}). Please correct the price.";
        }
        /// <summary>
        /// Validate the cell value.
        /// </summary>
        /// <param name="sender">
        /// The Grid view that is being edited.
        /// </param>
        /// <param name="e">
        /// The cell validation event.
        /// </param>
        private void ValidateCell(object sender, GridCellValidationEventArgs e)
        {
            try
            {
                var row = e.Row as IRowViewModelBase <Thing>;
                if (row == null)
                {
                    return;
                }

                var error = row.ValidateProperty(e.Column.FieldName, e.Value);
                if (error != null)
                {
                    e.IsValid      = false;
                    e.ErrorContent = error;
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, "A problem occurend when executing ValidateCell");
            }
        }
Пример #14
0
 private void OnValidateCell(object sender, GridCellValidationEventArgs e)
 {
     if (e.Row != null)
     {
         if (e.CellValue != e.Value)
         {
             if (e.Value == null)
             {
                 e.Handled = false;
                 e.SetError(e.Column.Header + " can't be empty!", DevExpress.XtraEditors.DXErrorProvider.ErrorType.Critical);
             }
             else if (e.Row is BrowserData)
             {
                 B item = (B)e.Row;
                 e.Handled = EditProperty(item, e);
             }
         }
         else
         {
             e.Handled = true;
         }
     }
 }
Пример #15
0
 protected virtual void OnValidateCell(object sender, GridCellValidationEventArgs e)
 {
 }
Пример #16
0
        private void AllocationQuantity_Validate(object sender, GridCellValidationEventArgs e)
        {
            if (e.Row != null && e.Value != null)
            {
                int value;
                if (int.TryParse(e.Value.ToString(), out value) == false)
                    value = 0;

                if (value > 0)
                {
                    AnimationProductDetail apd = e.Row as AnimationProductDetail;
                    if (apd.ForecastProcQuantity == null || apd.ForecastProcQuantity.Value < value)
                    {
                        e.SetError("Allocation Quantity cannot exceed Forecast Procurement Quantity.");
                    }
                }
            }
        }
        protected bool IsEditionValid(GridItem item, GrilleColumn column, string oldValue, string newValue, GridCellValidationEventArgs args)
        {
            int? oid   = item.GetOid();
            bool isKey = column.position == 0;

            if (isKey)
            {
                if (string.IsNullOrWhiteSpace(newValue))
                {
                    args.ErrorContent = column.name + " can't be empty!";
                    args.IsValid      = false;
                    return(false);
                }
            }

            else if (!oid.HasValue)
            {
                LinkedAttributeGrid grid = (LinkedAttributeGrid)this.Grille;
                Object keyValue          = item.Datas[0];
                bool   emptyKeyValue     = keyValue == null || string.IsNullOrWhiteSpace(keyValue.ToString());
                if (emptyKeyValue && !grid.attribute.incremental)
                {
                    args.ErrorContent = "You have to set " + grid.attribute.name + " before set " + column.name;
                    args.IsValid      = false;
                    return(false);
                }
            }
            return(true);
        }
Пример #18
0
 private void Column_Validate(object sender, GridCellValidationEventArgs e)
 {
     if (e.Row != null)
     {
         string errorMessage;
         if ((e.Row as AnimationCustomerGroup).IsValidProperty(e.Column.FieldName, e.Value, out errorMessage) == false)
             e.SetError(errorMessage);
     }
 }