Example #1
0
        public override bool ShowBatchModeStats()
        {
            string message = string.Format("تعداد اصلاحات انجام شده: {0}", ParsingUtils.ConvertNumber2Persian(m_stats.ToString()));

            PersianMessageBox.Show(ThisAddIn.GetWin32Window(), message, Title);
            return(true);
        }
        public override bool ShowBatchModeStats()
        {
            string message = string.Format("تعداد اصلاحات انجام شده: {0}", ParsingUtils.ConvertNumber2Persian(m_bachModeStats.ToString()));

            PersianMessageBox.Show(ThisAddIn.GetWin32Window(), message, Constants.UIMessages.SuccessRefinementTitle);
            return(false);
        }
Example #3
0
        public void ShowPageNumberProgress(int pageNo, int pageCount)
        {
            string msg = String.Format("صفحهٔ {0} از {1}",
                                       ParsingUtils.ConvertNumber2Persian(pageNo.ToString()),
                                       ParsingUtils.ConvertNumber2Persian(pageCount.ToString()));
            var act = new Action(delegate
            {
                lblProgress.Text = msg;
                if (!progressBar.Visible)
                {
                    progressBar.Visible = true;
                }
                progressBar.Minimum = 0;
                progressBar.Maximum = pageCount;
                progressBar.Value   = Math.Min(pageNo, pageCount);
            });

            if (InvokeRequired)
            {
                Invoke(act);
            }
            else
            {
                act.Invoke();
            }
        }
Example #4
0
        private string StatsticsMessage()
        {
            var sb = new StringBuilder();

            long sum = 0L;

            foreach (var pair in m_dicRefinementStats)
            {
                sum += pair.Value;
                sb.AppendLine(String.Format("{0}: {1}", GetRefinementTypeLabel(pair.Key), ParsingUtils.ConvertNumber2Persian(pair.Value.ToString())));
            }

            return(String.Format("{0}: {1}{2}{2}", "تعداد کل نویسه‌های اصلاح شده", ParsingUtils.ConvertNumber2Persian(sum.ToString()), Environment.NewLine) + sb);
        }
        private void AddPossibleYearNumbers(int yearNumber, DateCalendarType calendarType)
        {
            comboYearNumber.Items.Clear();
            if (yearNumber <= 0)
            {
                return;
            }

            if (yearNumber < 100)
            {
                int newYear = yearNumber;
                switch (calendarType)
                {
                case DateCalendarType.Gregorian:
                    if ((2000 - (1900 + yearNumber)) < ((2000 + yearNumber) - 2000))
                    {
                        newYear += 1900;
                    }
                    else
                    {
                        newYear += 2000;
                    }
                    break;

                case DateCalendarType.HijriGhamari:
                    newYear += 1400;
                    break;

                case DateCalendarType.Jalali:
                    newYear += 1300;
                    break;

                default:
                    break;
                }

                comboYearNumber.Items.Add(ParsingUtils.ConvertNumber2Persian(newYear.ToString()));

                comboYearNumber.Visible = true;
                comboYearNumber.Enabled = true;
            }

            comboYearNumber.Items.Add(ParsingUtils.ConvertNumber2Persian(yearNumber.ToString()));

            comboYearNumber.SelectedIndex = 0;
        }
        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[] CreateGeneralNumberSuggestions(NumberChangeRule rule, GeneralNumberInfo pi)
        {
            if (pi == null)
            {
                return(new string[0]);
            }

            var lstSug = new List <string>();

            string fracStr    = pi.IsFraction ? pi.FractionString : null;
            string fracStrPer = fracStr == null ? null : ParsingUtils.ConvertNumber2Persian(fracStr);

            double value = pi.GetValue();

            if (pi.IsFraction)
            {
                value = Math.Round(value, 3);
            }
            string f20Normalized    = MathUtils.NormalizeForF20Format(value.ToString("F20"));
            string f20Currency      = MathUtils.InsertThousandSeperator(f20Normalized);
            bool   addCurrency      = (f20Normalized != f20Currency);
            string f20NormalizedPer = ParsingUtils.ConvertNumber2Persian(f20Normalized);
            string f20CurrencyPer   = ParsingUtils.ConvertNumber2Persian(f20Currency);

            string strWritten;

            if (!NumberToPersianString.TryConvertNumberToPersianString(value, out strWritten))
            {
                strWritten = null;
            }

            var inpFormat = NumberChangeRule.InputFormats.Letters;
            var inpLang   = NumberChangeRule.InputDigitLanguages.None;

            KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages>?sugPrior = null;

            if (rule != null)
            {
                if (rule.ContainsKey(inpFormat, inpLang))
                {
                    sugPrior = rule.GetValueForKey(inpFormat, inpLang);
                }
                else if (rule.ContainsKey(inpFormat, NumberChangeRule.InputDigitLanguages.Persian))
                {
                    sugPrior = rule.GetValueForKey(inpFormat, NumberChangeRule.InputDigitLanguages.Persian);
                }
            }

            // now giving orders

            if (sugPrior != null)
            {
                if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPoint &&
                    sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.Persian)
                {
                    // add in persian digits
                    lstSug.Add(f20NormalizedPer);
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }

                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStrPer);
                        lstSug.Add(fracStr);
                    }

                    // add in english digits
                    lstSug.Add(f20Normalized);
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep &&
                         sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.Persian)
                {
                    // add in persian digits
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }
                    lstSug.Add(f20NormalizedPer);

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }

                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStrPer);
                        lstSug.Add(fracStr);
                    }

                    // add in english digits
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }
                    lstSug.Add(f20Normalized);
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.Fractional &&
                         sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.Persian)
                {
                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStrPer);
                        lstSug.Add(fracStr);
                    }

                    // add in persian digits
                    lstSug.Add(f20NormalizedPer);
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }

                    // add in english digits
                    lstSug.Add(f20Normalized);
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.Letters)
                {
                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }

                    // add in persian digits
                    lstSug.Add(f20NormalizedPer);
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }

                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStrPer);
                        lstSug.Add(fracStr);
                    }

                    // add in english digits
                    lstSug.Add(f20Normalized);
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPoint &&
                         sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.English)
                {
                    // add in english digits
                    lstSug.Add(f20Normalized);
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }

                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStr);
                        lstSug.Add(fracStrPer);
                    }

                    // add in persian digits
                    lstSug.Add(f20NormalizedPer);
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep &&
                         sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.English)
                {
                    // add in english digits
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }
                    lstSug.Add(f20Normalized);

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }

                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStr);
                        lstSug.Add(fracStrPer);
                    }

                    // add in persian digits
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }
                    lstSug.Add(f20NormalizedPer);
                }
                else if (sugPrior.Value.Key == NumberChangeRule.OutputFormats.Fractional &&
                         sugPrior.Value.Value == NumberChangeRule.OutputDigitLanguages.English)
                {
                    // add fractions
                    if (!String.IsNullOrEmpty(fracStr))
                    {
                        lstSug.Add(fracStr);
                        lstSug.Add(fracStrPer);
                    }

                    // add in english digits
                    lstSug.Add(f20Normalized);
                    if (addCurrency)
                    {
                        lstSug.Add(f20Currency);
                    }

                    // add in persian digits
                    lstSug.Add(f20NormalizedPer);
                    if (addCurrency)
                    {
                        lstSug.Add(f20CurrencyPer);
                    }

                    // add the number in letters
                    if (!String.IsNullOrEmpty(strWritten))
                    {
                        lstSug.Add(strWritten);
                    }
                }
            }

            if (lstSug.Count <= 0)
            {
                // add fractions
                if (!String.IsNullOrEmpty(fracStr))
                {
                    lstSug.Add(fracStrPer);
                    lstSug.Add(fracStr);
                }

                // add in persian digits
                lstSug.Add(f20NormalizedPer);
                if (addCurrency)
                {
                    lstSug.Add(f20CurrencyPer);
                }

                // add in english digits
                lstSug.Add(f20Normalized);
                if (addCurrency)
                {
                    lstSug.Add(f20Currency);
                }

                // add the number in letters
                if (!String.IsNullOrEmpty(strWritten))
                {
                    lstSug.Add(strWritten);
                }
            }

            return(lstSug.ToArray());
        }
        /// <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());
        }
        private static string CreateGeneralNumberSuggestionFor(GeneralNumberInfo pi, KeyValuePair <NumberChangeRule.OutputFormats, NumberChangeRule.OutputDigitLanguages> ruleValue)
        {
            if (pi == null)
            {
                return(null);
            }

            string fracStr    = pi.IsFraction ? pi.FractionString : null;
            string fracStrPer = fracStr == null ? null : ParsingUtils.ConvertNumber2Persian(fracStr);

            double value = pi.GetValue();

            if (pi.IsFraction)
            {
                value = Math.Round(value, 3);
            }
            string f20Normalized    = MathUtils.NormalizeForF20Format(value.ToString("F20"));
            string f20Currency      = MathUtils.InsertThousandSeperator(f20Normalized);
            bool   addCurrency      = (f20Normalized != f20Currency);
            string f20NormalizedPer = ParsingUtils.ConvertNumber2Persian(f20Normalized);
            string f20CurrencyPer   = ParsingUtils.ConvertNumber2Persian(f20Currency);

            string strWritten;

            if (!NumberToPersianString.TryConvertNumberToPersianString(value, out strWritten))
            {
                strWritten = null;
            }

            // now giving orders

            if (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPoint &&
                ruleValue.Value == NumberChangeRule.OutputDigitLanguages.Persian)
            {
                // add in persian digits
                return(f20NormalizedPer);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep &&
                     ruleValue.Value == NumberChangeRule.OutputDigitLanguages.Persian)
            {
                return(f20CurrencyPer);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.Fractional &&
                     ruleValue.Value == NumberChangeRule.OutputDigitLanguages.Persian)
            {
                return(fracStrPer);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.Letters)
            {
                return(strWritten);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPoint &&
                     ruleValue.Value == NumberChangeRule.OutputDigitLanguages.English)
            {
                return(f20Normalized);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.FloatingPointWithSep &&
                     ruleValue.Value == NumberChangeRule.OutputDigitLanguages.English)
            {
                return(f20Currency);
            }
            else if (ruleValue.Key == NumberChangeRule.OutputFormats.Fractional &&
                     ruleValue.Value == NumberChangeRule.OutputDigitLanguages.English)
            {
                return(fracStr);
            }

            return(null);
        }
Example #11
0
        private void AboutWindow_Load(object sender, EventArgs e)
        {
            string version = ParsingUtils.ConvertNumber2Persian(ThisAddIn.InstalledVersion.ToString(3));

            lblVersion.Text = "نگارش " + version;
        }
        private ListViewItem[] CreateGeneralDateSuggestions(NumericDatePatternInfo pi, DateCalendarType calendarType)
        {
            if (pi == null)
            {
                return(new ListViewItem[0]);
            }

            currentNumericDatePatternInfo = pi;

            List <ListViewItem> lstSug = new List <ListViewItem>();

            if (pi.YearNumber >= 0 && pi.DayNumber > 0 && pi.MonthNumber > 0)
            {
                if (calendarType == DateCalendarType.Jalali)
                {
                    try
                    {
                        cmboGuessedCalendarType.SelectedIndex = 0;

                        PersianCalendarEx pc = new PersianCalendarEx(pi.YearNumber, pi.MonthNumber, pi.DayNumber);
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(pc.ToString()), UIDateTypes.NumericalPersian, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(pc.ToString(), UIDateTypes.NumericalEnglish, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(pc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Jalali));

                        DateTime dt = pc.DateTime;
                        lstSug.Add(CreateListViewItem(CalendarStringUtils.GetPersianDateString(dt), UIDateTypes.Literal, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(dt.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(dt.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Gregorian));

                        HijriCalendarEx hc = new HijriCalendarEx(pc.DateTime);
                        lstSug.Add(CreateListViewItem(hc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(hc.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(hc.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Ghamari));
                    }
                    catch { }
                }
                else if (calendarType == DateCalendarType.Gregorian)
                {
                    try
                    {
                        cmboGuessedCalendarType.SelectedIndex = 1;

                        DateTime dt = new DateTime(pi.YearNumber, pi.MonthNumber, pi.DayNumber);
                        lstSug.Add(CreateListViewItem(dt.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(dt.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(CalendarStringUtils.GetPersianDateString(dt), UIDateTypes.Literal, UIDateGroups.Gregorian));

                        PersianCalendarEx pc = new PersianCalendarEx(dt);
                        lstSug.Add(CreateListViewItem(pc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(pc.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(pc.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Jalali));

                        HijriCalendarEx hc = new HijriCalendarEx(dt);
                        lstSug.Add(CreateListViewItem(hc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(hc.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(hc.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Ghamari));
                    }
                    catch /*(Exception ex)*/ { }
                }
                else if (calendarType == DateCalendarType.HijriGhamari)
                {
                    try
                    {
                        cmboGuessedCalendarType.SelectedIndex = 2;

                        HijriCalendarEx hc = new HijriCalendarEx(pi.YearNumber, pi.MonthNumber, pi.DayNumber);
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(hc.ToString()), UIDateTypes.NumericalPersian, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(hc.ToString(), UIDateTypes.NumericalEnglish, UIDateGroups.Ghamari));
                        lstSug.Add(CreateListViewItem(hc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Ghamari));

                        DateTime dt = hc.DateTime;
                        lstSug.Add(CreateListViewItem(CalendarStringUtils.GetPersianDateString(dt), UIDateTypes.Literal, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(dt.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Gregorian));
                        lstSug.Add(CreateListViewItem(dt.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Gregorian));

                        PersianCalendarEx pc = new PersianCalendarEx(hc.DateTime);
                        lstSug.Add(CreateListViewItem(pc.ToString("D"), UIDateTypes.Literal, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(ParsingUtils.ConvertNumber2Persian(pc.ToString("d")), UIDateTypes.NumericalPersian, UIDateGroups.Jalali));
                        lstSug.Add(CreateListViewItem(pc.ToString("d"), UIDateTypes.NumericalEnglish, UIDateGroups.Jalali));
                    }
                    catch (Exception ex) { }
                }
            }

            return(lstSug.ToArray());
        }