private void BtnModifyPart_Click(object sender, RoutedEventArgs e) { if (partsList.Count > 0) { if (currentPart != 0) { var part = partsList.Find(e => e.PartId == currentPart); EditPart ep = new EditPart(part); ep.ShowDialog(); DgParts.ItemsSource = null; DgParts.ItemsSource = partsList; } else { MessageBox.Show("Please select a part to modify", "Error", MessageBoxButton.OKCancel); } } else { MessageBox.Show("There are no parts to modify", "Error", MessageBoxButton.OKCancel); } }
private bool IsEntryValid(int intIndex, string strText, Key enmKey) { EditPart objCurrentPart = lstParts[intCurrentPartIndex]; if ((enmKey >= Key.A) & (enmKey <= Key.Z)) { if (objCurrentPart.CharacterClass == EditPart.E_CharacterClass.Numeric) { return(false); } switch (objCurrentPart.Multiplicity) { case EditPart.E_Multiplicity.One: if (objCurrentPart.CurrentText.Length >= 1) { return(false); } break; case EditPart.E_Multiplicity.Many: break; case EditPart.E_Multiplicity.Defined: if (objCurrentPart.CurrentText.Length >= objCurrentPart.Count) { return(false); } break; } } else if ((enmKey >= Key.D0) & (enmKey <= Key.D9) || (enmKey >= Key.NumPad0) & (enmKey <= Key.NumPad9)) { if (objCurrentPart.CharacterClass == EditPart.E_CharacterClass.Alpha) { return(false); } switch (objCurrentPart.Multiplicity) { case EditPart.E_Multiplicity.One: if (objCurrentPart.CurrentText.Length >= 1) { return(false); } break; case EditPart.E_Multiplicity.Many: break; case EditPart.E_Multiplicity.Defined: if (objCurrentPart.CurrentText.Length >= objCurrentPart.Count) { return(false); } break; } } else { //Invalid key return false return(false); } //No problems so retrun true return(true); }
public virtual void OnInputMaskChanged(string strOldValue, string strNewValue) { //Clear the text Text = ""; //Need to section up the Input Mask lstParts = new List <EditPart>(); string strPart = ""; string strDisplayTextCalc = ""; string strMaskTextCalc = ""; for (int i = 0; i <= strNewValue.Length; i++) { if (i == strNewValue.Length || (strNewValue[i] == '.') | (strNewValue[i] == '-') | (strNewValue[i] == '@')) { EditPart.E_CharacterClass enmCharacterClass = default(EditPart.E_CharacterClass); EditPart.E_Multiplicity enmMultiplicity = default(EditPart.E_Multiplicity); int intCount = 0; if (strPart.StartsWith("X")) { enmCharacterClass = EditPart.E_CharacterClass.AlphaNumeric; } else if (strPart.StartsWith("A")) { enmCharacterClass = EditPart.E_CharacterClass.Alpha; } else if (strPart.StartsWith("N")) { enmCharacterClass = EditPart.E_CharacterClass.Numeric; } if (strPart.Length == 1) { enmMultiplicity = EditPart.E_Multiplicity.One; } else if (strPart.EndsWith("*")) { enmMultiplicity = EditPart.E_Multiplicity.Many; } else if (strPart.Contains("+")) { enmMultiplicity = EditPart.E_Multiplicity.Defined; intCount = Convert.ToInt32(strPart.Substring(strPart.IndexOf("+") + 1)); } EditPart objEditPart = new EditPart(enmCharacterClass, enmMultiplicity, intCount); if (i != strNewValue.Length) { objEditPart.PartEndString = strNewValue[i].ToString(); } lstParts.Add(objEditPart); strPart = ""; if ((objEditPart.Multiplicity == EditPart.E_Multiplicity.One) | (objEditPart.Multiplicity == EditPart.E_Multiplicity.Many)) { strDisplayTextCalc += " " + objEditPart.PartEndString; strMaskTextCalc += "X" + objEditPart.PartEndString; } else { for (int j = 0; j <= intCount - 1; j++) { strDisplayTextCalc += " " + objEditPart.PartEndString; strMaskTextCalc += "X" + objEditPart.PartEndString; } } } else { strPart += strNewValue[i]; } } strDisplayText = strDisplayTextCalc; Text = strDisplayTextCalc; strMaskText = strMaskTextCalc; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("InputMask")); } }