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

    +119

    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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    string str;
            if (((str = path) != null) && (str != "basic"))
            {
                if (str == "contact")
                {
                    BindContact();
                    PageTitle = "Contact info";
                    editform.SetActiveView(vi_contact);
                    return;
                }
                if (str == "personal")
                {
                    PageTitle = "More about me";
                    BindPersonal();
                    editform.SetActiveView(vi_personal);
                    return;
                }
                if (str == "career")
                {
                    PageTitle = "Work info";
                    BindCareer();
                    editform.SetActiveView(vi_career);
                    return;
                }
                if (str == "tags")
                {
                    BindTags();
                    PageTitle = "Tags I Follow";
                    editform.SetActiveView(vi_tags);
                    return;
                }
                if (str == "biography")
                {
                    ph_page_title.Visible = false;
                    bind_biography();
                    editform.SetActiveView(vi_biography);
                    return;
                }
                if (str == "pp")
                {
                    ph_picpage_title.Visible = true;
                    ph_page_title.Visible = false;
                    PageTitle = "Edit profile photo";
                    BindProfilePhoto();
                    return;
                }
            }
    
            PageTitle = "Basic info";
            BindBasic();
            editform.SetActiveView(vi_basic);

    switch на диалекте хинди ;[ слава asp.net! убить Мартинса и Фаулера за чистокодную ересь!

    qwertylolman, 28 Марта 2012

    Комментарии (9)
  2. C# / Говнокод #9771

    +114

    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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    private void button8_Click(object sender, EventArgs e)
            {
    
                string fn = "";
                string st = "";
                string value = "";
                string dirfile = "";
                StreamWriter sw;
    
    
                if (textBox1.Text != "")
                {
                    dirfile = textBox1.Text + "\\" + GetFileName(openFileDialog1.FileName) + comboBox1.SelectedValue.ToString() + ".csv";
                    sw = new StreamWriter(dirfile, false, System.Text.Encoding.UTF8);
                }
                else
                {
                    sw = new StreamWriter(openFileDialog1.FileName + comboBox1.SelectedValue.ToString() + ".csv", false, System.Text.Encoding.UTF8);
                }
    
                // Создаем колонки
    
                for (int cl = 0; cl < dt.Columns.Count; cl++)
                {
                    fn = dt.Columns[cl].ColumnName;
    
    
                    if (cl == 0)
                    {
                        st =  fn.Replace("\n", "").Replace(";", "");
                    }
                    else
                    {
                        st += ";" +  fn.Replace("\n", "").Replace(";", "");
                    }
    
    
                }
                sw.WriteLine(st);
    
    
                progressBar1.Minimum = 1;
                progressBar1.Maximum = dt.Rows.Count;
    
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    progressBar1.Value = i + 1;
    
                    Application.DoEvents();
    
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        value = dt.Rows[i][j].ToString();
    
                        if (value == "") { value = " "; }
    
                        try
                        {
                            Convert.ToInt16(value);
                            if (j == 0)
                            {
                                st = value.Replace("\n", "").Replace(";", "");
                            }
                            else
                            {
    
                                st += ";" + value.Replace("\n", "").Replace(";", "");
                            }
                        }
                        catch (System.FormatException exp)
                        {
                            if (j == 0)
                            {
                                st =  value.Replace("\n", "").Replace(";", "");
    
                            }
                            else
                            {
    
                                st += ";" +  value.Replace("\n", "").Replace(";", "") ;
                            }
                        }
                        catch (OverflowException oe)
                        {
                            if (j == 0)
                            {
                                st = value.Replace("\n", "").Replace(";", "");
                            }
                            else
                            {
    
                                st += ";" + value.Replace("\n", "").Replace(";", "");
                            }
                        }
                    }
                    sw.WriteLine(st);
                }
                sw.Close();
                MessageBox.Show("Ok");

    досталось в наследство, сохранение DataTable в CSV :)

    Lokich, 26 Марта 2012

    Комментарии (1)
  3. C# / Говнокод #9770

    +109

    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
    33. 33
    public static MyResultData SqlReturnDataset(string sql, string connection)
                {
                    MyResultData result = new MyResultData();
                    try
                    {
                        MySql.Data.MySqlClient.MySqlConnection connRC = new MySql.Data.MySqlClient.MySqlConnection(connection);
                        MySql.Data.MySqlClient.MySqlCommand commRC = new MySql.Data.MySqlClient.MySqlCommand(sql, connRC);
                        connRC.Open();
    
                        try
                        {
                            MySql.Data.MySqlClient.MySqlDataAdapter AdapterP = new MySql.Data.MySqlClient.MySqlDataAdapter();
                            AdapterP.SelectCommand = commRC;
                            DataSet ds1 = new DataSet();
                            AdapterP.Fill(ds1);
                            result.ResultData = ds1.Tables[0];
                        }
                        catch (Exception ex)
                        {
                            result.HasError = true;
                            result.ErrorText = ex.Message;
                        }
                        connRC.Close();
                    }
                    catch (Exception ex)//Этот эксепшн на случай отсутствия соединения с сервером.
                    {
                        result.ErrorText = ex.Message;
                        result.HasError = true;
                    }
                
                    return result;
    
                }

    Govnisti_Diavol, 26 Марта 2012

    Комментарии (1)
  4. C# / Говнокод #9754

    +116

    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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    int min = 32000;
    int max = 0;
    int mind = 0;
    int i;
    int j;
    double t;
    double f;
    int p = 0;
    double[] x = new double[4];
    double[] k = new double[4];          //массив для К
    double[,] s = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[,] a = { { 2, 4, 5, 1, 0, 0, 0 }, { 1, 8, 6, 0, 1, 0, 0 }, { 7, 4, 5, 0, 0, 1, 0 }, { 4, 6, 7, 0, 0, 0, 1 } };
    double[] b = { 120, 280, 240, 360 };
    double[] c = { 10, 14, 12, 0, 0, 0, 0 };
    double[] r = new double[7];
    double[,] s1 = new double[4, 7];
    for ( i = 0; i < 4; i++)
    {
        for (j = 0; j < 7; j++)
            Console.Write(a[i, j] + "\t");
        Console.WriteLine("\n");
     
    }
    for (j = 0; j < 4; j++)
        Console.Write(b[j] + "\t");
    Console.WriteLine();
     
    for (j = 0; j < 7; j++)
        Console.Write(c[j] + "\t");
    Console.WriteLine();
    Console.WriteLine();
      //первая итерация         
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    if (a[i, j] != 0)
        s[i, j] = b[i] / a[i, j];
     
    Console.Write(s[i, j] + "\t");
            }
            Console.WriteLine();
        }
        for (j = 0; j < 7; j++)
        {
            for (i = 0; i < 4; i++)
            {
    if (s[i, j] < min)
        min = Convert.ToInt32(s[i, j]);
     
     
     
            }
            r[j] = min * c[j];
            Console.Write(r[j] + "\t");
     
        }
        Console.WriteLine();
        for (j = 0; j < 7; j++)
        {
            if (r[j] > max)
            {
    max = Convert.ToInt32(r[j]);
    p = j;
     
     
     
            }
     
        }
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    k[i] = a[i, p];
            }
        }
        min = 32000;
     
        for (i = 0; i < 4; i++)
        {
            if (s[i, p] < min)
            {
    min = Convert.ToInt32(s[i, p]);
    mind = i;
     
            }
            Console.WriteLine();
     
     
        }
        t = a[mind, p];
        for (i = 0; i < 4; i++)
        {
            for (j = 0; j < 7; j++)
            {
    s[i, j] = a[i, j];
            }
        }

    Полная версия: http://pastebin.com/p36MWPXR
    Этот код был выложен на одном из форумов с просьбой объяснить "Что делает приложенный код".
    Посмотрев строчек 50 из почти 300, понял, что мои нервы дороже этого говнокода.
    Форматирование практически полностью сохранено.
    Был один интересный пост к этой теме: "могу ошибаться, но по-моему - позорит автора", согласен с мнением автора этого поста.

    FutureCome, 24 Марта 2012

    Комментарии (15)
  5. C# / Говнокод #9751

    +114

    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
    private int GetInsertion(byte[] firstArr, byte[] secondArr)
            {
                int result = -1;
                int counter = 0;
                if (firstArr.Count() >= secondArr.Count())
                {
                    for (int i = 0; i < firstArr.Count(); i++)
                    {
                        if (firstArr[i] == secondArr[counter])
                        {
                            counter++;
                            if (counter == secondArr.Count())
                            {
                                result = i - counter + 1;
                                break;
                            }
                        }
                        else
                        {
                            counter = 0;
                        }
                    }
                }
                return result;
            }

    находит индекс вхождения одного массива в другой

    razzil, 23 Марта 2012

    Комментарии (1)
  6. C# / Говнокод #9737

    +963

    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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    public partial class Form1 : Form  
        {
            public Form1()
            {
                InitializeComponent();
            }
           
            public void label1_Click(object sender, EventArgs e)
            {
     
            }
     
            public void button1_Click(object sender, EventArgs e)
            {
                label1.Text = "неправильно, вы проиграли";
                button1.Dispose();
                button2.Dispose();
                button3.Dispose();
                button4.Dispose();
                this.BackColor = System.Drawing.Color.Red;
            }
     
            public void button2_Click(object sender, EventArgs e)
            {
               
                label1.Text = "неправильно, вы проиграли";
                button1.Dispose();
                button2.Dispose();
                button3.Dispose();
                button4.Dispose();
                this.BackColor = System.Drawing.Color.Red;
            }
     
            public void button4_Click(object sender, EventArgs e)
            {
                label1.Text = "неправильно, вы проиграли";
                button1.Dispose();
                button2.Dispose();
                button3.Dispose();
                button4.Dispose();
                this.BackColor = System.Drawing.Color.Red;
            }
     
            public void button3_Click(object sender, EventArgs e)
            {
                label1.Text = "правильно";
                button1.Dispose();
                button2.Dispose();
                button3.Dispose();
                button4.Dispose();
                btn.Dispose();
                this.BackColor = System.Drawing.Color.Green;
                btn = new Button();
                btn.Text = "Дальше";
                btn.Top = 200;
                btn.Left = 360;
                btn.Height = 165;
                btn.Width = 269;
                btn.Click += new EventHandler(Press_ok);
                this.Controls.Add(btn);
                
            }
                public void Press_ok (object sender, EventArgs e)
            {
                this.BackColor = System.Drawing.Color.White;
                    btn.Dispose();
                    label1.Text = "сколько должно быть зубов у человека?";
                    button1 = new Button();
                    button1.Text = "16";
                    button1.Height = 23;
                    button1.Width = 142;
                    button1.Left = 272;
                    button1.Top = 414;
                    button1.Click += new EventHandler(Press_1);
                    this.Controls.Add(button1);
              
                    
     
                    button2 = new Button();
                    button2.Text = "32";
                    button2.Height = 23;
                    button2.Width = 142;
                    button2.Left = 711;
                    button2.Top = 414;
                    button2.Click += new EventHandler(Press_2);
                    this.Controls.Add(button2);
     
                    button3 = new Button();
                    button3.Text = "28";
                    button3.Height = 23;
                    button3.Width = 142;
                    button3.Left = 272;
                    button3.Top = 491;
                    button3.Click += new EventHandler(Press_3);
                    this.Controls.Add(button3);
     
                    button4 = new Button();
                    button4.Text = "101";
                    //еще over100500 ГК

    psina-from-ua, 22 Марта 2012

    Комментарии (14)
  7. C# / Говнокод #9734

    +961

    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
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
            protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
            {
                switch (keyData)
                {
                    case Keys.Up:
                        if ((pictureBox1.Location.X + pictureBox1.Width >= pictureBox4.Location.X) & (pictureBox1.Location.X <= pictureBox4.Location.X + pictureBox4.Width) & (pictureBox1.Location.Y <= pictureBox4.Location.Y + pictureBox4.Height) & (pictureBox1.Location.Y >= pictureBox4.Location.Y + pictureBox4.Height / 2)) ;
                        else pictureBox1.Top -= 5;
                        if ((pictureBox2.Visible) & (pictureBox3.Visible))
                            if ((pictureBox1.Location.Y >= pictureBox2.Location.Y) & (pictureBox1.Location.Y + pictureBox1.Height <= pictureBox2.Location.Y + pictureBox2.Height) & (pictureBox1.Location.X >= pictureBox2.Location.X) & (pictureBox1.Location.X + pictureBox1.Width <= pictureBox2.Location.X + pictureBox2.Width))
                                pictureBox1.Location = new Point(pictureBox3.Location.X + (pictureBox1.Location.X - pictureBox2.Location.X), pictureBox3.Location.Y - 5);
                        if ((pictureBox2.Visible) & (pictureBox3.Visible))
                            if ((pictureBox1.Location.Y >= pictureBox3.Location.Y) & (pictureBox1.Location.Y + pictureBox1.Height <= pictureBox3.Location.Y + pictureBox3.Height) & (pictureBox1.Location.X >= pictureBox3.Location.X) & (pictureBox1.Location.X + pictureBox1.Width <= pictureBox3.Location.X + pictureBox3.Width))
                                pictureBox1.Location = new Point(pictureBox2.Location.X + (pictureBox1.Location.X - pictureBox3.Location.X), pictureBox2.Location.Y - 5);
                                break;
                    case Keys.Down:
                                if ((pictureBox1.Location.X + pictureBox1.Width >= pictureBox4.Location.X) & (pictureBox1.Location.X <= pictureBox4.Location.X + pictureBox4.Width) & (pictureBox1.Location.Y + pictureBox1.Height <= pictureBox4.Location.Y + pictureBox4.Height / 2) & (pictureBox1.Location.Y + pictureBox1.Height >= pictureBox4.Location.Y)) ;
                        else pictureBox1.Top += 5;
                        if ((pictureBox2.Visible) & (pictureBox3.Visible))
                            if ((pictureBox1.Location.Y >= pictureBox2.Location.Y) & (pictureBox1.Location.Y + pictureBox1.Height <= pictureBox2.Location.Y + pictureBox2.Height) & (pictureBox1.Location.X >= pictureBox2.Location.X) & (pictureBox1.Location.X + pictureBox1.Width <= pictureBox2.Location.X + pictureBox2.Width))
                                pictureBox1.Location = new Point(pictureBox3.Location.X + (pictureBox1.Location.X - pictureBox2.Location.X), (pictureBox3.Location.Y + pictureBox3.Height) - 5);
                        if ((pictureBox2.Visible) & (pictureBox3.Visible))
                            if ((pictureBox1.Location.Y >= pictureBox3.Location.Y) & (pictureBox1.Location.Y + pictureBox1.Height <= pictureBox3.Location.Y + pictureBox3.Height) & (pictureBox1.Location.X >= pictureBox3.Location.X) & (pictureBox1.Location.X + pictureBox1.Width <= pictureBox3.Location.X + pictureBox3.Width))
                                pictureBox1.Location = new Point(pictureBox2.Location.X + (pictureBox1.Location.X - pictureBox3.Location.X), (pictureBox2.Location.Y + pictureBox2.Height) - 5);
                                break;

    Это не поддаётся описанию. Полная версия: http://pastebin.com/97sbSVLa

    P4R4, 22 Марта 2012

    Комментарии (14)
  8. C# / Говнокод #9732

    +122

    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
    else
                    {
                        if ((textBox1.Text == textBox2.Text) | (textBox1.Text == textBox3.Text) | (textBox1.Text == textBox4.Text) | (textBox1.Text == textBox7.Text)) textBox1.ForeColor = Color.Red; else textBox1.ForeColor = Color.Black;
                        if ((textBox2.Text == textBox1.Text) | (textBox2.Text == textBox3.Text) | (textBox2.Text == textBox5.Text) | (textBox2.Text == textBox8.Text)) textBox2.ForeColor = Color.Red; else textBox2.ForeColor = Color.Black;
                        if ((textBox3.Text == textBox1.Text) | (textBox3.Text == textBox2.Text) | (textBox3.Text == textBox6.Text) | (textBox3.Text == textBox9.Text)) textBox3.ForeColor = Color.Red; else textBox3.ForeColor = Color.Black;
                        if ((textBox4.Text == textBox5.Text) | (textBox4.Text == textBox6.Text) | (textBox4.Text == textBox1.Text) | (textBox4.Text == textBox7.Text)) textBox4.ForeColor = Color.Red; else textBox4.ForeColor = Color.Black;
                        if ((textBox5.Text == textBox4.Text) | (textBox5.Text == textBox6.Text) | (textBox5.Text == textBox2.Text) | (textBox5.Text == textBox8.Text)) textBox5.ForeColor = Color.Red; else textBox5.ForeColor = Color.Black;
                        if ((textBox6.Text == textBox4.Text) | (textBox6.Text == textBox5.Text) | (textBox6.Text == textBox3.Text) | (textBox6.Text == textBox9.Text)) textBox6.ForeColor = Color.Red; else textBox6.ForeColor = Color.Black;
                        if ((textBox7.Text == textBox8.Text) | (textBox7.Text == textBox9.Text) | (textBox7.Text == textBox1.Text) | (textBox7.Text == textBox4.Text)) textBox7.ForeColor = Color.Red; else textBox7.ForeColor = Color.Black;
                        if ((textBox8.Text == textBox7.Text) | (textBox8.Text == textBox9.Text) | (textBox8.Text == textBox2.Text) | (textBox8.Text == textBox5.Text)) textBox8.ForeColor = Color.Red; else textBox8.ForeColor = Color.Black;
                        if ((textBox9.Text == textBox7.Text) | (textBox9.Text == textBox8.Text) | (textBox9.Text == textBox3.Text) | (textBox9.Text == textBox6.Text)) textBox9.ForeColor = Color.Red; else textBox9.ForeColor = Color.Black;
                        if ((textBox1.Text == textBox2.Text) | (textBox1.Text == textBox3.Text) | (textBox1.Text == textBox4.Text) | (textBox1.Text == textBox7.Text) |
                            (textBox2.Text == textBox1.Text) | (textBox2.Text == textBox3.Text) | (textBox2.Text == textBox5.Text) | (textBox2.Text == textBox8.Text) |
                            (textBox3.Text == textBox1.Text) | (textBox3.Text == textBox2.Text) | (textBox3.Text == textBox6.Text) | (textBox3.Text == textBox9.Text) |
                            (textBox4.Text == textBox5.Text) | (textBox4.Text == textBox6.Text) | (textBox4.Text == textBox1.Text) | (textBox4.Text == textBox7.Text) |
                            (textBox5.Text == textBox4.Text) | (textBox5.Text == textBox6.Text) | (textBox5.Text == textBox2.Text) | (textBox5.Text == textBox8.Text) |
                            (textBox6.Text == textBox4.Text) | (textBox6.Text == textBox5.Text) | (textBox6.Text == textBox3.Text) | (textBox6.Text == textBox9.Text) |
                            (textBox7.Text == textBox8.Text) | (textBox7.Text == textBox9.Text) | (textBox7.Text == textBox1.Text) | (textBox7.Text == textBox4.Text) |
                            (textBox8.Text == textBox7.Text) | (textBox8.Text == textBox9.Text) | (textBox8.Text == textBox2.Text) | (textBox8.Text == textBox5.Text) |
                            (textBox9.Text == textBox7.Text) | (textBox9.Text == textBox8.Text) | (textBox9.Text == textBox3.Text) | (textBox9.Text == textBox6.Text)) ;
                        else
                        {
                            label1.Visible = true;
                            label2.Visible = true;
                        }

    Удивлению нет границ! Полная версия: http://pastebin.com/S2getyHn

    P4R4, 22 Марта 2012

    Комментарии (6)
  9. C# / Говнокод #9717

    +109

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    private IEnumerable<CharacteristicValue> GetCharacteristicValues(IQueryable<CharacteristicValue> allCharacteristicValues, int characteristicId)
    {
          var characteristicValues = new CharacteristicValue[userIds.Length];
    
           for (var i = 0; i < userIds.Length; i++)
           {
               characteristicValues[i] = allCharacteristicValues.FirstOrDefault(cv => cv.UserId == userIds[i] && cv.CharacteristicId == characteristicId); // Todo: Try to replace with a single query.
           }
    
           return characteristicValues;
    }

    Драсьте, нашёл в коде такую вот какашку. Как видите параметр allCharacteristicsValues реализует интерфейс IQuarable из EF. То бишь каждый раз, когда будет вызываться метод FirstOrDefault будет делаться запрос к базе. В идеале это должно было бы выглядеть так:

    var characteristicValues = allCharacteristicValues.Where(cv => cv.CharacteristicId == characteristicId && userIds.Contains(cv.UserId));

    Но при такой реализации размер масива пользователей и значение может разниться:

    Values:
    val1
    val2
    val3

    Users:
    1
    2
    3
    4
    5

    Для первого же варианта результат будет выглядеть так:
    Values:
    val1
    val2
    val3
    null
    null

    Users:
    1
    2
    3
    4
    5


    Собственно всё )))) Надеюсь подсоветуете чего-нибудь хорошего ;)

    walash, 20 Марта 2012

    Комментарии (21)
  10. C# / Говнокод #9715

    +113

    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
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    if ((label1.Text == "O") & (label2.Text == "O") & (label3.Text == "O") | ((label1.Text == "X") & (label2.Text == "X") & (label3.Text == "X")))
                {
                    label1.ForeColor = Color.Red;
                    label2.ForeColor = Color.Red;
                    label3.ForeColor = Color.Red;
                    win = false;
                }
                if ((label4.Text == "O") & (label5.Text == "O") & (label6.Text == "O") | ((label4.Text == "X") & (label5.Text == "X") & (label6.Text == "X")))
                {
                    label4.ForeColor = Color.Red;
                    label5.ForeColor = Color.Red;
                    label6.ForeColor = Color.Red;
                    win = false;
                }
                if ((label7.Text == "O") & (label8.Text == "O") & (label9.Text == "O") | ((label7.Text == "X") & (label8.Text == "X") & (label9.Text == "X")))
                {
                    label4.ForeColor = Color.Red;
                    label5.ForeColor = Color.Red;
                    label6.ForeColor = Color.Red;
                    win = false;
                }
                if ((label1.Text == "O") & (label4.Text == "O") & (label7.Text == "O") | ((label1.Text == "X") & (label4.Text == "X") & (label7.Text == "X")))
                {
                    label1.ForeColor = Color.Red;
                    label4.ForeColor = Color.Red;
                    label7.ForeColor = Color.Red;
                    win = false;
                }
                if ((label2.Text == "O") & (label5.Text == "O") & (label8.Text == "O") | ((label2.Text == "X") & (label5.Text == "X") & (label8.Text == "X")))
                {
                    label2.ForeColor = Color.Red;
                    label5.ForeColor = Color.Red;
                    label8.ForeColor = Color.Red;
                    win = false;
                }
                if ((label3.Text == "O") & (label6.Text == "O") & (label9.Text == "O") | ((label3.Text == "X") & (label6.Text == "X") & (label9.Text == "X")))
                {
                    label3.ForeColor = Color.Red;
                    label6.ForeColor = Color.Red;
                    label9.ForeColor = Color.Red;
                    win = false;
                }
                if ((label1.Text == "O") & (label5.Text == "O") & (label9.Text == "O") | ((label1.Text == "X") & (label5.Text == "X") & (label9.Text == "X")))
                {
                    label1.ForeColor = Color.Red;
                    label5.ForeColor = Color.Red;
                    label9.ForeColor = Color.Red;
                    win = false;
                }
                if ((label3.Text == "O") & (label5.Text == "O") & (label7.Text == "O") | ((label3.Text == "X") & (label5.Text == "X") & (label7.Text == "X")))
                {
                    label3.ForeColor = Color.Red;
                    label5.ForeColor = Color.Red;
                    label7.ForeColor = Color.Red;
                    win = false;
                }
            }
    
            private void label7_MouseDown(object sender, MouseEventArgs e)
            {
                if (win)
                    for (int i = 0; i < 1; i++)
                    {
                        if (label7.Text == "")
                        {
                            label7.Text = "X";
    
                            if ((label1.Text == "O") & (label2.Text == "O") & (label3.Text == ""))
                            {
                                label3.Text = "O"; break;
                            }
                            if ((label1.Text == "O") & (label2.Text == "") & (label3.Text == "O"))
                            {
                                label2.Text = "O"; break;
                            }
                            if ((label1.Text == "") & (label2.Text == "O") & (label3.Text == "O"))
                            {
                                label1.Text = "O"; break;
                            }

    Крестики-нолики с одного форума. Полная версия: http://pastebin.com/59W3547n

    P4R4, 19 Марта 2012

    Комментарии (7)