private bool DataElementRowControl_ValidateOnSubmitText(object sender, EventArgs e) { AAMVADataElementInfo info = this.DataElementInfo[this.ElementID]; if (info.LengthType == AAMVALengthType.Fixed && this.TextBox.Text.Length != info.ValueMaxLength && this.CheckBox.Checked) { ((BorderedTextBox)this.TextBox).BorderColor = Color.Red; return(false); } if (_elementID == "DAU") //height { string expression = @"^\d{3,} (?:in|cm)$"; bool match = Regex.IsMatch(_textBoxValue.Text, expression); if (!match) { ((BorderedTextBox)this.TextBox).BorderColor = Color.Red; return(false); } } return(true); }
public AAMVADialogBox(AAMVAID id) { InitializeComponent(); _id = id; this.FormClosed += HandleClose; _infoDictionary = (Dictionary <string, AAMVADataElementInfo>)AAMVADataElementInfo.RetrieveAll(id.Version); Populate(); }
private void PopulateRaw() { _listViewRawDataElements.Items.Clear(); for (int i = 0; i < _id.NumberOfEntries; i++) { IDictionary <string, AAMVADataElement> dictionary = _id.Subfiles[i].DataElements; foreach (KeyValuePair <string, AAMVADataElement> kvp in dictionary) { bool containsKey = _infoDictionary.ContainsKey(kvp.Key); AAMVADataElementInfo info = containsKey ? _infoDictionary[kvp.Key] : null; string[] arr = new string[5]; arr[0] = kvp.Key; arr[1] = containsKey ? info.FriendlyName : ""; arr[2] = _id.Subfiles[i].SubfileTypeCode; arr[3] = kvp.Value.Value; arr[4] = containsKey ? info.Definition : ""; ListViewItem item = new ListViewItem(arr); _listViewRawDataElements.Items.Add(item); } } }
private string GetTooltipText(string elementID) { AAMVADataElementInfo info = null; try { info = _dataElementInfo[elementID]; } catch { return("Jurisdiction-specific data element"); } StringBuilder sb = new StringBuilder(); if (info != null) { //alpha? bool alpha = (info.ValidCharacters & ((int)AAMVAValidCharacters.Alpha)) == (int)AAMVAValidCharacters.Alpha; bool numeric = (info.ValidCharacters & ((int)AAMVAValidCharacters.Numeric)) == (int)AAMVAValidCharacters.Numeric; bool special = (info.ValidCharacters & ((int)AAMVAValidCharacters.Special)) == (int)AAMVAValidCharacters.Special; sb.Append("Element ID: ") .Append(info.ElementID) .Append(Environment.NewLine) .Append(Environment.NewLine) .Append("Friendly Name: ") .Append(info.FriendlyName) .Append(Environment.NewLine) .Append(Environment.NewLine) .Append("Definition: ") .Append(info.Definition) .Append(Environment.NewLine) .Append(Environment.NewLine) .Append("Value Max Length: ") .Append(Convert.ToString(info.ValueMaxLength)) .Append(Environment.NewLine) .Append(Environment.NewLine) .Append("Length Type: ") .Append(Convert.ToString(info.LengthType)) .Append(Environment.NewLine) .Append(Environment.NewLine) .Append("Valid Characters: "); if (alpha) { sb.Append("Alphabetical "); } if (numeric) { sb.Append("Numeric "); } if (special) { sb.Append("Special"); } } return(sb.ToString()); }
//Generic validator private bool IsInputKeyValid(KeyPressEventArgs e) { AAMVADataElementInfo info = null; try { info = _dataElementInfo[_elementID]; } catch { //For jurisdiction-specific info = new AAMVADataElementInfo(); info.LengthType = AAMVALengthType.Variable; info.ValueMaxLength = 99; info.ValidCharacters = (int)AAMVAValidCharacters.Alpha | (int)AAMVAValidCharacters.Numeric | (int)AAMVAValidCharacters.Special; } if (_textBoxValue.Text.Length == info.ValueMaxLength && !char.IsControl(e.KeyChar) && _textBoxValue.SelectedText.Length == 0) { return(false); } bool allowNumeric = (info.ValidCharacters & (int)AAMVAValidCharacters.Numeric) == (int)AAMVAValidCharacters.Numeric; bool allowAlpha = (info.ValidCharacters & (int)AAMVAValidCharacters.Alpha) == (int)AAMVAValidCharacters.Alpha; bool allowSpecial = (info.ValidCharacters & (int)AAMVAValidCharacters.Special) == (int)AAMVAValidCharacters.Special; if (!allowNumeric) { if (char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) { return(false); } } if (!allowAlpha) { if (char.IsLetter(e.KeyChar) && !char.IsControl(e.KeyChar)) { return(false); } } if (!allowSpecial) { if (!char.IsLetterOrDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) { if (!(allowAlpha && e.KeyChar == ' '))//allow spaces with alpha fields -- do not consider space a special char { return(false); } } } if (!(e.KeyChar < 128) && !char.IsControl(e.KeyChar)) //ASCII only { return(false); } return(true); }
private void DataElementRowControl_BeforeSubmitText(object sender, EventArgs e) { AAMVADataElementInfo info = this.DataElementInfo[this.ElementID]; if (info.LengthType == AAMVALengthType.Variable && (info.ValidCharacters & (int)AAMVAValidCharacters.Alpha) == (int)AAMVAValidCharacters.Alpha && info.ValueMaxLength >= 4 && this.TextBox.Text.Length == 0 && this.CheckBox.Checked) { this.TextBox.Text = "NONE"; } if (_elementID == "DAK") //Postal code { AAMVARegion rgn = AAMVAID.LookupRegion(_jurisdiction); if (rgn == AAMVARegion.UnitedStates) { if (_textBoxValue.Text.Length >= 5 && _textBoxValue.Text.Length < 9) { StringBuilder sb = new StringBuilder(_textBoxValue.Text); while (sb.Length < 9) { sb.Append('0'); } while (sb.Length < 11) { sb.Append(' '); } _textBoxValue.Text = sb.ToString(); } else if (_textBoxValue.Text.Length >= 9 && _textBoxValue.Text.Length < 11) { StringBuilder sb = new StringBuilder(_textBoxValue.Text); while (sb.Length < 11) { sb.Append(' '); } _textBoxValue.Text = sb.ToString(); } } else if (rgn == AAMVARegion.Canada) { if (_textBoxValue.Text.Length > 5) { StringBuilder sb = new StringBuilder(_textBoxValue.Text); while (sb.Length < 11) { sb.Append(' '); } _textBoxValue.Text = sb.ToString(); } } else if (rgn == AAMVARegion.Mexico) { if (_textBoxValue.Text.Length > 6) { StringBuilder sb = new StringBuilder(_textBoxValue.Text); while (sb.Length < 11) { sb.Append(' '); } _textBoxValue.Text = sb.ToString(); } } } }
private void AddDataElementRows(HashSet <string> values, int tabIndex) { _dataElementInfo = AAMVADataElementInfo.RetrieveAll(AAMVAVersion.Version2016); if (tabIndex == 0) { Label label = new Label(); label.Text = "Per AAMVA CDS 2016 §D.12.5, mandatory data elements that call for variable length, alphabetical values will be filled with \"NONE\" if no value is provided."; label.Dock = DockStyle.Top; _tabControl.TabPages[tabIndex].Controls.Add(label); _tabControl.TabPages[tabIndex].Controls.SetChildIndex(label, 0); } if (tabIndex == 1) { _cbDHS = new CheckBox(); _cbDHS.Text = "DHS (REAL ID) Required Data Elements"; _cbDHS.Dock = DockStyle.Top; _cbDHS.CheckedChanged += (s, e) => { if (_cbDHS.Checked) { foreach (Control ctrl in _tabControl.TabPages[tabIndex].Controls) { if (ctrl is DataElementRowControl) { DataElementRowControl rowInner = (DataElementRowControl)ctrl; if (DHSDataElements.Contains(rowInner.ElementID)) { rowInner.CheckBox.Checked = true; } } } } else { bool shouldUncheckAll = true; foreach (Control ctrl in _tabControl.TabPages[tabIndex].Controls) { if (ctrl is DataElementRowControl) { DataElementRowControl rowInner = (DataElementRowControl)ctrl; if (DHSDataElements.Contains(rowInner.ElementID) && !rowInner.CheckBox.Checked) { shouldUncheckAll = false; } } } if (shouldUncheckAll) { foreach (Control ctrl in _tabControl.TabPages[tabIndex].Controls) { if (ctrl is DataElementRowControl) { DataElementRowControl rowInner = (DataElementRowControl)ctrl; if (DHSDataElements.Contains(rowInner.ElementID)) { rowInner.CheckBox.Checked = false; } } } } } }; _tabControl.TabPages[tabIndex].Controls.Add(_cbDHS); _tabControl.TabPages[tabIndex].Controls.SetChildIndex(_cbDHS, 0); } foreach (string elementID in values) { AAMVADataElementInfo info = _dataElementInfo[elementID]; if ((info.ValidSubfileTypes & (int)_subfileSkeleton.SubfileType) == (int)_subfileSkeleton.SubfileType) { DataElementRowControl row = new DataElementRowControl(); row.DataElementInfo = _dataElementInfo; row.Jurisdiction = _jurisdiction; row.ElementID = elementID; row.Dock = DockStyle.Top; row.CheckBox.CheckedChanged += (s, e) => { CheckBox cb = (CheckBox)s; if (!cb.Checked && DHSDataElements.Contains(row.ElementID)) { _cbDHS.Checked = false; } }; if (tabIndex == 1) //optional { row.CheckBox.Enabled = true; row.CheckBox.Checked = false; } _tabControl.TabPages[tabIndex].Controls.Add(row); _tabControl.TabPages[tabIndex].Controls.SetChildIndex(row, 0); } } }