Exemplo n.º 1
0
 private void Refresh()
 {
     using (Models.MaestroDetalleEntities db = new Models.MaestroDetalleEntities())
     {
         dataGridView1.DataSource = db.venta.Select(d => new { d.id, d.fecha, d.total }).ToList();
     }
 }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            using (Models.MaestroDetalleEntities db = new Models.MaestroDetalleEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        Models.venta oVenta = new Models.venta();
                        oVenta.fecha = DateTime.Now;
                        oVenta.total = decimal.Parse(lblTotal.Text.ToString());

                        db.venta.Add(oVenta);
                        db.SaveChanges();

                        foreach (DataGridViewRow dr in dgvVentas.Rows)
                        {
                            Models.concepto oConcepto = new Models.concepto();

                            oConcepto.cantidad       = int.Parse(dr.Cells[2].Value.ToString());
                            oConcepto.descripcion    = dr.Cells[0].Value.ToString();
                            oConcepto.precioUnitario = decimal.Parse(dr.Cells[1].Value.ToString());
                            oConcepto.importe        = decimal.Parse(dr.Cells[3].Value.ToString());
                            oConcepto.id_venta       = oVenta.id;
                            db.concepto.Add(oConcepto);
                        }

                        db.SaveChanges();


                        dbContextTransaction.Commit();
                        dbContextTransaction.Dispose();
                        this.Close();
                    }catch (Exception ex)
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }