コード例 #1
0
        private void ParseIds()
        {
            foreach (DataGridViewRow item in dgvActivos.Rows)
            {
                int activoId = int.Parse(item.Cells["Codigo_Activo"].Value.ToString());
                int deptId   = int.Parse(item.Cells["Id_Dept"].Value.ToString());
                int ubicId   = int.Parse(item.Cells["Id_Ubicacion"].Value.ToString());
                int tipoId   = int.Parse(item.Cells["Id_TipoActivo"].Value.ToString());

                using (ActivosEntities db = new ActivosEntities())
                {
                    Activos_Fijos activo   = db.Activos_Fijos.FirstOrDefault(a => a.Codigo_Activo == activoId);
                    string        deptName = db.Departamento
                                             .FirstOrDefault(d => d.Codigo_Departamento == deptId).Nombre;
                    string ubicacion = db.Ubicacion.FirstOrDefault(u => u.Codigo_Ubicacion == ubicId).Descripcion;
                    string tipo      = db.Tipo_Activo.FirstOrDefault(t => t.Codigo_TipoActivo == tipoId).Descripcion;

                    item.Cells["Departamento"].Value = deptName;
                    item.Cells["Ubicacion"].Value    = ubicacion;
                    item.Cells["Tipo"].Value         = tipo;

                    if (activo.Calculo_Depreciacion.Count > 0)
                    {
                        Calculo_Depreciacion depre = activo.Calculo_Depreciacion.OrderBy(a => a.Fecha_Proceso).Last();

                        item.Cells["Depreciacion"].Value = depre.Depreciacion_Acumulada;
                    }
                    else
                    {
                        item.Cells["Depreciacion"].Value = "0.00";
                    }
                }
            }
        }
コード例 #2
0
        private void dgvUsuarios_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            frmUsuariosForm frm = new frmUsuariosForm();
            var             row = dgvUsuarios.CurrentRow;
            var             db  = new ActivosEntities();

            frm.isEditing = true;
            frm.Id        = (int)row.Cells["Id"].Value;
            frm.Usuario   = row.Cells["Usuario"].Value.ToString();
            frm.Nombre    = row.Cells["Nombre"].Value.ToString();
            frm.Apellido  = row.Cells["Apellido"].Value.ToString();

            int IdUser = (int)row.Cells["Id"].Value;
            var a      = db.Usuarios
                         .FirstOrDefault(d => d.Id == IdUser).Roles;


            foreach (Roles item in a)
            {
                frm.Rol = item.Nombre;
                break;
            }

            frm.ShowDialog();
        }
コード例 #3
0
        private void InsertarActivoCalculado(int IdActivo, decimal MontoDepreciado, decimal DepreciacionAcumulada, DateTime Fecha)
        {
            try
            {
                using (ActivosEntities db = new ActivosEntities())
                {
                    Calculo_Depreciacion CalcDeprec = new Calculo_Depreciacion
                    {
                        Codigo_Activo_Fijo     = IdActivo,
                        Fecha_Proceso          = Fecha,
                        Monto_Depreciado       = MontoDepreciado,
                        Depreciacion_Acumulada = DepreciacionAcumulada
                    };

                    db.Calculo_Depreciacion.Add(CalcDeprec);

                    db.SaveChanges();
                    Close();
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #4
0
        private void frmEmpleadosForm_Load(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                cbxDept.DataSource = db.Departamento.Select(d => d.Nombre).ToList();
            }

            if (isEditing)
            {
                lblTitle.Text          = "Editar empleado";
                txtNombre.Text         = Nombre;
                txtApellido.Text       = Apellido;
                txtCedula.Text         = Cedula;
                cbxDept.SelectedItem   = Departamento;
                cbxTipo.SelectedItem   = Tipo_Persona;
                dtpFecha.Value         = DateTime.Parse(Fecha_Ingreso.ToShortDateString());
                cbxEstado.SelectedItem = Estado;
            }
            else
            {
                cbxTipo.SelectedIndex   = 0;
                cbxEstado.SelectedIndex = 0;
                btnEliminar.Visible     = false;
            }
        }
コード例 #5
0
        private void GetActivos(string search)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                if (!(search.Trim().Length > 0))
                {
                    if (cbxCriterio.Text.Equals("Tipo"))
                    {
                        dgvActivos.DataSource = db.Activos_Fijos.OrderBy(a => a.Tipo_Activo.Descripcion).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Departamento"))
                    {
                        dgvActivos.DataSource = db.Activos_Fijos.OrderBy(a => a.Departamento.Nombre).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Valor"))
                    {
                        dgvActivos.DataSource = db.Activos_Fijos.OrderByDescending(a => a.Valor_Compra).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Fecha"))
                    {
                        dgvActivos.DataSource = db.Activos_Fijos.OrderBy(a => a.Fecha_Registro).ToList();
                    }
                    else
                    {
                        dgvActivos.DataSource = db.Activos_Fijos.ToList();
                    }

                    return;
                }

                var activos = db.Activos_Fijos.Where(a => a.Descripcion.Contains(search) || a.Tipo_Activo.Descripcion.Contains(search) ||
                                                     a.Departamento.Nombre.Contains(search) || a.Ubicacion.Descripcion.Contains(search));

                if (cbxCriterio.Text.Equals("Tipo"))
                {
                    dgvActivos.DataSource = activos.OrderBy(a => a.Tipo_Activo.Descripcion).ToList();
                }
                else if (cbxCriterio.Text.Equals("Departamento"))
                {
                    dgvActivos.DataSource = activos.OrderBy(a => a.Departamento.Nombre).ToList();
                }
                else if (cbxCriterio.Text.Equals("Valor"))
                {
                    dgvActivos.DataSource = activos.OrderByDescending(a => a.Valor_Compra).ToList();
                }
                else if (cbxCriterio.Text.Equals("Fecha"))
                {
                    dgvActivos.DataSource = activos.OrderBy(a => a.Fecha_Registro).ToList();
                }
                else
                {
                    dgvActivos.DataSource = activos.ToList();
                }
            }
        }
コード例 #6
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtApellido.Text.Length == 0)
            {
                MessageBox.Show("Introduzca un apellido");
                return;
            }

            if (CheckCedula(txtCedula.Text))
            {
                using (ActivosEntities db = new ActivosEntities())
                {
                    Empleado empleado = new Empleado
                    {
                        Codigo_Empleado     = Id,
                        Nombre              = txtNombre.Text,
                        Apellido            = txtApellido.Text,
                        Cedula              = txtCedula.Text,
                        Codigo_Departamento = db.Departamento
                                              .FirstOrDefault(d => d.Nombre == cbxDept.SelectedValue.ToString()).Codigo_Departamento,
                        Tipo_Persona  = cbxTipo.SelectedItem.ToString(),
                        Fecha_Ingreso = dtpFecha.Value,
                        Estado        = cbxEstado.SelectedItem.ToString()
                    };

                    if (Id != 0)
                    {
                        var empInDb = db.Empleado.FirstOrDefault(emp => emp.Codigo_Empleado == empleado.Codigo_Empleado);

                        if (empInDb != null)
                        {
                            db.Entry(empInDb).State  = System.Data.Entity.EntityState.Detached;
                            db.Entry(empleado).State = System.Data.Entity.EntityState.Modified;
                        }

                        MessageBox.Show("El empleado ha sido modificado exitosamente.");
                    }
                    else
                    {
                        db.Empleado.Add(empleado);
                        MessageBox.Show("El empleado ha sido creado exitosamente.");
                    }

                    db.SaveChanges();

                    Close();
                }
            }
            else
            {
                MessageBox.Show("Introduzca una cedula valida");
            }
        }
コード例 #7
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var parametro = db.Parametro.FirstOrDefault(para => para.Codigo_Parametro == Id);

                db.Parametro.Remove(parametro);
                db.SaveChanges();
            }

            MessageBox.Show("El parametro ha sido eliminado exitosamente");
            Close();
        }
コード例 #8
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var Usuario = db.Usuarios.FirstOrDefault(user => user.Id == Id);

                db.Usuarios.Remove(Usuario);
                db.SaveChanges();
            }

            MessageBox.Show("El usuario ha sido eliminado exitosamente");
            Close();
        }
コード例 #9
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var ubicacion = db.Ubicacion.FirstOrDefault(ubi => ubi.Codigo_Ubicacion == Id);

                db.Ubicacion.Remove(ubicacion);
                db.SaveChanges();
            }

            MessageBox.Show("La ubicacion ha sido eliminada exitosamente");
            Close();
        }
コード例 #10
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var proveedor = db.Proveedor.FirstOrDefault(pro => pro.Codigo_Proveedor == Id);

                db.Proveedor.Remove(proveedor);
                db.SaveChanges();
            }

            MessageBox.Show("El proveedor ha sido eliminado exitosamente");
            Close();
        }
コード例 #11
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var empleado = db.Empleado.FirstOrDefault(emp => emp.Codigo_Empleado == Id);

                db.Empleado.Remove(empleado);
                db.SaveChanges();
            }

            MessageBox.Show("El empleado ha sido eliminado exitosamente");
            Close();
        }
コード例 #12
0
        private void btnEliminar_Click(object sender, EventArgs e)
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                var departamento = db.Departamento.FirstOrDefault(dept => dept.Codigo_Departamento == Id);

                db.Departamento.Remove(departamento);
                db.SaveChanges();
            }

            MessageBox.Show("El departamento ha sido eliminado exitosamente");
            Close();
        }
コード例 #13
0
        static void DefaultUsersAndRoles()
        {
            using (ActivosEntities db = new ActivosEntities())
            {
                // If Admin user doesn't exist, then this block hasn't been run before
                if (db.Usuarios.FirstOrDefault(u => u.Usuario == "admin") == null)
                {
                    var RoleAdmin = db.Roles.Add(new Roles {
                        Nombre = "Admin"
                    });
                    var RoleRRHH = db.Roles.Add(new Roles {
                        Nombre = "RRHH"
                    });
                    var RoleLogis = db.Roles.Add(new Roles {
                        Nombre = "Logistica"
                    });
                    var RoleCont = db.Roles.Add(new Roles {
                        Nombre = "Contable"
                    });

                    db.Usuarios.Add(new Usuarios
                    {
                        Usuario    = "admin",
                        Nombre     = "Miguel",
                        Apellido   = "Araujo",
                        Contrasena = SecurePasswordHasher.Hash("asdf1234"),
                        Roles      = { RoleAdmin, RoleRRHH, RoleLogis }
                    });

                    db.Usuarios.Add(new Usuarios
                    {
                        Usuario    = "wcruz",
                        Nombre     = "Winston",
                        Apellido   = "Cruz",
                        Contrasena = SecurePasswordHasher.Hash("asdf1234"),
                        Roles      = { RoleRRHH }
                    });

                    db.Usuarios.Add(new Usuarios
                    {
                        Usuario    = "ldavid",
                        Nombre     = "Luis",
                        Apellido   = "Laureano",
                        Contrasena = SecurePasswordHasher.Hash("asdf1234"),
                        Roles      = { RoleLogis }
                    });

                    db.SaveChanges();
                }
            }
        }
コード例 #14
0
        private void GetUbicacion(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
                        if (cbxCriterio.Text.Equals("Descripcion"))
                        {
                            dgvUbicacion.DataSource = db.Ubicacion.OrderBy(a => a.Descripcion).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Direccion"))
                        {
                            dgvUbicacion.DataSource = db.Ubicacion.OrderBy(a => a.Direccion).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Edificio"))
                        {
                            dgvUbicacion.DataSource = db.Ubicacion.OrderBy(a => a.Edificio).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Estado"))
                        {
                            dgvUbicacion.DataSource = db.Ubicacion.OrderBy(a => a.Estado).ToList();
                        }
                        //else
                        //    dgvUbicacion.DataSource = db.Ubicacion.ToList();

                        return;
                    }

                    var ubicacion = db.Ubicacion.Where(a => a.Descripcion.Contains(search));

                    if (cbxCriterio.Text.Equals("Descripcion"))
                    {
                        dgvUbicacion.DataSource = ubicacion.OrderBy(a => a.Descripcion).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Direccion"))
                    {
                        dgvUbicacion.DataSource = ubicacion.OrderBy(a => a.Direccion).ToList();
                    }
                    else
                    {
                        dgvUbicacion.DataSource = ubicacion.ToList();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #15
0
        private void DeptName()
        {
            foreach (DataGridViewRow item in dgvEmpleados.Rows)
            {
                int id = int.Parse(item.Cells["Id_Dept"].Value.ToString());

                using (ActivosEntities db = new ActivosEntities())
                {
                    string deptName = db.Departamento
                                      .FirstOrDefault(d => d.Codigo_Departamento == id).Nombre;

                    item.Cells["Departamento"].Value = deptName;
                }
            }
        }
コード例 #16
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (ValidarCampos())
            {
                using (ActivosEntities db = new ActivosEntities())
                {
                    var rol = db.Roles
                              .FirstOrDefault(d => d.Nombre == cobRol.SelectedValue.ToString());

                    Usuarios Usuario = new Usuarios
                    {
                        Id         = Id,
                        Usuario    = txtUsuario.Text,
                        Apellido   = txtApellido.Text,
                        Nombre     = txtNombre.Text,
                        Roles      = { rol },
                        Contrasena = SecurePasswordHasher.Hash(txtContrasena.Text),
                    };

                    if (Id != 0)
                    {
                        var UserInDB = db.Usuarios.FirstOrDefault(user => user.Id == Usuario.Id);

                        if (UserInDB != null)
                        {
                            db.Entry(UserInDB).State = System.Data.Entity.EntityState.Detached;
                            db.Entry(Usuario).State  = System.Data.Entity.EntityState.Modified;

                            foreach (var item in Usuario.Roles)
                            {
                                db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                            }
                        }

                        MessageBox.Show("El usuario ha sido modificado exitosamente.");
                    }
                    else
                    {
                        db.Usuarios.Add(Usuario);
                        MessageBox.Show("El usuario ha sido creado exitosamente.");
                    }

                    db.SaveChanges();

                    Close();
                }
            }
        }
コード例 #17
0
        private void GetParametros(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
                        if (cbxCriterio.Text.Equals("Año/Mes"))
                        {
                            dgvParametros.DataSource = db.Parametro.OrderBy(a => a.Ano_Mes_Proceso).ToList();
                        }

                        else if (cbxCriterio.Text.Equals("RNC"))
                        {
                            dgvParametros.DataSource = db.Parametro.OrderBy(a => a.RNC_Empresa).ToList();
                        }
                        //else
                        //    dgvProveedores.DataSource = db.Empleado.Include("Departamento").ToList();

                        return;
                    }

                    var parametros = db.Parametro.Where(a => a.RNC_Empresa.Contains(search));

                    if (cbxCriterio.Text.Equals("Año/Mes"))
                    {
                        dgvParametros.DataSource = parametros.OrderBy(a => a.Ano_Mes_Proceso).ToList();
                    }

                    else if (cbxCriterio.Text.Equals("RNC"))
                    {
                        dgvParametros.DataSource = parametros.OrderBy(a => a.RNC_Empresa).ToList();
                    }
                    else
                    {
                        dgvParametros.DataSource = parametros.ToList();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex.InnerException);
                }
            }
        }
コード例 #18
0
        private void GetProveedores(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
                        if (cbxCriterio.Text.Equals("Tipo"))
                        {
                            dgvProveedores.DataSource = db.Proveedor.OrderBy(a => a.Tipo_Proveedor).ToList();
                        }

                        else if (cbxCriterio.Text.Equals("Estado"))
                        {
                            dgvProveedores.DataSource = db.Proveedor.OrderBy(a => a.Estado).ToList();
                        }
                        //else
                        //    dgvProveedores.DataSource = db.Empleado.Include("Departamento").ToList();

                        return;
                    }

                    var Proveedores = db.Proveedor.Where(a => a.Nombre.Contains(search) || a.Cedula_RNC.Contains(search));

                    if (cbxCriterio.Text.Equals("Tipo"))
                    {
                        dgvProveedores.DataSource = Proveedores.OrderBy(a => a.Tipo_Proveedor).ToList();
                    }

                    else if (cbxCriterio.Text.Equals("Estado"))
                    {
                        dgvProveedores.DataSource = Proveedores.OrderBy(a => a.Estado).ToList();
                    }
                    else
                    {
                        dgvProveedores.DataSource = Proveedores.ToList();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #19
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (CheckCedula(txtCedula.Text))
            {
                using (ActivosEntities db = new ActivosEntities())
                {
                    Proveedor proveedor = new Proveedor
                    {
                        Codigo_Proveedor = Id,
                        Nombre           = txtNombre.Text,
                        Cedula_RNC       = txtCedula.Text,
                        Tipo_Proveedor   = cbxTipo.SelectedItem.ToString(),
                        Fecha_Registro   = dtpFecha.Value,
                        Estado           = cbxEstado.SelectedItem.ToString()
                    };

                    if (Id != 0)
                    {
                        var proinDb = db.Proveedor.FirstOrDefault(pro => pro.Codigo_Proveedor == proveedor.Codigo_Proveedor);

                        if (proinDb != null)
                        {
                            db.Entry(proinDb).State   = System.Data.Entity.EntityState.Detached;
                            db.Entry(proveedor).State = System.Data.Entity.EntityState.Modified;
                        }

                        MessageBox.Show("El proveedor ha sido modificado exitosamente.");
                    }
                    else
                    {
                        db.Proveedor.Add(proveedor);
                        MessageBox.Show("El proveedor ha sido creado exitosamente.");
                    }

                    db.SaveChanges();

                    Close();
                }
            }
            else
            {
                MessageBox.Show("Introduzca una cedula valida");
            }
        }
コード例 #20
0
 private void frmUsuariosForm_Load(object sender, EventArgs e)
 {
     using (ActivosEntities db = new ActivosEntities())
     {
         cobRol.DataSource = db.Roles.Select(d => d.Nombre).ToList();
     }
     if (isEditing)
     {
         lblTitle.Text       = "Editar Usuario";
         txtUsuario.Text     = Usuario;
         txtNombre.Text      = Nombre;
         txtApellido.Text    = Apellido;
         cobRol.SelectedItem = Rol;
     }
     else
     {
         btnEliminar.Visible = false;
     }
 }
コード例 #21
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (txtRNC.Text.Length == 0)
            {
                MessageBox.Show("Por favor introduzca un RNC");
                return;
            }

            using (ActivosEntities db = new ActivosEntities())
            {
                Parametro parametro = new Parametro
                {
                    Codigo_Parametro = Id,
                    Ano_Mes_Proceso  = dtpAnoMes.Value,
                    Deprec_Calculada = chkDeprecCalculada.Checked,
                    RNC_Empresa      = txtRNC.Text,
                    Met_Drepeciacion = cbxMetDeprec.SelectedItem.ToString(),
                };

                if (Id != 0)
                {
                    var paraDb = db.Parametro.FirstOrDefault(para => para.Codigo_Parametro == Id);

                    if (paraDb != null)
                    {
                        db.Entry(paraDb).State    = System.Data.Entity.EntityState.Detached;
                        db.Entry(parametro).State = System.Data.Entity.EntityState.Modified;
                    }

                    MessageBox.Show("El parametro ha sido modificado exitosamente.");
                }
                else
                {
                    db.Parametro.Add(parametro);
                    MessageBox.Show("El parametro ha sido creado exitosamente.");
                }

                db.SaveChanges();

                Close();
            }
        }
コード例 #22
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (!checkFields())
            {
                MessageBox.Show("Por favor llene todas las entradas");
                return;
            }

            using (ActivosEntities db = new ActivosEntities())
            {
                Ubicacion ubicacion = new Ubicacion
                {
                    Codigo_Ubicacion = Id,
                    Descripcion      = tbxDescripcion.Text,
                    Direccion        = tbxDireccion.Text,
                    Edificio         = tbxEdificio.Text,
                    Estado           = cbxEstado.SelectedItem.ToString()
                };

                if (Id != 0)
                {
                    var ubInDb = db.Ubicacion.FirstOrDefault(ubi => ubi.Codigo_Ubicacion == ubicacion.Codigo_Ubicacion);

                    if (ubInDb != null)
                    {
                        db.Entry(ubInDb).State    = System.Data.Entity.EntityState.Detached;
                        db.Entry(ubicacion).State = System.Data.Entity.EntityState.Modified;
                    }

                    MessageBox.Show("La ubicacion ha sido modificado exitosamente.");
                }
                else
                {
                    db.Ubicacion.Add(ubicacion);
                    MessageBox.Show("La ubicacion ha sido creado exitosamente.");
                }

                db.SaveChanges();

                Close();
            }
        }
コード例 #23
0
        private void btnGuardar_Click(object sender, EventArgs e)
        {
            if (tbxDepartamento.Text.Length == 0)
            {
                MessageBox.Show("Introduzca un nombre");
                return;
            }

            using (ActivosEntities db = new ActivosEntities())
            {
                Departamento departamento = new Departamento
                {
                    Codigo_Departamento = Id,
                    Nombre = tbxDepartamento.Text,
                };

                if (Id != 0)
                {
                    var deptInDb = db.Departamento.FirstOrDefault(dept => dept.Codigo_Departamento == departamento.Codigo_Departamento);

                    if (deptInDb != null)
                    {
                        db.Entry(deptInDb).State     = System.Data.Entity.EntityState.Detached;
                        db.Entry(departamento).State = System.Data.Entity.EntityState.Modified;
                    }

                    MessageBox.Show("El departamento ha sido modificado exitosamente.");
                }
                else
                {
                    db.Departamento.Add(departamento);
                    MessageBox.Show("El departamento ha sido creado exitosamente.");
                }

                db.SaveChanges();

                Close();
            }
        }
コード例 #24
0
        private void GetUsuario(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
                        dgvUsuarios.DataSource = db.Usuarios.ToList();

                        return;
                    }

                    var Usuarios = db.Usuarios.Where(a => a.Nombre.Contains(search) || a.Usuario.Contains(search));

                    dgvUsuarios.DataSource = Usuarios.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #25
0
        private void GetDepartamento(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
 
                            dgvDepartamento.DataSource = db.Departamento.ToList();

                        return;
                    }

                    var departamentos = db.Departamento.Where(a => a.Nombre.Contains(search));

                        dgvDepartamento.DataSource = departamentos.ToList();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #26
0
 public frmActivosFijosForm()
 {
     InitializeComponent();
     db = new ActivosEntities();
 }
コード例 #27
0
        private void cmdCalcular_Click(object sender, EventArgs e)
        {
            //try
            //{
            var db = new ActivosEntities();

            var ActivosFijos      = db.Activos_Fijos.ToList();
            var ActivosCalculados = db.Calculo_Depreciacion.ToList();


            DataTable dt = new DataTable(); // Crea tabla en memoria

            dt.Clear();
            dt.Columns.Add("IdActivo");
            dt.Columns.Add("Activo");
            dt.Columns.Add("Mes"); // Crea columnas de dicha tabla
            dt.Columns.Add("MontoDep");
            dt.Columns.Add("TotalDep");
            dt.Columns.Add("TotalRest");
            dt.Columns.Add("Fecha");
            double depAcumulada = 0;

            digitoAnos = 0;


            foreach (var activo in ActivosFijos)
            {
                valorCompra    = 0;
                depAnual       = 0;
                depAcumulada   = 0;
                depRestante    = 0;
                digitoAnos     = 0;
                dtpFecha.Value = DateTime.Now;
                int ContadorFecha = 0;

                bool Calculado = false;

                foreach (var deprec in ActivosCalculados)
                {
                    if (deprec.Codigo_Activo_Fijo == activo.Codigo_Activo)
                    {
                        Calculado = true;
                        break;
                    }
                }

                if (Calculado == false)
                {
                    valorCompra = (double)activo.Valor_Compra;

                    for (int anoDep = 1; anoDep <= nudAnosDep.Value; anoDep++)
                    {
                        digitoAnos += anoDep;
                    }

                    for (int anoDep = 1; anoDep <= nudAnosDep.Value; anoDep++)
                    {
                        if (rbLineaRecta.Checked)
                        {
                            depAnual = valorCompra / (int)nudAnosDep.Value;
                        }
                        else
                        {
                            depAnual = (valorCompra * anoDep) / digitoAnos;
                        }

                        depAcumulada += depAnual;
                        depRestante   = valorCompra - depAcumulada;

                        DataRow fila = dt.NewRow();
                        fila["IdActivo"]  = activo.Codigo_Activo;
                        fila["Activo"]    = activo.Descripcion;
                        fila["Mes"]       = anoDep; // Mueve valor a columnas de la tabla
                        fila["Fecha"]     = dtpFecha.Value.AddMonths(ContadorFecha); ContadorFecha++;
                        fila["MontoDep"]  = depAnual.ToString("#,##0.00");
                        fila["TotalDep"]  = depAcumulada.ToString("#,##0.00");
                        fila["TotalRest"] = depRestante.ToString("#,##0.00");
                        dt.Rows.Add(fila);
                    }

                    dgvResultados.DataSource = dt;
                    dgvResultados.Refresh(); // Muestra resultado en grid
                }
            }


            if (dgvResultados.Rows.Count == 0)
            {
                MessageBox.Show("Todos los activos registrados ya han sido calculados", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
コード例 #28
0
        private void GetEmpleados(string search)
        {
            using (var db = new ActivosEntities())
            {
                try
                {
                    if (!(search.Trim().Length > 0))
                    {
                        if (cbxCriterio.Text.Equals("Apellido"))
                        {
                            dgvEmpleados.DataSource = db.Empleado.Include("Departamento").OrderBy(a => a.Apellido).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Tipo"))
                        {
                            dgvEmpleados.DataSource = db.Empleado.Include("Departamento").OrderBy(a => a.Tipo_Persona).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Departamento"))
                        {
                            dgvEmpleados.DataSource = db.Empleado.Include("Departamento").OrderBy(a => a.Codigo_Departamento).ToList();
                        }
                        else if (cbxCriterio.Text.Equals("Estado"))
                        {
                            dgvEmpleados.DataSource = db.Empleado.Include("Departamento").OrderBy(a => a.Estado).ToList();
                        }
                        else
                        {
                            dgvEmpleados.DataSource = db.Empleado.Include("Departamento").ToList();
                        }

                        return;
                    }

                    var empleados = db.Empleado.Include("Departamento")
                                    .Where(a => a.Nombre.Contains(search) || a.Apellido.Contains(search) ||
                                           a.Departamento.Nombre.Contains(search));

                    if (cbxCriterio.Text.Equals("Apellido"))
                    {
                        dgvEmpleados.DataSource = empleados.OrderBy(a => a.Apellido).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Tipo"))
                    {
                        dgvEmpleados.DataSource = empleados.OrderBy(a => a.Tipo_Persona).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Departamento"))
                    {
                        dgvEmpleados.DataSource = empleados.OrderBy(a => a.Codigo_Departamento).ToList();
                    }
                    else if (cbxCriterio.Text.Equals("Valor"))
                    {
                        dgvEmpleados.DataSource = empleados.OrderBy(a => a.Estado).ToList();
                    }
                    else
                    {
                        dgvEmpleados.DataSource = empleados.ToList();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }