Пример #1
0
        private void btnCrear_Click(object sender, EventArgs e)
        {
            bool   error         = false;
            bool   errorPermisos = false;
            string errorMsg      = "";

            string rolNombre      = txtNombre.Text;
            string rolDescripcion = txtDescripcion.Text;

            if (String.IsNullOrWhiteSpace(rolNombre) || String.IsNullOrWhiteSpace(rolDescripcion))
            {
                error    = true;
                errorMsg = "Rellene todos los campos requeridos.";
            }

            if (error)
            {
                fo.MostrarLabelMsg(lblResultadoMsg, errorMsg, error = true);
            }

            else
            {
                int insertedRolId = sp.InsertRol(rolNombre, rolDescripcion);

                if (insertedRolId > 0)
                {
                    int cb = 0;

                    foreach (DataRowView tarea in clbRolPermisos.Items)
                    {
                        int tareaId   = int.Parse(tarea["id"].ToString());
                        int permitido = Convert.ToInt32(clbRolPermisos.GetItemChecked(cb));

                        int i = sp.InsertPermiso(insertedRolId, tareaId, permitido);

                        if (i == 0)
                        {
                            errorPermisos = true;
                        }

                        cb++;
                    }
                }

                if (insertedRolId > 0 && !errorPermisos)
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Rol creado exitosamente.");
                    fo.LimpiarForm();
                    fo.LimpiarCheckedListBox(clbRolPermisos);
                }

                else if (insertedRolId > 0 && errorPermisos)
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Rol creado, pero hubo errores almacenando los permisos.", error = true);
                    fo.LimpiarForm();
                    fo.LimpiarCheckedListBox(clbRolPermisos);
                }

                else
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Ocurrió un error al crear el rol. Intente nuevamente.", error = true);
                }
            }
        }
Пример #2
0
        private void btnCrear_Click(object sender, EventArgs e)
        {
            bool   error    = false;
            string errorMsg = "";

            string doc      = txtDocumento.Text;
            string nombre   = txtNombre.Text;
            string apellido = txtApellido.Text;
            string telefono = txtTelefono.Text;
            string correo   = txtCorreo.Text;

            int rolId     = int.Parse(cmbRol.SelectedValue.ToString());
            int tipoDocId = int.Parse(cmbTipoDoc.SelectedValue.ToString());

            string pass1 = txtContrasena1.Text;
            string pass2 = txtContrasena2.Text;

            if (telefono.Length != 10)
            {
                error    = true;
                errorMsg = "El número de teléfono es inválido.";
            }

            if (!correo.Contains("@") && !correo.Contains("."))
            {
                error    = true;
                errorMsg = "El formato de correo es inválido.";
            }

            if (!String.IsNullOrWhiteSpace(pass1) && !String.IsNullOrWhiteSpace(pass2))
            {
                if (pass1 != pass2)
                {
                    error    = true;
                    errorMsg = "La contraseña no coincide.";
                }
            }

            if (String.IsNullOrWhiteSpace(doc) || String.IsNullOrWhiteSpace(nombre) || String.IsNullOrWhiteSpace(apellido) || String.IsNullOrWhiteSpace(telefono) || String.IsNullOrWhiteSpace(correo) || String.IsNullOrWhiteSpace(pass1) || String.IsNullOrWhiteSpace(pass2))
            {
                error    = true;
                errorMsg = "Rellene todos los campos requeridos.";
            }

            if (error)
            {
                fo.MostrarLabelMsg(lblResultadoMsg, errorMsg, error = true);
            }

            else
            {
                int i = sp.InsertEmpleado(rolId, tipoDocId, doc, nombre, apellido, telefono, correo, pass1);

                if (i > 0)
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Usuario creado exitosamente.");
                    fo.LimpiarForm();
                }

                else
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Ocurrió un error al crear el usuario. Intente nuevamente.", error = true);
                }
            }
        }
Пример #3
0
        private void btnCrearCliente_Click(object sender, EventArgs e)
        {
            bool   error    = false;
            string errorMsg = "";

            int tipoClienteId = int.Parse(cmbTipo.SelectedValue.ToString());
            int tipoDocId     = int.Parse(cmbTipoDoc.SelectedValue.ToString());

            string doc       = txtDocumento.Text;
            string nombre    = txtNombre.Text;
            string apellido  = txtApellido.Text;
            string direccion = txtDireccion.Text;
            string telefono  = txtTelefono.Text;
            string correo    = txtCorreo.Text;

            string fechaDia = "";
            string fechaMes = "";
            string fechaAno = txtFechaAno.Text;

            int fechaDiaInt = 0;
            int fechaMesInt = 0;
            int fechaAnoInt = 0;

            if (cmbFechaDia.SelectedItem != null)
            {
                fechaDia = cmbFechaDia.SelectedItem.ToString();
            }
            if (cmbFechaMes.SelectedItem != null)
            {
                fechaMes = cmbFechaMes.SelectedItem.ToString();
            }

            if (telefono.Length != 10)
            {
                error    = true;
                errorMsg = "El número de teléfono es inválido.";
            }

            if (!correo.Contains("@") && !correo.Contains("."))
            {
                error    = true;
                errorMsg = "El formato de correo es inválido.";
            }

            if (!String.IsNullOrWhiteSpace(fechaDia) && !String.IsNullOrWhiteSpace(fechaMes))
            {
                fechaDiaInt = int.Parse(fechaDia);
                fechaMesInt = cmbFechaMes.SelectedIndex + 1;
            }

            if (!String.IsNullOrWhiteSpace(fechaAno))
            {
                if (int.TryParse(fechaAno, out int ano))
                {
                    fechaAnoInt = ano;
                }

                else
                {
                    error    = true;
                    errorMsg = "El año de nacimiento es inválido.";
                }
            }

            if (String.IsNullOrWhiteSpace(doc) || String.IsNullOrWhiteSpace(nombre) || String.IsNullOrWhiteSpace(apellido) || String.IsNullOrWhiteSpace(direccion) || String.IsNullOrWhiteSpace(telefono) || String.IsNullOrWhiteSpace(correo))
            {
                error    = true;
                errorMsg = "Rellene todos los campos requeridos.";
            }

            if (error)
            {
                fo.MostrarLabelMsg(lblResultadoMsg, errorMsg, error = true);
            }

            else
            {
                int i;

                if (fechaDiaInt > 0 && fechaMesInt > 0 && fechaAnoInt > 0)
                {
                    i = sp.InsertCliente(tipoClienteId, tipoDocId, doc, nombre, apellido, direccion, telefono, correo, fechaDiaInt, fechaMesInt, fechaAnoInt);
                }

                else if (fechaDiaInt > 0 && fechaMesInt > 0 && fechaAnoInt == 0)
                {
                    i = sp.InsertCliente(tipoClienteId, tipoDocId, doc, nombre, apellido, direccion, telefono, correo, fechaDiaInt, fechaMesInt);
                }

                else
                {
                    i = sp.InsertCliente(tipoClienteId, tipoDocId, doc, nombre, apellido, direccion, telefono, correo);
                }

                if (i > 0)
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Cliente creado exitosamente.");
                    fo.LimpiarForm();
                }

                else
                {
                    fo.MostrarLabelMsg(lblResultadoMsg, "Ocurrió un error al crear el cliente. Intente nuevamente.", error = true);
                }
            }
        }