0

Greeting,

I have already checked for my question with no luck of an answer or something similar.

So here it's my problem:

I have created a cafe cashier software for my boss that it has buttons for each product that cashier wants to add on a bill/table. If a button is clicked, for example btnOrangeJuice, on its click event, it call a function for example named: addOrder("Orange Juice");

Inside this function it does the simple follow code:

a) it connect to the database
b) returns price of product "Orange Juice" for example (select price from products where product_name = '" + product_parameter + "'")
c) take the result, and add it to the order list box with it's price and so on..

The problem here is, (lets go with the previews example) every time we have a new product, I have to manually customize the form by adding a button 52x52 pixels, name btnOrangeJuice, text name "Orange Juice", and on the click event to call my function addOrder("Orange Juice"), then upload the new version of my software to my online web hosting, and update the software from the cashier's pc. This is time consuming for me, especially when we make new deals with suppliers so i wanted to make my program to add dynamically buttons, to do all this by just having a form, type in the button properties, calling a function, and add a button by its self with its dimensions, check if its out of form space, if it is, the add the button bellow instead on the right, and of course add the button properties and its click event (that call my built-in function).

If you need any farther details regarding my software/problem please do ask.

So can you assist me on this please?

1
  • WPF or Windows Forms? I suspect you mean Windows Forms Commented Jun 6, 2012 at 14:15

1 Answer 1

2

The standard approach is to assign each product a unique identifier and have one mechanism for adding an order which takes the unique identifier as the parameter. Your products already presumably have a unique identifier as they are persisted entities (a database primary key for example).

If you wish the add button to have the text of the product, then you can dynamically set this from the product name, which is again already stored in the database. There is no need to replicate this information in your UI code.

Sign up to request clarification or add additional context in comments.

2 Comments

if i understood correctly your answer, is to include all button properties to my product's table. That's a good mechanic. Let's say i do this, i have a row in my product table with values, name: Orange Juice, price: 2.00, form: SoftDrinks.frm etc. How do i load the new button on software loading phase? To add it on SoftDrinks.frm form, check what position is available regarding the empty available spaces (not outside of the form)? And how do i include the button Click_Event code?
Firstly, what technology are you using, it seems you are referring to WinForms, but you also mentioned online web hosting, which would probably imply WebForms. Either way the principles are the same, your UI would retrieve a list of all the products (or all soft drinks say) and then create a new UI element for each item in the result set. This would include an 'order' button which runs one piece of code, passing in the unique ID of that product. I don't know what you mean by 'check what position is available regarding the empty available spaces (not outside of the form)?'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.