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

    +116

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    if ( check < 50000 ) {
        primaryAnimation = primaryAnimation;
    } else {
        int ani = (check - 50000) / 100;
        primaryAnimation = _OptionalAnimations["Run"][ani];
     }

    Найдено в недрах загрузчика MD2-моделек для XNA.

    RaZeR, 23 Июня 2011

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

    +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
    public void chkStatus_OnCheckedChanged(object sender, EventArgs e)
    {
        CheckBox chkStatus = (CheckBox)sender;
        GridViewRow row = (GridViewRow)chkStatus.NamingContainer;
    
        
        string cid = row.Cells[1].Text;
        bool status = chkStatus.Checked;
    
        
        string constr = @"Server=.\SQLEXPRESS;Database=TestDB;uid=waqas;pwd=sql;";
        string query = "UPDATE Categories SET Approved = @Approved WHERE CategoryID = @CategoryID";
            
        SqlConnection con = new SqlConnection(constr);
        SqlCommand com = new SqlCommand(query, con);
    
        
        com.Parameters.Add("@Approved", SqlDbType.Bit).Value = status;
        com.Parameters.Add("@CategoryID", SqlDbType.Int).Value = cid;
    
        
        con.Open();
        com.ExecuteNonQuery();
        con.Close();
    
        
        LoadData();
    }

    Полезный говнокод

    in4man, 23 Июня 2011

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

    +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
    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
    // создаём источник для репитера
    
    private DataTable EventsDataTable
            {
                get
                {
                    DataTable dt = new DataTable();
                    dt.Columns.Add(
                        new DataColumn("ID", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("day", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("date", typeof(DateTime)));
                    dt.Columns.Add(
                        new DataColumn("title", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("url", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("description", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("location", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("place", typeof(string)));
                    dt.Columns.Add(
                        new DataColumn("FileDirRef", typeof(string)));
                    // Добавляем строчки
                    foreach (EventInfo ei in CalendarEvents)
                    {
                        DataRow dr = dt.NewRow();
                        dr["day"] = ei.EventDate.Date.ToString("ddMMyyyy");
                        dr["date"] = ei.EventDate;
                        dr["title"] = ei.Title;
                        dr["location"] = ei.Location;
                        dr["ID"] = ei.ID;
                        dr["FileDirRef"] = ei.FileDirRef;
                        dt.Rows.Add(dr);
                    }
                    return dt;
                }
            }
    
    
    protected void repeaterItemDataBound(object sender, RepeaterItemEventArgs e)
    {
    if (e != null
                        && e.Item != null
                        && e.Item.DataItem != null
                        && e.Item.DataItem is DataRow)
                    {
                        DataRow dataItem = (DataRow)e.Item.DataItem;
    
                        Label date = (Label)(e.Item.FindControl("date"));
                        date.Text = 
                            dataItem["date"] != null
                            ? Convert.ToDateTime(dataItem["date"].ToString()).ToString()
                            : Convert.ToDateTime(dataItem["Created"].ToString()).ToString();
                        date.Text = date.Text.Substring(0, date.Text.Length - 3);
    
                        HyperLink title = (HyperLink)(e.Item.FindControl("title"));
                        title.Text = dataItem["title"].ToString();
                        Label location = (Label)(e.Item.FindControl("location"));
                        location.Text = "Расположение: " + dataItem["location"].ToString();
                    }
    }

    Современный способ привязки данных в asp.net Repeater

    Gnet, 22 Июня 2011

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

    +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
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    var trimmedKey = Regex.Split(key, @"\.").Last();
                    if (_options.Any(o => o == ModelBinderOptions.ExpectUnderLineSymbolAsPrefixDelimiter))
                        trimmedKey = Regex.Split(trimmedKey, "_").Last();
    
                    if (_allRequiredParameters.Any(p => p.Key.ToLower() == trimmedKey.ToLower()))
                    {
                        var param = _allRequiredParameters.Single(p => p.Key.ToLower() == trimmedKey.ToLower());
    
                        try
                        {
                            if (param.Value != typeof(string))
                            {
                                if (Nullable.GetUnderlyingType(param.Value) != null)
                                {
                                    try
                                    {
                                        var parseMethod = Nullable.GetUnderlyingType(param.Value).GetMethods().Where(m => m.Name == "Parse").First(m => m.GetParameters().Count() == 1 && m.GetParameters().First().ParameterType == typeof(string));
                                        var value = parseMethod.Invoke(null, new object[] { form[key] });
                                        formValues.Add(param.Key, value);
                                    }
                                    catch(Exception)
                                    {
                                        formValues.Add(param.Key, null);
                                    }
                                }
                                else
                                {
                                    var parseMethod = param.Value.GetMethods().Where(m => m.Name == "Parse").First(m => m.GetParameters().Count() == 1 && m.GetParameters().First().ParameterType == typeof(string));
                                    var value = parseMethod.Invoke(null, new object[] { form[key] });
                                    formValues.Add(param.Key, value);
                                }
                                
                            }
                            else
                            {
                                formValues.Add(param.Key, form[key]);
                            }
                        }
                        catch (Exception)
                        {
                            // Если произошла ошибка парсинга - печально, но ничего не поделать
                        }
                    }

    Фееричный парсер

    dans, 21 Июня 2011

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

    +130

    1. 1
    2. 2
    3. 3
    4. 4
    private static bool? GetBoolFromObject(object o)
            {
                return string.IsNullOrEmpty(o.ToString()) ? (bool?)null : (bool)o;
            }

    и как такое можно только писать...

    testguru, 20 Июня 2011

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

    +132

    1. 1
    for(dynamic o=0; o!=237; o++){

    Ох, что мне досталось поддерживать... dynamic почти везде... :( Кто это написал??? Хочу этого человека взять и @#$%^&... :(

    Говногость, 19 Июня 2011

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

    +128

    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 string GetUserCurrentStage(int stage)
     {
                string stageName = "";
                if (stage == 1)
                    stageName += "Initial Certification";
                else if (stage == 2)
                {
                    stageName += "Maintenance *";
                }
                else if (stage == 3)
                    stageName += "Recertification";
                else
                    return string.Empty;
                return stageName;
     }

    Когда платят за строчки кода...

    musuk, 17 Июня 2011

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

    +123

    1. 1
    this.Border1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(111)))), ((int)(((byte)(111)))), ((int)(((byte)(111)))));

    Встретилось такое внутри сгенеренной системой InitializeComponent()

    absolut, 17 Июня 2011

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

    +127

    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
    try
                {
                     this.DBConn.Open();
                }
                catch (Exception)
                {
                    try
                    {
                        this.DBConn.Close();
                        this.DBConn.Open();
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.EventLog.WriteEntry("Agent", "Ошибка подключения к базе данных: " + ex.ToString(),
                            System.Diagnostics.EventLogEntryType.Error);
                        return;
                    }
                }

    Поразительная настойчивость

    dens, 16 Июня 2011

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

    +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
    protected string getUpdateNotesDE(string fieldNameAlias, string fieldName, string fieldValue, ASPxDateEdit newValue)
            {
                if (isSaveField("fieldName"))
                {
                    if (fieldValue != "")
                        return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = " + Convert.ToDateTime(fieldValue).ToString("dd/MM/yyyy") + ", New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                    else
                        if (newValue.Text != "")
                            return "Field " + locCom.getFieldAlias("payTFNDeclaredOn") + ", Old Value = , New Value = " + Convert.ToDateTime(newValue.Text).ToString("dd/MM/yyyy") + " ; ";
                }
                return "";
    
            }
    
     protected Boolean isSaveField(string fieldName)
            {
                if (locCom.getVisible(fieldName))
                    return true;
                return false;
            }
    
     public bool getVisible(string fldName)
                {
                    Boolean showall = Convert.ToBoolean(System.Web.Configuration.WebConfigurationManager.AppSettings.Get("Show-all-fields"));
                    if (showall) return true;
    
                    if (fldAccess.Tables.Count == 0) return false;
    
                    foreach (System.Data.DataRow item in fldAccess.Tables[0].Rows)
                    {
                        if (item["fieldname"].ToString().Replace('@', 'a').Replace("%", "percent").Replace("$", "dollar").ToLower() == fldName.ToLower())
                            return Convert.ToBoolean(item["visible"]);
                    }
                    return false;
                }

    особенно доставляет
    protected string getUpdateNotesDE(string fieldName){
    if (isSaveField( !!! "fieldName" !!!)){}
    }

    valorkin, 15 Июня 2011

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