Beispiel #1
0
 // datagrid view event
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         // select Id value
         var id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
         //select  product name value
         var name = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
         //Select product price
         var price = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
         //Select quantity
         var quantity = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
         // get date value
         var dateAdded = DateTime.Now.ToString("yyyy-MM-dd");
         // check if value is not assigned
         var valueId = UtilityClass.CheckIfIntEmpty(int.Parse(id));
         // new product object
         cart.AddToChart(valueId, name, Convert.ToDecimal(price), int.Parse(quantity), dateAdded);
         // display message
         MessageBox.Show("Item added sucessfully");
     }
     catch (Exception)
     {
         // display error
         MessageBox.Show("Operation Error ");
     }
 }