//Make Order btn private void button2_Click(object sender, EventArgs e) { try { if (dataGridView1.Rows[0].Cells[0].Value == null || dataGridView1.Rows[0].Cells[1].Value == null) { MessageBox.Show("error !!"); } else { dliveryboy boy = new dliveryboy(); products p = new products(); List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >(); float total = 0; DateTime t = DateTime.Now; bool flag = false; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (p.check(dataGridView1.Rows[i].Cells[0].Value.ToString()) && int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) <= p.check_quantity(dataGridView1.Rows[i].Cells[0].Value.ToString())) { flag = true; } else { flag = false; } } if (boy.assgin() == null) { MessageBox.Show("Please wait few minutes to make order"); } else { bool ff = true; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { if (int.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString()) <= 0) { MessageBox.Show("falid quantity in row " + ++i); ff = false; } } if (ff) { for (int j = 0; j < dataGridView1.Rows.Count - 1; j++) { if (flag) { p.buy(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString())); total += p.return_price_order(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString())); list.Add(new KeyValuePair <string, int>(dataGridView1.Rows[j].Cells[0].Value.ToString(), int.Parse(dataGridView1.Rows[j].Cells[1].Value.ToString()))); MessageBox.Show("done & total= " + total); } else { MessageBox.Show("invalid name or quantity !!"); } } if (flag) { total += 5; orders order = new orders(sign_in.t1, t, list, total, boy.assgin()); order.bill(order); } } } } } catch { MessageBox.Show("invalid enter"); } }