mercredi 1 juillet 2015

Handling similar checkbox values in .NET Web App

List<char> errorList = new List<char>();
        if (meetingErrorCheckBox.Checked)
            errorList.Add('M');
        if (ScheduledMachineDowntimeCheckBox.Checked)
            errorList.Add('S');
        if (ToolingCheckbox.Checked)
            errorList.Add('T');
        if (ProcessIssueCheckBox.Checked)
            errorList.Add('P');
        if (OperatorMaintenanceCheckBox.Checked)
            errorList.Add('O');
        if (VactionCheckBox.Checked)
            errorList.Add('V');
        if (CellLeadCheckBox.Checked)
            errorList.Add('C');
        if (WaitToolsCheckBox.Checked)
            errorList.Add('W');
        if (UnscheduledMaintenanceCheckBox.Checked)
            errorList.Add('U');
        if (WaitMaterialCheckBox.Checked)
            errorList.Add('A');
        if (WaitInspectionCheckBox.Checked)
            errorList.Add('I');
        if(AlternateDepartmentCheckBox.Checked)
            errorList.Add('D');
        if (TrainingCheckBox.Checked)
            errorList.Add('B');

Is there any way to make this.. cleaner? I thought about like using an interface or something, but it seems like there isn't an easier way with .NET Web Forms and the asp:CheckBox.

Basically I'm using this list to fill an intermediate table between 2 tables in a database and I'm wondering of there's a better way, since I still need to do a check on which box was checked regardless if I can iterate through all the boxes.




Aucun commentaire:

Enregistrer un commentaire