Beispiel #1
0
        private void frmPerfiles_Load(object sender, EventArgs e)
        {
            /// _tipoOperacion CONSULTA = 1, EDICION = 2
            if (_tipoOperacion == GLOBALES.CONSULTAR || _tipoOperacion == GLOBALES.MODIFICAR)
            {
                cnx = new MySqlConnection();
                cnx.ConnectionString = cdn;
                cmd            = new MySqlCommand();
                cmd.Connection = cnx;
                ph             = new Perfil.Core.PerfilesHelper();
                ph.Command     = cmd;

                Perfil.Core.Perfiles p = new Perfil.Core.Perfiles();
                p.idperfil = _idperfil;
                List <Perfil.Core.Perfiles> lstPerfil;

                Autorizaciones.Core.Autorizacion auth = new Autorizaciones.Core.Autorizacion();
                auth.idperfil = _idperfil;
                List <Autorizaciones.Core.Autorizacion> lstAutorizacion;

                try
                {
                    cnx.Open();
                    lstPerfil = ph.obtenerPerfile(p);
                    cnx.Close();
                    cnx.Dispose();

                    for (int i = 0; i < lstPerfil.Count; i++)
                    {
                        txtNombre.Text = lstPerfil[i].nombre;
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                }

                if (_tipoOperacion == GLOBALES.CONSULTAR)
                {
                    toolTitulo.Text = "Consulta Perfil";
                    GLOBALES.INHABILITAR(this, typeof(TextBox));
                }
                else
                {
                    toolTitulo.Text = "Edición Perfil";
                }
            }
        }
Beispiel #2
0
        private void Guardar(int tipoGuardar)
        {//SE VALIDA SI TODOS LOS TEXTBOX HAN SIDO LLENADOS.
         //string control = GLOBALES.VALIDAR(this, typeof(TextBox));
         //if (!control.Equals(""))
         //{
         //    MessageBox.Show("Falta el campo: " + control, "Información");
         //    return;
         //}

            int idperfil;

            cnx = new MySqlConnection();
            cnx.ConnectionString = cdn;
            cmd            = new MySqlCommand();
            cmd.Connection = cnx;

            ph         = new Perfil.Core.PerfilesHelper();
            ph.Command = cmd;

            ///ASIGNACION DEL NOMBRE DEL PERFIL A LA CLASE PERFILES
            Perfil.Core.Perfiles p = new Perfil.Core.Perfiles();
            p.nombre = txtNombre.Text;

            ///ASIGNACION DE LOS CHECKBOXES A LA CLASE AUTORIZACION
            List <Autorizaciones.Core.Autorizacion> lstAutorizacion = new List <Autorizaciones.Core.Autorizacion>();

            var controls = this.Controls.Cast <Control>();

            foreach (Control c in controls.Where(c => c.GetType() == typeof(CheckBox)))
            {
                Autorizaciones.Core.Autorizacion a = new Autorizaciones.Core.Autorizacion();
                switch ((c as CheckBox).Text)
                {
                case "Recursos Humanos":
                    a.idacceso = 1;
                    a.acceso   = int.Parse(chkRecursosHumanos.Checked.ToString());
                    break;

                case "Seguro Social":
                    a.idacceso = 2;
                    a.acceso   = int.Parse(chkSeguroSocial.Checked.ToString());
                    break;

                case "Contratos":
                    a.idacceso = 3;
                    a.acceso   = int.Parse(chkContratos.Checked.ToString());
                    break;

                case "Nominas":
                    a.idacceso = 4;
                    a.acceso   = int.Parse(chkNominas.Checked.ToString());
                    break;

                case "Catálogos":
                    a.idacceso = 5;
                    a.acceso   = int.Parse(chkCatalogos.Checked.ToString());
                    break;

                case "Configuración":
                    a.idacceso = 6;
                    a.acceso   = int.Parse(chkConfiguracion.Checked.ToString());
                    break;
                }
                lstAutorizacion.Add(a);
            }

            switch (_tipoOperacion)
            {
            case 0:
                try
                {
                    cnx.Open();
                    ph.insertaPerfil(p);
                    idperfil = (int)ph.obtenerIdPerfil(p);
                    auth.insertaAutorizacion(idperfil, lstAutorizacion);
                    cnx.Close();
                    cnx.Dispose();

                    if (OnNuevoPerfil != null)
                    {
                        OnNuevoPerfil(0);
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                }
                break;

            case 2:
                try
                {
                    cnx.Open();
                    p.idperfil = _idperfil;
                    ph.actualizaPerfil(p);
                    cnx.Close();
                    cnx.Dispose();

                    if (OnNuevoPerfil != null)
                    {
                        OnNuevoPerfil(2);
                    }
                }
                catch (Exception error)
                {
                    MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                }
                break;
            }

            switch (tipoGuardar)
            {
            case 0:
                limpiar(this, typeof(TextBox));
                break;

            case 1:
                this.Dispose();
                break;
            }
        }
Beispiel #3
0
        private void Guardar(int tipoGuardar)
        {
            //SE VALIDA SI TODOS LOS TEXTBOX HAN SIDO LLENADOS.
            //string control = GLOBALES.VALIDAR(this, typeof(TextBox));
            //if (!control.Equals(""))
            //{
            //    MessageBox.Show("Falta el campo: " + control, "Información");
            //    return;
            //}

            int idperfil;

            cnx = new SqlConnection();
            cnx.ConnectionString = cdn;
            cmd = new SqlCommand();
            cmd.Connection = cnx;

            ph = new Perfil.Core.PerfilesHelper();
            ph.Command = cmd;

            auth = new Autorizaciones.Core.AutorizacionHelper();
            auth.Command = cmd;

            ///ASIGNACION DEL NOMBRE DEL PERFIL A LA CLASE PERFILES
            Perfil.Core.Perfiles p = new Perfil.Core.Perfiles();
            p.nombre = txtNombre.Text;

            ///ASIGNACION DE LOS CHECKBOXES A LA CLASE AUTORIZACION
            List<Autorizaciones.Core.Autorizacion> lstAutorizacion = new List<Autorizaciones.Core.Autorizacion>();

            var controls = this.Controls.Cast<Control>();
            foreach (Control c in controls.Where(c => c.GetType() == typeof(CheckBox)))
            {
                Autorizaciones.Core.Autorizacion a = new Autorizaciones.Core.Autorizacion();
                switch ((c as CheckBox).Text)
                {
                    case "Recursos Humanos":
                        a.idacceso = 1;
                        a.acceso = chkRecursosHumanos.Checked;
                        break;
                    case "Seguro Social":
                        a.idacceso = 2;
                        a.acceso = chkSeguroSocial.Checked;
                        break;
                    case "Nominas":
                        a.idacceso = 3;
                        a.acceso = chkNominas.Checked;
                        break;
                    case "Catálogos":
                        a.idacceso = 4;
                        a.acceso = chkCatalogos.Checked;
                        break;
                    case "Configuración":
                        a.idacceso = 5;
                        a.acceso = chkConfiguracion.Checked;
                        break;
                }
                lstAutorizacion.Add(a);
            }

            switch (_tipoOperacion)
            {
                case 0:
                    try
                    {
                        cnx.Open();
                        ph.insertaPerfil(p);
                        idperfil = (int)ph.obtenerIdPerfil(p);
                        auth.insertaAutorizacion(idperfil, lstAutorizacion);
                        cnx.Close();
                        cnx.Dispose();

                        if (OnNuevoPerfil != null)
                            OnNuevoPerfil(0);
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
                case 2:
                    try
                    {
                        cnx.Open();
                        p.idperfil = _idperfil;
                        ph.actualizaPerfil(p);
                        auth.actualizaAutorizacion(_idperfil, lstAutorizacion);
                        cnx.Close();
                        cnx.Dispose();

                        if (OnNuevoPerfil != null)
                            OnNuevoPerfil(2);
                    }
                    catch (Exception error)
                    {
                        MessageBox.Show("Error: \r\n \r\n " + error.Message, "Error");
                    }
                    break;
            }

            switch (tipoGuardar)
            {
                case 0:
                    limpiar(this, typeof(TextBox));
                    break;
                case 1:
                    this.Dispose();
                    break;
            }
        }