private void textBox3_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar==(char)13) { string y = textBox3.Text; string sql = "SELECT * FROM item_data where stock_code='" + textBox3.Text + "'"; cmd = new SqlCommand(sql, con); for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { if (dataGridView1.Rows[i].Cells[0].Value.ToString() == y) { //total =0; quantity1++; //total = price1+price; // price = total; //total1 = total1+total; //textBox2.Text = total1.ToString (); dataGridView1.Rows[i].Cells[4].Value = quantity1; // dataGridView1.Rows[i].Cells[3].Value = price; // textBox2.Text =price .ToString (); break; } } else { try { con.Open(); dr = cmd.ExecuteReader(); if (dr.Read()) { int stock_code = (int)dr["stock_code"]; string description = (string)dr["descriptionOfItem"]; price = (int)dr["selling_price"]; quantity = (int)dr["quantity"]; string name = (string)dr["name"]; string stock_date = (string)dr["stock_date"]; stock_code.ToString(); price.ToString(); quantity.ToString(); con.Close(); ///////////////////////checking if there's still items in the database///////////////////////// if (quantity >= 1) { string sql1 = "update item_data set quantity=quantity-1 where stock_code='" + textBox3.Text + "'"; cmd = new SqlCommand(sql1, con); try { con.Open(); cmd.ExecuteNonQuery(); row = new string[] { stock_code.ToString(), description, price.ToString(), quantity1.ToString(), name.ToString(), stock_date }; // row = new string[] { b, contact, c, d }; dataGridView1.Rows.Add(stock_code.ToString(), description, name.ToString(), price.ToString(), quantity1.ToString(), stock_date); // dataGridView1.CurrentRow.Cells[4].Value = x; price1 = price; // textBox2.Text = price.ToString (); con.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); con.Close(); } } else { con.Close(); } } else con.Close(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); con.Close(); } } } /* */ } amount(); } public void amount() { for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (dataGridView1.Rows[i].Cells[0].Value != null) { if (dataGridView1.Rows[i].Cells[3].Value != null && dataGridView1.Rows[i].Cells[4].Value != null) { p1 = dataGridView1.Rows[i].Cells[3].Value.ToString(); q1 = dataGridView1.Rows[i].Cells[4].Value.ToString(); p = Convert.ToInt32(p1); q = Convert.ToInt32(q1); t = t + price; t1 = t1 + t; textBox2.Text = t1.ToString(); break; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)