Exemple #1
0
        private void button3_Click(object sender, EventArgs e)
        {
            string controlID = string.Empty;
            int    roleID    = 0;

            try
            {
                string[] node = PermissionTree.SelectedNode.FullPath.Split(':');
                string[] nameForm;
                if (node.Length > 1)
                {
                    if (!ByRoleRB.Checked)
                    {
                        nameForm = node[1].Split('-');

                        var roleId = this.controlSecurityDataSet1.Roles.Where(u => u.RoleName == nameForm[1].ToString()).Select(s => s.RoleID);

                        foreach (var item in roleId)
                        {
                            roleID = item;
                        }

                        string nameForms = nameForm[0].ToString();

                        nameForm  = node[0].Split('\\');
                        controlID = nameForm[0].ToString();

                        SqlParameter[] ParamSQl = GuardarDatos.Parametros_Update_Rol(roleID, nameForms, controlID, InVisible.Checked ? 1 : 0, Disabled.Checked ? 1 : 0, checkBox1.Checked ? 1 : 0, checkBox2.Checked ? 1 : 0, checkBox4.Checked ? 1 : 0);

                        GuardarDatos Guardar = new GuardarDatos();

                        bool rowsInserted = Guardar.booleano("spUpdateControlToRole", ParamSQl);

                        if (!rowsInserted)
                        {
                            DisplayError(controlID, roleID, "Registros insertados= " + rowsInserted.ToString());
                        }
                        else
                        {
                            MessageBox.Show("Registro actualizado con exito!");
                        }
                    }
                    else
                    {
                        nameForm = node[0].Split('-');
                        string[] nameForm1 = nameForm[0].ToString().Split('\\');
                        var      roleId    = this.controlSecurityDataSet1.Roles.Where(u => u.RoleName == nameForm1[0].ToString()).Select(s => s.RoleID);

                        foreach (var item in roleId)
                        {
                            roleID = item;
                        }

                        string nameForms = nameForm[0].ToString();

                        nameForm  = node[1].Split('-');
                        nameForms = nameForm[0].ToString();
                        controlID = nameForm[1].ToString();

                        SqlParameter[] ParamSQl = GuardarDatos.Parametros_Update_Rol(roleID, nameForms, controlID, InVisible.Checked ? 1 : 0, Disabled.Checked ? 1 : 0, checkBox1.Checked ? 1 : 0, checkBox2.Checked ? 1 : 0, checkBox4.Checked ? 1 : 0);

                        GuardarDatos Guardar = new GuardarDatos();

                        bool rowsInserted = Guardar.booleano("spUpdateControlToRole", ParamSQl);

                        if (!rowsInserted)
                        {
                            DisplayError(controlID, roleID, "Registros insertados= " + rowsInserted.ToString());
                        }
                        else
                        {
                            MessageBox.Show("Registro actualizado con exito!");
                        }
                    }


                    LlenarLog.Registro(DateTime.Now, this.Usuario, this.IpLocal, this.IpPublica, this.SerialHDD, Environment.MachineName, "Modifiación de permisos", "Asignación de permisos");
                }
            }
            catch (Exception ex)
            {
                DisplayError(controlID, roleID, ex.Message);
            }

            PopulatePermissionTree();
        }