Example #1
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text != string.Empty)
            {
                using (Entitidades contexto = new Entitidades())
                {
                    int codFactura = Convert.ToInt32(txtCodigo.Text);
                    Factura oFactura = contexto.Factura.Single(f => f.CodFactura == codFactura);

                    contexto.Factura.Remove(oFactura);
                    contexto.SaveChanges();
                    CargarDatos();
                }
            }
            else
            {
                MessageBox.Show("Debe Seleccionar un Registro");
            }
        }
Example #2
0
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();
            if (txtCodigo.Text == string.Empty)
            {
                errorProvider1.SetError(txtCodigo, "Digite un codigo");
            }
            if (txtValorTotal.Text == string.Empty)
            {
                errorProvider1.SetError(txtValorTotal, "Digite el total");
            }
            if (cbCiudad.Text == string.Empty)
            {
                errorProvider1.SetError(cbCiudad, "Seleccione una ciudad");
            }
            else
            {
                using (Entitidades contexto = new Entitidades())
                {
                    Factura oFactura = new Factura()
                    {
                        CodFactura = Convert.ToInt32(txtCodigo.Text),
                        Fecha = dtFecha.Value,
                        ValorTotal = Convert.ToDecimal(txtValorTotal.Text),
                        Ciudad = cbCiudad.Text
                    };

                    contexto.Factura.Add(oFactura);
                    contexto.SaveChanges();
                    CargarDatos();
                    MessageBox.Show("Registo Ingresado Correctamente");
                    txtCodigo.Text = "";
                    txtValorTotal.Text = "";
                }
            }
        }
Example #3
0
        private void btnModificar_Click(object sender, EventArgs e)
        {
            if (txtCodigo.Text != string.Empty)
            {
                using (Entitidades contexto = new Entitidades())
                {
                    int codFactura = Convert.ToInt32(txtCodigo.Text);
                    Factura oFactura = contexto.Factura.Single(f => f.CodFactura == codFactura);

                    oFactura.Fecha = dtFecha.Value;
                    oFactura.ValorTotal = Convert.ToDecimal(txtValorTotal.Text);
                    oFactura.Ciudad = cbCiudad.Text;

                    contexto.SaveChanges();
                    CargarDatos();

                    MessageBox.Show("Registro Modificado Correctamente");
                };
            }
            else
            {
                MessageBox.Show("Debe Seleccionar un Registro");
            }
        }
Example #4
0
        private void CargarDatos()
        {
            DgFactura.AutoGenerateColumns = false;
            List<Factura> fac = null;
            using (Entitidades contexto = new Entitidades())
            {
                fac = (from q in contexto.Factura
                       select q).ToList();
            }

            DgFactura.DataSource = fac;
        }