Click here to Skip to main content
12,699,054 members (25,642 online)
Rate this:
 
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"?>
<configuration>
Posted 19-Nov-12 21: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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.170118.1 | Last Updated 20 Nov 2012
Copyright © CodeProject, 1999-2017
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