public static void CurrencyFormat(object sender, ConvertEventArgs e) { if (e.Value is System.DBNull) { return; } e.Value = (Convert.ToDouble(e.Value)).ToString("C"); }
public static void DateFormat(object sender, ConvertEventArgs e) { if (e.Value is System.DBNull) { return; } e.Value = Convert.ToDateTime(e.Value).ToShortDateString(); }
public static void PercentFormat(object sender, ConvertEventArgs e) { if (e.Value is System.DBNull) { return; } double percentValue = Convert.ToDouble(e.Value); percentValue = percentValue / 100; e.Value = percentValue.ToString("P0"); }
/// <summary> /// TextBox控件绑定到货币类型数据源时的数据显示格式处理,添加到控件的Format事件。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void TextBox_Currency_Format(object sender, ConvertEventArgs e) { if (e.Value != null) { try { e.Value = ((int)e.Value).ToString() + "张"; } catch { } } }
/// <summary> /// TextBox控件绑定到货币类型数据源时的数据显示格式处理,添加到控件的Format事件。 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void TextBox_Currency_Format1(object sender, ConvertEventArgs e) { if (e.Value != null) { try { e.Value = ((float)e.Value).ToString("0.00") + "元"; } catch { } } }
protected virtual void AppointmentTypeToIconConverter(object o, ConvertEventArgs e) { AppointmentType type = (AppointmentType)e.Value; if (type == AppointmentType.Pattern) { e.Value = RecurringIcon; } else { e.Value = NormalIcon; } }
private void CheckBoxBinding_Format(object sender, ConvertEventArgs e) { switch (e.Value.ToString()) { case "true": e.Value = true; break; default: e.Value = false; break; } }
protected override void OnFormat(ConvertEventArgs cevent) { if (this._converter != null) { var converterdValue = this._converter.Convert(cevent.Value, cevent.DesiredType, _converterParameter, _converterCulture); cevent.Value = converterdValue; } else { base.OnFormat(cevent); } }
/// <summary> /// This handles converting from the selected index to a value /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void RoleStatus_Parse(object sender, ConvertEventArgs e) { ComboBox c = (ComboBox)(((Binding)sender).Control); if (c.SelectedIndex != -1) { e.Value = c.Items[c.SelectedIndex]; } else { e.Value = null; } }
private void ExtractBit7FromGivenRegisterContent(object sender, ConvertEventArgs e) { var givenRegisterContent = (int)e.Value; if ((givenRegisterContent & 128) != 0) { e.Value = "1"; } else { e.Value = "0"; } }
private void ConvertRegisterContentToHexWith4Digits(object sender, ConvertEventArgs e) { var givenNumber = (int)e.Value; if (givenNumber == 0) { e.Value = "0000"; } else { e.Value = givenNumber.ToString("X4").ToUpper(); } }
public static void LocalCurrency(object sender, ConvertEventArgs cevent) { // The method converts only to string type. Test this using the DesiredType. if ((cevent.DesiredType != typeof(string)) || cevent.Value == null) { return; } NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.CurrentCulture.NumberFormat.Clone(); nfi.CurrencySymbol = LocalSimbolCurrency; // Use the ToString method to format the value as currency ("c"). cevent.Value = ((decimal)cevent.Value).ToString("c" + DecimalLenght, nfi); }
public static void rdSum_Parse(object sender, ConvertEventArgs e) { if (e.Value != System.DBNull.Value && e.Value != null && !string.IsNullOrEmpty(Convert.ToString(e.Value))) { //Делаем так, чтобы дробные числа всегда корректно переводились double d; if (SafeConvertToString(Convert.ToString(e.Value), out d)) { d = Math.Round(d, 2); e.Value = d; } } }
private void OnCustomerResultName_Convert(object sender, ConvertEventArgs e) { if (e.DesiredType == typeof(string)) { if (viewModel.SelectedResult != null && viewModel.SelectedResult.SearchType == SearchType.Customer) { e.Value = viewModel.SelectedResult.Name; } else { e.Value = null; } } }
public void DateFormat(object sender, ConvertEventArgs e) { if ((e.DesiredType == typeof(string)) && (e.Value != null)) { if (e.Value.Equals(DBNull.Value)) { e.Value = ""; } else if ((DateTime.Compare(Conversions.ToDate(e.Value), new UltraDateTimeEditor().MinDate) < 0) || (DateTime.Compare(Conversions.ToDate(e.Value), new UltraDateTimeEditor().MaxDate) > 0)) { e.Value = ""; } } }
public override void ObjectParse(object sender, ConvertEventArgs e) { Font font = (DataSource as TextAttibute).Font; if ((bool)e.Value) { font = new Font(font, font.Style | style); } else { font = new Font(font, font.Style & (~style)); } e.Value = font; }
public override void ObjectFormat(object sender, ConvertEventArgs e) { ComboBoxEdit comboBoxEdit = ((sender as Binding).BindableComponent as ComboBoxEdit); string rowHeight = string.Format("{0:f2}倍行高", e.Value); for (int index = 0; index < comboBoxEdit.Properties.Items.Count; index++) { if (comboBoxEdit.Properties.Items[index].ToString() == rowHeight) { e.Value = index; break; } } }
public override void ObjectFormat(object sender, ConvertEventArgs e) { ComboBoxEdit comboBoxEdit = ((sender as Binding).BindableComponent as ComboBoxEdit); Font font = e.Value as Font; for (int index = 0; index < comboBoxEdit.Properties.Items.Count; index++) { if (comboBoxEdit.Properties.Items[index].ToString() == "-" + font.Size) { e.Value = index; break; } } }
public override void ObjectFormat(object sender, ConvertEventArgs e) { string fontName = (e.Value as Font).Name; ComboBoxEdit comboBoxEdit = ((sender as Binding).BindableComponent as ComboBoxEdit); if (comboBoxEdit.Properties.Items.Contains(fontName)) { e.Value = comboBoxEdit.Properties.Items.IndexOf(fontName); } else { e.Value = 0; } }
void CheckBoxEndOn_Parse(object sender, ConvertEventArgs e) { // from control to object if (e.DesiredType == typeof(DateTime?) && e.Value is bool) { //e.Value = ((bool)e.Value == true ? DateTime.Today : (DateTime?)null); if ((bool)e.Value == true) { e.Value = dtpEndDate.Value; } //else // e.Value = ((Schedule)((BindingSource)((Binding)sender).DataSource).Current).EndDate; } }
private void BinImg_Format(object sender, ConvertEventArgs e) { if (e.Value == null) { e.Value = null; return; } byte[] b = ((Binary)e.Value).ToArray(); MemoryStream stream = new MemoryStream(b); Bitmap bitmap = new Bitmap(stream); stream.Close(); e.Value = bitmap; }
private void FormatPercent(object sender, ConvertEventArgs e) { if (decimal.TryParse(e.Value == null ? null : e.Value.ToString(), out decimal comissao)) { if (comissao > 0.99m) { e.Value = (((decimal)e.Value) / 100).ToString("#,##0.00%"); } else { e.Value = ((decimal)e.Value).ToString("#,##0.00%"); } } }
protected override void OnParse(ConvertEventArgs cevent) { if (this._converter != null) { object converterdValue = this._converter.ConvertBack(cevent.Value, cevent.DesiredType, _converterParameter, _converterCulture); cevent.Value = converterdValue; } else { base.OnParse(cevent); } }
private void phoneBinding_Parse(Object sender, ConvertEventArgs e) { String phoneNumberAndExt = e.Value.ToString(); int extIndex = phoneNumberAndExt.IndexOf("x"); String ext = phoneNumberAndExt.Substring(extIndex).Trim(); String phoneNumber = phoneNumberAndExt.Substring(0, extIndex).Trim(); DataRowView currentRow = (DataRowView)BindingContext[employeesTable, "Employees"].Current; currentRow["Extension"] = ext.Substring(1); e.Value = phoneNumber; }
public override void ObjectParse(object sender, ConvertEventArgs e) { if ((int)e.Value == 0) { e.Value = 0; relateControl.Enabled = true; } else { e.Value = -1; relateControl.Enabled = false; } relateControl.Refresh(); }
private void OnDateTimePicker_Parse(object sender, ConvertEventArgs e) { // CONTROL => OBJECT // e.Value is the formatted value coming from the control, we change it to want we want to set on the object if (this.dateTimePicker.Checked) { e.Value = new Nullable <DateTime>(Convert.ToDateTime(e.Value)); } else { e.Value = null; } }
void textLUBinding_Parse(object sender, ConvertEventArgs e) { Binding b = (Binding)sender; DataTable dt = (DataTable)((BindingSource)b.DataSource).DataSource; DataColumn dc = dt.Columns[b.BindingMemberInfo.BindingMember]; if (_performLookups && !string.IsNullOrEmpty(e.Value.ToString())) { //e.Value = _lookupTables.GetValueMember(dc.ExtendedProperties["foreign_key_resultset_name"].ToString(), e.Value.ToString(), "", e.Value.ToString()); //e.Value = _sharedUtils.GetLookupValueMember(dc.ExtendedProperties["foreign_key_resultset_name"].ToString(), e.Value.ToString(), "", e.Value.ToString()); e.Value = _sharedUtils.GetLookupValueMember(((DataRowView)((BindingSource)b.DataSource).Current).Row, dc.ExtendedProperties["foreign_key_dataview_name"].ToString(), e.Value.ToString(), "", e.Value.ToString()); } }
void OnFormat(object sender, ConvertEventArgs e) { if (_keyProperty > 0) { _errorProvider.SetError(_comboBox, ""); return; } if (string.IsNullOrEmpty(_comboBox.Text)) { e.Value = ""; _errorProvider.SetError(_comboBox, string.Format("{0} required.", _friendlyName)); } }
private void bind_Parse(object sender, ConvertEventArgs e) { try { var val = e.Value.ToString(); if (val == "") { e.Value = null; } } catch (Exception ex) { } }
// Called when formatting value is needed private static void BindingFormat(object sender, ConvertEventArgs e) { var _sender = sender as Binding; if (_sender != null && _sender.Control.Tag is FormatValueDelegate) { var _data = (FormatValueDelegate)_sender.Control.Tag; var _value = _data.Invoke(_sender.BindingManagerBase.Current, _sender.BindingMemberInfo.BindingField); if (_value != null) { e.Value = _value.ToString(); } } }
/** * Function to format the zip code with a hyphen between the first 5 and last 4 digits for readability */ private void FormatZipCode(object sender, ConvertEventArgs e) { if (e.Value.GetType().ToString() == "System.String") { string s = e.Value.ToString(); if (IsInt64(s)) { if (s.Length == 9) { e.Value = s.Substring(0, 5) + "-" + s.Substring(5, 4); } } } }
/// <summary> /// Invokes list item formatting /// </summary> protected String PerformFormat(object item) { if (HasEvents) { ConvertEventHandler handler = (ConvertEventHandler)Events[FormatEvent]; if (handler != null) { var e = new ConvertEventArgs(item, typeof(String)); handler(this, e); return(e.Value != null?e.Value.ToString() : null); } } return(null); }
void LapTimeView_MPHDelta_Format(object sender, ConvertEventArgs e) { if ((Single)e.Value == 0) { this.lapMPHDeltaLabel1.ForeColor = Color.Black; } else if ((Single)e.Value > 0) { this.lapMPHDeltaLabel1.ForeColor = Color.Green; } else { this.lapMPHDeltaLabel1.ForeColor = Color.Red; } }
private void ReturnEmpty( object sender, ConvertEventArgs e) { e.Value = GetEmptyValue(e.DesiredType); }
/// <summary> /// 转换文件的某些过程中触发 /// </summary> /// <param name="e"></param> private void OnConvertEvent(ConvertEventArgs e) { if (m_processBar.InvokeRequired) { Convertor.ConvertEventHandler invokeProcess = new Convertor.ConvertEventHandler(OnConvertEvent); this.Invoke(invokeProcess, new object[] { e }); } else { switch (e.ConvertedNum) { case 0: m_processBar.Visible = true; m_processBar.Minimum = 0; m_processBar.Maximum = e.TotalFileNum; m_processBar.Value = 0; m_processBar.Step = 1; break; case -1: m_processBar.Step = 0; m_processBar.Visible = false; break; default: m_processBar.PerformStep(); break; } } }
/// <summary> /// Updates the customer's last activity date after the basket has been converted /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void OnBasketConverted(BasketConversionBase sender, ConvertEventArgs<BasketConversionPair> e) { foreach (var pair in e.CovertedEntities.ToArray()) { var customer = (ICustomer)pair.CustomerBasket.Customer; customer.LastActivityDate = DateTime.Now; MerchelloContext.Current.Services.CustomerService.Save(customer); } }