0
I cannot find a solution for stock and sales management.
The scenario would be a stock of Auto parts, where I register the entry of a product in the stock with a certain amount.
Cod - name - Qtd - vlr
3239 - Water pump - 2 - R$300,00
and soon I want to add 3 more quantities of the same item totaling 5 items of the Water Pump, or reducing quantities as sales are made.
maybe some IF, FOR, COLLECTION
Ex:
If (cod == cod)
{
++1 qtd
}
I have an Access database, I am accessing directly in the database without being Dataset:
An example of how I’m recording the data today in db:
OleDbConnection Con = new OleDbConnection();
Con.ConnectionString = Properties.Settings.Default.dbqtd;
Con.Open();
OleDbCommand Cmm = new OleDbCommand();
Cmm.CommandText = "INSERT INTO estoque (codproduto, nome, qtd, local, numero) VALUES (?, ?, ?, ?, ?) ";
Cmm.Parameters.Clear();
Cmm.Parameters.Add("@codproduto", OleDbType.VarChar, 50).Value = txtCodProd.Text;
Cmm.Parameters.Add("@nome", OleDbType.VarChar, 50).Value = txtNome.Text;
Cmm.Parameters.Add("@qtd", OleDbType.VarChar,50).Value = txtQtd.Text;
Cmm.Parameters.Add("@local", OleDbType.VarChar, 50).Value = txtLocal.Text;
Cmm.Parameters.Add("@numero", OleDbType.VarChar, 50).Value = txtNumero.Text;
Cmm.CommandType = CommandType.Text;
Cmm.Connection = Con;
Cmm.ExecuteNonQuery();
MessageBox.Show("Inclusão efetuada com Sucesso !");
Use the operator
+=
, ex.:qtd += 3
– stderr
@zekk I could not make it work, or I did not understand how it does. could put a more complete explanation please ?
– Maurício Sanches
You want to increment before or after saving to the bank?
– stderr
The situation here is as follows: 1 initially. if later I need to insert this same item and it still contains 1 in my stock, I would like it not to duplicate but to transform the value into 2.
– Maurício Sanches
You can consult the quantity of such product in a
select ...
, by the number in a variablex
and check that it is equal to 1, if it is, you increasex
thus:x += 1
, and then you update the fieldqtd
of that product with the variablex
.– stderr
@Mauritosanches, as the zekk said, you have to check if it contains the product in the table. If the product exists you update the quantity with the UPDATE command, otherwise you insert this product in the table with the quantities you want using the INSERT command.
– Diego Farias