Friday, November 6, 2015

crystal report tashkeel Diacritics remove function using c# to avoid crystal report Problem


when display arabic text includes diacritics (punctuations)
it will not working if you create paragraph direction rtl support
so before passing datasource to crystal report i fixes data using this function


using System.Globalization;
using System;
using System.Data;


/// <summary>
/// the function remove all diacritics from passed text and make it on original format (no tashkeel).
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
    static string RemoveDiacritics(string text)
    {
        var normalizedString = text.Normalize(NormalizationForm.FormD);
        var stringBuilder = new StringBuilder();

        foreach (var c in normalizedString)
        {
            var unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c);
            if (unicodeCategory != UnicodeCategory.NonSpacingMark)
            {
                stringBuilder.Append(c);
            }
        }

        return stringBuilder.ToString().Normalize(NormalizationForm.FormC);
    }

}

---------------------------------------------------------
fix table before bind it to crystal report

  DataTable Original = this.db.ReturnTableS("CRM_Original_Offer_Load_Detail_Print", "@OfferId", Request_No);

        if (Original.Rows.Count > 0)
        {
            for (int i = 0; i < Original.Rows.Count ; i++)
            {
                Original.Rows[i]["A_Name"] = RemoveDiacritics(Original.Rows[i]["A_Name"].ToString());
            }

        }

-------------------------------------------------------------------------

No comments:

Post a Comment