示例#1
0
        /// <summary>
        /// Fill the data object with a type
        /// </summary>
        /// <param name="textField">Field of the text.</param>
        /// <param name="dataObject">Data object to be filled.</param>
        /// <param name="dataField">Data field to be filled.</param>
        public void FillDataObject(object textField, string dataField, ref object dataObject)
        {
            bool isBasedDto = (dataObject is BaseViewObject);

            if (dataObject == null)
            {
                return;
            }
            try
            {
                if (!isBasedDto)
                {
                    ComponentUtils.SetPropValue(dataObject, "Value." + dataField, textField, true);
                    var tmpValue = ComponentUtils.GetPropValue(dataObject, "Value." + dataField);
                    if (tmpValue.ToString() != textField.ToString())
                    {
                        ComponentUtils.SetPropValue(dataObject, "Value." + dataField.ToUpper(), textField, true);
                    }
                }
                else
                {
                    ComponentUtils.SetPropValue(dataObject, dataField, textField, true);
                    var tmpValue = ComponentUtils.GetPropValue(dataObject, dataField);
                    if (tmpValue.ToString() != textField.ToString())
                    {
                        ComponentUtils.SetPropValue(dataObject, dataField.ToUpper(), textField, true);
                    }
                }
            }
            catch (Exception e)
            {
                string msg = e.Message;
            }
        }
示例#2
0
        /// <summary>
        /// CheckAndAssign
        /// </summary>
        /// <param name="dataFieldCheckBox"></param>
        /// <param name="sourceNew"></param>
        /// <param name="path"></param>
        private static void CheckAndAssign(DataFieldCheckBox dataFieldCheckBox, object sourceNew, string path)
        {
            Contract.Requires((dataFieldCheckBox != null) &&
                              (sourceNew != null) &&
                              !string.IsNullOrEmpty(path));


            var propValue = ComponentUtils.GetPropValue(sourceNew, path);
            int value     = 0;

            if (propValue != null)
            {
                if (propValue is string)
                {
                    value = int.Parse(propValue as string);
                    dataFieldCheckBox.IsChecked = value != 0;
                }

                if (propValue is bool)
                {
                    dataFieldCheckBox.IsChecked = (bool)propValue;
                }
                if (propValue is byte)
                {
                    value = Convert.ToByte(propValue);
                    dataFieldCheckBox.IsChecked = value != 0;
                }
                if (propValue.GetType().IsAssignableFrom(typeof(int)))
                {
                    // here we have a tinyint.
                    value = Convert.ToInt32(propValue);
                    dataFieldCheckBox.IsChecked = value != 0;
                }
            }
        }
示例#3
0
        private void SetTextContent(object dataObject, string path)
        {
            object value       = ComponentUtils.GetPropValue(_dataObject, path);
            string objectValue = string.Empty;

            if (value != null)
            {
                if (value is Decimal currentValue)
                {
                    objectValue = currentValue.ToString("0.00");
                }
                else
                {
                    objectValue = value.ToString();
                }
                if (DataAllowed == KarveCommon.Generic.DataType.Email)
                {
                    objectValue = objectValue.Replace("#", "@");
                }
                if (!string.IsNullOrEmpty(objectValue))
                {
                    TextContent = objectValue;
                }
            }
        }
示例#4
0
        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;
            }
        }
示例#5
0
        /// <summary>
        /// CheckAndAssignText.
        /// </summary>
        /// <param name="dataAreaFiled"></param>
        /// <param name="sourceNew"></param>
        /// <param name="path"></param>
        private static void CheckAndAssignText(DataArea dataAreaFiled, object sourceNew, string path)
        {
            string propValue = ComponentUtils.GetPropValue(sourceNew, path) as string;

            if (!string.IsNullOrEmpty(propValue))
            {
                dataAreaFiled.TextContent = propValue;
            }
        }
示例#6
0
        /// <summary>
        /// CheckAndAssignDate
        /// </summary>
        /// <param name="dataDatePicker">DataDatePicker component</param>
        /// <param name="sourceNew">Object to be assigned</param>
        /// <param name="path">Path of the date</param>
        private static void CheckAndAssignDate(DataDatePicker dataDatePicker, object sourceNew, string path)
        {
            Contract.Requires((dataDatePicker != null) &&
                              (sourceNew != null) &&
                              !string.IsNullOrEmpty(path));

            if ((dataDatePicker == null) ||
                (sourceNew == null) ||
                (string.IsNullOrEmpty(path)))
            {
                return;
            }
            var propValue = ComponentUtils.GetPropValue(sourceNew, path);

            if (propValue == null)
            {
                var otherPath = "Value." + path;
                propValue = ComponentUtils.GetPropValue(sourceNew, otherPath);
            }
            if (propValue != null)
            {
                DateTime timeValue = DateTime.Now;
                if (propValue is string)
                {
                    try
                    {
                        timeValue = DateTime.Parse(propValue as string);
                    }
                    // this is wanted. We need to provide a default.
#pragma warning disable 0168
                    catch (Exception e)
                    {
#pragma warning restore 0168
                        timeValue = DateTime.Now;
                    }
                }
                else
                {
                    timeValue = (DateTime)propValue;
                }
                dataDatePicker.DateContent = timeValue;
            }
        }
示例#7
0
        /// <summary>
        /// This handle the logic for changing the depedency object using a data object.
        /// </summary>
        /// <param name="e"></param>
        private void OnItemSourceDoChanged(DependencyPropertyChangedEventArgs e)
        {
            if (e.NewValue == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(_dataField))
            {
                return;
            }

            _dataObject = e.NewValue;

            Type   dataType    = _dataObject.GetType();
            object valueObject = dataType.GetProperty("Value");

            if (valueObject != null)
            {
                string currentValue = "Value." + DataSourcePath.ToUpper();
                object value        = ComponentUtils.GetPropValue(_dataObject, currentValue);
                if (value != null)
                {
                    string objectValue = value.ToString();
                    if (DataAllowed == ControlExt.DataType.Email)
                    {
                        objectValue = objectValue.Replace("#", "@");
                    }
                    if (!string.IsNullOrEmpty(objectValue))
                    {
                        TextContent = objectValue;
                    }
                    if (IsReadOnly)
                    {
                        TextField.Background = Brushes.LightCyan;
                    }
                    else
                    {
                        TextField.Background = Brushes.White;
                    }
                }
            }
        }
示例#8
0
        private static void DataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            object sourceNew = e.NewValue;
            string path      = GetDataSourcePath(d);

            if (sourceNew == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(path))
            {
                return;
            }
            if (d is DataFieldCheckBox dataFieldCheckBox)
            {
                dataFieldCheckBox.DataObject = sourceNew;
                if (!string.IsNullOrEmpty(path))
                {
                    CheckAndAssign(dataFieldCheckBox, sourceNew, path);
                }
            }

            if (d is DataArea dataArea)
            {
                CheckAndAssignText(dataArea, sourceNew, path);
                dataArea.DataSource     = e.NewValue;
                dataArea.DataSourcePath = path;
            }
            if (d is TextBox)
            {
                TextBox box       = (TextBox)d;
                string  propValue = ComponentUtils.GetPropValue(sourceNew, path) as string;
                if (propValue != null)
                {
                    box.Text = propValue;
                }
            }
            if (d is DataDatePicker dataPicker)
            {
                CheckAndAssignDate(dataPicker, sourceNew, path);
            }
        }
示例#9
0
        private static void CheckBox_DataChecked(object sender, RoutedEventArgs e)
        {
            var dataFieldCheckBox = sender as DataFieldCheckBox;
            var path = ControlExt.GetDataSourcePath(dataFieldCheckBox);

            if (!string.IsNullOrEmpty(path))
            {
                var tmp = ControlExt.GetDataSource(dataFieldCheckBox);
                if (tmp == null)
                {
                    return;
                }
                var propValue = ComponentUtils.GetPropValue(tmp, path);
                if (dataFieldCheckBox != null)
                {
                    dataFieldCheckBox.IsChecked = true;
                    ControlExt.SetDataSource(dataFieldCheckBox, true);
                    EnforceDoChange(dataFieldCheckBox, path, 1);
                }
            }
        }
示例#10
0
        private static void DataSourcePathChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            string          path   = e.NewValue as string;
            object          value  = GetDataSource(d);
            ComponentFiller filler = new ComponentFiller();

            if (value != null)
            {
                if (value is DataTable)
                {
                    DataTable currentTable = value as DataTable;
                    filler.FetchDataFieldObject(currentTable, path);
                }
                else
                {
                    var propValue = ComponentUtils.GetPropValue(value, path);
                    if (propValue != null)
                    {
                        ComponentUtils.SetPropValue(value, path, propValue);
                    }
                }
            }
        }
示例#11
0
        /// <summary>
        ///  This is a property changed util.
        /// </summary>
        /// <param name="dependencyObject"></param>
        /// <param name="eventArgs"></param>
        public static void PropertyChangedCb(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs eventArgs)
        {
            // dry : the change is handled by the PasswordBox properties as well.
            if (dependencyObject is PasswordBox)
            {
                return;
            }
            if (dependencyObject is PercentTextBox)
            {
                PercentTextBox box = dependencyObject as PercentTextBox;
                box.LostFocus += Box_LostFocus1;
                return;
            }
            if (dependencyObject is SfDataGrid currentDataGrid)
            {
                //  currentDataGrid.CurrentCellEndEdit += CurrentDataGrid_CurrentCellEndEdit;
                currentDataGrid.RecordDeleted       += CurrentDataGrid_RecordDeleted;
                currentDataGrid.AddNewRowInitiating += CurrentDataGrid_AddNewRowInitiating;

                currentDataGrid.RowValidated   += CurrentDataGrid_RowValidated;
                currentDataGrid.PreviewKeyDown += CurrentDataGrid_PreviewKeyDown;
            }
            if (dependencyObject is DataArea)
            {
                var dataArea = dependencyObject as DataArea;
                dataArea.ItemChangedCommand = GetItemChangedCommand(dataArea);
                dataArea.DataSource         = GetDataSource(dataArea);
                dataArea.DataSourcePath     = GetDataSourcePath(dataArea);
                return;
            }
            if (dependencyObject is SfTimePicker)
            {
                SfTimePicker picker = dependencyObject as SfTimePicker;
                picker.ValueChanged += Picker_ValueChanged;
            }
            if (dependencyObject is DatePicker datePicker)
            {
                datePicker.SelectedDateChanged += SelectedDate_Changed;
            }
            if (dependencyObject is DataDatePicker)
            {
                DataDatePicker dataDatePicker = dependencyObject as DataDatePicker;
                dataDatePicker.DataDatePickerChanged += DataDatePicker_DataDatePickerChanged;
                return;
            }

            if (dependencyObject is TextBox)
            {
                TextBox box = dependencyObject as TextBox;
                box.TextChanged += TextBox_ChangedBehaviour;
                box.LostFocus   += Box_LostFocus;
                return;
            }
            if (dependencyObject is DataFieldCheckBox)
            {
                DataFieldCheckBox checkBox = dependencyObject as DataFieldCheckBox;
                var path = ControlExt.GetDataSourcePath(checkBox);
                if (!string.IsNullOrEmpty(path))
                {
                    var tmp = ControlExt.GetDataSource(checkBox);
                    if (tmp != null)
                    {
                        var propValue = ComponentUtils.GetPropValue(tmp, path);
                        if (propValue is string)
                        {
                            byte value = Convert.ToByte(propValue);
                            if (value > 0)
                            {
                                checkBox.IsChecked = true;
                            }
                        }
                        else
                        {
                            checkBox.IsChecked = Convert.ToBoolean(propValue);
                        }
                    }
                }
                //checkBox.Checked += CheckBox_DataChecked;
                // checkBox.Unchecked += CheckBox_DataUnChecked;
                checkBox.DataFieldCheckBoxChanged += CheckBox_DataFieldCheckBoxChanged;
                return;
            }
            if (dependencyObject is CheckBox checkBox1)
            {
                checkBox1.Checked   += CheckBox_Checked;
                checkBox1.Unchecked += CheckBox_Unchecked;
                checkBox1.Click     += checkBox_Clicked;
                return;
            }
            if (dependencyObject is ComboBox comboBox)
            {
                // here we do the combox box.
                comboBox.SelectionChanged += ComboBox_SelectionChanged;
            }
        }