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

    +114

    1. 1
    2. 2
    // FxCop does not allow the string "Uri" in a method name that does not return a Uri object.
        public static string To_U_r_i_TypeString(DeviceType type)

    dirtygopher, 26 Декабря 2012

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

    +132

    1. 1
    public virtual int ReadByte()

    Тут в соседнем треде появилась такая тема:

    http://msdn.microsoft.com/ru-ru/library/system.io.stream.readbyte.aspx
    http://govnokod.ru/12311#comment164854

    LispGovno, 20 Декабря 2012

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

    +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
    public static string GetCommandLineParameter(string ParameterName)
        {
          ParameterName = ParameterName.ToLower();
          string ParameterIdentifikator = ParameterName.ToLower() + "=";
          
          string RetVal = null;
          foreach(string Arg in Environment.GetCommandLineArgs())
          {
            string ArgLower = Arg.ToLower();
            if(ArgLower.IndexOf(ParameterIdentifikator) == 0)
            {
              RetVal = Arg.Substring(ParameterIdentifikator.Length, Arg.Length - ParameterIdentifikator.Length);
              return RetVal;
            }
          }
          return RetVal;
        }

    читаем параметры из командной строки

    taburetka, 19 Декабря 2012

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

    +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
    public bool checkUser(UserModel model = null)
    {
    	check:
    	if(model != null)
    		if(model.authenticated != false)
    			if(model._id > 0)
    				return true;
    			else
    				goto check;
    		else
    			goto check;
    	else
    		goto check;
    	return false;
    }

    а вдруг?!

    d3n4, 19 Декабря 2012

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

    +102

    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
    /// <summary>
    /// Проверка пароля *
    /// </summary>
    private string CheckPassword(String _password)
    {
        int kol = 0;
        const int LEN = 32;
        if (_password.Length == LEN)
            return _password;
        else
        {
            StringBuilder _pass = new StringBuilder(_password, LEN);
            if (_password.Length > LEN)
            {
                kol = _password.Length - LEN;
                return (_password.Substring(0, _password.Length - kol));
            }
            else
            {
                kol = LEN - _password.Length;
                int i = 0;
                while (i != kol)
                {
                    _pass.Append(" ");
                    i++;
                }
            }
            return _pass.ToString();
        }
    }

    Crazzy, 12 Декабря 2012

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

    +102

    1. 1
    2. 2
    3. 3
    4. 4
    var usr = Enumerable.Range(1, 1) 
    	.Select(id => new User(1, "FooBar", "desc" + 1, DateTime.UtcNow)) 
    	.ToReadonly() 
    	.GetRandomElement();

    Из юнит-теста. Копипаста рождает чудовищ.

    VasyaMatros, 08 Декабря 2012

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

    +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
    string New_naim = E.Remove(0, (NameGR(E.Trim()).Length)).Trim() + " " + Na;
                                    New_naim = New_naim.Trim();
                                    string check_naim =
                                        (E+Na).ToUpper().Replace(" ", "").Replace(",", ".").Replace("-", "").Replace("Е", "E")
                                        .Replace(";", "").Replace("*", "").Replace("Х", "X").Replace("О", "O").Replace("А", "A")
                                        .Replace("В", "B").Replace("М", "M").Replace("Н", "H").Replace("С", "C").Replace("Т", "T").Replace("З", "3")
                                        .Replace("Р", "P").Replace("Q", "G").Replace("К", "K").Replace("О", "O").Replace("0", "O").Replace("%", "").Replace("И", "U");
                                    string check_gosttu = GU.ToUpper().Replace(" ", "").Replace(",", ".").Replace("Е", "E").Replace(".", "")
                                        .Replace("З", "3").Replace(";", "").Replace("*", "").Replace("Х", "X").Replace("О", "O").Replace("А", "A")
                                        .Replace("И", "U").Replace("В", "B").Replace("М", "M").Replace("Н", "H").Replace("С", "C").Replace("Т", "T").Replace("-", "")
                                        .Replace("Р", "P").Replace("Q", "G").Replace("К", "K").Replace("О", "O").Replace("0", "O").Replace("+", "");
                                    /*quer = "SELECT PIN From dbo.Tb_Element Where (Id = '" + Id_el + "') AND "+
                                        "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(GOSTTU)" +
                                        ",' ',''),',','.') ,'Е','E'),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'.','') = '"+ check_gosttu+   
                                        "' AND replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(naim)" +
                                        ",' ',''),',','.') ,'Е','E'),'-',''),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O') = '" + check_naim + "'";*/
                                    quer = "SELECT e.PIN From dbo.Tb_Element e, dbo.tb_elementname n Where e.id = n.id AND "+
                                        "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(GOSTTU)" +
                                        ",' ',''),',','.') ,'Е','E'),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'.',''),'И','U'),'З','3'),'+',''),'-','') = '" + check_gosttu +
                                        "' AND replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(UPPER(LTRIM(RTRIM(n.element))+RTRIM(LTRIM(e.naim)))" +
                                        ",' ',''),',','.') ,'Е','E'),'-',''),'Х','X'),'Т','T'),'К','K'),'О','O'),';',''),'*',''),'А','A'),'В','B'),'М','M'),'Н','H'),'С','C'),'Р','P'),'Q','G'),'О','O'),'0','O'),'%',''),'З','3'),'И','U') = '" + check_naim + "'";

    Читаю старый код и радуюсь, что больше с ним не работаю. Правим результаты кривых рук операторов, заводящих данные.

    Grover, 04 Декабря 2012

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

    +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
    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
    if (parameter == null)//если ведомость доков...
                    {
                        cmd.Connection = dbc;
                        cmd.CommandText =
                            "SELECT RTRIM(n.Element) + ' '+ RTRIM(e.Naim) " +
                            "FROM tb_Element e, tb_ElementName n " +
                            "WHERE n.id = e.id " +
                            "AND e.GostTU ='" + head.Text.Substring(0, head.Text.IndexOf(" ")) + "'";
                        dbc.Open();
                        naim = cmd.ExecuteScalar().ToString();
                        dbc.Close();
                        cmd.CommandText =
                        "SELECT " +
                        " LTRIM(RTRIM(s.NameProject)) " +
                        ",LTRIM(RTRIM(n.Element)) + ' '+ LTRIM(RTRIM(e.Naim)) " +
                        ",LTRIM(RTRIM(d.Obozn)) " +
                        "FROM " +
                        " tb_document d " +
                        ",tb_specificationproject s " +
                        ",tb_element e " +
                        ",tb_elementname n " +
                        "WHERE " +
                        "d.pinsp = s.pinsp " +
                        "AND e.pin = s.pinsp " +
                        "AND n.id = e.id " +
                        "AND s.NameProject IN  " +
                        "( " +
                        namelist +
                        ") " +
                        "ORDER BY d.Pinsp ";
                        dbc.Open();
                        dbr = cmd.ExecuteReader();
                        counter = 0;
                        template = File.ReadAllLines(System.Windows.Forms.Application.StartupPath + "\\doclist.xml");
                        while (template[counter].Trim() != "</Table>")
                        {
                            if (template[counter].Trim() != "<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">%name%</Data></Cell>")
                            {
                                filedata.Add(template[counter]);
                            }
                            else
                            {
                                filedata.Add("<Cell ss:MergeAcross=\"4\" ss:StyleID=\"s67\"><Data ss:Type=\"String\">" + naim + "</Data></Cell>");
                            }
                            counter++;
    
                        }
                        tail_start = counter;
                        counter = 8;
                        tmp = "";
                        while (dbr.Read())
                        {
                            if (tmp != dbr[0].ToString())
                            {
                                tmp = dbr[0].ToString();
                                //Определяю высоту строки
                                CalcHeight = " ss:Height = " + '"' + Convert.ToString(rowHeight * (1 + dbr[1].ToString().Length / 10)) + '"';
                                filedata.Add("<Row" + CalcHeight.Replace(',', '.') + ">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[1].ToString().TrimEnd() + "</Data></Cell>");
                            }
                            else
                            {
                                filedata.Add("<Row ss:Height = \"" + Convert.ToString(rowHeight).Replace(',', '.') + "\">");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"Number\">" + (counter - 7).ToString() + "</Data></Cell>");
                                filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            }
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\">" + dbr[2].ToString().TrimEnd() + "</Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("<Cell ss:StyleID=\"s100\"><Data ss:Type=\"String\"> </Data></Cell>");
                            filedata.Add("</Row>");
                            counter++;
                        }
                        counter = tail_start;
                        while (counter < template.GetLength(0))
                        {
                            filedata.Add(template[counter]);
                            counter++;
                        }
                    }

    Суровый промышленный код. Выгружаем в эксель данные из БД.

    Grover, 03 Декабря 2012

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

    +107

    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
    //  define types
    const int FB2 = 0;
    const int TXT = 1;
    
    // private
    private int Type;
    …
    
    //  class methods
    public CVBook(string path, string type) {
        switch(type)
        {
            case "fb2":
                {
                    Type = 0;
                }
                break;
            case "txt":
                {
                    Type = 1;
                }
                break;
            default:
                {
                    throw new Exception("Unknown Book Format");
                }
        }
        …
        switch (Type) {
            case FB2: { … }
            case TXT: { … }
            default:
                {
                    throw new Exception("Unknown Book Format");
                }
            }
        }
    }

    Парсер книг, все в одном методе.

    ArtFeel, 30 Ноября 2012

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

    +106

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    private void FlowMouseEnter(object sender, MouseEventArgs e)
    {
        var dt = DateTime.Now;
        _currentTime = dt.Hour * 3600 + dt.Minute * 60 + dt.Second;
    }

    запоминаем время наведения на кнопку

    ArtFeel, 30 Ноября 2012

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