Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I am doing an app which will generate invoices by fetching from database SQL.
Here see What I did :

C#
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[5] {
                        new DataColumn("ProductId", typeof(string)),
                        new DataColumn("Product", typeof(string)),
                        new DataColumn("Price", typeof(int)),
                        new DataColumn("Quantity", typeof(int)),
                        new DataColumn("Total", typeof(int))});
dt.Rows.Add(101, "Sun Glasses", 200, 5, 1000);
dt.Rows.Add(102, "Jeans", 400, 2, 800);
dt.Rows.Add(103, "Trousers", 300, 3, 900);
dt.Rows.Add(104, "Shirts", 550, 2, 1100);


So here As you can see we have Product, Price of the product , the quantity and the total (Price * Quantity)
So my aim is for example

Invoice 1 I want inside it the total price of 1 500

so here my need is that how can we fetch from database so that it will automatically fill the right amount that i need.

INVOICE 1 : TOTAL 1 500 USD

Product1 : Shirts - 550 -2 - 1100
Product2: Jeans - 400 - 1- 400
Total = 1500 (1100+400)
And it automatically removes the quantity of products taken in the database.

Is it possible ?

What I have tried:

So here As you can see we have Product, Price of the product , the quantity and the total (Price * Quantity)
So my aim is for example

Invoice 1 I want inside it the total price of 1 500

so here my need is that how can we fetch from database so that it will automatically fill the right amount that i need.

INVOICE 1 : TOTAL 1 500 USD

Product1 : Shirts - 550 -2 - 1100
Product2: Jeans - 400 - 1- 400
Total = 1500 (1100+400)
And it automatically removes the quantity of products taken in the database.

Is it possible ?
Posted
Comments
j snooze 5-Feb-18 17:26pm    
not sure I quite understand why you would have a total quantity on the total price. Much of the database layout and app don't make sense. In most order situations(and maybe you were just trying to be brief) there would be an orderheader table and the detail table which you have outlined. Right now if you had more than one order, you wouldn't know which items are on which order. Also, why are you storing the total? Just storing the item, quantity and purchase price saves database space because you can write functions to calculate or calculate in your select statement.
RDBurmon 7-Feb-18 1:39am    
Should the total be 3800.00 (1000 + 800 + 900 + 1100) ?
an0ther1 7-Feb-18 17:47pm    
You are probably better off using a Report to generate an invoice. You will be able to format it to meet any requirements that you have and you will avoid a lot of effort.

As for "automatically removes the quantity of the products..." You need to do a rethink.
Each action should be considered a separate process - submit order, adjust stock quantities, create invoice, email/display invoice etc
TatsuSheva 9-Feb-18 15:51pm    
DataTable here is not already in the invoice.
This is in the stock and now I will use it to store it in the invoice because of that I said I give the total amount and automatically it will fill the invoice with the right items , quantity and price according to the total amount

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900