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

    +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
    private void ProcessMessages()
    {
    	if (!string.IsNullOrEmpty(Request.QueryString["m"]))
    	{
    		string mes = string.Empty;
    		switch (Request.QueryString["m"])
    		{
    			case "2":
    				mes = "Настройки были успешно сохранены.";
    				break;
    			
    			...
    			
    			case "10":
    				mes = "Изменения в получении отчётов на e-mail, были сохранены.";
    				break;
    			case "11":
    				mes = "Установлен новый основной счет.";
    				break;
    			case "12":
    				mes = "Счёт был успешно отключен.";
    				break;
    		}
    
    		webMessage.Text = HtmlUtils.PrintBreak(mes);
    	}
    }

    Enum?

    asilmacc, 01 Сентября 2010

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

    +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
    using System;
    using System.IO;
    using System.IO.Compression;
    using System.Text;
    using System.Net;
    
    class Data : IDisposable
    {
        public void Dispose() { }
    
        MemoryStream MemStr;
    
        public Data(string Url)
        {
            UnZipFile(Url);
        }
    
        MemoryStream DownloadData(string Url)
        {
            using (WebClient Wc = new WebClient())
            {
                MemStr = new MemoryStream(Wc.DownloadData(Url));
            }
    
            return MemStr;
        }
    
        void UnZipFile(string Url)
        {
            MemoryStream MemStr = DownloadData(Url);
    
            using (GZipStream ZipStr = new GZipStream(MemStr, CompressionMode.Decompress))
            {
                byte[] P = new byte[ZipStr.BaseStream.Length];
                ZipStr.BaseStream.Read(P, 0, P.Length);
                FileStream Fs = new FileStream("TmpFile.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                Fs.Write(P, 0, P.Length);
                Fs.Flush();
            }
        }
    }
    
    class Program
    {
        static void Main()
        {
            while (true)
            {
                Console.Write("\nPlease, insert link to download ZIP-file >> ");
                string Abc = Console.ReadLine();
    
                using (Data Obj = new Data(Abc)) ;
            }
        }
    }

    sergylens, 29 Августа 2010

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

    +123

    1. 1
    2. 2
    3. 3
    4. 4
    string mailTo = ((Config.GetSetting("AdminNotifications_EmailAddress") == null) ||
                                 (Config.GetSetting("AdminNotifications_EmailAddress").Length <= 0))
                                    ? Globals.GetHostPortalSettings().HostSettings["SMTPPassword"].ToString()
                                    : Config.GetSetting("AdminNotifications_EmailAddress");

    из модуль для DotNetNuke

    Coffeeholic, 28 Августа 2010

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

    +124

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    // Split the domain in parts
    string[] sParts = sEmailAddress.Split("@".ToCharArray(), 42);
    
    // An e-mail address must, as a minimum, contain 2 parts separated by a @
    if (sParts.Length != 2) 
    {
        throw new InvalidEmailAddressException(sEmailAddress);
    }

    Валидатор email-адреса.

    musuk, 26 Августа 2010

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

    +114

    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
    public class VKUrlManager
        {
            public static string API_URL = "http://api.vkontakte.ru/api.php";
    
            public static string WithdrawVotes(int iVotes, int iUserID)
            {
                string sTime = "timestamp=" + DateTime.Now.ToFileTimeUtc();
                string sRandom = "random=" + GE.Utils.GetRandom(int.MaxValue);
    
                return API_URL + "?api_id=" + DA.AppConfig.ApiId
                    + "&method=secure.withdrawVotes"
                    + "&v=2.0"
                    + "&" + sRandom
                    + "&" + sTime
                    + "&uid=" + iUserID
                    + "&votes=" + iVotes
                    + "&sig=" + GenerateSig(new string[] 
                        { "api_id=" + DA.AppConfig.ApiId, "v=2.0", "method=secure.withdrawVotes",
                            "uid=" + iUserID, "votes=" + iVotes,
                            sTime,sRandom
                        });
    
            }
    
            public static string GenerateSig(string[] aParams)
            {
                Array.Sort(aParams);
                string s = "";
                for(var i = 0; i< aParams.Length; i++)
                    s += aParams[i];
                s += DA.AppConfig.ApiSecret;
                return GE.Utils.GetMD5Hash(s);
            }
        }

    главный метод во всех приложениях вконтакте, ради которого эти приложения, собственно, и пишутса!
    ps:// по-моему говнокод

    nolka4, 24 Августа 2010

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

    +101

    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
    90. 90
    private void SetValue(UserStructure item, int id, int tabKey, int elementKey, string newValue)
            {
                if (!item.Chats.ContainsKey(id))
                    throw new KeyNotFoundException(String.Format(
                        "Чат с id = '{0}' недоступен с этой учётной записи", id));
    
                if (item.UserName != item.Chats[id].Own)
                {
                    switch (item.Chats[id].UserPremission)
                    {
                        case UserPremission.AccountLocked:
                            throw new AccessViolationException(String.Format(
                                "Чат с id = '{0}' заблокирован", id));
                    }
                }
    
                int assemblyNumber = item.Chats[id].AssemplyNumber;
    
                if (!_contentManager.AssembplyContent.ContainsKey(assemblyNumber))
                    throw new NotImplementedException(String.Format(
                        "Для сборки = '{0}' контент не реализован", assemblyNumber));
    
                Dictionary<int, TabItem> tabs = _contentManager.AssembplyContent[assemblyNumber];
    
                if (!tabs.ContainsKey(tabKey))
                    throw new NotImplementedException(String.Format(
                        "Вкладка с ключём = '{0}' в сборке = '{1}' не существует", tabKey, assemblyNumber));
    
                if (!tabs[tabKey].Elements.ContainsKey(elementKey))
                    throw new NotImplementedException(String.Format(
                        "Элемент с ключём = '{0}' во вкладке = '{1}' и сборке = '{2}' не существует", 
                        elementKey, tabKey, assemblyNumber));
    
                ElementItem element = tabs[tabKey].Elements[elementKey];
    
                GetSetParametrs getSetParametrs = new GetSetParametrs(item.Chats[id]);
    
                switch (element.ContentType)
                { 
                    case ContentType.text_box:
                        switch (element.Resource)
                        { 
                            case ResourceType.file:
                                getSetParametrs.SetValueToFile(element.Value, newValue);
                                break;
    
    			...............................................
    
                            case ResourceType.change_login:
                                getSetParametrs.SetValueToChangeLogin(item.UserName, newValue);
                                break;
    
                            case ResourceType.change_password:
                                getSetParametrs.SetValueToChangePassword(newValue);
                                break;
                        }
                        break;
    
                    case ContentType.payment_button:
                        switch (element.Resource)
                        {
                            case ResourceType.extend_chat:
                                getSetParametrs.PayForChat();
                                break;
    
                            case ResourceType.clear_credentials:
                                getSetParametrs.SetValueToClearCredentials(element.Price);
                                break;
    
                            case ResourceType.clear_users:
                                getSetParametrs.SetValueToClearUsers(element.Price);
                                break;
                        }
                        break;
    
                    case ContentType.money_transfer:
                        switch (element.Resource)
                        {
                            case ResourceType.money_to_chat:
                                getSetParametrs.SetValueToMoneyTransfer(item.MainChat, newValue);
                                break;
                        }
                        break;
    
                    default:
                        throw new FieldAccessException(String.Format(
                            "Ресурс '{0}' с ключём = '{1}' во вкладке = '{2}' и сборке = '{3}' недоступен для редакирования",
                            element.Resource, elementKey, tabKey, assemblyNumber));
                }
            }

    Люди, не гавнокод ли?
    Напрягает объёмность метода.
    А сколько по вашему максимальное кол-во строк в методе?
    Кодинг мой, приму любую критику. По поводу использования встроенных исключений попрошу промолчать

    Nigma143, 21 Августа 2010

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

    +144

    1. 1
    2. 2
    // TODO: Rewiew
    // ...

    жопой чую, что ниже этих строк - пиздец

    mozg_raka, 19 Августа 2010

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

    +120

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    string makesig(string mid, string apiid, string method, string secret, string[] param)
            {
                string[] fullparams = new string[] { "api_id=" + apiid, "method=" + method, "v=3.0", "format=JSON" };
                string methodparams = String.Join("©", param);
                string fullparams_j = String.Join("©", fullparams);
                string fpr = String.Join("©", new string[] { fullparams_j, methodparams });
                string[] fpr_s = fpr.Split(new char[] { Convert.ToChar("©") });
                Array.Sort(fpr_s);
                fpr = String.Join("", fpr_s);
                string last = String.Concat(mid, fpr, secret);
                return getMd5Hash(last);
            }

    Так люди делают подпись для запроса к API ВКонтакте

    A1mighty, 19 Августа 2010

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

    +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
    TestIssue = new Issue(Id, ProjectId, ProjectName, Code, Title,  
        Description, CategoryId, CategoryName, PriorityId,
        PriorityName,PriorityImageUrl, StatusId, StatusName, 
        StatusImageUrl, IssueTypeId, IssueTypeName,IssueTypeImageUrl,
        ResolutionId, ResolutionName,ResolutionImageUrl, 
        AssignedDisplayName, AssignedUsername, AssignedUserId,
        CreatorDisplayName, CreatorUsername, CreatorUserId, 
        OwnerDisplayName, OwnerUsername, OwnerUserId, DueDate, 
        MilestoneId, MilestoneName, MilestoneImageUrl, 
        MilestoneDueDate, AffectedMilestoneId, AffectedMilestoneName, 
        AffectedMilestoneImageUrl, Visibility, TimeLogged, Estimation, 
        DateCreated, LastUpdate, LastUpdateUsername, 
        LastUpdateDisplayName, Progress, Disabled, Votes);

    В конструкторе класса Issue 47 аргументов (http://codehelper.ru/questions/156).

    admax, 18 Августа 2010

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

    +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
    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
    public string ConvDoubToStr(double doub)
            {
                string str = ((int)doub).ToString();
                double k = (doub - (int)doub);
                if (k > 0)
                    str += ",";
                while (k > 0)
                {
                    k = k * 10;
                    switch ((int)k)
                    {
                        case 0:
                            str += "0";
                            break;
                        case 1:
                            str += "1";
                            break;
                        case 2:
                            str += "2";
                            break;
                        case 3:
                            str += "3";
                            break;
                        case 4:
                            str += "4";
                            break;
                        case 5:
                            str += "5";
                            break;
                        case 6:
                            str += "6";
                            break;
                        case 7:
                            str += "7";
                            break;
                        case 8:
                            str += "8";
                            break;
                        case 9:
                            str += "9";
                            break;
                    }
                    k = k - (int)k;
                }
                return str;
     
            }

    Мега конверт
    http://www.cyberforum.ru/csharp-net/thread20446.html#post667930

    Nigma143, 18 Августа 2010

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