1
Good evening community,I have a stock program that I am finalizing and I want to do a validation for him to always check if he has enough of that product before adding to the sale. For this I used a simple mathematical operation, where one variable stores the requested value, another the value that exists in the database and then a third variable stores their subtraction and tests an if. However I’m having difficulty storing the Select result in the variable, is there a command to get the value of a table cell or something? follows below the code
Code:
private void btAddProd_Click(object sender, EventArgs e)
{
DataTable tabela = new DataTable();
DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
var cod = Convert.ToString(txtProCod.Text);
SqlDataAdapter da = new SqlDataAdapter("Select pro_qtde from produto where pro_cod like '%" + cod + "%' ", cx.StringConexao);
da.Fill(tabela);
double testeqtde = 0;
double estoqueqtde = 0;
double testetotal = 0;
testeqtde = Convert.ToDouble(txtQtde.Text);
estoqueqtde = Convert.ToDouble(tabela.Rows[0]);
testetotal = estoqueqtde - testeqtde;
if (testetotal < 0)
{
MessageBox.Show("Não há quantidade o bastante no estoque! Quantidade:" + estoqueqtde);
}
else
{
if ((txtProCod.Text != "") && (txtQtde.Text != "") && (txtValor.Text != ""))
{
Double TotalLocal = Convert.ToDouble(txtQtde.Text) * Convert.ToDouble(txtValor.Text);//metodo para calcular o total do produto
this.totalVenda = this.totalVenda + TotalLocal;//metodo para somar o total da compra
String[] i = new String[] { txtProCod.Text, lProduto.Text, txtQtde.Text, txtValor.Text, TotalLocal.ToString() };//criado vetor de string
this.dgvItens.Rows.Add(i);//adicionando o string dentro da datagrid
txtProCod.Clear();//limpar o campo
lProduto.Text = "Informe o código do produto ou clique em localizar";
txtQtde.Clear();//limpar o campo
txtValor.Clear();//limpar o campo
txtTotalVenda.Text = this.totalVenda.ToString();//atualizar o total da compra
}
}
}
The problem is really there in the stock,I don’t know what command to use to get the only value that has inside the table that is the pro_qtde of the product that is being requested.
You’re absolutely right,this solves,Thank you very much for helping Batista, I will try to improve the code as well, even being a small test base it is always ideal to acquire good programming habits like this
– UnbornHexa