private void button1_Click_1(object sender, EventArgs e) { if (searchbox.Text != "") { button2.Hide(); product p = new product(); if (p.search(searchbox.Text)) { namebox.Text = p.name; codebox.Text = p.code; // stockbox.Text = p.stk.ToString(); sratebox.Text = p.sr.ToString(); pratebox.Text = p.pr.ToString(); } else { MessageBox.Show("No Item Found"); clear(); } } }
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 6) { int amount = 0; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { amount += Convert.ToInt32(dataGridView1[e.ColumnIndex, i].Value.ToString()); } textBox3.Text = amount.ToString(); } if (e.ColumnIndex == 1 && e.RowIndex != -1) { product p = new product(); string q = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (p.search(q)) { dataGridView1[0, e.RowIndex].Value = p.code; // dataGridView1[7, e.RowIndex].Value = p.stk; dataGridView1[5, e.RowIndex].Value = p.sr; } } }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 0 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { product p = new product(); string q = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); if (p.search(q)) { dataGridView1[1, e.RowIndex].Value = p.name; // dataGridView1[7, e.RowIndex].Value = p.stk; dataGridView1[5, e.RowIndex].Value = p.sr; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); SendKeys.Send("{Right}"); } else { MessageBox.Show("Invalid Product Code"); SendKeys.Send("{UP}"); return; } } else if (e.ColumnIndex == 2 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[3, e.RowIndex].Value = null; dataGridView1[4, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 3 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[2, e.RowIndex].Value = null; dataGridView1[4, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 4 && dataGridView1[e.ColumnIndex, e.RowIndex].Value != null) { dataGridView1[3, e.RowIndex].Value = null; dataGridView1[2, e.RowIndex].Value = null; SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex < dataGridView1.Columns.Count - 3) { SendKeys.Send("{UP}"); SendKeys.Send("{Right}"); } else if (e.ColumnIndex == 5) { int col = e.ColumnIndex; dataGridView1.CurrentCell = dataGridView1[0, e.RowIndex]; int row = e.RowIndex, unit, rate, amount; if (dataGridView1[2, e.RowIndex].Value != null) { unit = Convert.ToInt32(dataGridView1[2, e.RowIndex].Value); } else if (dataGridView1[3, e.RowIndex].Value != null) { unit = Convert.ToInt32(dataGridView1[3, e.RowIndex].Value); } else { unit = Convert.ToInt32(dataGridView1[4, e.RowIndex].Value); } rate = Convert.ToInt32(dataGridView1[col, row].Value); amount = unit * rate; dataGridView1[col + 1, row].Value = amount; } counter(); }