Jul 19, 2013

Currency format with decimal point in asp.net

 protected void Page_Load(object sender, EventArgs e)
    {
        string CurrencySymbols = "xof";
        Response.Write(string.Format("{0:F" + getCurrencyDecimalPlaces(CurrencySymbols.ToUpper()) + "}", 12456.017312) + "
");

       

    }
    public static int getCurrencyDecimalPlaces(string CurrencySymbols)
    {
        Dictionary oCurrencyDictionary = new Dictionary();

        #region Add Decimal
        oCurrencyDictionary.Add("RUB", 2); //Russian Ruble
        oCurrencyDictionary.Add("CHF", 2); //Swiss Franc
        oCurrencyDictionary.Add("GBP", 2); //British Pound
        oCurrencyDictionary.Add("EUR", 2); //Euro
        oCurrencyDictionary.Add("USD", 2); //American Dollar
        oCurrencyDictionary.Add("CAD", 2); //Canadian Dollar
        oCurrencyDictionary.Add("INR", 2); //Indian Rupee
        oCurrencyDictionary.Add("GHS", 2); //Ghana Cedi
        oCurrencyDictionary.Add("NGN", 2); //Nigerian Naira
        oCurrencyDictionary.Add("CNY", 2); //Chinese Yuan
        oCurrencyDictionary.Add("BRL", 2); //Brazilian Real
        oCurrencyDictionary.Add("HKD", 2); //Hong Kong Dollar
        oCurrencyDictionary.Add("AED", 2); //UAE Dirham
        oCurrencyDictionary.Add("JPY", 0); //Japanese Yen
        oCurrencyDictionary.Add("XOF", 0); //CFA Franc (BCEAO)
        oCurrencyDictionary.Add("XAF", 0); //CFA Franc (BEAC)
        oCurrencyDictionary.Add("ARS", 2); //Argentine Peso
        oCurrencyDictionary.Add("MXN", 2); //Mexican Peso
        oCurrencyDictionary.Add("NPR", 2); //Nepalese Rupee
        oCurrencyDictionary.Add("THB", 2); //Thai Baht
        oCurrencyDictionary.Add("TRY", 2); //Turkish Lira
        oCurrencyDictionary.Add("VEB", 2); //bolivar fuerte
        oCurrencyDictionary.Add("VND", 2); //Vietnam Dong
        oCurrencyDictionary.Add("UAH", 2); //Ukraine Hryvnia
        oCurrencyDictionary.Add("SEK", 2); //Swedish Kronor
        oCurrencyDictionary.Add("ZAR", 2); //South African Rand
        oCurrencyDictionary.Add("PKR", 2); //Pakistani Rupee
        oCurrencyDictionary.Add("PAB", 2); //Panama Balboa
        oCurrencyDictionary.Add("NZD", 2); //New Zealand Dollar
        oCurrencyDictionary.Add("MYR", 2); //Malaysian Ringgit
        oCurrencyDictionary.Add("SGD", 2); //Singapore Dollar
        oCurrencyDictionary.Add("BDT", 2); //Bangladeshi Taka
        #endregion

        if (oCurrencyDictionary.ContainsKey(CurrencySymbols))
        {
            return oCurrencyDictionary[CurrencySymbols];
        }
        else
        {
            return 2;
        }
    }

May 31, 2013

Convert enum to hashtable for dropdown list binding

We have one enum

enum ContractType
{
    Permanent = 1,
    Contract = 2,
    Internship = 99
}

Below function for convert enum to hashtable

public static Hashtable BindToEnum(Type enumType)
{
    // get the names from the enumeration
    string[] names = Enum.GetNames(enumType);
    // get the values from the enumeration
    Array values = Enum.GetValues(enumType);
    // turn it into a hash table
    Hashtable ht = new Hashtable();
    for (int i = 0; i < names.Length; i++)
        // note the cast to integer here is important
        // otherwise we'll just get the enum string back again
        ht.Add(names[i], (int)values.GetValue(i));
    // return the dictionary to be bound to
    return ht;
}

Now we can direct call above function for convert enum to hashtable and use for dropdown bind.


MyDropDownList.DataSource = BindToEnum(typeof(ContractType));

Hope you will help above code !!

Mar 19, 2013

Search text in stored procedure


Search text in store procedure...

SELECT NameFROM sys.proceduresWHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%Employee%'


Happy Coding... !! :)