1. C# / Говнокод #17960

    +133

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("");
    else if (textBox[0].Text != "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%'", textBox[0].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%'", textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%'", textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0}", textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("group={0}", textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%'", textBox[0].Text, textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%'", textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1}", textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0} and group={1}", textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%'", textBox[0].Text, textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2}", textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1} and group={2}", textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2} and group={3}", textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3} and group={4}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);

    "Есть 5 текстовых полей и желание понять, как можно в зависимости от пустоты или заполненности этих полей, одного или нескольких создать малое количество операторов if else"

    Порадовало "малое количество"

    Запостил: Psilon, 08 Апреля 2015

    Комментарии (50) RSS

    Добавить комментарий