public int GetSelectedYearNumber() { int yearNumber = -1; if (comboYearNumber.SelectedIndex >= 0 && comboYearNumber.Items.Count > 0) { string selectedYear = comboYearNumber.Items[comboYearNumber.SelectedIndex] as string; if (selectedYear != null) { if (Int32.TryParse(ParsingUtils.ConvertNumber2English(selectedYear), out yearNumber)) { return(yearNumber); } } } return(-1); }
private void comboYearNumber_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Return || e.KeyCode == Keys.Enter) { e.Handled = true; string text = ParsingUtils.ConvertNumber2English(comboYearNumber.Text).Trim(); int newYear; if (Int32.TryParse(text, out newYear)) { string persianNumber = ParsingUtils.ConvertNumber2Persian(newYear.ToString()); if (comboYearNumber.Items.Contains(persianNumber)) { comboYearNumber.SelectedItem = persianNumber; } else { comboYearNumber.Items.Add(persianNumber); comboYearNumber.SelectedItem = persianNumber; } } } }
private static string CreateDigitizedNumberSuggestionFor(DigitizedNumberPatternInfo pi, KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue) { if (pi == null) { return(null); } //string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); //string f20CurrencyEng = MathUtils.InsertThousandSeperator(f20NormalizedEng); //bool addCurrency = (f20NormalizedEng != f20CurrencyEng); //string f20NormPer = ParsingUtils.ConvertNumber2Persian(f20NormalizedEng); //string f20CurrencyPer = ParsingUtils.ConvertNumber2Persian(f20CurrencyEng); //string perLetterNumber; //if (!NumberToPersianString.TryConvertNumberToPersianString(pi.Number, out perLetterNumber)) //{ // perLetterNumber = null; //} //string perLetterNegNumber = null; //if (pi.Content[0] == '-') //{ // if (!NumberToPersianString.TryConvertNumberToPersianString(-pi.Number, out perLetterNegNumber)) // { // perLetterNegNumber = null; // } // else // { // perLetterNegNumber = "-" + perLetterNegNumber; // } //} //else if (pi.Content[0] == '+' && !String.IsNullOrEmpty(perLetterNumber)) //{ // perLetterNegNumber = "+" + perLetterNumber; //} // now giving orders if ((ruleValue.Value == NumberChangeRule.OutputDigitLanguages.Persian) && (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPoint || ruleValue.Key == NumberChangeRule.OutputFormats.Fractional)) { string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); string f20NormPer = ParsingUtils.ConvertNumber2Persian(f20NormalizedEng); return(f20NormPer); } else if ((ruleValue.Value == NumberChangeRule.OutputDigitLanguages.Persian) && (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep)) { string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); string f20CurrencyEng = MathUtils.InsertThousandSeperator(f20NormalizedEng); string f20CurrencyPer = ParsingUtils.ConvertNumber2Persian(f20CurrencyEng); return(f20CurrencyPer); } else if (ruleValue.Key == NumberChangeRule.OutputFormats.Letters) { string perLetterNumber; if (!NumberToPersianString.TryConvertNumberToPersianString(pi.Number, out perLetterNumber)) { perLetterNumber = null; } return(perLetterNumber); } else if (ruleValue.Key == NumberChangeRule.OutputFormats.LettersWithSign) { string perLetterNumber; if (!NumberToPersianString.TryConvertNumberToPersianString(pi.Number, out perLetterNumber)) { perLetterNumber = null; } string perLetterNegNumber = null; if (pi.Content[0] == '-') { if (!NumberToPersianString.TryConvertNumberToPersianString(-pi.Number, out perLetterNegNumber)) { perLetterNegNumber = null; } else { perLetterNegNumber = "-" + perLetterNegNumber; } } else if (pi.Content[0] == '+' && !String.IsNullOrEmpty(perLetterNumber)) { perLetterNegNumber = "+" + perLetterNumber; } return(perLetterNegNumber); } else if ((ruleValue.Value == NumberChangeRule.OutputDigitLanguages.English) && (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPoint || ruleValue.Key == NumberChangeRule.OutputFormats.Fractional)) { string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); return(f20NormalizedEng); } else if ((ruleValue.Value == NumberChangeRule.OutputDigitLanguages.English) && (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep)) { string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); string f20CurrencyEng = MathUtils.InsertThousandSeperator(f20NormalizedEng); return(f20CurrencyEng); } return(null); }
/// <summary> /// Creates suggestions for the given pattern info /// </summary> /// <param name="rule">the change rules that give order to the suggestions</param> /// <param name="pi">the pattern info object to create suggestions for</param> /// <returns></returns> private static string[] CreateDigitizedNumberSuggestions(NumberChangeRule rule, DigitizedNumberPatternInfo pi) { if (pi == null) { return(new string[0]); } var lstSug = new List <string>(); var inpFormat = NumberChangeRule.InputFormats.Digits; var inpLang = NumberParsersSuggestions.DetectInputDigitLanguage(pi.Content); if (inpLang == NumberChangeRule.InputDigitLanguages.None) { inpLang = NumberChangeRule.InputDigitLanguages.English; } string f20NormalizedEng = ParsingUtils.ConvertNumber2English(MathUtils.NormalizeForF20Format(pi.Number.ToString("F20"))); string f20CurrencyEng = MathUtils.InsertThousandSeperator(f20NormalizedEng); bool addCurrency = (f20NormalizedEng != f20CurrencyEng); string f20NormPer = ParsingUtils.ConvertNumber2Persian(f20NormalizedEng); string f20CurrencyPer = ParsingUtils.ConvertNumber2Persian(f20CurrencyEng); string perLetterNumber; if (!NumberToPersianString.TryConvertNumberToPersianString(pi.Number, out perLetterNumber)) { perLetterNumber = null; } string perLetterNegNumber = null; if (pi.Content[0] == '-') { if (!NumberToPersianString.TryConvertNumberToPersianString(-pi.Number, out perLetterNegNumber)) { perLetterNegNumber = null; } else { perLetterNegNumber = "-" + perLetterNegNumber; } } else if (pi.Content[0] == '+' && !String.IsNullOrEmpty(perLetterNumber)) { perLetterNegNumber = "+" + perLetterNumber; } KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages>?sugPrior = null; if (rule != null) { if (!String.IsNullOrEmpty(perLetterNegNumber)) { inpFormat = NumberChangeRule.InputFormats.DigitsWithSign; } if (rule.ContainsKey(inpFormat, inpLang)) { sugPrior = rule.GetValueForKey(inpFormat, inpLang); } else if (inpFormat == NumberChangeRule.InputFormats.DigitsWithSign && rule.ContainsKey(NumberChangeRule.InputFormats.Digits, inpLang)) { sugPrior = rule.GetValueForKey(NumberChangeRule.InputFormats.Digits, inpLang); } } // now giving orders if ((sugPrior != null && (sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.Persian) && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPoint || sugPrior.Value.Key == NumberChangeRule.OutputFormats.Fractional)) || (sugPrior == null && inpLang != NumberChangeRule.InputDigitLanguages.Persian)) { // adding floating in Persian digits lstSug.Add(f20NormPer); if (addCurrency) { lstSug.Add(f20CurrencyPer); } // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in english digits lstSug.Add(f20NormalizedEng); if (addCurrency) { lstSug.Add(f20CurrencyEng); } } else if ((sugPrior != null && (sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.Persian) && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep))) { // adding floating in Persian digits if (addCurrency) { lstSug.Add(f20CurrencyPer); } lstSug.Add(f20NormPer); // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in english digits if (addCurrency) { lstSug.Add(f20CurrencyEng); } lstSug.Add(f20NormalizedEng); } else if ((sugPrior != null && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.Letters)) || (sugPrior == null && inpLang == NumberChangeRule.InputDigitLanguages.Persian)) { // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in english digits lstSug.Add(f20NormalizedEng); if (addCurrency) { lstSug.Add(f20CurrencyEng); } // adding floating in Persian digits lstSug.Add(f20NormPer); if (addCurrency) { lstSug.Add(f20CurrencyPer); } } else if (sugPrior != null && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.LettersWithSign)) { // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } // adding number in english digits lstSug.Add(f20NormalizedEng); if (addCurrency) { lstSug.Add(f20CurrencyEng); } // adding floating in Persian digits lstSug.Add(f20NormPer); if (addCurrency) { lstSug.Add(f20CurrencyPer); } } else if (sugPrior != null && (sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.English) && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPoint || sugPrior.Value.Key == NumberChangeRule.OutputFormats.Fractional)) { // adding number in english digits lstSug.Add(f20NormalizedEng); if (addCurrency) { lstSug.Add(f20CurrencyEng); } // adding floating in Persian digits lstSug.Add(f20NormPer); if (addCurrency) { lstSug.Add(f20CurrencyPer); } // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } } else if (sugPrior != null && (sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.English) && (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep)) { // adding number in english digits if (addCurrency) { lstSug.Add(f20CurrencyEng); } lstSug.Add(f20NormalizedEng); // adding floating in Persian digits if (addCurrency) { lstSug.Add(f20CurrencyPer); } lstSug.Add(f20NormPer); // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } } else { // adding number in persian letters if (!String.IsNullOrEmpty(perLetterNumber)) { lstSug.Add(perLetterNumber); } // adding number in persian letters and sign if (!String.IsNullOrEmpty(perLetterNegNumber)) { lstSug.Add(perLetterNegNumber); } // adding number in english digits lstSug.Add(f20NormalizedEng); if (addCurrency) { lstSug.Add(f20CurrencyEng); } // adding floating in Persian digits lstSug.Add(f20NormPer); if (addCurrency) { lstSug.Add(f20CurrencyPer); } } return(lstSug.ToArray()); }