Some little help. Need if exist in datagrid value from textbox1 ( column name: bar_code) to increment cell kolicina (quantity eng.) + 1
private void prijavaAction()
{
int sno = dataGridView1.Rows.Count + 1;
SqlConnection con = new SqlConnection(cs);
if (textBox1.Text.All(char.IsDigit))
{
string queryString = "select bar_kod, ime, cijena_sa_porezom from roba_usluge WHERE bar_kod = '" + textBox1.Text + "'";// pronaci artikl u bazi
using (SqlConnection connection = new SqlConnection(cs))
{
SqlCommand command = new SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
var itemAndPrice = textBox1.Text;
if (reader.Read())
{
var index = dataGridView1.Rows.Add();
dataGridView1.Rows[index].Cells["redni_broj"].Value = index + 1;
dataGridView1.Rows[index].Cells["bar_kod"].Value = reader["bar_kod"].ToString();
dataGridView1.Rows[index].Cells["naziv_artikla"].Value = reader["ime"].ToString();
dataGridView1.Rows[index].Cells["cijena"].Value = reader["cijena_sa_porezom"].ToString();
dataGridView1.Rows[index].Cells["kolicina"].Value = "1";
foreach (DataGridViewRow g1 in dataGridView1.Rows)
{
g1.Cells["ukupno"].Value = (Convert.ToDouble(g1.Cells["kolicina"].Value) * Convert.ToDouble(g1.Cells["cijena"].Value)).ToString("0.00");
g1.Cells["kolicina"].Value = Convert.ToInt32(g1.Cells["kolicina"].Value) + 1;
}
}
else
{
MessageBox.Show("Bar kod ne postoji u bazi!", "Obavještenje", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text = "";
}
}
}
else
{
MessageBox.Show("Bar kod ne postoji ili nije bar kod!", "Obavještenje", MessageBoxButtons.OK, MessageBoxIcon.Information);
textBox1.Text = "";
}
}