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

    +95.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    static bool EqStr(string s)
    {
                Regex r = new Regex(@"STRING");
                Match m = r.Match(s);
                if (m.Success == true) return true;
                else return false;
    }

    Изощренный способ сравнивать строки :)

    psina-from-ua, 10 Ноября 2009

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

    +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
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    public string generateEMail()
    		{
    			string res;
    			int i = PersonName.IndexOf(" ");
    			char[] str1 = new char[i];
    			PersonName.CopyTo(0, str1, 0, i);
    			string str11 = new string(str1);
    			char[] str2 = new char[PersonName.Length - i - 1];
    			PersonName.CopyTo(i + 1, str2, 0, PersonName.Length - i - 1);
    			string str22 = new string(str2);
    			res = str11.ToString() + "." + str22.ToString();
    			if (res.Length > 20)
    			{
    				str1 = new char[20];
    				res.CopyTo(0, str1, 0, 20);
    				res = new string(str1);
    			}
    			res += "@domain.ua";
    			return res;
    		}

    Вот вам шаблон для получения емейла из имени и фамилии сотрудника.

    Woonder, 10 Ноября 2009

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

    +123.7

    1. 1
    Request.QueryString["outer_email"] = null;

    Это я намерил на несколько места :)

    bugotrep, 09 Ноября 2009

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

    +126.4

    1. 1
    2. 2
    3. 3
    4. 4
    foreach (object item in this.cbFind.Properties.Items)
                    {
                        int a = -1;
                    }

    Behemoth, 06 Ноября 2009

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

    +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
    public Int32 SectionType
            {
                get
                {
                    if (this.StaticRecord) return -1;
                    if ((!this.SectionIsReference) && this.SectionDoNotMakeUp) return 4;
                    if (this.SectionIsSlave)
                    {
                        switch (this.SectionUnionMode)
                        {
                            case 1:
                                return 2;
                            case 2:
                                return 0;
                            default:
                                return 1;
                        }
                    }
                    if (this.SectionIsReference) return 5;
                    if (this.SectionIsUnion) return 3;
                    return 0;
                }
            }

    Собственноручно нагадил...

    Behemoth, 06 Ноября 2009

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

    +136.7

    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
    void parseDate(String str, ref int day, ref int month, ref int year)
            {
                String[] strings = str.Split('/');
                day = Int32.Parse(strings[0]);
                month = Int32.Parse(strings[1]);
                year = Int32.Parse(strings[2]);
            }
    
    bool validateDate(String s)
            {
                //let the data be null
                if (s == null || s == "")
                    return true;
                try
                {
                    String[] strings = s.Split('/');
                    if (strings.Length != 3)
                        return false;
    
                    String day = strings[0];
                    if (Int32.Parse(day) > 31)
                    {
                        return false;
                    }
                    String month = strings[1];
                    if (Int32.Parse(month) > 12)
                    {
                        return false;
                    }
                    String year = strings[2];
                    if (year.Length != 4)
                    {
                        return false;
                    }
                }
                catch (SystemException)
                {
                    return false;
                }
                return true;
            }
    
    int compareDates(String s1, String s2)
            {
                if (s1 == "" && s2 != "")
                    return -1;
                if (s1 == s2)
                    return 0;
                if (s1 != "" && s2 == "")
                    return 1;
    
                int day1 = 0, month1 = 0, year1 = 0, day2 = 0, month2 = 0, year2 = 0;
                parseDate(s1, ref day1, ref month1, ref year1);
                parseDate(s2, ref day2, ref month2, ref year2);
                if (year1 > year2)
                    return -1;
                if (year1 < year2)
                    return 1;
    
                if (month1 > month2)
                    return -1;
                if (month2 < month1)
                    return 1;
    
                if (day1 > day2)
                    return -1;
                if (day2 > day1)
                    return 1;
    
                return 0;
            }

    no comments

    alex, 06 Ноября 2009

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

    +947.7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    foreach (string id in sourceIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    sourceId = Convert.ToInt32(id);
                    break;
                }

    Как взять первую цифру в строке - конечно без цикла тут никак

    eval_2009, 03 Ноября 2009

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

    +98

    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
    static void CompressFile(string inFilename, 
                                 string outFilename)
        {
    
          FileStream sourceFile = File.OpenRead(inFilename);
          FileStream destFile = File.Create(outFilename);
    
          // Create the Compressed stream
          GZipStream compStream =
            new GZipStream(destFile, CompressionMode.Compress);
    
          // Write the data
          int theByte = sourceFile.ReadByte();
          while (theByte != -1)
          {
            compStream.WriteByte((byte)theByte);
            theByte = sourceFile.ReadByte();
          }
    
          // Clean it up
          sourceFile.Close();
          compStream.Close();
          destFile.Close();
        }

    Пример из книги "Microsoft .NET Framework 2.0 Application Development Foundation", официального пособия для подготовки к экзамену 70-536.
    Угадайте, почему "сжатые" файлы получаются больше несжатых.

    gecko, 02 Ноября 2009

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

    +135.9

    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
    StiReport report = // создание отчета  StimulSoft Reporter          
     // . . . . .
     
    // . . . . . 
                string tempfilename = System.Guid.NewGuid().ToString() + ".tmp";
                report.ExportDocument(StiExportFormat.Word2007, tempfilename);    //позволяет конвертировать отчет только в поток 
    
                FileStream stream = new FileStream(tempfilename, FileMode.Open);
                byte[] reportFile = new byte[stream.Length];
                stream.Read(reportFile, 0, (int)stream.Length);
                stream.Close();
                File.Delete(tempfilename);
    
                if (reportFile.Length > 0)
                    if (MessageBox.Show("Зберегти друковану форму?", "Запит", MessageBoxButtons.OKCancel) == DialogResult.OK)
                         WriteToDB(reportFile, "Документ.docx");

    sven47, 31 Октября 2009

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

    +105.3

    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 class ImportService : System.Web.Services.WebService
       {
           private const string KEY = "*******";
           [WebMethod]
           public void AddFileInQueue(string aKey, ..., out String error)
           {
                     ...
                   if (KEY == aKey)
                     ...
                   else
                   {
                       error = "Invalid key";
                   }
            }
        }

    Мне предложили использовать эту же авторизацию для нового веб-сервиса в том же проекте со словами "there is normal login implemented somewhere"

    Yagg, 28 Октября 2009

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