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

    +133

    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
    if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("");
    else if (textBox[0].Text != "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%'", textBox[0].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%'", textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%'", textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0}", textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("group={0}", textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text == "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%'", textBox[0].Text, textBox[1].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%'", textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1}", textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text == "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("course={0} and group={1}", textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text == "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%'", textBox[0].Text, textBox[1].Text, textBox[2].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2}", textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text == "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[midname] LIKE '%{0}%' and course={1} and group={2}", textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text == "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text);
    else if (textBox[0].Text == "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[name] LIKE '%{0}%' and [midname] LIKE '%{1}%' and course={2} and group={3}", textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);
    else if (textBox[0].Text != "" && textBox[1].Text != "" && textBox[2].Text != "" && textBox[3].Text != "" && textBox[4].Text != "")
        myViewStudentsTable.DefaultView.RowFilter = string.Format("[surname] LIKE '%{0}%' and [name] LIKE '%{1}%' and [midname] LIKE '%{2}%' and course={3} and group={4}", textBox[0].Text, textBox[1].Text, textBox[2].Text, textBox[3].Text, textBox[4].Text);

    "Есть 5 текстовых полей и желание понять, как можно в зависимости от пустоты или заполненности этих полей, одного или нескольких создать малое количество операторов if else"

    Порадовало "малое количество"

    Psilon, 08 Апреля 2015

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

    +132

    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 JsonResult Autocomplete(string term)
            {
                var result = new List<KeyValuePair<string, string>>();
    
                IList<SelectListItem> List = new List<SelectListItem>();
                List.Add(new SelectListItem { Text = "test1", Value = "0" });
                List.Add(new SelectListItem { Text = "test2", Value = "1" });
                List.Add(new SelectListItem { Text = "test3", Value = "2" });
                List.Add(new SelectListItem { Text = "test4", Value = "3" });
    
                foreach (var item in List)
                {
                    result.Add(new KeyValuePair<string, string>(item.Value.ToString(), item.Text));            
                }
                var result3 = result.Where(s => s.Value.ToLower().Contains(term.ToLower())).Select(w => w).ToList();
                return Json(result3, JsonRequestBehavior.AllowGet);
            }

    Наткнулся на CodeProject.

    kasthack, 06 Апреля 2015

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

    +839

    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
    protected virtual string GetParentTableControlID()
            {
                try
                {
                    if (this.Parent is BaseApplicationTableControl) return this.Parent.ID;
                    if (this.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.ID;
                    if (this.Parent.Parent.Parent.Parent is BaseApplicationTableControl) return this.Parent.Parent.Parent.Parent.ID;
                }
                catch (Exception)
                {
                }
                return "";
            }

    greyb, 03 Апреля 2015

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

    +95

    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
    var dt = DateTime.Now;
                var strTimeFilter = string.Empty;
                switch (filter.TimeTypeId)
                {
                    case 2:
                        strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-01 00:00:00.000") +
                                    "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 3:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-1).ToString("yyyy-MM-dd hh:mm:ss.fff") +
                                    "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 4:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-1).ToString("yyyy-MM-01 00:00:00.000") +
                                     "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 5:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-2).ToString("yyyy-MM-01 00:00:00.000") +
                                     "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 6:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddMonths(-5).ToString("yyyy-MM-01 00:00:00.000") +
                                    "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 7:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddYears(-1).ToString("yyyy-MM-dd hh:mm:ss.fff") +
                                    "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd hh:mm:ss.fff") + "'";
                        break;
                    case 8:
                        strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-dd 00:00:00.000") +
                                    "' AND r.ExpirationDateTime<='" + dt.ToString("yyyy-MM-dd 23:59:59.999") + "'";
                        break;
                    case 9:
                        strTimeFilter = "r.StartDateTime>='" + dt.AddDays(1).ToString("yyyy-MM-dd 00:00:00.000") +
                                        "' AND r.ExpirationDateTime<='" + dt.AddDays(1).ToString("yyyy-MM-dd 23:59:59.999") + "'";
                        break;
                    case 10:
                        strTimeFilter = "r.StartDateTime>='" + dt.ToString("yyyy-MM-dd 00:00:00.000") + "'";
                        break;
                    case -1:
                        var fds = filter.FirstTime.ToTrim();
                        var lds = filter.LastTime.ToTrim();
                        if (!string.IsNullOrEmpty(fds) && string.IsNullOrEmpty(lds))
                        {
                            DateTime fd;
                            if (DateTime.TryParse(fds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out fd))
                            {
                                strTimeFilter = " r.StartDateTime>='" + fd.ToString("yyyy-MM-dd 00:00:00.000") + "' ";
                            }
                        }
                        else if (string.IsNullOrEmpty(fds) && !string.IsNullOrEmpty(lds))
                        {
                            DateTime ld;
                            if (DateTime.TryParse(lds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out ld))
                            {
                                strTimeFilter = " r.ExpirationDateTime<='" + ld.ToString("yyyy-MM-dd 23:59:59.999") + "' ";
                            }
                        }
                        else if (!string.IsNullOrEmpty(fds) && !string.IsNullOrEmpty(lds))
                        {
                            DateTime fd, ld;
                            if (DateTime.TryParse(fds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out fd)
                                && DateTime.TryParse(lds, new CultureInfo("ru-RU", false), DateTimeStyles.None, out ld))
                            {
                                strTimeFilter = "r.StartDateTime>='" + DateTime.Parse(filter.FirstTime, new CultureInfo("ru-RU", false)).ToString("yyyy-MM-dd 00:00:00.000") +
                                    "' AND r.ExpirationDateTime<='" + DateTime.Parse(filter.LastTime, new CultureInfo("ru-RU", false)).ToString("yyyy-MM-dd 23:59:59.999") + "'";
                            }
                        }
                        break;
                }

    Это часть метода для формирования where-clause SQL-запроса для фильтра данных по дате вида "Сегодня", "Вчера", "За последний месяц", "За последние два месяца" и т. п.

    retter, 24 Марта 2015

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

    +780

    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 class B
    {
        private readonly List<M> ms = new List<M>(); 
    
        // ...
    
        public void Match(M m) { ms.Add(m); }
    
        public int IndexOf(M m) { return ms.IndexOf(m) == 0 ? 0 : 1; }
    
        // ...
    }
    
    public class M
    {
        // ...
    
        public void Match(B b)
        {
            try { b.Match(this); }
            catch (Exception e)
            {
                // ...
            }
        }
    
        // ...
    }

    Угадай песню по говнокоду. Сложность: 2/10.
    Можете минусовать, в общем-то.

    pushistayapodmyshka, 23 Марта 2015

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

    +772

    1. 1
    var ecwld = (from path in args let dirs = Directory.GetDirectories(path) from dirName in dirs.Select(dir => dir.Replace(path, "").Replace("\\", "")) let files = Directory.GetFiles(path + dirName) from file in files where file.Contains(dirName + ".ecwld") select file).ToList();

    skydev, 22 Марта 2015

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

    +774

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    Form f = new Form1();
    f.FormBorderStyle = FormBorderStyle.FixedToolWindow;
    f.WindowState = FormWindowState.Minimized;
    f.ShowInTaskbar = false;
    f.StartPosition = FormStartPosition.Manual;
    f.Location = new System.Drawing.Point(-2000, -2000);
    f.Size = new System.Drawing.Size(1, 1);
    f.Hide();
    f.Visible = false;
    f.Opacity = 0;
    Application.Run(f);

    LispGovno, 21 Марта 2015

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

    +354

    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
    private ChessField Recognize()
            {
                var output = new ChessField();
                for (int x = 0; x < 8; x++)
                {
                    for (int y = 0; y < 8; y++)
                    {
                        var xs = x*50;
                        var ys = y*50;
    
                        if (IsNeutral(bitmap.GetPixel(xs + 25, ys + 33)) && IsNeutral(bitmap.GetPixel(xs + 8, ys + 40)))
                        {
                            output.figures[y,x].kindOfFigure = Figure.KindOfFigure.Empty;
                        }
                        else
                        {
                            if ((IsWhite(bitmap.GetPixel(xs + 25, ys + 34)) ||
                                IsWhite(bitmap.GetPixel(xs + 30, ys + 25))) && !IsBlack(bitmap.GetPixel(xs + 9, ys + 42)))
                            {
                                output.figures[y, x].color = Figure.Color.White;
                                //white rec
    
                                
                                if (IsBlack(bitmap.GetPixel(xs + 25, ys + 7)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.King;
                                    continue;
                                }
                                if (!IsWhite(bitmap.GetPixel(xs + 25, ys + 32)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Queen;
                                    continue;
                                }
                                if (IsBlack(bitmap.GetPixel(xs + 25, ys + 22)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Bishop;
                                    continue;
                                }
                                if (IsBlack(bitmap.GetPixel(xs + 25, ys + 27)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Knight;
                                    continue;
                                }
                                if (IsWhite(bitmap.GetPixel(xs + 15, ys + 15)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Rook;
                                    continue;
                                }
                                output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Pawn;
    
                            }
                            else
                            {
                                output.figures[y, x].color = Figure.Color.Black;
                                //black rec
                                if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 25)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Bishop;
                                    continue;
                                }
                                if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 28))||
                                    !IsBlack(bitmap.GetPixel(xs + 25, ys + 29)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Knight;
                                    continue;
                                }
                                if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 36)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Rook;
                                    continue;
                                }
                                if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 31)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.King;
                                    continue;
                                }
                                if (!IsBlack(bitmap.GetPixel(xs + 25, ys + 33)))
                                {
                                    output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Queen;
                                    continue;
                                }
                                output.figures[y, x].kindOfFigure = Figure.KindOfFigure.Pawn;
                            }
                        }
    
                    }
                }
                return output;
            }

    4 часа ночи, вино, кофе, чужой курсач, распознание шахматных фигур со скриншота типа этого

    http://download.hdd.tomsk.ru/preview/xjntlwtz.jpg

    естесно поле уже вырезано и поджато под 400 на 400 пикселей

    kegdan, 20 Марта 2015

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

    +132

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    // var doc = new Document(file);
    var stream = new MemoryStream();
    file.CopyTo(stream);
    file.Position = 0;
    stream.Position = 0;
    var doc = new Document(stream);

    Ебал в рот Spire.Doc
    Нагло жует чужие потоки
    Причем только если документ - RTF
    Какого хуя вообще?

    ebal, 18 Марта 2015

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

    +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
    public static DateTime DateStringConvert(string dateString)
            {
                var dd = dateString.Substring(0, dateString.IndexOf('-'));
                var mm = dateString.Substring(dateString.IndexOf('-') + 1).Substring(0, dateString.IndexOf('-'));
                var yyyy = dateString.Substring(dateString.IndexOf('-') + 1).Substring(dateString.IndexOf('-') + 1)
                    .Substring(0, dateString.Substring(dateString.IndexOf('-') + 1)
                    .Substring(dateString.IndexOf('-') + 1).IndexOf(' '));
                var time = dateString.Substring(dateString.IndexOf('-') + 1).Substring(dateString.IndexOf('-') + 1)
                    .Substring(dateString.Substring(dateString.IndexOf('-') + 1)
                    .Substring(dateString.IndexOf('-') + 1).IndexOf(' ') + 1);
    
                var hh = time.Substring(0, time.IndexOf(':'));
                var MM = time.Substring(time.IndexOf(':') + 1);
                return new DateTime(
                    Convert.ToInt16(yyyy),
                    Convert.ToInt16(mm),
                    Convert.ToInt16(dd),
                    Convert.ToInt16(hh),
                    Convert.ToInt16(MM),
                    0);
            }

    Вот что происходит, когда не знаешь, как парсить string в DateTime. Говнокод получен от украинских фрилансеров.

    RaTT, 18 Марта 2015

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