Exemple #1
0
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            bool banderaCorrecto = false;

            if (txtTotalDevolucion.Text != "")
            {
                if (MessageBox.Show("¿Desea Gaurdar la Nota de Credito?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (txtSerie1.Text != "" && txtSerie2.Text != "" && txtNumero.Text != "" && txtAutorizacionNC.Text != "" && txtSerie1NC.Text != "" && txtSerie2NC.Text != "" && txtNumeroNC.Text != "")
                    {
                        if (txtTotalDevolucion.Text != "0.00")
                        {
                            if (!modificar)
                            {
                                objENC = new EncabezadoNotaCredito(txtSerie1NC.Text, txtSerie2NC.Text, txtNumeroNC.Text, compraDetalle, Convert.ToSingle(Funcion.reemplazarcaracterViceversa(txtTotalDevolucion.Text)), sumasubcero, sumasubiva, ivatotal, sumaice, sumairbp, Convert.ToDateTime(dtpFechaEmision.Value.ToShortDateString()), txtAutorizacionNC.Text, subtotalPie);
                                string resultado = objENC.InsertarEncabezadoNC(objENC);
                                if (resultado == "Datos Guardados")
                                {
                                    string idEncabezadoNC = objConsultas.ObtenerValorCampo("IDENCABEZADONOTACREDITO", "TbEncabezadoNotaCredito", " where IDENCABEZADOCOMPRA = " + compraDetalle + " and SERIE1 = " + txtSerie1NC.Text + " and SERIE2 = " + txtSerie2NC.Text + " and NUMERO = " + txtNumeroNC.Text + " ");
                                    for (int i = 0; i < dgvProductosDevolucion.RowCount - 1; i++)
                                    {
                                        string[] porcentaje       = dgvProductosDevolucion.Rows[i].Cells[10].Value.ToString().Split('%');
                                        float    precioPorcentaje = Convert.ToSingle(porcentaje[0]);
                                        objDNC = new DetalleNotaCredito(Convert.ToInt32(idEncabezadoNC), Convert.ToSingle(Funcion.reemplazarcaracterViceversa(dgvProductosDevolucion.Rows[i].Cells[9].Value.ToString())), Convert.ToString(dgvProductosDevolucion.Rows[i].Cells[0].Value), Convert.ToSingle(Funcion.reemplazarcaracterViceversa(precioPorcentaje.ToString())));
                                        string resultadoDetalle = objDNC.InsertarDetalleNC(objDNC);
                                        if (resultadoDetalle == "Datos Guardados")
                                        {
                                            banderaCorrecto = true;
                                        }
                                        else if (resultadoDetalle == "Error al Registrar")
                                        {
                                            banderaCorrecto = false;
                                            break;
                                        }
                                        if (Convert.ToString(dgvProductosDevolucion.Rows[i + 1].Cells[0].Value) == "")
                                        {
                                            break;
                                        }
                                    }
                                    if (!banderaCorrecto)
                                    {
                                        MessageBox.Show("Error al guardar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbEncabezadoNotaCredito] WHERE IDENCABEZADOCOMPRA = " + compraDetalle + "");
                                        objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbDetalleNotaCredito] WHERE IDENCABEZADONOTACREDITO = " + idEncabezadoNC + "");
                                        inicializar();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Guardada correctamente la Nota de Crédito");
                                        inicializar();
                                    }
                                }
                                else if (resultado == "Error al Registrar")
                                {
                                    MessageBox.Show("Error al guardar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                    objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbEncabezadoNotaCredito] WHERE IDENCABEZADOCOMPRA = " + encabezadoNotaCredito + "");
                                }
                                else if (resultado == "Existe")
                                {
                                    MessageBox.Show("No hay mas crédito para esta compra", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                            }
                            else if (modificar)
                            {
                                objENC = new EncabezadoNotaCredito(txtSerie1NC.Text, txtSerie2NC.Text, txtNumeroNC.Text, compraDetalle, Convert.ToSingle(Funcion.reemplazarcaracterViceversa(txtTotalDevolucion.Text)), sumasubcero, sumasubiva, ivatotal, sumaice, sumairbp, Convert.ToDateTime(dtpFechaEmision.Value.ToShortDateString()), txtAutorizacionNC.Text, subtotalPie);
                                string resultado = objENC.ActualizarEncabezadoNC(encabezadoNotaCredito);
                                if (resultado == "Datos Guardados")
                                {
                                    string idEncabezadoNC = objConsultas.ObtenerValorCampo("IDENCABEZADONOTACREDITO", "TbEncabezadoNotaCredito", " where IDENCABEZADOCOMPRA = " + compraDetalle + " and SERIE1 = '" + txtSerie1NC.Text + "' and SERIE2 = '" + txtSerie2NC.Text + "' and NUMERO = '" + txtNumeroNC.Text + "' ");
                                    for (int i = 0; i < dgvProductosDevolucion.RowCount - 1; i++)
                                    {
                                        string[] porcentaje       = dgvProductosDevolucion.Rows[i].Cells[10].Value.ToString().Split('%');
                                        float    precioPorcentaje = Convert.ToSingle(porcentaje[0]);
                                        objDNC = new DetalleNotaCredito(Convert.ToInt32(idEncabezadoNC), Convert.ToSingle(Funcion.reemplazarcaracterViceversa(dgvProductosDevolucion.Rows[i].Cells[9].Value.ToString())), Convert.ToString(dgvProductosDevolucion.Rows[i].Cells[0].Value), Convert.ToSingle(Funcion.reemplazarcaracterViceversa(precioPorcentaje.ToString())));
                                        string resultadoDetalle = objDNC.ActualizarDetalleNC();
                                        if (resultadoDetalle == "Datos Guardados")
                                        {
                                            banderaCorrecto = true;
                                        }
                                        else if (resultadoDetalle == "Error al Registrar")
                                        {
                                            banderaCorrecto = false;
                                            break;
                                        }
                                        if (Convert.ToString(dgvProductosDevolucion.Rows[i + 1].Cells[0].Value) == "")
                                        {
                                            break;
                                        }
                                    }
                                    if (!banderaCorrecto)
                                    {
                                        MessageBox.Show("Error al guardar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                        inicializar();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Guardada correctamente la Nota de Crédito");
                                        inicializar();
                                    }
                                }
                                else if (resultado == "Error al Registrar")
                                {
                                    MessageBox.Show("Error al actualizar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                }
                            }
                            else
                            {
                                MessageBox.Show("No se a realizado ninguna devolución", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Debe ingresar todos los datos", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        MessageBox.Show("No se a realizado ninguna devolución", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Exemple #2
0
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            bool banderaCorrecto = false;

            if (txtTotalDevolucion.Text != "")
            {
                if (MessageBox.Show("¿Desea Gaurdar la Nota de Credito?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (txtSerie1.Text != "" && txtSerie2.Text != "" && txtNumero.Text != "")
                    {
                        objENC = new EncabezadoNotaCredito(txtSerie1NC.Text, txtSerie2NC.Text, txtNumeroNC.Text, encabezadoCompra, Convert.ToSingle(Funcion.reemplazarcaracterViceversa(txtTotalDevolucion.Text)), sumasubcero, sumasubiva, ivatotal);
                        string resultado = objENC.InsertarEncabezadoNC(objENC);
                        if (resultado == "Datos Guardados")
                        {
                            string idEncabezadoNC = objConsultas.ObtenerValorCampo("IDENCABEZADONOTACREDITO", "TbEncabezadoNotaCredito", " where IDENCABEZADOCOMPRA = " + encabezadoCompra + "");
                            for (int i = 0; i < dgvProductosDevolucion.RowCount - 1; i++)
                            {
                                objDNC = new DetalleNotaCredito(Convert.ToInt32(idEncabezadoNC), Convert.ToInt32(dgvProductosDevolucion.Rows[i].Cells[10].Value), Convert.ToString(dgvProductosDevolucion.Rows[i].Cells[0].Value));
                                if (Convert.ToString(dgvProductosDevolucion.Rows[i].Cells[10].Value) != "")
                                {
                                    string resultadoDetalle = objDNC.InsertarDetalleNC(objDNC);
                                    if (resultado == "Datos Guardados")
                                    {
                                        banderaCorrecto = true;
                                    }
                                    else if (resultado == "Error al Registrar")
                                    {
                                        banderaCorrecto = false;
                                        break;
                                    }
                                    if (Convert.ToString(dgvProductosDevolucion.Rows[i + 1].Cells[0].Value) == "")
                                    {
                                        break;
                                    }
                                }
                            }
                            if (!banderaCorrecto)
                            {
                                MessageBox.Show("Error al guardar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                //string idEncabezadoNC = objConsultas.ObtenerValorCampo("IDENCABEZADONOTACREDITO", "TbEncabezadoNotaCredito", " where IDENCABEZADOCOMPRA = " + encabezadoCompra + "");
                                objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbEncabezadoNotaCredito] WHERE IDENCABEZADOCOMPRA = " + encabezadoCompra + "");
                                objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbDetalleNotaCredito] WHERE IDENCABEZADONOTACREDITO = " + idEncabezadoNC + "");
                                inicializar();
                            }
                            else
                            {
                                MessageBox.Show("Guardada correctamente la Nota de Crédito");
                                string numeroNC = (Convert.ToInt32(txtNumeroNC.Text) + 1).ToString("D9");
                                objConsultas.EjecutarSQL("UPDATE [dbo].[TbCajasTalonario] SET [DOCUMENTOACTUAL] = '" + numeroNC + "' WHERE SERIE1 = '" + txtSerie1NC.Text + "' and SERIE2 = '" + txtSerie2NC.Text + "' and IPESTACION = '" + bitacora.LocalIPAddress() + "' and TIPODOCUMENTO = 'NCRE'");
                                inicializar();
                            }
                        }
                        else if (resultado == "Error al Registrar")
                        {
                            MessageBox.Show("Error al guardar la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            objConsultas.EjecutarSQL("DELETE FROM [dbo].[TbEncabezadoNotaCredito] WHERE IDENCABEZADOCOMPRA = " + encabezadoCompra + "");
                        }
                        else if (resultado == "Existe")
                        {
                            MessageBox.Show("Ya existe la Nota de Crédito", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No se a realizado ninguna devolución", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }