Exemplo n.º 1
0
        private void nuevoPlan()
        {
            bool valido = true;

            this.lblNombre.Visible        = false;
            this.lblCantCuotas.Visible    = false;
            this.lblTasaAnual.Visible     = false;
            this.lblIva.Visible           = false;
            this.lblErrorGenerico.Visible = false;

            // Control de campos obligatorios
            if (this.texBoxNombrePlan.Text.Trim() == "")
            {
                this.lblNombre.Visible = true;
                this.lblNombre.Text    = "Campo obligatorio";
                valido = false;
            }

            if (this.txtBoxCantCuotas.Text.Trim() == "")
            {
                this.lblCantCuotas.Visible = true;
                this.lblCantCuotas.Text    = "Campo obligatorio";
                valido = false;
            }
            else if (!(esEntero(txtBoxCantCuotas.Text)))
            {
                this.lblCantCuotas.Visible = true;
                this.lblCantCuotas.Text    = "Ingrese Nro Entero";
                valido = false;
            }

            if (this.txtBoxTasaAnualSinIVA.Text.Trim() == "")
            {
                this.lblTasaAnual.Visible = true;
                this.lblTasaAnual.Text    = "Campo obligatorio";
                valido = false;
            }
            else if (!(esDecimal(txtBoxTasaAnualSinIVA.Text)))
            {
                this.lblTasaAnual.Visible = true;
                this.lblTasaAnual.Text    = "Ingrese número válido";
                valido = false;
            }

            if (this.txtBoxIVA.Text.Trim() == "")
            {
                this.lblIva.Visible = true;
                this.lblIva.Text    = "Campo obligatorio";
                valido = false;
            }
            else if (!(esDecimal(txtBoxIVA.Text)))
            {
                this.lblIva.Visible = true;
                this.lblIva.Text    = "Ingrese número válido";
                valido = false;
            }

            int index = this.cmbPlan.SelectedIndex;

            // Control de duplicado para código, nombre e inciso. Se hace en memoria y luego a nivel de BD
            for (int i = 0; i < dsPlanes.Tables["planprestamo"].Rows.Count; i++)
            {
                if (this.texBoxNombrePlan.Text.Trim() == dsPlanes.Tables["planprestamo"].Rows[i][5].ToString())
                {
                    this.lblNombre.Visible = true;
                    this.lblNombre.Text    = "Ya exíste";
                    valido = false;
                }
            }

            if (valido)
            {
                try
                {
                    int vigencia;

                    if (chkVigencia.Checked)
                    {
                        vigencia = 1;
                    }
                    else
                    {
                        vigencia = 0;
                    }

                    double CuotaCada1000 = 0; // Calcular luego de hablar con la coop

                    Double tasaConIva = empresa.agregarleIvaAtasaAnual(Convert.ToDouble(txtBoxTasaAnualSinIVA.Text.Replace(".", ",")), Convert.ToDouble(txtBoxIVA.Text.Replace(".", ",")));
                    CuotaCada1000 = empresa.Cuota(tasaConIva, Convert.ToInt32(txtBoxCantCuotas.Text), 1000);

                    empresa.AltaPlan(Convert.ToInt32(txtBoxCantCuotas.Text), Convert.ToDouble(txtBoxTasaAnualSinIVA.Text.Replace(".", ",")), Convert.ToDouble(txtBoxIVA.Text.Replace(".", ",")), vigencia, texBoxNombrePlan.Text, CuotaCada1000);

                    MessageBox.Show("Plan creado correctamente");

                    RegistroSLogs registroLogs = new RegistroSLogs();
                    registroLogs.grabarLog(DateTime.Now, Utilidades.UsuarioLogueado.Alias, "Alta Plan de Préstamos " + texBoxNombrePlan.Text);

                    //Cargo planes
                    dsPlanes = empresa.DevolverPlanes();
                    pantallaInicial();
                }
                catch (Exception ex)
                {
                    this.lblErrorGenerico.Visible = true;
                    this.lblErrorGenerico.Text    = ex.Message;
                }
                this.lblCantCuotas.Visible = false;
                this.lblNombre.Visible     = false;
                this.lblTasaAnual.Visible  = false;
            }
        }