1. 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)
  2. 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)
  3. 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)
  4. 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)
  5. C# / Говнокод #6958

    +129

    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
    public void ReadFromFile()
    {
    	LoadIntervals = new TimeIntervals(Color.Black);
    	StreamReader tReader = null;
    	tReader = File.OpenText("DefaultIntervals");
    	string income = null;
    	while ((income = tReader.ReadLine()) != null)
    	{
    		// string income = tReader.ReadLine();
    		string colorR = null; string colorG = null; string colorB = null; string colorA = null; string interval = null;
    		int i = 0;
    		for (i = 4; i < income.Length; i++)
    		{
    			if (income[i] != ',')
    			{
    
    				interval += income[i];
    			}
    			else { break; }
    		}
    
    		for (int a = i + 10; a < income.Length; a++)
    		{
    			if (income[a] != ',')
    			{
    				colorA += income[a];
    			}
    			else
    			{
    
    				for (int r = a + 4; r < income.Length; r++)
    				{
    					if (income[r] != ',')
    					{
    						colorR += income[r];
    					}
    					else
    					{
    						for (int g = r + 4; g < income.Length; g++)
    							if (income[g] != ',')
    							{
    								colorG += income[g];
    							}
    							else
    							{
    								for (int b = g + 4; b < income.Length; b++)
    									if (income[b] != ',')
    									{
    										if (income[b] != ']')
    											colorB += income[b];
    									}
    									else
    									{
    										break;
    									}
    								break;
    							}
    						break;
    					}
    				}
    				break;
    			}
    		}
    		TimePoint tp = new TimePoint(Convert.ToDouble(interval), Color.FromArgb(Convert.ToInt32(colorA), Color.FromArgb(Convert.ToInt32(colorR), Convert.ToInt32(colorG), Convert.ToInt32(colorB))));
    		LoadIntervals.Add(tp);
    	}
    
    	tReader.Close();
    	Intervals = LoadIntervals;
    }

    Так мы парсим файл конфигов вида. (Формат придуман автором кода)
    Int=3,Color [A=223, R=253, G=4, B=38]
    Int=10,Color [A=255, R=86, G=86, B=185]
    Int=20,Color [A=200, R=255, G=215, B=0]
    Int=50,Color [A=200, R=255, G=165, B=0]

    lomomike, 15 Июня 2011

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

    +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
    16. 16
    if (body.ToLower().Contains("pr") || 
                    subject.Contains("PM") ||
                    subject.Contains("pm") ||
                    subject.Contains("Pm") ||
                    subject.Contains("pM") ||
                    subject.Contains("PMR") ||
                    subject.Contains("prs") || 
                    subject.ToLower().Contains("prt") ||
                    subject.ToLower().Contains("prm") ||
                    subject.ToLower().Contains("pmt") ||
                    subject.ToLower().Contains("pmk") ||
                    subject.ToLower().Contains("pml") ||
                    subject.ToLower().Contains("pal"))
                {
                    result = true;
                }

    Пишут друзья из Норвегии

    jenik15, 15 Июня 2011

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

    +126

    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
    public static bool ValidateEmailAddress(string emailAddress)
            {
                try
                {
                    string TextToValidate = emailAddress;
                    // test email address with expression
                    if (emailExpression.IsMatch(TextToValidate))
                    {
                        // is valid email address
                        return true;
                    }
                    else
                    {
                        // is not valid email address
                        return false;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

    public static bool ValidateEmailAddress(string emailAddress)
    {
    if(string.IsNullOrEmpty(emailAddress))
    return false;
    return emailExpression.IsMatch(TextToValidate);
    }

    jenik15, 14 Июня 2011

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

    +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
    private string CalculateDecadeOrYear(string year)
    		{
    			string decade = year.Remove(3) + "0";
    			string currentYear = DateTime.Now.Year.ToString();
    			string currentDecade = currentYear.Remove(3) + "0";
    			string prevDecade = ((Convert.ToInt32(currentYear.Remove(3)) - 1)).ToString() + "0";
    			if (!(decade == currentDecade) && !(decade == prevDecade))
    			{
    				return decade;
    			}
    			return year;
    		}

    stringly typed вычисление декады. нашел в исходниках индусов

    overberk, 14 Июня 2011

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

    +121

    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
    // первай варянт
    string[] GetMonth = 
    { 
        "Январь", "Февраль", "Март", "Апрель", 
        "Май", "Июнь", "Июль", "Август", "Сентябрь", 
        "Октябрь", "Ноябрь", "Декабрь" 
    };
    for (int i = 1; i <= 12; i++)
    {
         Console.WriteLine(GetMonth[i]);
    }
    
    // вторый варянт
    
    System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();
    for(int i = 1; i <= 12; i++)
    {
        string strMonthName = mfi.GetMonthName(i).ToString();
        Console.WriteLine(strMonthName);
    }

    Как в C# автоматически получить массив или список всех месяцев года (январь ... декабрь)?

    Paragraf, 12 Июня 2011

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

    +126

    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
    FileStream fsSource = new FileStream(fileName, FileMode.Open, FileAccess.Read);
    
    byte[] b = new byte[8192];
    int[] a = new int[4096];
    
    fsSource.Read(b, 0, 8192);
    
    int sum=0;
    int elem;
    for (int i = 0; i < 4096; i++)
    {
    elem = b[i * 2] * 256 + b[i*2+1];
    a[i] = elem; //раз уж нам всё равно надо заполнять этот массив, то мы его заполним
    sum += elem;
    }

    задача: считать 2-х байтные числа с бинарного файла и посчитать его сумму.

    slirx, 12 Июня 2011

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