示例#1
0
        private void EditRol_Click(object sender, RoutedEventArgs e)
        {
            //Get button control
            Button Control = (Button)sender;

            string rolid = NovaAPI.APIRoles.userrols.Find(x => x.rolid == Control.Tag.ToString()).rolid;

            if (rolid == "1")
            {
                MessageBox.Show("No se puede editar el rol de administrador del sistema");
                return;
            }

            if (FormGrid.Opacity == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
            }

            //Set rol information to controls
            RolNameTX.Text     = NovaAPI.APIRoles.userrols.Find(x => x.rolid == Control.Tag.ToString()).rolname;
            RolDescriptTX.Text = NovaAPI.APIRoles.userrols.Find(x => x.rolid == Control.Tag.ToString()).roldescription;

            EditPermBT.IsEnabled = true;

            //Set selected rol id index for edition save
            SelectedIndex = Control.Tag.ToString();

            //Focus editable rol
            RolNameTX.Focus();
            SaveBT.IsEnabled = true;
        }
示例#2
0
        private void NewRolBT_Click(object sender, RoutedEventArgs e)
        {
            //From grid animation
            if (FormGrid.Opacity == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
                RolNameTX.Focus();
                SaveBT.IsEnabled = true;
            }
            else if (RolNameTX.Text.Length == 0)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                SaveBT.IsEnabled = false;
            }

            //Clear rol values
            if (RolNameTX.Text.Length > 0)
            {
                ResetForm();
            }
        }
示例#3
0
        private async void SaveRolBT_Click(object sender, RoutedEventArgs e)
        {
            NewRolBT.Focus();

            if (RolNameTX.Text.Length == 0 || RolNameTX.Text.Length < 5)
            {
                MessageBox.Show("El nombre del rol no puede estar en blanco o ser inferior a 5 caracteres");
                RolNameTX.Focus();
                return;
            }

            //Get rol parameters
            var Data = new rolData();

            Data.id          = SelectedIndex;
            Data.name        = RolNameTX.Text;
            Data.description = RolDescriptTX.Text;

            //rol json data
            string requestData = JsonConvert.SerializeObject(Data);

            bool response;

            //Modify / Create request
            if (Data.id.Length > 0)
            {
                response = await NovaAPI.APIRoles.GetValues("2", DataConfig.LocalAPI, requestData);
            }
            else
            {
                response = await NovaAPI.APIRoles.GetValues("1", DataConfig.LocalAPI, requestData);
            }

            //Request response
            if (response)
            {
                if (Data.id.Length > 0)
                {
                    //On role modified
                    NovaAPI.APIRoles.userrols.Find(x => x.rolid == Data.id).rolname        = Data.name;
                    NovaAPI.APIRoles.userrols.Find(x => x.rolid == Data.id).roldescription = Data.description;

                    RolGrid.Items.Refresh();
                    FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetForm();
                    SaveBT.IsEnabled = false;
                }
                else
                {
                    //On new rol created response
                    var newRol = new NovaAPI.APIRoles.Rols();
                    newRol.rolname        = Data.name;
                    newRol.roldescription = Data.description;
                    newRol.rolid          = NovaAPI.APIRoles.LastID;
                    newRol.usercount      = "0";

                    //CREATE ROL DEFAULT PERMISSION DATA

                    FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetForm();

                    NovaAPI.APIRoles.userrols.Add(newRol);

                    //Reload rol data
                    LoadData();
                    SaveBT.IsEnabled = false;
                }
            }
            else
            {
                MessageBox.Show($"Error al crear el rol, INFO: {Environment.NewLine}{NovaAPI.APIRoles.Message}");
            }
        }