示例#1
0
        private void editarPlan()
        {
            bool valido = true;

            this.lblCantCuotas.Visible    = false;
            this.lblNombre.Visible        = false;
            this.lblTasaAnual.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 (Convert.ToInt32(dsPlanes.Tables["planprestamo"].Rows[index][0].ToString()) != Convert.ToInt32(dsPlanes.Tables["planprestamo"].Rows[i][0].ToString()))
                {
                    if (this.texBoxNombrePlan.Text.Trim() == dsPlanes.Tables["planprestamo"].Rows[i][1].ToString())
                    {
                        this.lblNombre.Visible = true;
                        this.lblNombre.Text    = "Ya exíste";
                        valido = false;
                    }
                }
            }

            if (valido)
            {
                string            message = "¿Está seguro de que desea modificar el plan?";
                string            caption = "Modificar plan";
                MessageBoxButtons buttons = MessageBoxButtons.YesNo;
                DialogResult      result;
                result = MessageBox.Show(message, caption, buttons);

                if (result == System.Windows.Forms.DialogResult.Yes)
                {
                    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.ModificarPlan(Convert.ToInt32(dsPlanes.Tables["planprestamo"].Rows[index][0].ToString()), Convert.ToInt32(txtBoxCantCuotas.Text), Convert.ToDouble(txtBoxTasaAnualSinIVA.Text.Replace(".", ",")), Convert.ToDouble(txtBoxIVA.Text.Replace(".", ",")), vigencia, texBoxNombrePlan.Text, CuotaCada1000);
                        MessageBox.Show("Plan modificado correctamente");

                        RegistroSLogs registroLogs = new RegistroSLogs();
                        registroLogs.grabarLog(DateTime.Now, Utilidades.UsuarioLogueado.Alias, "Modificar 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;
                }
            }
        }