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

    0

    1. 1
    if (html.Contains("The report you've designed is invalid. Please verify that everything is correct."))

    Как проверить нет ли ошибок в только что сгенерированном отчете?
    Теперь я знаю где работает Капитан Очевидность! ))))
    (Из исходников одной популярной генерилки отчетов Кстати, локализованной на штук 8 языков)

    RadChand, 12 Апреля 2016

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

    +3

    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
    public class MyEnglishRadGridLocalizationProvider : RadGridLocalizationProvider
    {
        public override string GetLocalizedString(string id)
        {
            switch (id)
            {
                case RadGridStringId.ConditionalFormattingPleaseSelectValidCellValue: return "Please select valid cell value";
                case RadGridStringId.ConditionalFormattingPleaseSetValidCellValue: return "Please set a valid cell value";
                case RadGridStringId.ConditionalFormattingPleaseSetValidCellValues: return "Please set a valid cell values";
                case RadGridStringId.ConditionalFormattingPleaseSetValidExpression: return "Please set a valid expression";
                case RadGridStringId.ConditionalFormattingItem: return "Item";
                case RadGridStringId.ConditionalFormattingInvalidParameters: return "Invalid parameters";
                case RadGridStringId.FilterFunctionBetween: return "Between";
                case RadGridStringId.FilterFunctionContains: return "Contains";
                case RadGridStringId.FilterFunctionDoesNotContain: return "Does not contain";
                case RadGridStringId.FilterFunctionEndsWith: return "Ends with";
                case RadGridStringId.FilterFunctionEqualTo: return "Equals";
                case RadGridStringId.FilterFunctionGreaterThan: return "Greater than";
                case RadGridStringId.FilterFunctionGreaterThanOrEqualTo: return "Greater than or equal to";
                case RadGridStringId.FilterFunctionIsEmpty: return "Is empty";
                case RadGridStringId.FilterFunctionIsNull: return "Is null";

    Зачем мне ресурсы и конфиги локализации, у меня нет времени чтобы ебаться с ними!
    Лучше я захардкожу локализацию ещё раз!

    http://docs.telerik.com/devtools/winforms/gridview/localization/localization

    gost, 12 Апреля 2016

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

    +3

    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
    namespace БиблиотекаКлассов
    {
         public class Картинки
         {
              public Vector2 Расположение_ЖивойКартинки;
              public Vector2 Расположение_НеЖивойКартинки;
              public Texture2D Объект_ЖиваяКартинка;
              public Texture2D Объект_НеЖиваяКартинка;
    
              public class ЖивыеКартинки : Картинки
              {
    
                   private Point Переменная_Номер_Текущего_Кадра;
    
                   private int Переменная_Скорость_ЖивыхКартинок;
                   private double Переменная_ВремяРаботыКадра;
                   private double Переменная_ВремяОтНачалаРаботыВсехКадров;
                   private Rectangle Объект_Кадр;
                   private float Переменная_Поворот_ЖивойКартинки;
                   private Vector2 Переменная_Центр_Поворота;
                   private int Переменная_Количество_Строк;
                   private int Переменная_Количество_Столбцов;
                   public int Переменная_Ширина_Кадра_ЖивыхКартинок;
                   public int Переменная_Высота_Кадра_ЖивыхКартинок;
    
                   
                 
                   // Метод создания живых картинок с параметрами
                   public ЖивыеКартинки(int ЗАДАТЬ_Количество_Строк, int ЗАДАТЬ_Количество_Столбцов, double ЗАДАТЬВремяРаботыКадраВСекунду, int ЗАДАТЬ_СкоростьКартинок)
                        {
                        Переменная_Количество_Строк = ЗАДАТЬ_Количество_Строк;
                        Переменная_Количество_Столбцов = ЗАДАТЬ_Количество_Столбцов;
                        Переменная_ВремяРаботыКадра = (float)1 / ЗАДАТЬВремяРаботыКадраВСекунду;
                        Переменная_ВремяОтНачалаРаботыВсехКадров = 0;
                        Переменная_Номер_Текущего_Кадра = new Point(0, 0);
                        Переменная_Скорость_ЖивыхКартинок = ЗАДАТЬ_СкоростьКартинок;
                        }
    
                   public void Метод_ПереходПоКадрам(double ПройденноеВремя)
                        {
    
                        Переменная_ВремяОтНачалаРаботыВсехКадров += ПройденноеВремя;
    
                        if (Переменная_ВремяОтНачалаРаботыВсехКадров > Переменная_ВремяРаботыКадра)
                        {
    
                                  ++Переменная_Номер_Текущего_Кадра.X;
                                  if (Переменная_Номер_Текущего_Кадра.X >= Переменная_Количество_Столбцов)
                                  {
                                  Переменная_Номер_Текущего_Кадра.X = 0;
                                  ++Переменная_Номер_Текущего_Кадра.Y;
    
                                  if (Переменная_Номер_Текущего_Кадра.Y >= Переменная_Количество_Строк)
                                       { 
                                            Переменная_Номер_Текущего_Кадра.Y = 0;
                                       }
                                  }
    
                             Переменная_ВремяОтНачалаРаботыВсехКадров -= Переменная_ВремяРаботыКадра;
                             }
                        }
    
    
                   public void Метод_КОМП_ДвижениеЖивыхКартинок()
                   {
                   }
    
    
                   public void Метод_ЗАГРУЗКА_ЖивойКартинки(ContentManager Переменная_ContentManager, String Переменная_ДляХраненияПутиКартинки)
                        {
                        Объект_ЖиваяКартинка = Переменная_ContentManager.Load<Texture2D>(Переменная_ДляХраненияПутиКартинки);
                        }
    
                   // Рисование Картинки
                   public void Метод_РИСОВАНИЕ_ЖивойКартинки(SpriteBatch Переменная_SpriteBatch, int x)   // x - Помогает задать центр поворота картинки
                        {
                             Переменная_Ширина_Кадра_ЖивыхКартинок = Объект_ЖиваяКартинка.Width / Переменная_Количество_Столбцов;
                             Переменная_Высота_Кадра_ЖивыхКартинок = Объект_ЖиваяКартинка.Height / Переменная_Количество_Строк;
                             if (x != 0)
                             {
                                  Переменная_Центр_Поворота = Vector2.Zero;
                             }
                             if (x == 0)
                             {
                                  Переменная_Центр_Поворота = new Vector2(Переменная_Ширина_Кадра_ЖивыхКартинок / 2, Переменная_Высота_Кадра_ЖивыхКартинок / 2);
                             }
    
                             Объект_Кадр = new Rectangle(Переменная_Номер_Текущего_Кадра.X * Переменная_Ширина_Кадра_ЖивыхКартинок, Переменная_Номер_Текущего_Кадра.Y * Переменная_Высота_Кадра_ЖивыхКартинок, Переменная_Ширина_Кадра_ЖивыхКартинок, Переменная_Высота_Кадра_ЖивыхКартинок);
                             Переменная_SpriteBatch.Draw(Объект_ЖиваяКартинка, Расположение_ЖивойКартинки, Объект_Кадр, Color.White, Переменная_Поворот_ЖивойКартинки, Переменная_Центр_Поворота, 1, SpriteEffects.None, 0);
                        }
              }
    
    
              public class НеЖивыеКартинки : Картинки
              {
                   private Vector2 Переменная_Центр_Поворота;
       //            private Rectangle Объект_Кадр;
                   public int Переменная_Ширина_НеЖивыхКартинок;

    http://www.gamedev.ru/code/forum/?id=208792

    Vasia, 11 Апреля 2016

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

    +5

    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
    Action doItWrong;
    var filename = "sdf";
    using (var fileStream = new FileStream(filename,FileMode.Create))
    {
    	doItWrong=()=>
    	{
    		for(int i = 0; i < 10; i++)
    		{
    			fileStream.WriteByte(255);
    		}
    	};
    }
    doItWrong();

    Интересно, почему такое вообще не запрещают компилировать?

    tucvbif, 11 Апреля 2016

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

    0

    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
    public enum EventType {
                Error,
                Notification,
                Success
            }
    ...
                            String sEventType = String.Empty;
                            switch (eType) {
                                case EventType.Error:
                                    sEventType = "Error: ";
                                    break;
                                case EventType.Notification:
                                    sEventType = "Notification: ";
                                    break;
                                case EventType.Success:
                                    sEventType = "Success: ";
                                    break;
                            }

    Lokich, 11 Апреля 2016

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (collection == null) collection = Rows.Where(r => r.ParentId == 0);
    foreach (var row in collection.Where(r => r.ParentId > 0))
    {
         //немного кода
    }

    Сам писал. Вчера. Трезвый.
    Сейчас вот думаю, а чо эта оно не работает?

    kerman, 11 Апреля 2016

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

    +3

    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
    public class Man
        {
            public Man(string id, string name, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, year)
            {
                this.Name = name;
                this.Brothers = brothers;
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, string note, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, note, year)
            {
                this.Name = name;
                this.Brothers = brothers;
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, year)
            {
                this.Name = name;
                this.Brothers = brothers;
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, string note, IEnumerable<Brother> brothers, Guid id, int year, int age) : base(id, note, year)
            {
                this.Name = name;
                this.Brothers = brothers;
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, Guid id, int year, int age) : base(id, year)
            {
                this.Name = name;
                this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, string note, Guid id, int year, int age) : base(id, note, year)
            {
                this.Name = name;
                this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, Guid id, int year, int age) : base(id, year)
            {
                this.Name = name;
                this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
                this.Id = id;
                this.Age = age;
            }
    
            public Man(string id, string name, string note, Guid id, int year, int age) : base(id, note, year)
            {
                this.Name = name;
                this.Id = id;
                this.Brothers = new List<Brother>() { new Brother(Guid.NewGuid().ToString()) };
                this.Age = age;
            }
    
            public string Name { get; }
    
            public Guid Id { get; }
    
            public IEnumerable<Brother> Brothers { get; }
    
            public int Age { get; }
    
        }

    Человек знал, но нехотел использовать значение параметра конструктора по умолчанию, потому что это усложняет структуру.
    Переменные переназвал почеловечнее.

    homk, 10 Апреля 2016

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

    +1

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    // 1188 references
    internal static string CombinePaths(string firstPath, string secondPath)
    {
        return Path.Combine(firstPath, secondPath);
    }

    - Шо это было?!!
    - Cэкономили точку. 1188 раз )))))

    RadChand, 08 Апреля 2016

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

    +1

    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
    public class FileStorage {
            public FileStorage() {
                try {
                    if (String.IsNullOrEmpty(Common.GlobalVariables.FileStorage)) {
                        throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorage", String.Empty));
                    }
    
                    if (!Directory.Exists(Common.GlobalVariables.FileStorage)) {
                        DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage);
                        if (!di.Exists) {
                            throw new Exception(Common.GuiHelper.ShowErrorMessage("FileStorageDir", String.Empty));
                        }
                    }
                } catch (Exception er) {
                    throw new Exception(er.Message);
                }
            }
    
            public String CreateFileDirectory() {
                try {
                    int iIdx = 0;
                    Boolean bIsCreated = false;
                    while (!bIsCreated && iIdx < 10) {
                        String sDir = Guid.NewGuid().ToString("N").ToLower();
                        sDir = sDir.Substring(0, 2);
                        if (!Directory.Exists(Common.GlobalVariables.FileStorage + sDir + @"\")) {
                            DirectoryInfo di = Directory.CreateDirectory(Common.GlobalVariables.FileStorage + sDir + @"\");
                            if (di.Exists) {
                                return Common.GlobalVariables.FileStorage + sDir + @"\";
                            }
                        }
    
                        iIdx++;
                    }
    
                    return null;
                } catch (Exception er) {
                    throw new Exception(er.Message);
                }
            }
        }

    может я чего не понимаю, но зачем?

    Lokich, 08 Апреля 2016

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

    +2

    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
    public struct TotalStat
    {
        public int Level { get; set; }
        public int Type { get; set; }
        public string Name { get; set; }
        public string Code { get; set; }
        public int VAL_01_1 { get; set; }
        public int VAL_01_2 { get; set; }
        public int VAL_01_3 { get; set; }
        public int VAL_01_4 { get; set; }
        public int VAL_51_1 { get; set; }
        public int VAL_51_2 { get; set; }
        public int VAL_51_3 { get; set; }
        public int VAL_51_4 { get; set; }
    
        public TotalStat[] Children;
    
    
        public FontWeight FontWeight
        {
            get
            {
                return Type == 2 ? FontWeights.Bold : FontWeights.Normal;
            }
        }
    
        public Thickness Margin
        {
            get
            {
                return new Thickness(this.Level * 10, 0, 0, 0);
            }
        }
    
        public string CNT_01
        {
            get
            {
                var v = VAL_01_1 + VAL_01_2 + VAL_01_3 + VAL_01_4;
                return v.ToString();
            }
        }
        public string CNT_51
        {
            get
            {
                var v = VAL_51_1 + VAL_51_2 + VAL_51_3 + VAL_51_4;
                return v.ToString();
            }
        }
        public string CNT_01_1
        {
            get
            {
                if (Type == 1) return "";
                if (VAL_01_1 == 0) return "-";
                return VAL_01_1.ToString();
            }
        }
        public string CNT_01_2
        {
            get
            {
                if (Type == 1) return "";
                if (VAL_01_2 == 0) return "-";
                return VAL_01_2.ToString();
            }
        }
        public string CNT_01_3
        {
            get
            {
                if (Type == 1) return "";
                if (VAL_01_3 == 0) return "-";
                return VAL_01_3.ToString();
            }
        }
    
    //В том же духе до CNT_51_4
    
        public static TotalStat operator +(TotalStat t, TotalStat c)
        {
            t.VAL_01_1 += c.VAL_01_1;
            t.VAL_01_2 += c.VAL_01_2;
            t.VAL_01_3 += c.VAL_01_3;
            t.VAL_01_4 += c.VAL_01_4;
            t.VAL_51_1 += c.VAL_51_1;
            t.VAL_51_2 += c.VAL_51_2;
            t.VAL_51_3 += c.VAL_51_3;
            t.VAL_51_4 += c.VAL_51_4;
            return t;
        }
    }

    На лабу похоже, да? А вот это не лаба. Сириозный праэкт для суровой организации (продолжение).

    kerman, 06 Апреля 2016

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