Beispiel #1
0
        private async void frmClientes_Load(object sender, EventArgs e)
        {
            Program.Cliente        = null;
            dgvClientes.DataSource = await _context.Clientes.Where(c => !c.IsDelete).Select(x => new
            {
                Id = x.ClienteId,
                x.Identificacion,
                x.Nombre,
                x.Correo,
                x.Telefono
            }).ToListAsync();

            lblCantidad.Text = dgvClientes.Rows.Count.ToString();

            DataGridViewColumn column = dgvClientes.Columns[0];

            column.Width = 40;
            funciones.ResetForm(panelFormulario);
            btnRestore.Visible = false;
            txtFecha.Text      = DateTime.Today.ToString("dd/MM/yyyy");
            chbActivo.Checked  = true;
            txtFecha.Text      = DateTime.Today.ToString("dd/MM/yyyy");

            if (clienteId > 0)
            {
                await Editar((int)dgvClientes.SelectedRows[0].Cells[0].Value);
            }
        }
Beispiel #2
0
        private async void btnGuardar_Click(object sender, EventArgs e)
        {
            if (interesId > 0)
            {
                var interes = await _context.Interes.FindAsync(interesId);

                interes.Igual                 = txtIgual.Text == "Igual que" ? 0 : int.Parse(txtIgual.Text);
                interes.Mayor                 = txtMayor.Text == "Mayor que" ? 0 : int.Parse(txtMayor.Text);
                interes.Menor                 = txtMenor.Text == "Menor que" ? 0 : int.Parse(txtMenor.Text);
                interes.Nombre                = txtNombre.Text;
                interes.Porcentaje            = txtValor.Text == "Porcentaje" ? 0 : double.Parse(txtValor.Text);
                interes.Bodega                = txtBodega.Text == "Bodega" ? 0 : double.Parse(txtBodega.Text);
                interes.Activo                = chbActivo.Checked;
                _context.Entry(interes).State = EntityState.Modified;
            }
            else
            {
                if (!funciones.Validate(txtNombre, lblNombre))
                {
                    return;
                }
                if (!funciones.ValidateNum(txtValor, lblValor))
                {
                    return;
                }


                var interes = new Interes
                {
                    Igual      = txtIgual.Text == "Igual que" ? 0 : int.Parse(txtIgual.Text),
                    Mayor      = txtMayor.Text == "Mayor que" ? 0 : int.Parse(txtMayor.Text),
                    Menor      = txtMenor.Text == "Menor que" ? 0 : int.Parse(txtMenor.Text),
                    Bodega     = txtBodega.Text == "Bodega" ? 0 : double.Parse(txtBodega.Text),
                    Nombre     = txtNombre.Text,
                    Activo     = chbActivo.Checked,
                    Porcentaje = txtValor.Text == "Porcentaje" ? 0 : double.Parse(txtValor.Text),
                };

                _context.Interes.Add(interes);
            }

            await _context.SaveChangesAsync();

            await LoadData();

            interesId = 0;
            funciones.ResetForm(panelFormulario);
            MessageBox.Show("Datos guardados correctamente");
        }
Beispiel #3
0
        private async void btnGuardar_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Validate(txtNombre, lblNombre))
                {
                    return;
                }
                if (!Validate(txtUsuario, lblUsuario))
                {
                    return;
                }
                if (!Validate(txtPassword, lblPassword))
                {
                    return;
                }
                if (!Validate(txtPIN, lblPIN))
                {
                    return;
                }

                if (cbPerfil.Text == "Perfil")
                {
                    MessageBox.Show("Seleccione el perfil del empleado", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (empleadoId == 0)
                {
                    if (_context.User.Where(d => d.Codigo == txtPIN.Text || d.Usuario == txtUsuario.Text).Count() > 0)
                    {
                        MessageBox.Show("Debe seleccionar un PIN diferente", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    var empleado = new Empleado
                    {
                        EmpleadoId = empleadoId,
                        Nombre     = GetValue(txtNombre, lblNombre),
                        Telefono   = GetValue(txtTelefono, lblTelefono),
                        Correo     = GetValue(txtCorreo, lblCorreo),
                        Activo     = chbActivo.Checked,
                        Usuario    = GetValue(txtUsuario, lblUsuario)
                    };

                    var user = new User
                    {
                        Activo   = chbActivo.Checked,
                        Usuario  = txtUsuario.Text,
                        Codigo   = txtPIN.Text,
                        Password = txtPassword.Text,
                        PerfilId = GetPerfilId(cbPerfil.Text)
                    };

                    _context.Empleados.Add(empleado);
                    _context.User.Add(user);
                }
                else
                {
                    var empleado = _context.Empleados.Find(empleadoId);
                    var user     = await _context.User.SingleOrDefaultAsync(u => u.Usuario == empleado.Usuario);

                    empleado.Correo   = txtCorreo.Text;
                    empleado.Nombre   = txtNombre.Text;
                    empleado.Telefono = txtTelefono.Text;
                    empleado.Activo   = chbActivo.Checked;
                    empleado.Usuario  = txtUsuario.Text;

                    if (user != null)
                    {
                        user.Activo  = chbActivo.Checked;
                        user.Usuario = txtUsuario.Text;
                        if (user.Codigo != txtPIN.Text)
                        {
                            if (_context.User.Where(d => d.Codigo == txtPIN.Text || d.Usuario == txtUsuario.Text).Count() > 0)
                            {
                                MessageBox.Show("Debe seleccionar un PIN diferente", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                                txtPIN.Text = user.Codigo;
                                return;
                            }
                        }
                        user.Codigo   = txtPIN.Text;
                        user.Password = txtPassword.Text;
                        user.PerfilId = GetPerfilId(cbPerfil.Text);

                        _context.Entry(user).State = EntityState.Modified;
                    }
                    else
                    {
                        user = new User
                        {
                            Activo   = chbActivo.Checked,
                            Usuario  = txtUsuario.Text,
                            Codigo   = txtPIN.Text,
                            Password = txtPassword.Text,
                            PerfilId = GetPerfilId(cbPerfil.Text)
                        };

                        _context.User.Add(user);
                    }

                    _context.Entry(empleado).State = EntityState.Modified;
                }
                await _context.SaveChangesAsync();
                await LoadData();

                funciones.ResetForm(panelFormulario);
                empleadoId = 0;
                MessageBox.Show("Datos guardados correctamente", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }