//Para Verificar que los Telefonos,Celulares,Fax estan llenado de Forma Correcta public static bool ValidarTelefono(MaskedTextBox Txt) { bool flag; Txt.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; if (Txt.Text.Length != 0 && Txt.MaskFull == false) { flag = false; Txt.Focus(); } else { flag = true; } return flag; }
/// <summary> /// Loads controls on the panel /// </summary> private void LoadControls() { foreach (SearchListBoxItem item in searchFieldsCollection) { //add masked textbox or textbox to the panel if (!string.IsNullOrEmpty(item.Pattern)) { //Add masked textbox to the panel MaskedTextBox fieldTextBox = new MaskedTextBox(); fieldTextBox.Location = new System.Drawing.Point(300, textLinePosition); fieldTextBox.Size = new System.Drawing.Size(286, 20); fieldTextBox.BringToFront(); fieldTextBox.Leave += new EventHandler(fieldTextBox_Leave); // fieldTextBox.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox_MaskInputRejected); string mask = AppData.Instance.DataPatternsDataTable.GetMaskByPattern(item.Pattern); //fieldTextBox.Mask = AppData.Instance.DataPatternsDataTable.GetExpressionByMask(mask, item.Pattern); fieldTextBox.Tag = item.Type; fieldTextBox.Name = item.Name; //fieldTextBox.Mask = mask; if (item.Type.Equals("Number") || item.Type.Equals("PhoneNumber")) { // fieldTextBox.PromptChar = '_'; } else if (item.Type.Equals("Date") || item.Type.Equals("DateTime")) { // fieldTextBox.PromptChar = '_'; fieldTextBox.Text = String.Format("{0}", string.Empty); } else if (item.Type.Equals("Time")) { // fieldTextBox.PromptChar = '_'; fieldTextBox.Text = String.Format("{0:T}", string.Empty); } splitContainer1.Panel2.Controls.Add(fieldTextBox); textLinePosition += 38; if (myControlDictionaryData.ContainsKey(item.Name.ToString())) { fieldTextBox.Text = myControlDictionaryData[item.Name.ToString()].ToString(); } myControlDictionary.Add(item.Name.ToString(), fieldTextBox); myControlItemDictionary.Add(fieldTextBox, item); fieldTextBox.Focus(); } else { //if (item.Type.Equals("YesNo")) //{ // ComboBox cbxYesNo = new ComboBox(); // Configuration config = Configuration.GetNewInstance(); // cbxYesNo.Items.AddRange(new object[] { config.Settings.RepresentationOfYes, config.Settings.RepresentationOfNo, config.Settings.RepresentationOfMissing }); // cbxYesNo.Location = new System.Drawing.Point(300, textLinePosition); // cbxYesNo.Size = new System.Drawing.Size(286, 20); // cbxYesNo.BringToFront(); // cbxYesNo.Leave += new EventHandler(fieldTextBox_Leave); // splitContainer1.Panel2.Controls.Add(cbxYesNo); // textLinePosition += 38; // myControlDictionary.Add(item.Name.ToString(), cbxYesNo); // myControlItemDictionary.Add(cbxYesNo, item); // cbxYesNo.Focus(); //} //else { ////add textbox to panel TextBox fieldTextBox = new TextBox(); fieldTextBox.Name = item.Name; fieldTextBox.Location = new System.Drawing.Point(300, textLinePosition); fieldTextBox.Size = new System.Drawing.Size(286, 20); fieldTextBox.BringToFront(); fieldTextBox.Leave += new EventHandler(fieldTextBox_Leave); splitContainer1.Panel2.Controls.Add(fieldTextBox); textLinePosition += 38; myControlDictionary.Add(item.Name.ToString(), fieldTextBox); myControlItemDictionary.Add(fieldTextBox, item); fieldTextBox.Focus(); } } //add field name label to panel Label fieldName = new Label(); fieldName.Tag = item.Name.ToString().ToUpper(); fieldName.Location = new System.Drawing.Point(26, labelLinePosition); fieldName.Size = new System.Drawing.Size(35, 13); fieldName.AutoSize = true; fieldName.FlatStyle = FlatStyle.System; fieldName.Text = item.Name.ToString(); splitContainer1.Panel2.Controls.Add(fieldName); labelLinePosition += 38; //add pattern label to panel Label lblPattern = new Label(); lblPattern.Tag = item.Name.ToString().ToUpper(); lblPattern.Location = new System.Drawing.Point(620, patternLinePosition); lblPattern.Size = new System.Drawing.Size(35, 13); lblPattern.AutoSize = true; lblPattern.FlatStyle = FlatStyle.System; splitContainer1.Panel2.Controls.Add(lblPattern); patternLinePosition += 38; if (!string.IsNullOrEmpty(item.Pattern)) { lblPattern.Text = item.Pattern.ToString(); } //myControlDictionary.Add(item.Name.ToString(), fieldTextBox); //myControlItemDictionary.Add(fieldTextBox, item); } }
/// <summary> /// Checks to see if the text box contains a phone number. /// </summary> /// <param name="textBox">The text box control</param> /// <returns>True IFF the text box contrains a phone number</returns> public static bool IsPhoneNumber(MaskedTextBox textBox) { string phoneChars = textBox.Text.Replace(".", "").Replace("(", "").Replace(")", "").Replace("-", "").Replace(" ", ""); try { Convert.ToInt64(phoneChars); return true; } catch (FormatException) { MessageBox.Show(textBox.Tag.ToString() + " must be in this format: 999-999-9999", Title); textBox.Focus(); return false; } }
/// <summary> /// Checks to see if the text box contains a zip code. /// </summary> /// <param name="textBox">The text box control</param> /// <param name="firstZip">The lowest numerical zip code</param> /// <param name="lastZip">The highest numerical zip code</param> /// <returns>True IFF the text box contrains a zip code</returns> public static bool IsStateZipCode(MaskedTextBox textBox, int firstZip, int lastZip) { //00501 //99950 int zipCode = Convert.ToInt32(textBox.Text); if (zipCode < firstZip || zipCode > lastZip) { MessageBox.Show(textBox.Tag.ToString() + " must be within this range: " + firstZip.ToString("D5") + " to " + lastZip.ToString("D5") + ".", Title); textBox.Focus(); return false; } else { return true; } }
public void continuidade(MaskedTextBox usado, MaskedTextBox texto1, MaskedTextBox texto2) { if (podeCodigo(Convert.ToInt16(usado.Text))) { if (texto1.Visible) { if (texto1.Text.Length>0 && podeCodigo(Convert.ToInt16(texto1.Text))) { if (texto2.Visible) { if (texto2.Text.Length > 0 && podeCodigo(Convert.ToInt16(texto2.Text))) { preencherLabelDescritivo(new Banco().codTamanho(cbTamanho.Text) , new Banco().codDivisorByDescricao(cbMista.Text)); gbQtd.Visible = true; gbQtd.Focus(); } else { texto2.Clear(); texto2.Focus(); } } else { preencherLabelDescritivo(new Banco().codTamanho(cbTamanho.Text) , new Banco().codDivisorByDescricao(cbMista.Text)); gbQtd.Visible = true; gbQtd.Focus(); } } else { texto1.Clear(); texto1.Focus(); } } else { preencherLabelDescritivo(new Banco().codTamanho(cbTamanho.Text) , new Banco().codDivisorByDescricao(cbMista.Text)); gbQtd.Visible = true; gbQtd.Focus(); } } else { usado.Clear(); usado.Focus(); } }
/// <summary> /// force means ignore any cache and require the user to enter a password /// </summary> /// <param name="prompt"></param> /// <param name="force"></param> /// <returns></returns> public static string Password(string prompt, bool requireEntry) { string passwordFileName; if (!string.IsNullOrWhiteSpace(prompt)) { if (ProcessFunctions.KeplerProcess != null) { passwordFileName = SwishFunctions.GeneratePasswordFileName(prompt, ProcessFunctions.KeplerProcess); passwordFileName = Path.Combine(Path.GetTempPath(), passwordFileName); if (!requireEntry && FileFunctions.FileExists(passwordFileName)) { string _encodedPassword = File.ReadAllText(passwordFileName); string _password = SwishFunctions.DecodePassword(_encodedPassword, ProcessFunctions.KeplerProcess); return _password; } } else { passwordFileName = string.Empty; } } else { prompt = "Please enter password"; passwordFileName = string.Empty; } string password; using (MaskedTextBox textBox = new MaskedTextBox()) using (Panel panel = new Panel()) using (Button buton = new Button()) using (Form form = new Form()) { textBox.SuspendLayout(); buton.SuspendLayout(); panel.SuspendLayout(); form.SuspendLayout(); textBox.UseSystemPasswordChar = true; textBox.Multiline = true; textBox.SelectionStart = 0; textBox.SelectionLength = 0; textBox.Size = new Size(300, textBox.Height); textBox.Dock = DockStyle.Top; textBox.Font = new Font(textBox.Font, FontStyle.Bold); textBox.TabIndex = 0; buton.Click += new EventHandler(buton_Click); buton.Dock = DockStyle.Left; buton.Text = "Ok"; buton.Size = new Size(75, 23); buton.TabIndex = 0; panel.Height = 23; panel.Controls.Add(buton); panel.Dock = DockStyle.Fill; panel.TabIndex = 1; form.ControlBox = false; form.Text = prompt; form.ClientSize = new Size(300, 43); form.Controls.Add(panel); form.Controls.Add(textBox); form.AcceptButton = buton; textBox.ResumeLayout(); buton.ResumeLayout(); panel.ResumeLayout(); form.ResumeLayout(); textBox.Focus(); form.ShowDialog(); password = textBox.Text; } if (string.IsNullOrWhiteSpace(password)) { return string.Empty; } if (string.IsNullOrWhiteSpace(passwordFileName)) { return password; } string encodedPassword = SwishFunctions.EncodePassword(password, ProcessFunctions.KeplerProcess); if (File.Exists(passwordFileName)) { FileFunctions.DeleteFile(passwordFileName, null); } File.WriteAllText(passwordFileName, encodedPassword); return password; }
//Para Verificar que los Telefonos,Celulares,Fax estan llenado de Forma Correcta public void ValidarTelefono(MaskedTextBox Txt, string mensaje) { Txt.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; if (Txt.Text.Length != 0 && Txt.MaskFull == false) { ErrPro.SetError(Txt, mensaje); Txt.Focus(); } else { ErrPro.SetError(Txt, null); } }