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

    +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
    command = new System.Data.SqlClient.SqlCommand();
    command.Connection = connection;
    
    command.CommandText = "select data from filestorage where id=@id;";            
    command.Parameters.AddWithValue("@id", fileId);
    command.CommandType = CommandType.Text;
    byte[] data = (byte[])command.ExecuteScalar();
    
    command.CommandText = "select filename from filestorage where id=@id;";
    string fName = (string)command.ExecuteScalar();
    
    command.CommandText = "select sizebytes from filestorage where id=@id;";
    long lngFileSize = (int)command.ExecuteScalar();
    
    command.CommandText = "select foldername from filestorage where id=@id;";
    string store= command.ExecuteScalar().ToString();

    akai_mirror, 11 Сентября 2010

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

    +144

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public class ВсеБудетХорошо : Exception
        {
            public ВсеБудетХорошо()
            {
                throw new ВсеБудетХорошо();
            }
        }

    throw new ВсеБудетХорошо();

    Anakonda, 09 Сентября 2010

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

    +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
    private const int _multiple_cols = 0x0000060D;  //0001000001101 - (Multiple view)
    private const int _single_cols = 0x000007F1;	//0001111110001 - (Single view)
    
    private void SetGridColumnVisibility()
    {
    	int bits = _view_type == NotificationContactViewType.Multiple ? _multiple_cols : _single_cols;
    	DataControlFieldCollection cols = gvContacts.Columns;
    	DataControlField col;
    	for (int i = 0; i < cols.Count; i++)
    	{
    		col = cols[i];
    		int bit = (int)Math.Pow(2, i);
    		col.Visible = ((bits & bit) == bit);
    	}
    }

    Интересный способ установки видимости колонкам в гриде :)

    olldman, 05 Сентября 2010

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

    +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
    if(Model.User != null && Model.User.t_ApplicationPropertyValue != null && Model.User.t_ApplicationPropertyValue.Count > 0)
        {
            foreach (var applicationPropertyValue in Model.User.t_ApplicationPropertyValue)
            {
                if (applicationPropertyValue.t_ApplicationProperty != null && applicationPropertyValue.t_ApplicationProperty.t_DisplayType != null
                    && propertyValues.ContainsKey(applicationPropertyValue.t_ApplicationProperty.PropertyName + "_" + 
                    applicationPropertyValue.t_ApplicationProperty.t_DisplayType.DisplayTypeName) == false 
                    && String.IsNullOrEmpty(applicationPropertyValue.PropertyValue) == false)
                    propertyValues.Add(applicationPropertyValue.t_ApplicationProperty.PropertyName + "_" + 
                    applicationPropertyValue.t_ApplicationProperty.t_DisplayType.DisplayTypeName, applicationPropertyValue.PropertyValue);
                else if (applicationPropertyValue.t_ApplicationProperty != null && applicationPropertyValue.t_ApplicationProperty.t_DisplayType != null
                    && propertyValues.ContainsKey(applicationPropertyValue.t_ApplicationProperty.PropertyName + "_" +
                    applicationPropertyValue.t_ApplicationProperty.t_DisplayType.DisplayTypeName) == false
                    && String.IsNullOrEmpty(applicationPropertyValue.PropertyValue) == true && string.IsNullOrEmpty(applicationPropertyValue.t_ApplicationProperty.DefaultValue) == false)
                    propertyValues.Add(applicationPropertyValue.t_ApplicationProperty.PropertyName + "_" +
                    applicationPropertyValue.t_ApplicationProperty.t_DisplayType.DisplayTypeName, applicationPropertyValue.t_ApplicationProperty.DefaultValue);    
            }
        }

    Логика внутри View

    zheka, 02 Сентября 2010

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

    +145

    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
    public double FindMax(double num1, double num2, double num3)
        {
            double max = num1;
            if (num2 > max)
            {
                max = num2;
            }
            if (num3 > max)
            {
                max = num3;
            }
            return max;
        }

    KamaZz, 02 Сентября 2010

    Комментарии (68)
  6. 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)
  7. 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)
  8. 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)
  9. 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)
  10. 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)