Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i design application using c sharp.
in that i have threecolumn as follows.
Rental cost ,Diesel service, Service Tax.
 

Rental Cost 231270
Diesel ser 19767
Ser Tax 30124(231270 + 19767 * 12/100).
Code as follows;
 
double o = Convert.ToDouble(txt_rentalcost.Text);
double p = Convert.ToDouble(txt_dieselservice.Text);
txt_servicetax.Text = Math.Round((o + p) * 0.12).ToString();
 
i am doing service tax calculation at that time service tax is 12 percentage.suppose in next year service tax percentage is 12.36.
 
i post the above question you said that we can write the code in App.config.
 
In App.config how to write the code.please help me.first time i am using App.config help me.
 

?xml version="1.0" encoding="utf-8"?>

Posted 19-Nov-12 20:45pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Adding Keys in app.config file
<appSettings>
    <add key="author" value="Palanisamy Veerasingam"/>
    <add key="article" value="Configuration Sections"/>
</appSettings>
 
Retreiving the Key value in your application
 return (ConfigurationSettings.AppSettings["author"]);
 

Check this article for more information
Understanding Section Handlers - App.config File[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use a settings file:
 
In Visual Studio, go to "project properties" -> "Settings"
 
In the shown datagrid add a row with "Name"->TaxPercentage, Type=double, Scope=Application, Value=12
this will result in a new section in your app.config:
 
    <configSections>
        <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="WindowsFormsApplication1.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        </sectionGroup>
    </configSections>
 
and the stored setting:
<applicationSettings>
        <WindowsFormsApplication1.Properties.Settings>
            <setting name="Setting" serializeAs="String">
                <value>0</value>
            </setting>
        </WindowsFormsApplication1.Properties.Settings>
    </applicationSettings>
 
to access your settings in Code just add a using directive like:
using WindowsFormsApplication1.Properties;
 
and access your configurable value with:
double value = Settings.Default.TaxPercentage;
 
this will give you a leightweight but typesafe configurable value in your application
- leightweight, cause you don´t have to write custom config sections, what i prefer if i have to manage many configurable parameters of my application/service/etc.
- typesafe, cause the configuration-system will make sure that the your setting will always be of the expected type
 
refer this link [^]for detailed information
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 363
1 OriginalGriff 354
2 George Jonsson 248
3 Shemeemsha RA 148
4 Animesh Datta 130
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100