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

    +146

    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
    case enter:
    						{
    							TreeNodeBackColorChange();
    							if (Connection.Login == "" || Connection.Login == null)
    							{
    								new fmlogin().ShowDialog();
    								try
    								{
    									if (Connection.Login != "")
    										foreach (TreeNode item in tvMenuList.Nodes)
    										{
    											if (item.Name == lk)
    											{
    												item.NodeFont = new Font("arial", 10, FontStyle.Bold);
    												item.Text += " (" + Connection.Login + ")";
    											}
    										}
    								}
    								catch { }
    							}
    							else MessageBox.Show("Вы уже авторизованы!", "Вход в личный кабинет", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    							break;
    						}
    					case leave:
    						{
    							TreeNodeBackColorChange();
    							if (Connection.Login != "" && Connection.Login != null)
    							{
    								if (MessageBox.Show("Вы уверены, что хотите выйти?", "Выход", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
    								{
    									Connection.Login = "";
    									Connection.Pass = "";
    									try
    									{
    										foreach (TreeNode item in tvMenuList.Nodes)
    										{
    											foreach (TreeNode item2 in item.Nodes)
    											{
    												foreach (TreeNode item3 in item2.Nodes)
    												{
    													if (item3.Name == lk)
    													{
    														item.NodeFont = tvMenuList.Font;
    														item3.Text = "Личный кабинет";
    													}
    												}
    												if (item2.Name == lk)
    												{
    													item.NodeFont = tvMenuList.Font;
    													item2.Text = "Личный кабинет";
    												}
    											}
    											if (item.Name == lk)
    											{
    												item.NodeFont = tvMenuList.Font;
    												item.Text = "Личный кабинет";
    											}
    										}
    									}
    									catch { }
    									MessageBox.Show("Выход произведен успешно!", "Выход", MessageBoxButtons.OK, MessageBoxIcon.Information);
    								}
    							}
    							else MessageBox.Show("Вы не авторизованы!", "Выход из личного кабинета", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    							break;
    						}

    извиняюсь) форматирование сбивается когда из студии вставляю)
    PS жалко что нельзя вставить больше 100 строк. А тут такие красивые функции есть, которые теряют всю свою зрелишность при их урезании

    slavenin, 02 Марта 2011

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

    +116

    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
    if (rbNewPackage.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id_user == ent.id
                                             select recb.date).Max() && r.id_status == 1
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbCancelled.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id_user == ent.id
                                             select recb.date).Max() && r.id_status == 5
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbConditional.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id == rp.id
                                             select recb.date).Max() && r.id_status == 3
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }
                    else if (rbOfficial.Checked)
                    {
                        var ls = from ent in Program.DB.UserInfos
                                 where
                                 (from rp in Program.DB.ReceivedPackages
                                  join r in Program.DB.RecordBooks on rp.id equals r.id_package
                                  where rp.id_user == ent.id &&
                                  r.date == (from recb in Program.DB.RecordBooks
                                             join recp in Program.DB.ReceivedPackages on recb.id_package equals recp.id
                                             where recp.id == rp.id
                                             select recb.date).Max() && r.id_status == 4
                                  select rp).Count() != 0
                                 select ent;
                        grdEntrantList.DataSource = Program.DB.UserInfos.Where(t => ls.ToList().Contains(t));
                    }

    говногод моего бывшего коллеги по работе))

    slavenin, 02 Марта 2011

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

    +118

    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
    foreach (var aiett in _selectApplItemEntranceTrial)
                {
                lbl2:
                    ReceptionReason_EducationLayout rrel_temp = null;
                    EntranceTrialItem_RecResEducLayout eti_rrel = null;
                    bool flag = false;
                    foreach (var rrel in _recReasonEducLay)
                        foreach (var ap in aiett.ListAppItem)
                            foreach (var rr in rrel.ListRecReas_EducLayout)
                                if (ap.ApplItem.Id_ReceptionReason_EducationLayout == rr.Id)
                                {
                                    rrel_temp = rr;
                                    eti_rrel = rrel;
                                    flag = true;
                                    goto lbl;
                                }
                lbl: ;
                    if (flag)
                    {
                        _recReasonEducLay.FirstOrDefault(x => x == eti_rrel).ListRecReas_EducLayout.Remove(rrel_temp);
                        if (_recReasonEducLay.FirstOrDefault(x => x == eti_rrel).ListRecReas_EducLayout.Count == 0)
                            _recReasonEducLay.Remove(eti_rrel);
                        goto lbl2;
                    }
                }

    Мой личный говнокод! Работающий правильно))))

    slavenin, 02 Марта 2011

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

    +124

    1. 1
    while (!Pr.HasExited) System.Threading.Thread.Sleep(250);

    Ожидание завершения запущенного процесса

    Мартин, 02 Марта 2011

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

    +115

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    RepaymentEvent e = DatabaseHelper.GetString("event_type", pReader) == "RBLE"
    	                ? new BadLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
    	                : (DatabaseHelper.GetString("event_type", pReader) == "RRLE"
    	                       ? new RescheduledLoanRepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
    	                       :(DatabaseHelper.GetString("event_type", pReader).StartsWith("P") 
                                    ? new PendingRepaymentEvent (DatabaseHelper.GetString("event_type", pReader)) {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}
                                    : new RepaymentEvent {Id = DatabaseHelper.GetInt32("rpe_id", pReader)}));

    Вот такую "элегантную" строчку нашел сегодня коллега в коде нашего проекта :)
    Создаем событие пойди разбери какое :)

    _Ru55_, 02 Марта 2011

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

    +112

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    DirectoryInfo dir = new DirectoryInfo(@"C:\Users\origLocation\");
    DirectoryInfo destDir = new DirectoryInfo(@"C:\Users\origLocation\destLocation\");
    FileInfo[] newVerFiles = dir.GetFiles("*.TXT");
    foreach (FileInfo newVerFile in newVerFiles)
    {
        Regex regex = new Regex("\\d+-new-ver.TXT", RegexOptions.IgnoreCase);
        if (regex.IsMatch(newVerFile.Name))
        {
            newVerFile.MoveTo(destDir.FullName);
        }
     }

    rusco_developer, 02 Марта 2011

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

    +123

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    private bool IsInt(object ValueToCheck)
    {
    	int Dummy = new int();
    	string InputValue = Convert.ToString(ValueToCheck);
    
    	//If user enters 45.00 This should not be allowed
    	//User must enter numbers without .00
    	if(InputValue.Contains("."))
    		return false;
    	bool Int = int.TryParse(InputValue, System.Globalization.NumberStyles.Any, null, out Dummy);
    	return Int;
    }

    Уже другой индусский автор наговнокодил. Орфография сохранена. Причем он сам себе в ногу выстрелил используя NumberStyles.Any...

    Вот как надо:

    private static bool IsInt(string valueToCheck) 
    {
    int dummy;
    return int.TryParse(valueToCheck, System.Globalization.NumberStyles.None, null, out dummy);
    }

    piocsic, 01 Марта 2011

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

    +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
    29. 29
    30. 30
    char[] splitter = { ',' };
    string types = hashtable[FlagsEnumValue].ToString();
    string[] typesStringArray = types.Split(splitter, StringSplitOptions.RemoveEmptyEntries);
    ArrayList typesArray = new ArrayList();
    
    foreach (string str in typesStringArray)
    {
       foreach (string type in Enum.GetNames(typeof(FlagsEnum)))
       {
          if (type == str.Trim())
          {
             typesArray.Add((FlagsEnum)Enum.Parse(typeof(FlagsEnum), str, true));
             break;
          }
       }
    }
    
    
    foreach (FlagsEnum type in typesArray)
    {
       if ((someObject.field & type) > 0)
       {
          typeFound = true;
       }
       else
       {
          typeFound = false;
          break;
       }
    }

    Автор хотел чтобы его любили. Точнее он хотел сконвертировать строковое представление битового енама в инам и сравнить по маске с проперти обьекта. Если бы автор прочел документацию то написал бы так:
    string types = hashtable[FlagsEnumValue].ToString();
    if (types != "")
    {
    FlagsEnum enum = (FlagsEnum)Enum.Parse(typeof(FlagsEnum), types, ignoreCase: true);
    if ((enum & someObject.field) == enum)
    typeFound = true;
    }

    piocsic, 01 Марта 2011

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

    +122

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    var product=dataContext.Products.Where(p=>p.Name == "SomeProductName")
    
    if (products.Count() != 0)
                {
                    return new Product
                    {
                        ProductId = products.First().AM_PRODUCT_ID,
                        ProductName = products.First().PRODUCT_NAME,
                        IsActive = products.First().IS_ACTIVE
                    };
                }

    this way of selecting product from table by its name generate 4 queries instead 1 ...

    O_O, 28 Февраля 2011

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

    +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
    int buf;
                    for (int j = 1; j < srows.Length; j++)
                        for (int i = 0; i < srows.Length - j; i++)
                        {
                            if (vrows[i] > vrows[i + 1])
                            {
                                buf = vrows[i];
                                vrows[i] = vrows[i + 1];
                                vrows[i + 1] = buf;
    
                                buf = srows[i];
                                srows[i] = srows[i + 1];
                                srows[i + 1] = buf;
                            }
                        }

    В коде формы. (c) EGAR

    jonie, 28 Февраля 2011

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