protected void CalculateBenefit(RadMaskedEditBox unitPrice, RadMaskedEditBox productCost, RadMaskedEditBox benefit) { var result = 0.00; if (Convert.ToDouble(productCost.Value) == 0.00) { errorProductProvider.SetError(ProductCostRadMaskedEditBox, "Introduzca el costo por unidad."); ProductCostRadMaskedEditBox.Focus(); return; } errorProductProvider.Clear(); var _productCost = Convert.ToDecimal(productCost.Value); var _unitprice = Convert.ToDecimal(unitPrice.Value); result = (double)(((_unitprice - _productCost) * 100) / _productCost); if (result != 0 & result > 1) { benefit.Text = string.Format("{0}", result); } else { benefit.Text = string.Format("{0}", 0); } }
private void InitLayerDataEntry() { this.deLayer.FitToParentWidth = true; this.deLayer.ShowValidationPanel = true; this.deLayer.EditorInitializing += (s, e) => { if (e.Property.Name == "LayerValue") { RadMaskedEditBox radMaskedEditBox = new RadMaskedEditBox(); radMaskedEditBox.MaskType = MaskType.Numeric; radMaskedEditBox.MaskedEditBoxElement.StretchVertically = true; e.Editor = radMaskedEditBox; //RadSpinEditor editor = new RadSpinEditor(); //editor.Maximum = 10000; //editor.SpinElement.StretchVertically = true; //editor.DecimalPlaces = 0; //e.Editor = editor; } e.Editor.Name = e.Property.Name; }; this.deLayer.ItemValidating += (s, e) => { var curr = this.deLayer.CurrentObject as QuoLayer; Control con = s as Control; switch (con.Name) { case "LayerName": if (string.IsNullOrWhiteSpace(curr.LayerName)) { string errorMessage = "不能为空!"; e.ErrorProvider.SetError(s as Control, errorMessage); e.Cancel = true; Helpers.DataEntryHelper.AddErrorLabel(this.deLayer, e.Label.Text, errorMessage); } else { e.ErrorProvider.Clear(); this.deLayer.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text); } break; case "LayerValue": if (curr.LayerValue < 1) { string errorMessage = "请输入大于0 的整数!"; e.ErrorProvider.SetError(s as Control, errorMessage); e.Cancel = true; Helpers.DataEntryHelper.AddErrorLabel(this.deLayer, e.Label.Text, errorMessage); } else { e.ErrorProvider.Clear(); this.deLayer.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text); } break; default: break; } }; }
public static decimal GetDecimal(RadMaskedEditBox ctrl) { try { return(decimal.Parse(ctrl.Value.ToString())); } catch { return(0); } }
public static long GetLong(RadMaskedEditBox ctrl) { try { return(long.Parse(ctrl.Value.ToString())); } catch { return(0); } }
public static int GetInt(RadMaskedEditBox ctrl) { try { return(int.Parse(ctrl.Value.ToString())); } catch { return(0); } }
public static bool HasText(RadMaskedEditBox msk) { msk.Text = msk.Text.Trim(); if (msk.Text != "__:__") { msk.BackColor = colorValid; return(true); } else { msk.BackColor = colorEmpty; return(false); } }
//判断指定控件的值是否为0 /// <summary> /// 判断指定控件的值是否为0 /// </summary> /// <param name="ctrl"></param> /// <param name="labelName"></param> /// <returns></returns> public static bool EqualsZero(RadMaskedEditBox ctrl, string labelName) { if (decimal.Parse(ctrl.Text.Trim()) == 0) { if (!string.IsNullOrEmpty(labelName)) { ShowError(labelName + "不能为零"); } ctrl.Focus(); return(true); } return(false); }
/// <summary> /// Update System Theme According to Selection /// </summary> /// <param name="c"></param> /// <param name="themeName"></param> internal static void UpdateControlTheme(Control c, string themeName) { if (c is RadMaskedEditBox) { RadMaskedEditBox rm = (RadMaskedEditBox)c; rm.ThemeName = themeName; } if (c is RadTextBox) { RadTextBox txt = (RadTextBox)c; txt.ThemeName = themeName; } if (c is RadDropDownList) { RadDropDownList ddl = (RadDropDownList)c; ddl.ThemeName = themeName; } if (c is RadGridView) { RadGridView ddl = (RadGridView)c; ddl.ThemeName = themeName; } if (c is RadGroupBox) { RadGroupBox rg = (RadGroupBox)c; rg.ThemeName = themeName; } if (c is RadButton) { RadButton btn = (RadButton)c; btn.ThemeName = themeName; } if (c is RadDateTimePicker) { RadDateTimePicker dtp = (RadDateTimePicker)c; dtp.ThemeName = themeName; } if (c is RadPageView) { RadPageView pv = new RadPageView(); pv.ThemeName = themeName; } //Also update theme for children foreach (Control ch in c.Controls) { UpdateControlTheme(ch, themeName); } }
void CulturesList_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e) { foreach (Control control in this.radPanelDemoHolder.Controls) { if (control is RadMaskedEditBox) { RadMaskedEditBox maskEdit = control as RadMaskedEditBox; maskEdit.Culture = (radComboCultures.SelectedValue as CultureInfo); if (maskEdit.MaskType == MaskType.DateTime) { maskEdit.Value = DateTime.Now; } } } }
public static bool IsDate(RadMaskedEditBox mskDate) { bool isValid = false; if (mskDate.Value.ToString() == "") { mskDate.BackColor = colorValid; return(true); } try { if ((Convert.ToInt16(mskDate.Text.Substring(3, 2)) > 12 || Convert.ToInt16(mskDate.Text.Substring(3, 2)) < 1) || (Convert.ToInt16(mskDate.Text.Substring(6, 2)) > 31 || Convert.ToInt16(mskDate.Text.Substring(6, 2)) < 1)) { mskDate.BackColor = colorInvalid; return(false); } else { try { FarsiLibrary.Utils.PersianDate pDate = FarsiLibrary.Utils.PersianDate.Parse("13" + mskDate.Text); isValid = true; mskDate.BackColor = colorValid; } catch { isValid = false; } } } catch { mskDate.BackColor = colorInvalid; return(false); } if (isValid) { mskDate.BackColor = colorValid; } else { mskDate.BackColor = colorInvalid; } return(isValid); }
public static bool IsTime(RadMaskedEditBox msk) { bool isvalid = true; string strInput = msk.Value.ToString(); if (strInput.Length == 0) { isvalid = true; } else if (strInput.Length < 4) { isvalid = false; } else { try { int hour = Convert.ToInt16(strInput.Substring(0, 2)); int min = Convert.ToInt16(strInput.Substring(2, 2)); if (hour > 23 || hour < 0 || min > 59 || min < 0) { isvalid = false; } } catch { isvalid = false; } } if (isvalid) { msk.BackColor = colorValid; } else { msk.BackColor = colorInvalid; } return(isvalid); }
public AppUserAddEditForm() { InitializeComponent(); this.AcceptButton = this.btnOk; this.CancelButton = this.btnCancel; this.FormClosed += (s, e) => { //释放 资源 if (bll != null) { bll.Dispose(); bll = null; } }; //设置dataentity this.deMain.FitToParentWidth = true; this.deMain.ShowValidationPanel = true; this.deMain.EditorInitializing += (s, e) => { e.Editor.Name = e.Property.Name; if (e.Property.Name == "UserName" && EditMode == Enums.EditFormMode.Edit) { e.Editor.Enabled = false; } else if (e.Property.Name == "Email") { RadMaskedEditBox editor = new RadMaskedEditBox(); editor.MaskType = MaskType.EMail; editor.MaskedEditBoxElement.StretchVertically = true; e.Editor = editor; } //else if (e.Property.Name == "Tel") //{ // RadMaskedEditBox editor = new RadMaskedEditBox(); // editor.MaskType = MaskType.Regex; // editor.MaskedEditBoxElement.StretchVertically = true; // //editor.Mask = "9"; // e.Editor = editor; //} }; this.deMain.ItemValidating += (s, e) => { Models.AppUser user = this.deMain.CurrentObject as Models.AppUser; switch (e.Label.Text) { case "用户名": if (string.IsNullOrWhiteSpace(user.UserName)) { string errorMessage = "用户名不能为空!"; e.ErrorProvider.SetError(s as Control, errorMessage); e.Cancel = true; AddErrorLabel(this.deMain, e.Label.Text, errorMessage); } else { e.ErrorProvider.Clear(); this.deMain.ValidationPanel.PanelContainer.Controls.RemoveByKey(e.Label.Text); } break; default: break; } }; this.Shown += (s, e) => { //设置窗体title switch (EditMode) { case Enums.EditFormMode.Add: this.Text = "新增"; DataEntry = new Models.AppUser() { Password = Helpers.EncryptDecryptHelper.GetStringMD5("888888") }; //新增用户默认密码 break; case Enums.EditFormMode.Edit: this.Text = "编辑"; break; case Enums.EditFormMode.Delete: this.Text = "删除"; break; default: this.Text = "新增/编辑"; break; } if (DataEntry != null) { this.deMain.DataSource = this.DataEntry; } }; this.btnCancel.Click += (s, e) => { //this.UserRole.CancelEdit(); this.DialogResult = DialogResult.Cancel; }; this.btnOk.Click += (s, e) => { var t = ValidationHelper.hasValidationErrors(this.deMain.Controls); if (t) { return; } this.btnOk.Enabled = false; Task.Factory.StartNew <AppUser>(() => { Models.AppUser re = null; if (EditMode == Enums.EditFormMode.Add) { re = bll.Insert <Models.AppUser>(this.DataEntry); } else if (EditMode == Enums.EditFormMode.Edit) { re = bll.Update <Models.AppUser>(this.DataEntry); } return(re); }).ContinueWith(tt => { if (!tt.IsFaulted) { syncContext.Post((state) => { Models.AppUser sta = (Models.AppUser)state; if (sta != null) { this.DataEntry = sta; this.DialogResult = DialogResult.OK; //this.SubmitSucess = true; } else { RadMessageBox.Show(this, "保存失败!", "", MessageBoxButtons.OK, RadMessageIcon.Error); } }, tt.Result); } syncContext.Post((state) => { this.btnOk.Enabled = true; }, tt.Result); }); }; }
private void Control_Leave(object sender, EventArgs e) { if (sender is RadTextBox) { objTextbox = (RadTextBox)sender; switch (objTextbox.Name) { //tab 2 case "Nombre_Fiscal": pvAddSupplier.SelectedPage = pvpDatosGenerales; RFC.Focus(); break; //tab 3 case "RFC": pvAddSupplier.SelectedPage = pvpDatosGenerales; Tipo_Inmueble.Focus(); break; //tab 6 case "Vialidad": pvAddSupplier.SelectedPage = pvpDatosGenerales; Codigo_Postal.Focus(); break; //tab 8 case "No_Ext": pvAddSupplier.SelectedPage = pvpDatosGenerales; No_Int.Focus(); break; //tab 9 case "No_Int": pvAddSupplier.SelectedPage = pvpDatosGenerales; Colonia.Focus(); break; //tab 10 case "Colonia": pvAddSupplier.SelectedPage = pvpDatosGenerales; Entidad_Federativa.Focus(); break; //tab 13 case "eMail": pvAddSupplier.SelectedPage = pvpDatosGenerales; Telefono.Focus(); break; //tab 16 case "Cuenta_Banco": pvAddSupplier.SelectedPage = pvpDatosGenerales; btnExaminar.Focus(); break; } } else if (sender is RadMaskedEditBox) { objMaskedEditBox = (RadMaskedEditBox)sender; switch (objMaskedEditBox.Name) { //tab 7 case "Codigo_Postal": pvAddSupplier.SelectedPage = pvpDatosGenerales; No_Ext.Focus(); break; //tab 14 case "Telefono": pvAddSupplier.SelectedPage = pvpDatosGenerales; Celular.Focus(); break; //tab 15 case "Celular": pvAddSupplier.SelectedPage = pvpDatosGenerales; Cuenta_Banco.Focus(); break; } } else if (sender is RadDropDownList) { objDropDownList = (RadDropDownList)sender; switch (objDropDownList.Name) { //tab 1 case "Giro_Comercial": pvAddSupplier.SelectedPage = pvpDatosGenerales; Nombre_Fiscal.Focus(); break; //tab 4 case "Tipo_Inmueble": pvAddSupplier.SelectedPage = pvpDatosGenerales; Tipo_Vialidad.Focus(); break; //tab 5 case "Tipo_Vialidad": pvAddSupplier.SelectedPage = pvpDatosGenerales; Vialidad.Focus(); break; //tab 11 case "Entidad_Federativa": pvAddSupplier.SelectedPage = pvpDatosGenerales; Municipio.Focus(); break; //tab 12 case "Municipio": pvAddSupplier.SelectedPage = pvpDatosGenerales; eMail.Focus(); break; } } else if (sender is RadButton) { objButton = (RadButton)sender; switch (objButton.Name) { //tab 17 case "btnExaminar": pvAddSupplier.SelectedPage = pvpDatosGenerales; btnAceptar.Focus(); break; //tab 18 case "btnAceptar": pvAddSupplier.SelectedPage = pvpDatosGenerales; btnCancelar.Focus(); break; } } }