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

    +109

    1. 001
    2. 002
    3. 003
    4. 004
    5. 005
    6. 006
    7. 007
    8. 008
    9. 009
    10. 010
    11. 011
    12. 012
    13. 013
    14. 014
    15. 015
    16. 016
    17. 017
    18. 018
    19. 019
    20. 020
    21. 021
    22. 022
    23. 023
    24. 024
    25. 025
    26. 026
    27. 027
    28. 028
    29. 029
    30. 030
    31. 031
    32. 032
    33. 033
    34. 034
    35. 035
    36. 036
    37. 037
    38. 038
    39. 039
    40. 040
    41. 041
    42. 042
    43. 043
    44. 044
    45. 045
    46. 046
    47. 047
    48. 048
    49. 049
    50. 050
    51. 051
    52. 052
    53. 053
    54. 054
    55. 055
    56. 056
    57. 057
    58. 058
    59. 059
    60. 060
    61. 061
    62. 062
    63. 063
    64. 064
    65. 065
    66. 066
    67. 067
    68. 068
    69. 069
    70. 070
    71. 071
    72. 072
    73. 073
    74. 074
    75. 075
    76. 076
    77. 077
    78. 078
    79. 079
    80. 080
    81. 081
    82. 082
    83. 083
    84. 084
    85. 085
    86. 086
    87. 087
    88. 088
    89. 089
    90. 090
    91. 091
    92. 092
    93. 093
    94. 094
    95. 095
    96. 096
    97. 097
    98. 098
    99. 099
    100. 100
    static void Main(string[] args)
            {
     
                Console.WriteLine("Как желаете заполнить?");
                Console.WriteLine("Цифра 1  = в столбик, цифра 2 = в строчку");
                int valMethod = Convert.ToInt32(Console.ReadLine());
     
                Console.Clear();
     
     
                Console.SetCursorPosition(1, 0);
                for (int index = 1; index != 22; index++)
                {
                    Console.CursorLeft = 1;
                    Console.WriteLine('║');
                    if (index < 21)
                    {
                        Console.CursorLeft = 19;
                        Console.Write('&#9553;');
                    }
                }
     
     
     
     
                Console.SetCursorPosition(1, 0);
                for (int index = 1; index != 62; index++)
                    Console.Write('&#9552;');
     
                Console.SetCursorPosition(35, 1);
     
                int valueRow = 0;
                for (int i = 0; i < 4; i++)
                {
                    for (int index = 1; index != 20; index++)
                    {
                        Console.SetCursorPosition(28 + valueRow, 1 + index);
                        Console.WriteLine('&#9553;');
                    }
                    valueRow += 8;
     
                }
     
                for (int index = 1; index != 20; index++)
                {
                    Console.SetCursorPosition(29 + valueRow, 0 + index);
                    Console.WriteLine('&#9553;');
                }
     
     
     
                Console.SetCursorPosition(20, 2);
                for (int index = 1; index != 43; index++)
                    Console.Write('&#9552;');
     
                int value = 4;
                for (int i = 0; i < 9; i++)
                {
                    Console.SetCursorPosition(1, value);
                    for (int index = 1; index != 62; index++)
                        Console.Write('&#9552;');
                    value += 2;
                }
     
                Console.SetCursorPosition(6, 2);
                Console.WriteLine("Спортсмен");
     
                Console.SetCursorPosition(25, 1);
                Console.WriteLine("Вид спорта");
     
     
                int value1 = 5;
                for (int i = 1; i < 9; i++)
                {
                    Console.SetCursorPosition(6, value1);
                    Console.WriteLine("{0}", i);
                    value1 += 2;
                }
     
                int value2 = 2;
                for (int i = 1; i < 6; i++)
                {
                    Console.SetCursorPosition(22 + value2, 3);
                    Console.Write("{0}", i);
                    value2 += 8;
                }
     
                Console.SetCursorPosition(1, 0);
                Console.Write("&#9556;");
     
                Console.SetCursorPosition(61, 0);
                Console.Write("&#9559;");
     
                Console.SetCursorPosition(1, 20);
                Console.Write("&#9562;");
                 
                Console.SetCursorPosition(61, 20);
                Console.Write("&#9565;");
    
    ...

    Мы так любим магические числа...

    Psilon, 29 Июля 2013

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

    +110

    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
    private void Save(string ThreadID, string Board)
            {
                string pathL;
                if (cbGIF.Checked)
                {
                    pathL = String.Format(path, Board, ThreadID, "-gif");
                }
                else
                {
                    pathL = String.Format(path, Board, ThreadID, "");
                }
                string htmlPath = String.Format(threadPath, Board, ThreadID);
    
                WebClient wcli = new GZipWebClient();
                string cThread = wcli.DownloadString(htmlPath);
                
                var rx = new Regex(cbGIF.Checked ? regExGif : regEx);
                var ms = rx.Matches(cThread);
                imgSaved = 0;
                imgCount = ms.Count;
                saveProgress.Minimum = 0;
                saveProgress.Maximum = imgCount;
                saveProgress.Value = 0;
                if (!Directory.Exists(pathL))
                {
                    Directory.CreateDirectory(pathL);
                }
                try
                {
                    foreach (Match m in ms)
                    {
                        WebClient ccl = new WebClient();
                        ccl.DownloadFileCompleted += new AsyncCompletedEventHandler(ccl_DownloadFileCompleted);
                        string[] v = m.Value.Split('"');
                        string sd = v[1].Split('/').Last();
                        string a = url + v[1];
                        string b = pathL + sd;
                        if (File.Exists(b))
                        {
                            imgSaved++;
                            saveProgress.Value = imgSaved;
                            lblSaveProgress.Text = imgSaved.ToString() + "/" + imgCount.ToString();
                            if (imgSaved == imgCount)
                            {
                                btnSave.Enabled = true;
                                lblSaveProgress.Text = "FUKKEN SAVED!";
                            }
                        }
                        else ccl.DownloadFileAsync(new Uri(a),b);
                    }
                }
                catch (WebException e)
                {
                    MessageBox.Show(e.Message + e.StackTrace);
                }          
            }

    В пределах одного метода бросаемся из крайности в крайность в именовании переменных.

    A1mighty, 26 Июля 2013

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

    +120

    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
    if (IsSetPrinter)
                            {
                                if (Counter == 0)
                                {
                                    printingIsOkay = PrintDocument(letterIDsString
                                   , row.DocumentTemplateVersionID
                                   , row.DocumentTemplate
                                   , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                   , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                   , true
                                   , Counter
                                   , Counter == documentTemplateVersions.Count - 1);
                                }
                                else
                                {
                                    printingIsOkay = PrintDocument(letterIDsString
                                  , row.DocumentTemplateVersionID
                                  , row.DocumentTemplate
                                  , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                  , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                  , false
                                  , Counter
                                  , Counter == documentTemplateVersions.Count - 1);
                                }
    
                            }
                            else
                            {
                                printingIsOkay = PrintDocument(letterIDsString
                                   , row.DocumentTemplateVersionID
                                   , row.DocumentTemplate
                                   , (row.IsHeader_DocumentTemplateVersionIDNull() ? (int?)null : row.Header_DocumentTemplateVersionID)
                                   , (row.IsFooter_DocumentTemplateVersionIDNull() ? (int?)null : row.Footer_DocumentTemplateVersionID)
                                   , false
                                   , Counter
                                   , Counter == documentTemplateVersions.Count - 1);
                            }

    Я бы выложил весь класс. Он весь такой. Но, думаю, вы поняли кто писал?

    kore_sar, 23 Июля 2013

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

    +115

    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
    private string GenerateUserName(ISession session)
    {
      string userName = "";
      while (true)
      {
        if (IsBrand) userName = FName.Replace(" ", "");
        else userName = string.Format("{0}.{1}", FName, LName);
    
        if (String.IsNullOrEmpty(FName) && String.IsNullOrEmpty(LName))
        {
          userName = UserID.ToString();
        }
        else
        {
          var i = 0;
          while (UserBeanHelper.GetUserByUserName(session, userName) != null)
          {
            i++;
            userName = string.Format("{0}.{1}-{2}", FName, LName, i);
          }
        }
    
        UserTransferBean userByUserName = UserBeanHelper.GetUserByUserName(session, userName);
        if (userByUserName != null)
           ;
        else
        {
          break;
        }
      }
      return userName;
    }

    DarkThinker, 19 Июля 2013

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

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    class Comparer : IComparer<int>
    {
        Random random = new Random();
    
        public int Compare(int x, int y)
        {
            return 1 - random.Next() % 3;
        }
    }

    Ccik, 18 Июля 2013

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

    +125

    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
    var colorInfoList = new List<ColorInfo>()
                    {
                        new ColorInfo("#000000", "	black", "	Черный"),
                        new ColorInfo("#000080","	navy","	Темно-синий"),
                        new ColorInfo("#00008B","	darkblue","	Темно-голубой"),
                        new ColorInfo("#0000CD","	mediumblue","	Умеренно-голубой"),
                        new ColorInfo("#0000FF","	blue	","Голубой"),
                        new ColorInfo("#006400","	darkgreen","	Темно-зеленый"),
                        new ColorInfo("#008000","	green","	Зеленый"),
                        new ColorInfo("#008080","	teal","	Чайный"),
                        new ColorInfo("#008B8B","	darkcyan","	Темный циан"),
                        new ColorInfo("#00BFFF","	deepskyblue","	Темный небесно-синий"),
                        new ColorInfo("#00CED1","darkturquoise	","Темно-бирюзовый"),
                        new ColorInfo("#00FA9A","	mediumspringgreen","	Умеренный синевато-серый"),
                        new ColorInfo("#00FF00","	lime","	Известковый"),
                        new ColorInfo("#00FFFF","	aqua","	Синий"),
                        new ColorInfo("#2E8B57","	seagreen","	Морской волны"),
                        new ColorInfo("#32CD32","	limegreen","	Зеленовато-известковый"),
                        new ColorInfo("#4B0082","	indigo","	Индиго"),
                        new ColorInfo("#696969","	dimgray","	Тускло-серый"),
                        new ColorInfo("#7CFC00","	lawngreen","	Зеленой травы"),    
                        new ColorInfo("#7FFFD4","	aquamarine","	Аквамарин"),
                        new ColorInfo("#800000","	maroon","	Оранжево-розовый"),
                        new ColorInfo("#808080"," 	gray","	Серый"),
                        new ColorInfo("#8B0000","	darkred","	Темно-красный"),
                        new ColorInfo("#9ACD32","	yellowgreen","	Желто-зеленый"),
                        new ColorInfo("#A52A2A","	brown","	Коричневый")
                    };
    
    
            public ColorInfo ColorCheck(List<ColorInfo> list, string colorHex)
            {
                for (int i = 0; i < list.Count-1; i++)
                {
                    if (String.Compare(list[i].HexInfo, colorHex, StringComparison.Ordinal) <= 0 && String.Compare(list[i + 1].HexInfo, colorHex, StringComparison.Ordinal)>=0)
                        return list[i+1];
                }
                return new ColorInfo();
            }

    Определение названия цвета

    iofjuupasli, 17 Июля 2013

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

    +121

    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
    /// Разрезать строку на части длиной не более maxRecordLen
      private static void splitText(ref List<string> splitTextArray,  string text) {
        splitTextArray = new List<string>();
        for (; ; ) {
          try {
            string str = text.Substring(0, maxRecordLen);
            splitTextArray.Add(str);
            try {
              text = text.Substring(maxRecordLen);
            }
            catch (Exception) {
              break;
            }
          }
          catch (Exception) {
            splitTextArray.Add(text);
            break;
          }
        }
      }

    no comment.

    diimdeep , 17 Июля 2013

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public class DataLayer
    {
    ...
    public List<Employee> GetEmployees() { ... }
    public List<Department> GetDepartments() {...}
    public List<Roles> GetRoles() {...}
    }

    Обратил внимание, что некоторые коллеги любят использовать в качестве возвращаемых типов не обычные массивы, а обязательно List<T>.
    Долго гадал, что-ж такая за практика интерсная, на стеке прям несколько вопросов подрял.
    Затем, обратил внимание, что все они используют в качестве основного инструмента паттерн MVC.
    Проштудировав самые известные книжки по MVC, таки нашёл виновника:
    http://www.ozon.ru/context/detail/id/19064535/ - Программирование на основе Microsoft ASP.NET MVC (Дино Эспозито)
    Везде где только можно, всё просто обделано LIst'ами. Даже данные передаваемые во View...

    TauSigma, 15 Июля 2013

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

    +135

    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
    switch (curWpn)
    {
        case WeaponType.Doublegun: DrawNumber(doublegunAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, doublegunAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(doublegunI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Grenade: DrawNumber(grenadeCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, grenadeCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(grenadeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), grenadeTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Knife: spriteBatch.Draw(knifeI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Launcher: DrawNumber(rocketCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, rocketCnt > 0 ? Color.White : Color.Red); spriteBatch.Draw(launcherI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), launchTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Revolver: spriteBatch.Draw(revolverI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), Color.White); break;
        case WeaponType.Cannon: DrawNumber(cannonAmmo, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, cannonAmmo > 0 ? Color.White : Color.Red); spriteBatch.Draw(cannonI, new Microsoft.Xna.Framework.Rectangle(graphics.PreferredBackBufferWidth - 64, graphics.PreferredBackBufferHeight - 64, 64, 64), cannonTimeout > 0.0f ? Color.Red : Color.White); break;
        case WeaponType.Laser: DrawNumber(laserAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, laserAmmoCnt > 0 ? Color.White : Color.Red); break;
        case WeaponType.Minigun: DrawNumber(minigunAmmoCnt, new Vector2(graphics.PreferredBackBufferWidth - 150, graphics.PreferredBackBufferHeight - 54), 1.0f, minigunAmmoCnt > 0 ? Color.White : Color.Red); break;
    }
    //в другом месте
    switch (curWpnIndex)
    {
        case 0: curWpn = WeaponType.Knife; break;
        case 1: curWpn = WeaponType.Revolver; break;
        case 2: curWpn = WeaponType.Doublegun; break;
        case 3: curWpn = WeaponType.Laser; break;
        case 4: curWpn = WeaponType.Minigun; break;
        case 5: curWpn = WeaponType.Rifle; break;
        case 6: curWpn = WeaponType.Grenade; break;
        case 7: curWpn = WeaponType.Launcher; break;
        case 8: curWpn = WeaponType.Cannon; break;
    }

    Это неописуемо. Нашел у себя...
    Видимо, придется снова идти мыться.

    RaZeR, 15 Июля 2013

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

    +128

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public void BuildInsertClause(OleDbCommand cmd, ObjectState objState)
            {
                  StringBuilder builder = new StringBuilder();
                  ..........
                  cmd.CommandText = builder.ToString() + "(" + columns.ToString() + ") VALUES (" +
                  values.ToString() + ")";
            }

    http://solidcoding.blogspot.ru/2008/01/linq-to-excel-provider-25.html
    Еще много смешного, для затравки:

    object val = reader[col.GetSelectColumn()];
    if (val is DBNull)
    {
    val = null;
    }

    neeedle, 15 Июля 2013

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