/// <summary>Método que representa la llamada lógica de 'Actualizar'</summary>
        public virtual ReturnValue Actualizar(List<Documento_Lin> oLista)
        {
            var oCursor = new Data.Cursor(true);
            RetValue.Send(false);
            try
            {
                Data.Documento_Cab.Actualizar(this, oCursor);

                var oDocumento_Lin = new Documento_Lin(ccosto,doc,numero, null);
                Data.Documento_Lin.Eliminar(oDocumento_Lin, oCursor);
                for (int i = 0; i <= oLista.Count - 1; i++)
                {
                    //Aqui le pasamos los valores de la llave de la cabecera al detalle
                    oLista[i].ccosto = this.ccosto;
                    oLista[i].doc = this.doc;
                    oLista[i].numero = this.numero;
                    Data.Documento_Lin.Insertar(oLista[i], oCursor);
                }
                return RetValue.Send(true);
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                oCursor.Finalizar(RetValue.IsOk);
            }
        }
        private void AsignarObjetoControl()
        {
            oDocumento_Cab.Obtener();
            txtCosto.Text = oDocumento_Cab.ccosto;
            txtDoc_Numero.Text = oDocumento_Cab.numero;
            txtAnioMes.Text = oDocumento_Cab.ej + "-" + oDocumento_Cab.mes;
            txtDescripcion.Text = oDocumento_Cab.descripcion;
            cboCliente.Text= oDocumento_Cab.cliente;
            cboEjecutivo.Text = oDocumento_Cab.ejecutivo;
            cboEncargado.SelectedValue = oDocumento_Cab.idPersona;
            txtTotalEgreso.Text = oDocumento_Cab.total.Value.ToString("0.00");
            cboEstado.SelectedValue = oDocumento_Cab.idEstado;

            var oDocumento_Lin = new Documento_Lin(oDocumento_Cab.ccosto, oDocumento_Cab.doc,oDocumento_Cab.numero, null);
            var LDocumento_Lin_LinListarUso = oDocumento_Lin.ListarUso();

            for (int i = 0; i <= LDocumento_Lin_LinListarUso.Count - 1; i++)
            {
                int Fila = dgvPartida.Rows.Add();
                dgvPartida.Rows[Fila].Cells[colPartida.Name].Value = LDocumento_Lin_LinListarUso[i].idPartida;
                dgvPartida.Rows[Fila].Cells[colDescripcion.Name].Value = LDocumento_Lin_LinListarUso[i].partida;
                dgvPartida.Rows[Fila].Cells[ColCantidad.Name].Value = LDocumento_Lin_LinListarUso[i].cantidad;
                dgvPartida.Rows[Fila].Cells[ColPrecioUnd.Name].Value = LDocumento_Lin_LinListarUso[i].precio;
                dgvPartida.Rows[Fila].Cells[colTotal.Name].Value = LDocumento_Lin_LinListarUso[i].  total;
            }
        }
Ejemplo n.º 3
0
        /// <summary>Método que representa la llamada lógica de 'Actualizar'</summary>
        public virtual ReturnValue Actualizar(List <Documento_Lin> oLista)
        {
            var oCursor = new Data.Cursor(true);

            RetValue.Send(false);
            try
            {
                Data.Documento_Cab.Actualizar(this, oCursor);

                var oDocumento_Lin = new Documento_Lin(ccosto, doc, numero, null);
                Data.Documento_Lin.Eliminar(oDocumento_Lin, oCursor);
                for (int i = 0; i <= oLista.Count - 1; i++)
                {
                    //Aqui le pasamos los valores de la llave de la cabecera al detalle
                    oLista[i].ccosto = this.ccosto;
                    oLista[i].doc    = this.doc;
                    oLista[i].numero = this.numero;
                    Data.Documento_Lin.Insertar(oLista[i], oCursor);
                }
                return(RetValue.Send(true));
            }
            catch (System.Exception)
            {
                throw;
            }
            finally
            {
                oCursor.Finalizar(RetValue.IsOk);
            }
        }
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            //Exige que se ingrese los datos antes de guardar
            if (!validarDatos())
            {
                return;
            }

            //Confirmacion para guardar
            if (MessageBox.Show("¿Desea guardar el Documento de Gasto?", Global.tituloPres, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

            var oCabecera = new Documento_Cab();
            var oLista = new List<Documento_Lin>();

            oCabecera.ccosto = txtCosto.Text;
            oCabecera.doc = "DG";
            oCabecera.idPersona = (int)cboEncargado.SelectedValue;
            oCabecera.idEstado = (string)cboEstado.SelectedValue;
            oCabecera.total = Convert.ToDecimal(txtTotalEgreso.Text);
            oCabecera.usr = Global._Usr;
            oCabecera.idEstado = cboEstado.Text.Substring(0, 1);

            for (int j = 0; j <= dgvPartida.Rows.Count - 1; j++)
            {
                var oDetalle = new Documento_Lin();
                oDetalle.idPartida = dgvPartida.Rows[j].Cells[colPartida.Name].Value.ToString();
                oDetalle.cantidad = Convert.ToInt16(dgvPartida.Rows[j].Cells[ColCantidad.Name].Value);
                oDetalle.precio = Convert.ToDecimal(dgvPartida.Rows[j].Cells[ColPrecioUnd.Name].Value);
                oDetalle.total = Convert.ToDecimal(dgvPartida.Rows[j].Cells[colTotal.Name].Value);
                oLista.Add(oDetalle);
            }

            if (Estado == 1)
            {
                oCabecera.Insertar(oLista);
                txtAnioMes.Text = oCabecera.ej + " - " + oCabecera.mes;
                txtDoc_Numero.Text = oCabecera.numero;
                DialogResult = DialogResult.OK;
                MessageBox.Show("El documento " + oCabecera.ccosto + "-" + oCabecera.numero + " se guardó satisfactoriamente.", Global.tituloPres, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            else
            {
                oCabecera.ccosto = oDocumento_Cab.ccosto;
                oCabecera.doc = oDocumento_Cab.doc;
                oCabecera.numero = oDocumento_Cab.numero;
                oCabecera.Actualizar(oLista);
            }

            DialogResult = DialogResult.OK;
            MessageBox.Show("El documento " + oCabecera.ccosto + "-"+ oCabecera.numero+ " se modifico satisfactoriamente.", Global.tituloPres, MessageBoxButtons.OK, MessageBoxIcon.Information);

            Close();
        }