public override FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { RadMaskedNumericInput radMask = new RadMaskedNumericInput(); radMask.SetBinding(RadMaskedNumericInput.ValueProperty, CreateValueBinding(dataItem)); radMask.Mask = Mask; radMask.HorizontalAlignment = HorizontalAlignment.Stretch; return(radMask); }
public override object GetNewValueFromEditor(object editor) { RadMaskedNumericInput colorPicker = editor as RadMaskedNumericInput; if (colorPicker != null) { return(colorPicker.Value.GetValueOrDefault()); } else { return(null); } }
public override IList <string> UpdateSourceWithEditorValue(GridViewCell gridViewCell) { List <String> errors = new List <String>(); RadMaskedNumericInput editor = gridViewCell.GetEditingElement() as RadMaskedNumericInput; BindingExpression bindingExpression = editor.ReadLocalValue(RadMaskedNumericInput.ValueProperty) as BindingExpression; if (bindingExpression != null) { bindingExpression.UpdateSource(); foreach (ValidationError error in Validation.GetErrors(editor)) { errors.Add(error.ErrorContent.ToString()); } } return(errors.ToList()); }
public NumericTextBoxHelper(ColumnDTO correspondingTypeProperty, ColumnUISettingDTO columnSetting, List <SimpleSearchOperator> operators = null) { theGrid = new Grid(); theGrid.ColumnDefinitions.Add(new ColumnDefinition()); theGrid.VerticalAlignment = System.Windows.VerticalAlignment.Center; textBox = new RadMaskedNumericInput(); textBox.Name = "txtControl"; textBox.ValueChanged += (sender, e) => textBox_ValueChanged(sender, e); textBox.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; textBox.IsLastPositionEditable = false; textBox.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Left; textBox.IsClearButtonVisible = false; textBox.TextMode = Telerik.Windows.Controls.MaskedInput.TextMode.PlainText; textBox.SelectionOnFocus = SelectionOnFocus.SelectAll; //if (correspondingTypeProperty.DataType.Contains("float") // || correspondingTypeProperty.DataType.Contains("decimal") // || correspondingTypeProperty.DataType.Contains("double")) //{ if (correspondingTypeProperty.NumericColumnType != null && correspondingTypeProperty.NumericColumnType.Precision != 0 && correspondingTypeProperty.NumericColumnType.Scale != 0) { textBox.Mask = "#" + (correspondingTypeProperty.NumericColumnType.Precision - correspondingTypeProperty.NumericColumnType.Scale); textBox.Mask += "." + correspondingTypeProperty.NumericColumnType.Scale; textBox.FormatString = ""; } else { textBox.Mask = ""; if (correspondingTypeProperty.DataType.Contains("float") || correspondingTypeProperty.DataType.Contains("decimal") || correspondingTypeProperty.DataType.Contains("double")) { //بطور پیش فرض دو رقم اعشار میگذارد و سه رقم سه رقم جدا میکند //textBox.FormatString = "n"; //اگر اعشار خواست از پرسیجن و اسکیل استفاده شود textBox.FormatString = "n0"; } else { //رقم اعشار نمیگذارد و سه رقم سه رقم جدا میکند textBox.FormatString = "n0"; } //بیشتر تست شود از نوع خود مقدار بایند شده به این کنترل //بعدا یک خصوصیت اضافه شود که جدا نکند مثل شماره شناسنامه // سه رقم سه رقم جدا نمیکند // textBox.FormatString = ""; } //} theGrid.Children.Add(textBox); if (operators != null && operators.Count > 0) { theGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(70) }); cmbOperators = new ComboBox(); cmbOperators.Name = "cmbOperators"; cmbOperators.ItemsSource = operators; cmbOperators.DisplayMemberPath = "Title"; cmbOperators.SelectedValuePath = "Operator"; Grid.SetColumn(cmbOperators, 1); theGrid.Children.Add(cmbOperators); } }
public override FrameworkElement CreateCellElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { DataRow dr = null; if (dataItem.GetType().Equals(typeof(DataRow))) { dr = (DataRow)dataItem; } else { dr = ((DataRowView)dataItem).Row; } string sHienThiDKhien = dr["HTHI_DIEU_KHIEN"].ToString(); string sHienThiTVan = dr["HTHI_SDUNG_TVAN"].ToString(); string sGiaTriTVan = dr["HTHI_SQL"].ToString(); string sGiaTri = dr["GTRI_TTIN"].ToString(); string sKieuDuLieu = dr["KIEU_DU_LIEU"].ToString(); var valueBinding = new System.Windows.Data.Binding(this.DataMemberBinding.Path.Path); if (sHienThiDKhien.Equals("Combobox")) { cmbCommon = new RadComboBox(); lstComboBox = new List <AutoCompleteEntry>(); KhoiTaoGiaTriComboBox(ref lstComboBox, ref cmbCommon, sGiaTriTVan); if (!sGiaTri.IsNullOrEmptyOrSpace()) { cmbCommon.SelectedIndex = lstComboBox.IndexOf(lstComboBox.FirstOrDefault(i => i.KeywordStrings.First().Equals(sGiaTri))); } else { cmbCommon.SelectedIndex = 0; } cmbCommon.IsEnabled = false; return(cmbCommon); } else if (sHienThiDKhien.Equals("Datetimebox")) { radMaskDate = new RadMaskedDateTimeInput(); if (!sGiaTri.IsNullOrEmptyOrSpace()) { radMaskDate.Value = LDateTime.StringToDate(sGiaTri, ApplicationConstant.defaultDateTimeFormat); } else { radMaskDate.Value = LDateTime.StringToDate(ClientInformation.NgayLamViecHienTai, ApplicationConstant.defaultDateTimeFormat); } radMaskDate.IsEnabled = false; radMaskDate.HorizontalAlignment = HorizontalAlignment.Stretch; var Control = grdControl.FindChildByType <RadMaskedDateTimeInput>(); if (Control != null) { grdControl.Children.Remove(Control); } var ControlDTP = grdControl.FindChildByType <DatePicker>(); if (ControlDTP != null) { grdControl.Children.Remove(ControlDTP); } grdControl.Children.Add(radMaskDate); return(grdControl); } else { if (sKieuDuLieu.Equals("Number")) { ctrMaskText = new RadMaskedNumericInput(); ctrMaskText.Mask = "#18"; if (!sGiaTri.IsNullOrEmptyOrSpace()) { ctrMaskText.Value = Convert.ToDouble(sGiaTri); } else { ctrMaskText.Value = null; } ctrMaskText.HorizontalAlignment = HorizontalAlignment.Stretch; ctrMaskText.IsEnabled = false; return(ctrMaskText); } else { ctrCommon = new TextBox(); ctrCommon.IsEnabled = false; if (!sGiaTri.IsNullOrEmptyOrSpace()) { ctrCommon.Text = sGiaTri; } else { ctrCommon.Text = ""; } return(ctrCommon); } } }
public override FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem) { DataRow dr = null; if (dataItem.GetType().Equals(typeof(DataRow))) { dr = (DataRow)dataItem; } else { dr = ((DataRowView)dataItem).Row; } string sHienThiDKhien = dr["HTHI_DIEU_KHIEN"].ToString(); string sHienThiTVan = dr["HTHI_SDUNG_TVAN"].ToString(); string sGiaTriTVan = dr["HTHI_SQL"].ToString(); string sGiaTri = dr["GTRI_TTIN"].ToString(); string sKieuDuLieu = dr["KIEU_DU_LIEU"].ToString(); TextBox ctrCommon = new TextBox(); Binding valueBinding = CreateValueBinding(); if (sHienThiDKhien.Equals("Combobox")) { lstComboBox = new List <AutoCompleteEntry>(); cmbCommon = new RadComboBox(); KhoiTaoGiaTriComboBox(ref lstComboBox, ref cmbCommon, sGiaTriTVan); if (!sGiaTri.IsNullOrEmptyOrSpace()) { cmbCommon.SelectedIndex = lstComboBox.IndexOf(lstComboBox.FirstOrDefault(i => i.KeywordStrings.First().Equals(sGiaTri))); } else { cmbCommon.SelectedIndex = 0; } cmbCommon.Tag = lstComboBox; cmbCommon.SetBinding(DisplayIndexProperty, valueBinding); cmbCommon.IsEnabled = true; return(cmbCommon as FrameworkElement); } else if (sHienThiDKhien.Equals("Datetimebox")) { var ControlRad = grdControl.FindChildByType <RadMaskedDateTimeInput>(); if (ControlRad != null) { grdControl.Children.Remove(ControlRad); } var ControlDTP = grdControl.FindChildByType <DatePicker>(); if (ControlDTP != null) { grdControl.Children.Remove(ControlDTP); } radMaskDate = new RadMaskedDateTimeInput(); if (!sGiaTri.IsNullOrEmptyOrSpace()) { radMaskDate.Value = LDateTime.StringToDate(sGiaTri, ApplicationConstant.defaultDateTimeFormat); } else { radMaskDate.Value = LDateTime.StringToDate(ClientInformation.NgayLamViecHienTai, ApplicationConstant.defaultDateTimeFormat); } radMaskDate.SetBinding(DisplayIndexProperty, valueBinding); radMaskDate.IsEnabled = true; radMaskDate.HorizontalAlignment = HorizontalAlignment.Stretch; radMaskDate.Margin = new Thickness(0, 0, 40, 0); dtpPicker.HorizontalAlignment = HorizontalAlignment.Right; dtpPicker.Width = 30; dtpPicker.SelectedDateChanged += new EventHandler <SelectionChangedEventArgs>(dtpPicker_SelectedDateChanged); grdControl.Children.Add(dtpPicker); grdControl.Children.Add(radMaskDate); return(grdControl as FrameworkElement); } else { if (sKieuDuLieu.Equals("Number")) { ctrMaskText = new RadMaskedNumericInput(); ctrMaskText.Mask = "#18"; if (!sGiaTri.IsNullOrEmptyOrSpace()) { ctrMaskText.Value = Convert.ToDouble(sGiaTri); } else { ctrMaskText.Value = null; } ctrMaskText.SetBinding(DisplayIndexProperty, valueBinding); ctrMaskText.HorizontalAlignment = HorizontalAlignment.Stretch; return(ctrMaskText as FrameworkElement); } else { ctrCommon = new TextBox(); if (!sGiaTri.IsNullOrEmptyOrSpace()) { ctrCommon.Text = sGiaTri; } else { ctrCommon.Text = ""; } ctrCommon.SetBinding(DisplayIndexProperty, valueBinding); return(ctrCommon as FrameworkElement); } } }