Relate Check Boxes to Radio Buttons

Asked

Viewed 282 times

1

I’m with a project where I have to put occurrences. This is a school project. So the occurrences would be like this: An occurrence would be a warning or a suspension, and its causes, that is, messed up in class, cursed teacher, did not do duty etc. My question is: How to relate these elements ? I say the radio button with the check box. Remembering that I already have the student model, and how to relate this in the student ? I mean, creating another table in the bank and relating the two ? Or can we do this in one table and how popular it is the right way ? And how can I put a status on this occurrence ? I say whether or not the occurrence has been solved, like: Status -> Pending, to know that it has not solved, and -> Solved, if it has already been resolved. Remembering that I want to be editable also this occurrence.

Summarizing I wanted to register and then display, in case you want to edit is also possible and delete too !

Here the code I put (HTML: using bootstrap cllapse):

<div class="panel-group" id="accordion">
<div class="panel panel-default">
    <div class="panel-heading">
        <h4 class="panel-title">
            <a data-toggle="collapse" data-parent="#accordion" href="#ocorrencias">
                Ocorrências do Aluno
            </a>
        </h4>
    </div>

    <div id="ocorrencias" class="panel-collapse collapse in">
        <div class="panel-body">
            <div class="radio-inline">
                <label class="radio-inline">
                    <input type="radio" value="Advertencia" id="Advertencia" />
                    Advertência
                </label>
                <label class="radio-inline">
                    <input type="radio" value="Suspensao" id="Suspensao" />
                    Suspensão por: <input type="text" class="col-xs-1" name="dias" id="dias"/> dias.
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="atividade" id="atividade" value="" checked>
                    Estar deixando de fazer as atividades discentes ou não ter concluido a mesma
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="material" id="material" value="">
                    Não trazer o material necessario para as aulas do dia
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="uniforme" id="uniforme" value="">
                    Não estar devidamente uniformizado
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="conversa" id="conversa" value="">
                    Estar conversando excessivamente em sala de aula
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="atrapalhando" id="atrapalhando" value="">
                    Estar brincando e atrapalhando os colegarr em sala de aula
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="atividadesDocentes" id="atividadesDocentes" value="">
                    Estar impedindo as atividades docentes
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="brincando" id="brincando" value="">
                    Estar com brincadeira de mau gosto na escola <input type="text" name="motivo" id="motivo"/>
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="aula" id="aula" value="">
                    Estar frequentemente "matando aula" ou chegando atrasado
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="fugindo" id="fugindo" value="">
                    Ter saído da escola sem autorização, fugiu ás <input type="text" name="hora" id="hora"/>
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="foraDeSala" id="foraDeSala" value="">
                    Estar fora da sala de aulas <input type="text" name="fora" id="fora"/>
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="agredido" id="agredido" value="">
                    Ter agredido, faltado com o devido respeito aos colegas <input type="text" name="respeito" id="respeito" />
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="respeito" id="respeito" value="">
                    Ter faltado com respeito ao professor
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="equipamentos" id="equipamentos" value="">
                    Estar usando equipamentos eletro-eletrônicos em sala de aula <input type="text" name="equipamentos" id="equipamentos" />
                </label>
            </div>

            <div class="checkbox">
                <label>
                    <input type="checkbox" name="outros" id="outros" value="">
                    Outros <textarea name="outros" id="outros"></textarea>
                </label>
            </div>

            <div class="form-group">
                <input type="submit" value="Salvar" class="btn btn-success" />
            </div>

        </div>
    </div>
</div>

And here’s my model(Student.Cs):

 public long Id { get; set; }

    [Required(ErrorMessage = "O nome do aluno é obrigatório")]
    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Aluno")]
    public string Nome { get; set; }

    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Pai")]
    public string NomePai { get; set; }

   // [Required(ErrorMessage = "O nome da mãe é obrigatório")]
    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome da Mãe")]
    public string NomeMae { get; set; }

    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Responsável")]
    public string NomeResponsavel { get; set; }

   // [Required(ErrorMessage = "O endereço é obrigatório")]
    [MinLength(10, ErrorMessage = "O endereço deve ter no mínimo 10 caracteres")]
    [Display(Name = "Endereço")]
    public string Endereco { get; set; }

   // [Required(ErrorMessage = "A data de nascimento é obrigatória")]
    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    [Display(Name = "Data de Nascimento")]
    public DateTime DataDeNascimento { get; set; }

    [MaxLength(4, ErrorMessage = "O ano letivo deve ter no máximo 4 caracteres: AAAA ")]
    [Display(Name = "Ano Letivo")]
    public string AnoLetivo { get; set; }

    [Required(ErrorMessage = "Informe o ano que o aluno está cursando")]
    public int Ano { get; set; }

    [Required(ErrorMessage = "Informe a turma do aluno")]
    public string Turma { get; set; }

   // [Required(ErrorMessage = "Informe o numero da turma")]
    public int Numero { get; set; }

    [Required(ErrorMessage = "informe o turno")]
    public string Turno { get; set; }

    //[Required(ErrorMessage="O telefone é obrigatório")]
    [Display(Name="Telefone")]
    public string Telefone { get; set; }

    [Display(Name="Telefone Alternativo")]
    public string TelefoneContato { get; set; }

    [Display(Name="Telefone Responsável")]
    public string TelefoneResponsavel { get; set; }

    [Display(Name = "Foto")]
    public string Foto { get; set; }

If I have to, I’ll put my controller !

  • If anyone has another answer, feel free ! Ideas are always welcome !

2 answers

1


I would do so:

  • An Occurrences Model for the Pupil (name suggestion: Hallucination) of cardinality N, i.e., his model of Pupil would look like this:

    public class Aluno {
        /* Aqui vão todas as propriedades já mencionadas */
    
        public virtual ICollection<AlunoOcorrencia> AlunoOcorrencias {get;set;}
    }
    
  • A Model Hallucination:

    public class AlunoOcorrencia {
        [Key]
        public long AlunoOcorrenciaId {get;set;}
    
        [Required]
        public TipoOcorrencia TipoOcorrencia {get;set;}
    
        /* Coloque aqui mais propriedades */
    }
    
  • Type would be a Enum:

    namespace SeuProjeto.Enums {
        public enum TipoOcorrencia {
            BaguncaSala, 
            DesacatoProfessor,
            NaoEntregouDeverDeCasa
        }
    }
    
  • Type in View (Razor):

    @Html.RadioButtonFor(model => model.TipoOcorrencia, Enums.TipoOcorrencia.BaguncaSala) Bagunça em Sala
    @Html.RadioButtonFor(model => model.DesacatoProfessor, Enums.TipoOcorrencia.BaguncaSala) Desacato ao Professor
    @Html.RadioButtonFor(model => model.NaoEntregouDeverDeCasa, Enums.TipoOcorrencia.BaguncaSala) Não Entregou Dever de Casa
    
  • CheckBoxes in View (Razor):

    CheckBoxes is already much more complicated to put, but it is possible using a component called Mvccheckboxlist. To answer not be too extensive, I will pass the link of a tutorial for you to check if the component meets your need: http://www.codeproject.com/Tips/613785/How-to-Use-CheckBoxListFor-With-ASP-NET-MVC

  • There in the class Alunoocorrencia would also have to have the occurrence, I say: Suspension or Warning also right ? And on suspension, for how many days the student was suspended. And I was messing with Num, and I had a lot of trouble. And how would I show what has already been registered of the occurrence ? Another screen with the values ?

  • What problems with Enum have you had? What I had imagined is that a record of the occurrence would have all the values about the occurrence. Then it would be the case that you work better this model.

  • Dude, when it was time to drop a few dropdowns (year, shift and class that you have there in the model) it worked, registration, everything in a good way. But when I wanted to edit the data, when it was time to load the saved data, the enums came back with default values and if I changed, I saved the edit with the default values. And it got in the way, because the user had to change it all the time.

  • @There is something wrong with the components that go on screen. How this was being done?

  • I carried the enums in the view and threw the values in the combos. Only when editing, in a I know what I did that the values that were registered, did not return and yes the default values.

  • Possibly because Modelbinder was not recognizing the values. I think the ideal would be to resolve this separately. I suggest you ask another question showing how you do to popular these values in View.

  • I made a list, and in the Edit controller, I pulled the values selected by the user. But returning the question here, how would I relate the radio Buttons and check boxes and popular in these models and records in the bank ? Would have a clue how I do ?

  • @Érikthiago I’ll edit the question for you.

  • OK. Quiet ! I will edit the question only in the html part, because I reversed the radios and checkes

  • @Érikthiago See now.

  • I see here the link. It got too complicated huh ? And another, so I would have to do other views to show what has already been registered and change, list or remove ? And here one could use Checkboxfor not ?

  • @Érikthiago The normal is to use a partial (in MVC it is usually named "_Createoredit.cshtml"). There you do not need to make a View detailed. Just call the partial.

  • I wonder if you could help me chat ?

Show 8 more comments

1

I would do so:

public class Aluno
{
    public long Id { get; set; }

    [Required(ErrorMessage = "O nome do aluno é obrigatório")]
    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Aluno")]
    public string Nome { get; set; }

    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Pai")]
    public string NomePai { get; set; }

    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome da Mãe")]
    public string NomeMae { get; set; }

    [MinLength(3, ErrorMessage = "O nome deve ter no mínimo 3 caracteres")]
    [Display(Name = "Nome do Responsável")]
    public string NomeResponsavel { get; set; }

    [MinLength(10, ErrorMessage = "O endereço deve ter no mínimo 10 caracteres")]
    [Display(Name = "Endereço")]
    public string Endereco { get; set; }

    [DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
    [DataType(DataType.Date)]
    [Display(Name = "Data de Nascimento")]
    public DateTime DataDeNascimento { get; set; }

    [MaxLength(4, ErrorMessage = "O ano letivo deve ter no máximo 4 caracteres: AAAA ")]
    [Display(Name = "Ano Letivo")]
    public string AnoLetivo { get; set; }

    [Required(ErrorMessage = "Informe o ano que o aluno está cursando")]
    public int Ano { get; set; }

    [Required(ErrorMessage = "Informe a turma do aluno")]
    public string Turma { get; set; }

    public int Numero { get; set; }

    [Required(ErrorMessage = "informe o turno")]
    public string Turno { get; set; }

    [Display(Name = "Telefone")]
    public string Telefone { get; set; }

    [Display(Name = "Telefone Alternativo")]
    public string TelefoneContato { get; set; }

    [Display(Name = "Telefone Responsável")]
    public string TelefoneResponsavel { get; set; }

    [Display(Name = "Foto")]
    public string Foto { get; set; }

    //adicionado ao seu exemplo a lista e o construtor
    public ICollection<Ocorrencia> Ocorrencias { get; set; }

    public Aluno()
    {
        this.Ocorrencias = new HashSet<Ocorrencia>();
    }
}

public class Ocorrencia
{
    public int Id { get; set; }

    public int AlunoId { get; set; }
    public virtual Aluno Aluno { get; set; }

    public int OcorrenciaTipoId { get; set; }
    public virtual OcorrenciaTipo OcorrenciaTipo { get; set; }

    public string Descricao { get; set; }

    /**outros campos referente as Ocorrencias*/
}

public class OcorrenciaTipo
{
    public int Id { get; set; }
    public string Descricao { get; set; }

    /**outros campos referente as OcorrenciaTipo*/
}

along with Model Aluno.cs, and as you yourself reported it takes some work with enum, and in that case could have the modifications in OcorrenciaTipo however you wish.

In case there are two more tables to have this control of Occurrences in your system .

  • 1

    I understood and in these descriptions there would be respectively: Warning and Suspension, and the causes: Mess, disrespect and etc right ? And how would I do that in the view? Do I say register view, edit, delete and list, the occurrences of a particular student, ie the student id ? You’d have to do other views and import them ?

  • There are n ways to do this, one with Tabs in the Student’s Dit, another by clicking on a button and redirected to some screen that can insert, change or delete with the Student’s Id, there goes even your creativity ... It has the normal form that ai loads a list of students in a select, I believe to be the most basic but, also be the one that carries a lot of unnecessary information on the screen

  • You can use a Jquery Tabs: http://jqueryui.com/tabs/

  • What happens, I’m putting the photo and this information in the detail part and the removal part right, to be all right and on the other screens as register and edit, only basic information, as name, photo, among others. I thought to put this part of occurrences on the screen of details same, to show the details of the student itself, ie, your information, photos and occurrences. It would be nice to put the list of occurrences there and import the views, I mean, all ?

  • Could be, and then do not need to show all occurrences show 3 until a 5 and a link to a page of occurrences that show all... I would do so

  • Well, that’s great. I’ll try it like this. I even thought it was cool the tabs part, but how would I use them to show the data for editing or removal ? Could you use the same registration tab to load the data? And a glyphicon with a link to remove ? I think it’s better to import the views not ? And another, how to relate there in html, the two things ? I say, The student was suspended for so many days because he was messing around in class...

  • Another thing, how do I put the status of the occurrence ?

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.