473,509 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditionally display excluding / including tax?

I'm creating an ASP.NET e-commerce web site and I have to conditionally
(depending on site / user settings) display prices either excluding or
including tax. Prices are typically read from a database (where also the tax
rates are stored) various places in the code and typically (but now always)
the values are returned in DataSets which are bound to controls and
displayed to the user.

What would be the most elegant way to implement the logic to add tax to the
values presented to the user depending on some kind of setting?

Olav
Nov 19 '05 #1
2 1328
Olav:
This might be overkill, but my personal preference would be to create a
custom server control which inherits from Label (assuming these are just
text), or TextBox (if the user can enter information), something as simple
as:

this code is just from the top of my head, but something like it ought to
work.

public class PriceDisplay
Inherits Label

private _price as decimal
public property Price() as Decimal
get
return _price
end get
set (ByVal value as Decimal)
_price = value
end set
end property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
If SHOULD_CALCULATE_TAX Then
_price = _price * (1 + GetTaxAmount())
End If
MyBase.Text = _price.ToString()
End Sub
end class

not that you can use a format string inside ToString() to get it to render
just like you want...

anyways, that's my $0.02...realize that I obviously left the the
SHOULD_CALCULATE_TAX logic as well as the GetTaxAmount() up to you to do...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Olav Tollefsen" <x@y.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
I'm creating an ASP.NET e-commerce web site and I have to conditionally
(depending on site / user settings) display prices either excluding or
including tax. Prices are typically read from a database (where also the tax rates are stored) various places in the code and typically (but now always) the values are returned in DataSets which are bound to controls and
displayed to the user.

What would be the most elegant way to implement the logic to add tax to the values presented to the user depending on some kind of setting?

Olav

Nov 19 '05 #2
Thanks for your suggestion!

Right now I lean towards doing the tax calculations closer to the database
layer. The main reason for this is that tax calculation could be quite
complex and depend heavily on knowing various business rules and exactly
what objects you are calculating tax on. It might not always be a flat rate
applied to all product prices.

This is an example on one way to do this (with a flat rate):

DataSet products = Product.GetProducts(catalogId, categoryId);

// Add the Price column (computed)
DataColumn column = new DataColumn("Price");
column.DataType = typeof(System.Double);
if (taxIncluded)
column.Expression = "(Listprice * (1 + TaxRate))";
else
column.Expression = "(Listprice)";
products.Tables["Products"].Columns.Add(column);

Now I can bind this dataset to a control and display the Price column.

Any other ideas / suggestions?

Olav

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:u1******************@TK2MSFTNGP10.phx.gbl...
Olav:
This might be overkill, but my personal preference would be to create a
custom server control which inherits from Label (assuming these are just
text), or TextBox (if the user can enter information), something as simple
as:

this code is just from the top of my head, but something like it ought to
work.

public class PriceDisplay
Inherits Label

private _price as decimal
public property Price() as Decimal
get
return _price
end get
set (ByVal value as Decimal)
_price = value
end set
end property

Protected Overrides Sub Render(ByVal writer As
System.Web.UI.HtmlTextWriter)
If SHOULD_CALCULATE_TAX Then
_price = _price * (1 + GetTaxAmount())
End If
MyBase.Text = _price.ToString()
End Sub
end class

not that you can use a format string inside ToString() to get it to render
just like you want...

anyways, that's my $0.02...realize that I obviously left the the
SHOULD_CALCULATE_TAX logic as well as the GetTaxAmount() up to you to
do...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Olav Tollefsen" <x@y.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
I'm creating an ASP.NET e-commerce web site and I have to conditionally
(depending on site / user settings) display prices either excluding or
including tax. Prices are typically read from a database (where also the

tax
rates are stored) various places in the code and typically (but now

always)
the values are returned in DataSets which are bound to controls and
displayed to the user.

What would be the most elegant way to implement the logic to add tax to

the
values presented to the user depending on some kind of setting?

Olav


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
9227
by: Monty | last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern Time (daylight time in the summer). Is there way of showing these hours of availability on a web page in the user's local...
1
1047
by: Noah Subrin | last post by:
Hello, I have a class like the following public class person public FirstName as string public LastName as string end class
1
1419
by: Danny Ni | last post by:
Hi, Is there a way to selectively display content of a DataGrid or DataList? Normally I bind them to datareader or datatable, and they will display all the rows, what if I don't want to display...
3
2977
by: | last post by:
One thing I did a lot of in Classic ASP involved showing page elements conditionally based on whether a user was logged in or not. Logged in users or "superusers" would get more content and/or more...
2
1238
by: Craig | last post by:
Is there a way to conditionally include a file in the HTML? <TD> if x= 1 then <!--#INCLUDE FILE="../File1"--> else <!--#INCLUDE FILE="../File2"--> end if
6
1602
by: Al-Burak | last post by:
I have a class which only purpose is to provide services to a variety of classes in other files. The 'manipulator' class is aware of the other classes only because the header files have been...
1
2720
by: Mike | last post by:
I'm using a SqlDataSource to fetch data and display it in a FormView. One of the elements is an image: <asp:Image ID="ImageFile" runat="server" ImageURL='<%# Eval("ImageFile",...
7
13075
by: lister | last post by:
Hi, I have a situation where I have a large block of HTML code that is conditionally displayed. In effect I have: html page some html <?php if (bShowBlock)
4
3035
by: =?Utf-8?B?ZGNoMw==?= | last post by:
Is there a way to conditionally format a dateTime field to produce on result if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another result if the value is 10/31/2008 5:30 PM...
0
7412
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3216
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3203
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
441
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.