David GodisTei

David GodisTei

  • 1.2k
  • 412
  • 389

How to subtract the sum of sale qty from the sum of stock qty to have

Jun 15 2024 7:24 PM

Greetings to all Forum members.

I am designing a sales database in C# Windows Form Application where I need to create a stored procedure to link the stock and sales tables to each other.


In the project I have textboxes named “grossStockQty” from the stock table, “grossSalesQty” from the sales table and “AvailableQty” stock table, respectfully.


I used the following code to sum up record from the “stockQty” in the stock table into the “grossStockQty” textbox:-

grossStockQtyTextBox.Text = (from DataGridViewRow row in stockDataGridView.Rows where row.Cells[7].FormattedValue.ToString() != string.Empty

select Convert.ToDecimal(row.Cells[7].FormattedValue)).Sum().ToString();


I also used the following code to sum up record from the “salesQty” in the sales table into the “grossSalesQty” textbox:-

grossSalesQtyTextBox.Text = (from DataGridViewRow row in salesDataGridView.Rows where row.Cells[17].FormattedValue.ToString() != string.Empty

select Convert.ToDecimal(row.Cells[17].FormattedValue)).Sum().ToString();

I build the AvailableQty stored procedure on the database server side but included it in the dataset from the project DataSource. I drew the stored procedure as controls on the Windows Form UI to create the interface to operate on the database server.

I closely observed that the only way (I don't know if there are different other ways) I can pull data from the two table on one interface is by using the stored procedure. I have successfully achieved that, through which I can pull data from the source.

Now, what I want to do is after pulling the data onto the form UI I can use a button to manipulate the data into the availableQty textbox control. All I need is a code in the button to subtract the gross sales qty from the gross stock qty to display the difference in the availableQty textbox.
Thanks


Answers (1)