Click here to Skip to main content
15,910,234 members
Please Sign up or sign in to vote.
1.44/5 (3 votes)
See more:
Hi
My intention is to calculate the products amount using unit * price .... but those item price are vary from each one. Like person A has item of $2 and person B has item of 5$ ..... I need to update them in my system daily.


Can you kindly tell me a method to track these data in C#?
Posted
Comments
Sergey Alexandrovich Kryukov 15-Jan-14 23:13pm    
"Real time"? Aren't you mixing something up?
—SA
Asa code 15-Jan-14 23:18pm    
which means I need to track the price of lets say PVC pipes ... One person has $3 * 100 and other has got 5$ * 45 so how to track them daily in an application?
should I get a average price or latest price of an item?
Asa code 16-Jan-14 0:14am    
Can we have this kind of a equation for that price = (Pnew - Pold)Pold / 100 ?
Richard MacCutchan 16-Jan-14 4:21am    
You can have any equation that you want. The question is not clear, but if you just want to display some information, then you would read the details from the database, calculate the results you need and display them on screen or report.

I assume that you store these values in a database (and you should). therefore, you can schedule a daily job to compute and store values that you want. every database system supports this functionality. tables would be like this.

SQL
table SALES (
int sales_id auto, // primary key
int customer_id, // foreign key to customer table
int product_id, // foreign key to product table
int cnt, // items count sold to customer for that product
float unit_price, // assuming unit price may change every sales for every product
datetime sdate 
);

table SALES_SUMMARY_DAILY (
int sales_summary_id auto, // primary key
datetime sdate, // only date & unique
int product_id, // foreign key to product table
int total_cnt, // shows total sales count for a product
float total_price, // total price for it
float avg_price // average price
);


A procedure to insert SALES_SUMMARY_DAILY
SQL
create procedure PROC_INSERT (
 insert into SALES_SUMMARY_DAILY (sdate, product_id, total_cnt, total_price, avg_price)
 select today(), product_id, sum(cnt), sum(cnt*unit_price), sum(cnt*unit_price)/sum(cnt)
 from SALES
 where dayof(sdate)=today()
 group by product_id
)


And the job for daily processing
SQL
create job DAILY_INSERT foreach day at 09:00 (
 execute PROC_INSERT;
)


Note that above codes are all pseudocode. Every DBMS has its own specific syntax, even they have graphical designers to produce code automatically.

At least, I can say that your question shouldn't be related to c# since your main question is about data management.
 
Share this answer
 
v2
In this you could use 2 tables(Transaction & Stock).
Store the Qty & Price in Transaction table.
-------------------------------------------------------------------------------------
Tbl_Transaction
-------------------------------------------------------------------------------------
Order_ID   Order_Date   ItemCode   Qty   Price
-------------------------------------------------------------------------------------
100        02-Jan-2014  Item001     1    2
101        05-Jan-2014  Item001     1    5
-------------------------------------------------------------------------------------

Update the Qty in Stock table.
-------------------------------------------------------------------------------------
Tbl_Stock
-------------------------------------------------------------------------------------
ItemCode   Qty
-------------------------------------------------------------------------------------
Item001    2
-------------------------------------------------------------------------------------

Using JOIN query(GROUP BY needed to be there for some conditions) you could get the available stock, stock price, other aggregate things like MAX, MIN, AVG, etc.,

This is just a sample & you could customize this based on your requirement.

EDIT
---------------------------------------------
It's up to your need. Show this data in a popup using following methods(As already said choose any one based on your requirement). Here few methods popular.
-------------------------------------------------------------------------------------
Actual Prices based on Transaction table -- JOIN
-------------------------------------------------------------------------------------
ItemCode   Qty   Price
-------------------------------------------------------------------------------------
Item001     1    2
Item001     1    5
-------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------
Based on Average price ( 2+5 = 7. 7/2 = 3.5 ) -- JOIN & AVG
-------------------------------------------------------------------------------------
ItemCode   Qty   Price
-------------------------------------------------------------------------------------
Item001     2    3.5
-------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------
Based on Latest price (2 vs 5 = 5) -- JOIN & MAX
-------------------------------------------------------------------------------------
ItemCode   Qty   Price
-------------------------------------------------------------------------------------
Item001     2    5
-------------------------------------------------------------------------------------

All you need to do is write SQL query using JOIN &/ GROUP BY to fetch records like this. That's it.
 
Share this answer
 
v3
Comments
Asa code 16-Jan-14 22:54pm    
actually the case is like that ..... company has many teams with their leaders..... all the items are assigned under leaders' name but item prices might be vary and they have no idea about the prices ... lets say one leader may have PVC pipe cost per one unit as 120 and other may have 130 .... So I need to insert this value for the rate.... So can you help to do this (idea) ?
thatraja 17-Jan-14 2:52am    
Check updated answer

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