public bool IsValidated() { var requidField = AreAllRequiredFieldsCaptured(); WebControl firstControl = null; if (requidField.Any()) { foreach (var control in requidField) { var moneyField = control as MoneyField; if (moneyField != null) { moneyField.TxtRands.BackColor = System.Drawing.ColorTranslator.FromHtml("#faffbd"); continue; } if (firstControl == null) { firstControl = ((WebControl)control); } ((WebControl)control).CssClass = "requireddata"; } if (firstControl != null) { firstControl.Focus(); } MessageBox.Show("Please complete all highlighted fields."); return(false); } return(true); }
public static void MakeDirty(WebControl control) { if (control != null) { control.CssClass = "dirty"; control.Focus(); } }
/// <summary> /// Asigna el focus al WebControl /// </summary> /// <param name="elem">WebControl </param> public static void SetFocus(WebControl elem) { elem.Focus( ); }
/// <summary> /// gets the data from the page and calls the function to calculate the break even point. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void GetBep(object sender, EventArgs e) { Validate(); // if the sender is a textbox remove leading zeros if any. if (sender is TextBox) { NoLeadingZeros(sender); } if (Page.IsValid) { double ticketPrice, guarantee, taxRatio, flatFee, percentage, minPRS, otherCosts; if (double.TryParse(tbTicketPrice.Text, out ticketPrice) && double.TryParse(tbArtist.Text, out guarantee) && double.TryParse(tbCosts.Text, out otherCosts)) { // VAT bool tax = cbVat.Checked; if (tax) { double.TryParse(tbVat.Text, out taxRatio); taxRatio = 1 + (taxRatio / 100); } else { taxRatio = 1; } //PRS int prsType = int.Parse(ddlPRS.SelectedValue.ToString()); switch (prsType) { case 0: // No fee flatFee = 0; percentage = 0; minPRS = 0; break; case 1: // flat fee double.TryParse(tbPRS1.Text, out flatFee); percentage = 0; minPRS = 0; break; case 2: // percentage default: flatFee = 0; double.TryParse(tbPRS1.Text, out percentage); percentage = percentage / 100; double.TryParse(tbPRS2.Text, out minPRS); break; } // calculate the break even point and display it. int bep = Calculate(tax, prsType, ticketPrice, guarantee, taxRatio, flatFee, percentage, minPRS, otherCosts); tbBEP.Text = bep.ToString(); // print feedback relative to capacity. int capacity; if (int.TryParse(tbCapacity.Text, out capacity)) { if (capacity != 0) // but only if a capacity has been provided. { if (bep < 0) { tbBEP.ForeColor = System.Drawing.Color.DarkRed; lFeedback.ForeColor = System.Drawing.Color.DarkRed; lFeedback.Text = "There was a problem while calculating the break even point."; } else if (bep >= capacity) { tbBEP.ForeColor = System.Drawing.Color.DarkRed; lFeedback.ForeColor = System.Drawing.Color.DarkRed; lFeedback.Text = "You cannot break even. The venue is too small or the costs are too high."; } else if (bep >= (capacity * 0.75)) { tbBEP.ForeColor = System.Drawing.Color.DarkOrange; lFeedback.ForeColor = System.Drawing.Color.DarkOrange; lFeedback.Text = "The possibilty of profits is very limited. The venue might be too small or the costs too high."; } else if (bep <= (capacity * 0.35)) { tbBEP.ForeColor = System.Drawing.Color.DarkOrange; lFeedback.ForeColor = System.Drawing.Color.DarkOrange; lFeedback.Text = "The venue may be too big."; } else { tbBEP.ForeColor = System.Drawing.Color.DarkGreen; lFeedback.ForeColor = System.Drawing.Color.DarkGreen; lFeedback.Text = "Everything seems fine."; } } else // if no capacity has been provided, clear feedback message. { lFeedback.Text = ""; } } } } // bring the focus back to the control that called the function. WebControl c = sender as WebControl; c.Focus(); }