I have a small app that is linked to a SQL table. That particular table has the following fields:
- key1(P. key)
- shortchar05
- number03
- number04
- number05
This app is to keep the stock updated.
So for key1=1
, I enter item1
in shortchar05
, number05
(total) I'll have 5
for example. number04
(this is used for how many item1
I have issued) and number03
should be updated stock (difference between number05
and number04
).
I know how to make the app work if values of shortchar05
are distinct (e.g. item1
, item2
, item3
etc.), but that's not what I am interested in.
What if I have the following situation:
key1 shortchar05 number05 number04 number03
===========================================
1 item1 5 3 2
2 item2 7 4 3
3 item3 8 2 6
Now if I am creating the next key1
with value 4 but want to select item1
and now the total would be 2
which would go in number05
and I want to issue 1 piece of item1
.
key1 shortchar05 number05 number04 number03
===========================================
4 item1 2 1 1
For key1=5
I want to select item1
again, so what I would like to have selected is the item1
with the lowest value from column number03
(key=4
and not key1=1
)
key1 shortchar05 number05 number04 number03
===========================================
5 item1 1 0 1
This is what I would like to have, for n number of items, if I select itemX, I'd like to display the duplicate itemX with lowest value in number03
(that would be the updated total)
I hope I have been clear enough
Thank you!
This is simply done when creating a new key1 and entering a new distinct item
foreach (var ttUD04_R in ttUD04)
{
var ttUD04_Recss = (from ttUD04_Row in Db.UD04 where ttUD04_Row.Company == Session.CompanyID orderby ttUD04_Row.Number03 ascending select ttUD04_Row).FirstOrDefault();
if (ttUD04_Recss != null)
{
ttUD04_R.Number05 = ttUD04_Recss.Number03;
ttUD04_R.Number03 = (Convert.ToInt32(ttUD04_R.Number05) - Convert.ToInt32(ttUD04_R.Number04));
}
}