private void btnAgregar_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtNombre.Text))
     {
         if (txtPassword.Text == txtConfirmarPassword.Text)
         {
             using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
             {
                 Usuario usuario = new Usuario();
                 usuario.Usuario1 = txtNombre.Text;
                 usuario.Password = txtPassword.Text;
                 db.Usuarios.Add(usuario);
                 MessageBox.Show("Usuario agregado!");
                 db.SaveChanges();
                 LoadData();
             }
         }
         else
         {
             MessageBox.Show("Los campos de contraseñas deben de ser identicos!", "ERROR!");
         }
     }
     else
     {
         MessageBox.Show("El campo de Usuario no puede estar vacío", "ERROR!");
     }
 }
 private void btnEditarCliente_Click(object sender, EventArgs e)
 {
     try
     {
         var id = GetId();
         using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
         {
             Usuario us = db.Usuarios.Find(id);
             if (id != null)
             {
                 us.Usuario1        = txtNombre.Text;
                 us.Password        = txtPassword.Text;
                 db.Entry(us).State = System.Data.Entity.EntityState.Modified;
                 db.SaveChanges();
                 MessageBox.Show("Se actualizó el usuario: " + us.Usuario1, "Información Actualizada");
                 btnEditarCliente.Enabled = false;
             }
             LoadData();
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Por favor haga click en un usuario.");
     }
 }
Exemplo n.º 3
0
        private void btnSalir_Click(object sender, EventArgs e)
        {
            DialogResult = MessageBox.Show("Esta seguro de que desea salir del programa?", "Aviso!", MessageBoxButtons.YesNo,
                                           MessageBoxIcon.Information);

            if (DialogResult == DialogResult.Yes)//Se crea el backup de DB cada 25 dias
            {
                using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
                {
                    DateTime fechaActual = DateTime.Now;
                    TimeSpan?diasDesdeUltimoBackUp;


                    var MyDate = db.BackUps.Select(x => x.UltimoBackUp).Max();

                    diasDesdeUltimoBackUp = fechaActual - MyDate;

                    if (diasDesdeUltimoBackUp.Value.Days > 25)
                    {
                        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=SistemaPrestamosPV;Integrated Security=True");
                        SqlCommand    cmd  = new SqlCommand();
                        cmd.Connection  = conn;
                        cmd.CommandText = "backupdb";
                        cmd.CommandType = CommandType.StoredProcedure;
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                Application.Exit();
            }
        }
 private void txtBuscar_TextChanged(object sender, EventArgs e)
 {
     using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
     {
         var lst = from d in db.Usuarios
                   select d;
         dgvUsuarios.DataSource = lst.Where(p => p.Usuario1.Contains(txtBuscar.Text)).ToList();
     }
 }
 private void LoadData()
 {
     using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
     {
         var lst = from d in db.Usuarios
                   select d;
         dgvUsuarios.DataSource = lst.ToList();
     }
 }
Exemplo n.º 6
0
 private void LoadData()
 {
     using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
     {
         var lst = from d in db.Deudores
                   where d.CuotasVencidas > 0
                   select d;
         dgvPool.DataSource = lst.ToList();
     }
 }
Exemplo n.º 7
0
 private void btnPagos_Click(object sender, EventArgs e)
 {
     using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
     {
         var             id   = GetId();
         Deudores        deu  = db.Deudores.Find(id);
         frmAbonarSaldar form = new frmAbonarSaldar(deu);
         form.ShowDialog();
         LoadData();
     }
 }
        private void dgvUsuarios_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            var id = GetId();

            using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
            {
                Usuario us = db.Usuarios.Find(id);
                txtNombre.Text           = us.Usuario1;
                txtPassword.Text         = us.Password;
                btnEditarCliente.Enabled = true;
                btnEliminar.Enabled      = true;
            }
        }
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            int?id = GetId();

            if (id != null)
            {
                using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
                {
                    Usuario us = db.Usuarios.Find(id);
                    db.Usuarios.Remove(us);
                    db.SaveChanges();
                    MessageBox.Show("Se eliminó el usuario: " + us.Usuario1, "Regristro Borrado!");
                }
                LoadData();
            }
        }
Exemplo n.º 10
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            int?id = GetId();

            if (id != null)
            {
                using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
                {
                    Deudores oTabla = db.Deudores.Find(id);
                    db.Deudores.Remove(oTabla);
                    db.SaveChanges();
                    MessageBox.Show("Regristro Borrado!");
                }
                LoadData();
            }
        }
Exemplo n.º 11
0
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
            {
                string query = (from c in db.Usuarios
                                where c.Usuario1 == txtUsuario.Text && c.Password == txtPassword.Text
                                select c.Usuario1).FirstOrDefault();
                if (query != null)
                {
                    MessageBoxButtons buttons     = MessageBoxButtons.YesNo;
                    DateTime          fechaActual = DateTime.Now;
                    DialogResult      result      = MessageBox.Show("Está seguro de que la fecha correcta es:" +
                                                                    fechaActual.ToString("dd/MM/yyyy"), "Confirme fecha correcta", buttons);
                    if (result == DialogResult.Yes)
                    {
                        TimeSpan cuotasGen;

                        var lst = from d in db.Deudores
                                  select d;

                        foreach (var item in lst)
                        {
                            cuotasGen            = fechaActual - item.FechaInicializacionPrestamo;
                            item.CuotasGeneradas = cuotasGen.Days / 30;
                            item.CuotasVencidas  = item.CuotasGeneradas - item.CuotasPagadas;
                            db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                        }
                        db.SaveChanges();
                        frmPrincipal frmPrincipal = new frmPrincipal();
                        frmPrincipal.Show();
                        Hide();
                    }
                    else
                    {
                        MessageBox.Show("Por favor configure la fecha correctamente en su sistema" +
                                        " y vuelva a iniciar sección",
                                        "Actualiza la fecha en su sistema");
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show("Usuario y/o Contraseña incorrecto", "ERROR!");
                }
            }
        }
Exemplo n.º 12
0
 private void CargarDatos()
 {
     using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
     {
         oTabla            = db.Deudores.Find(id);
         txtNombres.Text   = oTabla.Nombres;
         txtApellidos.Text = oTabla.Apellidos;
         txtCapital.Text   = oTabla.Capital.ToString();
         var interes = oTabla.Interes;
         txtInteres.Text = interes.ToString();
         dtpFechaInicializacionPrestamo.Value = oTabla.FechaInicializacionPrestamo;
         txtTelefono.Text  = oTabla.Telefono;
         txtTelefono2.Text = oTabla.Telefono2;
         txtDireccion.Text = oTabla.Direccion;
         txtEmail.Text     = oTabla.Email;
     }
 }
Exemplo n.º 13
0
        private void frmReporte_Load(object sender, EventArgs e)
        {
            using (var db = new SistemaPrestamosPVEntities())
            {
                label13.Text = db.spSumCuotasVencidas().Sum().ToString();

                var totalACobrar =
                    (from deu in db.Deudores
                     select deu.ReditoAcumulado)
                    .Sum();
                label7.Text = totalACobrar.ToString();


                var totalCapital =
                    (from deu in db.Deudores
                     select deu.Capital)
                    .Sum();
                label8.Text = totalCapital.ToString();


                var totalClientes =
                    (from deu in db.Deudores
                     select deu.ReditoAcumulado)
                    .Count();
                label9.Text = totalClientes.ToString();


                var totalClientesEnAtraso =
                    (from deu in db.Deudores
                     where deu.CuotasVencidas > 2
                     select deu)
                    .Count();
                label10.Text = totalClientesEnAtraso.ToString();

                var mayorDeudor = db.Deudores.OrderByDescending(x => x.Capital).FirstOrDefault();

                label11.Text = mayorDeudor.Nombres + " " + mayorDeudor.Apellidos;

                label15.Text = DateTime.Now.ToString("dd/MM/yyyy");
            }
        }
Exemplo n.º 14
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
                {
                    TimeSpan cuotasGen;
                    DateTime fechaActual = DateTime.Now;

                    if (id == null)
                    {
                        oTabla           = new Deudores();
                        oTabla.Nombres   = txtNombres.Text;
                        oTabla.Apellidos = txtApellidos.Text;
                        oTabla.Capital   = Convert.ToSingle(txtCapital.Text);
                        var interes = Convert.ToSingle(txtInteres.Text);
                        oTabla.Interes       = interes;
                        oTabla.ReditoMensual = Convert.ToSingle(txtCapital.Text) * (interes / 100);
                        oTabla.CuotasPagadas = 0;
                        oTabla.FechaInicializacionPrestamo = oTabla.UltimoPago = dtpFechaInicializacionPrestamo.Value;
                        cuotasGen = fechaActual - oTabla.FechaInicializacionPrestamo;
                        oTabla.CuotasGeneradas = cuotasGen.Days / 30;
                        oTabla.CuotasVencidas  = oTabla.CuotasGeneradas - oTabla.CuotasPagadas;
                        if (oTabla.CuotasVencidas == 0)
                        {
                            oTabla.ReditoAcumulado = oTabla.ReditoMensual;
                        }
                        else
                        {
                            oTabla.ReditoAcumulado = oTabla.ReditoMensual * oTabla.CuotasVencidas;
                        }
                        oTabla.CuotasPagadasATiempo = 0;
                        oTabla.Score     = 1;
                        oTabla.Telefono  = txtTelefono.Text;
                        oTabla.Telefono2 = txtTelefono2.Text;
                        oTabla.Email     = txtEmail.Text;
                        oTabla.Direccion = txtDireccion.Text;
                        oTabla.Cedula    = txtCedula.Text;

                        db.Deudores.Add(oTabla);
                        MessageBox.Show("Registro agregado");
                    }
                    else
                    {
                        oTabla.Nombres     = txtNombres.Text;
                        oTabla.Apellidos   = txtApellidos.Text;
                        txtCapital.Enabled = false;
                        var interes = Convert.ToSingle(txtInteres.Text);
                        oTabla.Interes       = interes;
                        oTabla.ReditoMensual = Convert.ToSingle(txtCapital.Text) * (interes / 100);
                        dtpFechaInicializacionPrestamo.Enabled = false;
                        oTabla.Interes   = interes;
                        oTabla.Telefono  = txtTelefono.Text;
                        oTabla.Telefono2 = txtTelefono2.Text;
                        oTabla.Email     = txtEmail.Text;
                        oTabla.Direccion = txtDireccion.Text;
                        oTabla.Cedula    = txtCedula.Text;

                        db.Entry(oTabla).State = EntityState.Modified;
                        MessageBox.Show("Registro editado");
                    }

                    db.SaveChanges();
                    Close();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Campos obligatorios: Nombres, capital(solo numéricos) e interes(solo numéricos)", "Error!!");
            }
        }
Exemplo n.º 15
0
        private void btnPagarUltimaCuota_Click(object sender, EventArgs e)
        {
            try
            {
                var      id    = GetId();
                DateTime fecha = DateTime.Now;
                using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
                {
                    Deudores deu = db.Deudores.Find(id);
                    if (id != null)
                    {
                        if (deu.CuotasVencidas < 2)
                        {
                            deu.CuotasPagadasATiempo++;
                        }
                        deu.CuotasVencidas--;
                        deu.UltimoPago = fecha;
                        deu.CuotasPagadas++;
                        deu.ReditoAcumulado -= deu.ReditoMensual;
                        db.Entry(deu).State  = EntityState.Modified;
                        var pregunta = MessageBox.Show("Desea guardar factura?", "Factura", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        if (pregunta == DialogResult.Yes)          //Imprime factura para una cuota
                        {
                            #region Factura

                            try
                            {
                                string     nombreMasFecha = deu.Nombres + " " + fecha.ToString("MM - dd - yy");
                                string     pdfFilename    = $@"C:\Sistema Repuestos Pavel\Facturas de Cuotas\{nombreMasFecha}.pdf";
                                FileStream fs             = new FileStream(pdfFilename, FileMode.Create, FileAccess.Write, FileShare.None);
                                Document   doc            = new Document();
                                PdfWriter  writer         = PdfWriter.GetInstance(doc, fs);
                                doc.Open();

                                Paragraph espacioEntreParrrafos = new Paragraph("  ");
                                Paragraph fechaFactura          = new Paragraph(fecha.ToString());
                                fechaFactura.Alignment = Element.ALIGN_RIGHT;
                                Paragraph linea       = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, BaseColor.BLACK, Element.ALIGN_LEFT, 1)));
                                Chunk     titulo      = new Chunk("GRUPO INVERSIONES VERAS");
                                Chunk     subtitulo   = new Chunk("República Dominicana ");
                                Chunk     descripcion = new Chunk("DESCRIPCION - PAGO DE CUOTA");

                                descripcion.Font.Size = 15;
                                descripcion.Font.SetStyle("Bold");
                                titulo.Font.SetStyle("Bold");
                                titulo.Font.Size = 40;
                                subtitulo.Font.SetStyle("Bold");
                                subtitulo.Font.Size = 20;
                                Paragraph Titulo      = new Paragraph(titulo);
                                Paragraph Subtitulo   = new Paragraph(subtitulo);
                                Paragraph Descripcion = new Paragraph(descripcion);

                                Descripcion.Alignment = Element.ALIGN_CENTER;
                                Titulo.Alignment      = Element.ALIGN_CENTER;
                                Subtitulo.Alignment   = Element.ALIGN_CENTER;
                                doc.Add(linea);
                                doc.Add(Titulo);
                                doc.Add(Subtitulo);
                                doc.Add(Descripcion);
                                doc.Add(linea);


                                Chunk deudorNombre = new Chunk("A nombre del deudor: " + deu.Nombres + " " + deu.Apellidos);
                                deudorNombre.Font.Size = 20;
                                deudorNombre.Font.SetStyle("Bold");
                                Paragraph DeudorNombre = new Paragraph(deudorNombre);
                                doc.Add(DeudorNombre);
                                doc.Add(espacioEntreParrrafos);
                                doc.Add(espacioEntreParrrafos);


                                Chunk cuota = new Chunk("Monto pagado:RD$" + deu.ReditoMensual.ToString());
                                cuota.Font.Size = 20;
                                cuota.Font.SetStyle("Bold");
                                Paragraph Cuota = new Paragraph(cuota);
                                doc.Add(Cuota);
                                doc.Add(espacioEntreParrrafos);
                                doc.Add(espacioEntreParrrafos);


                                Chunk reditoPendiente = new Chunk("Reditos Pendientes:RD$" + deu.ReditoAcumulado.ToString());
                                reditoPendiente.Font.Size = 20;
                                reditoPendiente.Font.SetStyle("Bold");
                                Paragraph ReditoPendiente = new Paragraph(reditoPendiente);
                                doc.Add(ReditoPendiente);
                                doc.Add(espacioEntreParrrafos);
                                doc.Add(espacioEntreParrrafos);

                                Chunk capitalPendiente = new Chunk("Capital Pendientes:RD$" + deu.Capital.ToString());
                                capitalPendiente.Font.Size = 20;
                                capitalPendiente.Font.SetStyle("Bold");
                                Paragraph CapitalPendiente = new Paragraph(capitalPendiente);
                                doc.Add(CapitalPendiente);

                                for (int i = 0; i < 8; i++)
                                {
                                    doc.Add(espacioEntreParrrafos);
                                }
                                doc.Add(linea);
                                doc.Add(fechaFactura);

                                doc.Close();
                                string pdfPath = Path.Combine(Application.StartupPath, pdfFilename);

                                Process.Start(pdfPath);
                            }

                            catch (Exception m)
                            {
                                MessageBox.Show(m.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            #endregion
                        }

                        else //De lo contrario solo se muestra MessageBox.
                        {
                            MessageBox.Show(deu.Nombres + " " + deu.Apellidos + " Ha pagado" +
                                            " una cuota, le quedan " + deu.CuotasVencidas.ToString() + " Cuotas vencidas");
                        }
                    }
                    db.SaveChanges();
                    LoadData();
                }
            }
            catch (Exception Men)
            {
                MessageBox.Show(Men.Message);
                MessageBox.Show("Por haga click en algun registro!", "Error:No cliente seleccionado");
            }
        }
Exemplo n.º 16
0
        private void btnAplicar_Click(object sender, EventArgs e)
        {
            using (SistemaPrestamosPVEntities db = new SistemaPrestamosPVEntities())
            {
                try
                {
                    float    abono    = Convert.ToSingle(txtMontoAbonar.Text);
                    DateTime fechaHoy = DateTime.Now;

                    if (abonador.ReditoAcumulado > 0)
                    {
                        abonador.ReditoAcumulado = abonador.ReditoAcumulado - abono;
                        if (abonador.ReditoAcumulado < 0)
                        {
                            float abonocapital = Convert.ToSingle(abonador.ReditoAcumulado) * (-1);
                            abonador.ReditoAcumulado = 0;
                            abonador.Capital         = abonador.Capital - abonocapital;
                            MessageBox.Show("El deudor " + abonador.Nombres + " tiene su balance de reditos en:$RD"
                                            + abonador.ReditoAcumulado);
                            MessageBox.Show("El deudor " + abonador.Nombres + " tiene su balance de capital en:$RD"
                                            + abonador.Capital);
                        }
                        db.Entry(abonador).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        Close();
                    }
                    else if (abonador.Capital > 0)
                    {
                        abonador.Capital         = abonador.Capital - abono;
                        abonador.ReditoMensual   = abonador.Capital * (abonador.Interes / 100);
                        db.Entry(abonador).State = System.Data.Entity.EntityState.Modified;
                        db.SaveChanges();
                        MessageBox.Show("El deudor " + abonador.Nombres + " ha disminuido su capital a " + abonador.Capital);
                    }
                    if (abonador.Capital <= 0) // Cuando el deudor salda el capital,
                    {                          // se borra de la tabla Deudores y se envia como historico a la tabla Saldadores
                        Saldadore saldador = new Saldadore();
                        saldador.Nombres        = abonador.Nombres;
                        saldador.Apellidos      = abonador.Apellidos;
                        saldador.CapitalSaldado = abonador.Capital;
                        saldador.FechaInicializacionPrestamo = abonador.FechaInicializacionPrestamo;
                        saldador.FechaFinalizacionPrestamo   = fechaHoy;
                        saldador.CuotasGeneradas             = abonador.CuotasGeneradas;
                        saldador.CuotasPagadasATiempo        = abonador.CuotasPagadasATiempo;
                        saldador.Score     = abonador.Score;
                        saldador.Telefono  = abonador.Telefono;
                        saldador.Direccion = abonador.Direccion;
                        saldador.Cedula    = abonador.Cedula;
                        db.Saldadores.Add(saldador);

                        db.Deudores.Remove(abonador);
                        db.SaveChanges();

                        MessageBox.Show("El deudor " + abonador.Nombres + " ha saldado su deuda a RD$0.00.");
                    }
                    Close();
                }
                catch (Exception)
                {
                    MessageBox.Show("Verifique el campo de abono, no puede estar vacio o con un caracter que no sea numeros", "Error!");
                }
            }
        }