I am creating a C# Windows application which is based on a medical inventory.In this application I have mainly three forms as PurchaseDetail,SalesDetail,and StockDetail.
Now I want a functionality in which if I insert or modify the records in PurchaseDetail,or SalesDetail, the data in the StockDetail should also be modified.(for example if i insert some quantity of medicines in PurchaseDetail then Quantity of that medicine in StockDetail should also modified and same as for SalesDetail )
Columns in PurchaseDetail: Id(Primary Key and auto increment int),BatchNumber,ProductName,ManufacturingDate,ExpiryDate,Rate,MRP,Tax,Discount,Quantity
Columns in SalesDetail: Id(PrimaryKey and auto increment int),BillNumber,CustomerName,BatchNumber,Quantity,Rate,SalesDate
Columns in StockDetail: Id(Primary Key and auto increment int),ProductId,ProductName,OpeningStock,ClosingStock,PurchaseQty,DispenseQty,PurchaseReturn,DispenseReturn
Please help me with any suitable example or code
you could easily write multiple SQL statements separated by semicolon “;”
example:
And you really should not be storing the product name all over again in each of the table. Instead, you should be storing ProductID. Your SalesDetails doesn’t say which product is sold.
The following is a suggested schema that is more normalized:
Product (ID, ProductName, Stock)
PurchaseDetail (ID, BatchID, ProductID, Quantity, …)
SalesDetail (ID, BillID, ProductID, Quantity, …)
PurchaseBatch (ID, PurchaseDate)
SalesBill (ID, SalesDate, CustomerID)
If you ever need to know the opening, closing, purchase and dispense for a specific duration, you can always run the SQL:
Current stock:
Purchased from @StartDate to @EndDate:
Sold from @StartDate to @EndDate:
Purchased from @EndDate till now:
Sold from @EndDate till now:
Therefore,
opening from @StartDate till @EndDate =
Current stock
– Purchased from @StartDate to @EndDate
– Purchased from @EndDate till now
+ Sales from @StartDate to @EndDate
+ Sales from @EndDate till now
closing from @StartDate till @EndDate =
Current stock
– Purchased from @EndDate till now
+ Sales from @EndDate till now
And you also have
Sales from @StartDate to @EndDate
Purchased from @StartDate to @EndDate