Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
GeneralMessage Removed Pin
27-Jul-12 12:24
professionalN_tro_P27-Jul-12 12:24 
GeneralRe: Track two types of values within one variable Pin
SledgeHammer0127-Jul-12 12:36
SledgeHammer0127-Jul-12 12:36 
GeneralMessage Removed Pin
27-Jul-12 13:52
professionalN_tro_P27-Jul-12 13:52 
GeneralRe: Track two types of values within one variable Pin
jschell28-Jul-12 6:33
jschell28-Jul-12 6:33 
AnswerRe: Track two types of values within one variable Pin
Trak4Net27-Jul-12 18:26
Trak4Net27-Jul-12 18:26 
GeneralRe: Track two types of values within one variable Pin
Paul Conrad28-Jul-12 9:32
professionalPaul Conrad28-Jul-12 9:32 
AnswerRe: Track two types of values within one variable Pin
Northcodedotno29-Jul-12 8:36
Northcodedotno29-Jul-12 8:36 
AnswerRe: Track two types of values within one variable Pin
BobJanova29-Jul-12 23:16
BobJanova29-Jul-12 23:16 
As is often the case with newish people, I don't think you've actually asked the right question. What's your real requirement here? From reading the thread, it appears to be that you want a surcharge, either a percentage or a fixed amount, to be applied to a bill. What's the interface to that?

interface ISurcharge {
 double GetAmount(Order order);
 string Name { get; }
}


... or, if it's just on the amount, you can pass a number instead of an order. My guess, though, is different tax rates may apply to different items so you will eventually need to pass the order. Note the important thing here: the value of the surcharge depends (in general) on the existing order so it needs to be part of the interface. The Name property is for what gets displayed on the bill; you may want a few other little things like that, but this is the core functionality.

Now you can create trivial implementation classes to solve the problem!

class FixedSurcharge : ISurcharge {
 private double amount;
 public string Name { get; private set; }
 public FixedSurcharge(string name, double amount) { Name = name; this.amount = amount; }
 public double GetAmount(Order order) { return amount; }
}

class PercentageSurcharge : ISurcharge {
 private double percentage;
 public string Name { get; private set; }
 public PercentageSurcharge (string name, double percentage) { Name = name; this.percentage = percentage; }
 public double GetAmount(Order order) { return percentage * 0.01 * order.TotalValue; }
}


... called like:

void placeOrder(Order order){
 foreach(OrderItem item in order.Items) { addBillItem(item.Name, item.Value); }
 addSurcharge(new PercentageSurcharge("VAT", 20), order);
 addSurcharge(new FixedSurcharge("Shipping", 2.50), order);
}

void addSurcharge(ISurcharge surcharge, Order order){
 addBillItem(surcharge.Name, surcharge.GetAmount(order));
}


(Actually, on reflection it may be cleaner to make fake order items, with a Value property, by passing the existing Order to a constructor and stashing it in the Surcharge instance. That's a matter of style, I think.)
GeneralAdding databound ComboBox into cells of a DataGridView Pin
Dewald27-Jul-12 2:11
Dewald27-Jul-12 2:11 
QuestionHow to make GRIDVIEW as Rounded Corners Pin
mukusingh27-Jul-12 0:33
mukusingh27-Jul-12 0:33 
AnswerRe: How to make GRIDVIEW as Rounded Corners Pin
Richard MacCutchan27-Jul-12 1:57
mveRichard MacCutchan27-Jul-12 1:57 
AnswerRe: How to make GRIDVIEW as Rounded Corners Pin
AmitGajjar27-Jul-12 17:54
professionalAmitGajjar27-Jul-12 17:54 
Questionrefresh result in MDI child Pin
Jassim Rahma27-Jul-12 0:05
Jassim Rahma27-Jul-12 0:05 
AnswerRe: refresh result in MDI child Pin
Eddy Vluggen27-Jul-12 0:09
professionalEddy Vluggen27-Jul-12 0:09 
GeneralRe: refresh result in MDI child Pin
Jassim Rahma27-Jul-12 0:28
Jassim Rahma27-Jul-12 0:28 
GeneralRe: refresh result in MDI child Pin
Eddy Vluggen27-Jul-12 0:47
professionalEddy Vluggen27-Jul-12 0:47 
GeneralRe: refresh result in MDI child Pin
Jassim Rahma27-Jul-12 2:52
Jassim Rahma27-Jul-12 2:52 
GeneralRe: refresh result in MDI child Pin
Eddy Vluggen27-Jul-12 2:59
professionalEddy Vluggen27-Jul-12 2:59 
QuestionHow can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Member 964871826-Jul-12 23:57
Member 964871826-Jul-12 23:57 
AnswerRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Eddy Vluggen27-Jul-12 0:52
professionalEddy Vluggen27-Jul-12 0:52 
GeneralRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Member 964871827-Jul-12 1:54
Member 964871827-Jul-12 1:54 
GeneralRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Eddy Vluggen27-Jul-12 1:59
professionalEddy Vluggen27-Jul-12 1:59 
GeneralRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Dave Kreskowiak27-Jul-12 2:13
mveDave Kreskowiak27-Jul-12 2:13 
GeneralRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Member 964871827-Jul-12 3:54
Member 964871827-Jul-12 3:54 
GeneralRe: How can I attach wndproc to another window and do something when certain wm_event appears ? Pin
Dave Kreskowiak27-Jul-12 15:28
mveDave Kreskowiak27-Jul-12 15:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.