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

    +137

    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
    Index and length must refer to a location within the string.
    Parameter name: length
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
    
    Exception Details: System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
    Parameter name: length
    
    Source Error:
    
    
    Line 1239:    // СЕГОДНЯ И ВЧЕРА
    Line 1240:    string agent = Request.UserAgent;
    Line 1241:    string sid = DateTime.Now.ToShortDateString().Substring(0, 10).Replace(".", "").Replace("/", "").Replace("-", "");
    Line 1242:    string sid2 = DateTime.Now.AddDays(-1).ToShortDateString().Substring(0, 10).Replace(".", "").Replace("/", "").Replace("-", "");
    Line 1243:    //

    http://tltgorod.ru/news/theme-5/news-21502

    Хуяк-хуяк и в продакшн.

    bakagaijin, 24 Апреля 2014

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

    +137

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    public class Entity
    {
        // пример
        private DateTime _modified = new DateTime(2014, 4, 18, 23, 59, 59);
    
      public void SaveModified()
      {
                var date = DateTime.Parce(this._datetime.ToShortDateString());
                base.Save(date, ... );
      }
    }

    Продолжение проекта http://govnokod.ru/15780

    Насколько я понял, то это "операция усечения даты" 8-D
    которая должна была выглядеть так:
    var date = this._datetime.Date;

    CodeKiller, 19 Апреля 2014

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

    +136

    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
    // где-то там ...  
    private int Kapital = 777;
    
    // ...
    
    void Save()
    {
    ...
                int kapital;
                try { kapital = (int)Double.Parse(Kapital.ToString()); }
                catch { kapital = 0; }
    ...
    }

    Проект из солнечной Швейцарии...
    И таких перлов много :)

    CodeKiller, 18 Апреля 2014

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

    +131

    1. 1
    2. 2
    3. 3
    4. 4
    DateTime dateEst = DateTime.Now.ToEstTime();
    StringBuilder responseTime = new StringBuilder();
    responseTime.Append(dateEst.ToString("MM/dd/yyyy"));
    responseTime.Append(dateEst.ToString("  h:mm:ss tt"));

    Отображаем время ответа от сервера в удобном формате.

    vertu, 17 Апреля 2014

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

    +137

    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
    model.PID = row["PID"].ToString();
    model.Rect = row["RECt"].ToString();
    model.Pubt = row["PUBt"].ToString();
    model.Ex = row["Ex"].ToString();
    model.Prev_Vol = row["Prev_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Prev_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Curr_Vol = row["Curr_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Curr_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Mov_Vol = row["Mov_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Mov_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    decimal tonavgvol = Tools.ParseDecimalValue(row["Mov_Vol"].ToString());
    decimal currentvol = Tools.ParseDecimalValue(row["Curr_Vol"].ToString());
    if (row["Mov_Vol"].ToString() != "" && row["Curr_Vol"].ToString() != "" && tonavgvol != 0)
    	model.VolRat = (currentvol / tonavgvol).FormatAmount();
    model.Open_Vol = row["Open_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Open_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.Close_Vol = row["Close_Vol"].ToString() != "" ? Tools.ParseDecimalValue(row["Close_Vol"].ToString()).FormatAmountWithoutDecimal() : "";
    model.AllTicks = row["AllTicks"].ToString() != "" ? Tools.ParseDecimalValue(row["AllTicks"].ToString()).FormatAmountWithoutDecimal() : "";
    model.ATR = row["ATR14"].ToString() != "" ? Tools.ParseDecimalValue(row["ATR14"].ToString()).FormatAmountFourDecimals() : "";
    decimal open = Tools.ParseDecimalValue(row["Open"].ToString());
    decimal close = Tools.ParseDecimalValue(row["Close"].ToString());
    if (row["Open"].ToString() != "" && row["Close"].ToString() != "" && open != 0)
    	model.PrevDay = (((close - open) / open) * 100).FormatPercent();
    model.PrevClose = row["PrevClose"].ToString() != "" ? Tools.ParseDecimalValue(row["PrevClose"].ToString()).FormatAmount() : "";
    model.DayOpen = row["DayOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["DayOpen"].ToString()).FormatAmount() : "";
    decimal prevclose = Tools.ParseDecimalValue(row["PrevClose"].ToString());
    decimal dayopen = Tools.ParseDecimalValue(row["DayOpen"].ToString());
    if (row["DayOpen"].ToString() != "" && row["PrevClose"].ToString() != "" && prevclose != 0)
    	model.OpenGap = (((dayopen - prevclose) / prevclose) * 100).FormatPercent();
    model.SPYLast = row["TONSPLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONSPLast"].ToString()).FormatAmount() : "";
    model.TONOpen = row["TONOpen"].ToString() != "" ? Tools.ParseDecimalValue(row["TONOpen"].ToString()).FormatAmount() : "";
    model.TONHigh = row["TONHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["TONHigh"].ToString()).FormatAmount() : "";
    model.TONLow = row["TONLow"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLow"].ToString()).FormatAmount() : "";
    model.TONLast = row["TONLast"].ToString() != "" ? Tools.ParseDecimalValue(row["TONLast"].ToString()).FormatAmount() : "";
    model.EODHigh = row["EODHigh"].ToString() != "" ? Tools.ParseDecimalValue(row["EODHigh"].ToString()).FormatAmount() : "";
    model.EODLow = row["EODLow"].ToString() != "" ? Tools.ParseDecimalValue(row["EODLow"].ToString()).FormatAmount() : "";
    model.EODClose = row["EODClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODClose"].ToString()).FormatAmount() : "";
    model.SPYClose = row["EODSPClose"].ToString() != "" ? Tools.ParseDecimalValue(row["EODSPClose"].ToString()).FormatAmount() : "";
    model.PostVWAP = row["PostVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PostVWAP"].ToString()).FormatAmount() : "";
    model.PreVWAP = row["PreVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["PreVWAP"].ToString()).FormatAmount() : "";
    model.MainVWAP = row["MainVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["MainVWAP"].ToString()).FormatAmount() : "";
    model.AllVWAP = row["AllVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["AllVWAP"].ToString()).FormatAmount() : "";
    model.EODVWAP = row["EODVWAP"].ToString() != "" ? Tools.ParseDecimalValue(row["EODVWAP"].ToString()).FormatAmount() : "";
    
    decimal tonlast = Tools.ParseDecimalValue(row["TONLast"].ToString());
    decimal eodhigh = Tools.ParseDecimalValue(row["EODHigh"].ToString());
    decimal eodlow = Tools.ParseDecimalValue(row["EODLow"].ToString());
    decimal tonhigh = Tools.ParseDecimalValue(row["TONHigh"].ToString());
    decimal tonlow = Tools.ParseDecimalValue(row["TONLow"].ToString());
    decimal eodclose = Tools.ParseDecimalValue(row["EODClose"].ToString());
    decimal oedspclose = Tools.ParseDecimalValue(row["EODSPClose"].ToString());
    decimal tonsplast = Tools.ParseDecimalValue(row["TONSPLast"].ToString());
    
    // еще где-то 100-150 строчек в таком же духе

    ADO.NET во все поля.
    Бизнес-логика? Что это такое?

    P.S. У класса model все свойства типа string, у всех decimal переменных потом тоже вызывается ToString().

    vertu, 11 Апреля 2014

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

    +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
    internal enum IsScanned
        {
            Create = 0,
            Scan = 1,
            Complete = 2,
            Error = 3,
            NoAccess = 4,
        }
    
    ...
    
    public int IsScanned { get; set; }
    
    ...
    
    if (details.IsScanned != (int)IsScanned.Create)

    paulem, 11 Апреля 2014

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

    +134

    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
    foreach (Admin _admin in _admins.Where(a => a.Login == _login))
                    {
                        if (_admin.Password == _password)
                        {
                            SessionObj = new Al2AllAuth
                            {
                                AccessId = _admin.Type,
                                Ename = _admin.Name,
                                Whoid = _admin.Id
                            };
                            var _type = (AdminTypes) _admin.Type;
                            switch (_type)
                            {
                                case AdminTypes.FirstType:
                                    return RedirectToAction(c_adminActionName, c_userControllerName);
                                case AdminTypes.SecondType:
                                    if (string.IsNullOrEmpty(model.Page) || string.IsNullOrEmpty(model.Uid))
                                        throw new ArgumentException(InternalResources.EmptyPageOrUid, "model");
                                    return RedirectToAction(model.Page, new { uid = model.Uid });
                                default: 
                                    break;
                            }
                        }
                        else
                        {
                            return RedirectToAction(_errorActionName);
                        }
                    }

    Лямбда в foreach очен смутила... Зачем?

    KonstantinK, 11 Апреля 2014

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

    +142

    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
    List<EntryChange> changes = new List<EntryChange>();
    
    for (int index = 0;
                index < partsContainer.transform.childCount;
                        ++index)
    {
    
        if (partsContainer
                    .transform
                        .GetChild(index)
                                .GetComponent<castle_parts_container>()
                                    .inSave()
                        ==
                        true)
        {
    
            // id of current part on scene
            int partId =
                    partsContainer.transform
                        .GetChild(index).gameObject
                                .GetComponent<castle_parts_container>()
                                                        .partIdentificator;
    
            int partColor =
                    partsContainer.transform
                        .GetChild(index).gameObject
                                .GetComponent<castle_parts_container>()
                                                            .savedColor();
            int partNumber =
                    partsContainer.transform
                        .GetChild(index).gameObject
                                .GetComponent<castle_parts_container>()
                                                            .savedNumber();
    
            EntryChange change = new EntryChange();
    
            change.original =
                    partsContainer.transform
                                    .GetChild(index).gameObject;
            change.target =
                    partPrefabs.Where(
                        x => x.GetComponent<castle_parts_container>().partIdentificator
                                ==
                                partId
                                    &&
                                x.GetComponent<castle_parts_container>().partColor
                                    ==
                                    partColor
                                        &&
                                    x.GetComponent<castle_parts_container>().partNumber
                                        ==
                                        partNumber
                    ).First();
    
            changes.Add(change);

    Избыточный код с форматированием в стиле Маяковского

    arazect, 08 Апреля 2014

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

    +128

    1. 1
    2. 2
    3. 3
    if (f > 1) { }
    else
    chart5.Series[1].Points.AddXY(i, f);

    Было замечено за коллегой

    goaquit, 05 Апреля 2014

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

    +131

    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
    xlApp = new Excel.Application();
                try
                {
                    xlApp.Workbooks.Add(Type.Missing);
    
                    xlApp.Interactive = false;
                    xlApp.EnableEvents = false;
    
                    xlSheet = (Excel.Worksheet)xlApp.Sheets[1];
                    xlSheet.Name = "Данные";
    
                    DataTable dt = GetData();
    
                    int collInd = 0;
                    int rowInd = 0;
                    string data = "";
    
                    for (int i = 0; i < dt.Columns.Count; i++)
                    {
                        data = dt.Columns[i].ColumnName.ToString();
                        xlSheet.Cells[1, i + 1] = data;
    
                        xlSheetRange = xlSheet.get_Range("A1:Z1", Type.Missing);
    
                        xlSheetRange.WrapText = true;
                        xlSheetRange.Font.Bold = true;
                    }
    
                    for (rowInd = 0; rowInd < dt.Rows.Count; rowInd++)
                    {
                        for (collInd = 0; collInd < dt.Columns.Count; collInd++)
                        {
                            data = dt.Rows[rowInd].ItemArray[collInd].ToString();
                            xlSheet.Cells[rowInd + 2, collInd + 1] = data;
                        }
                    }
    
                    xlSheetRange = xlSheet.UsedRange;
    
                    xlSheetRange.Columns.AutoFit();
                    xlSheetRange.Rows.AutoFit();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    xlApp.Visible = true;
    
                    xlApp.Interactive = true;
                    xlApp.ScreenUpdating = true;
                    xlApp.UserControl = true;
    
                    releaseObject(xlSheetRange);
                    releaseObject(xlSheet);
                    releaseObject(xlApp);
                }

    orozov, 04 Апреля 2014

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