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

    +121

    1. 1
    2. 2
    bool isManualExecute = (Request.QueryString["Manual"] != null && Request.QueryString["Manual"].ToLower() == "true")
              || (Request.QueryString["manual"] != null && Request.QueryString["manual"].ToLower() == "true");

    Передаю Вовчику привет!

    Semargl, 20 Сентября 2010

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

    +129

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    if (obj == null)
    	return 0;
    if (obj == DBNull.Value)
    	return 0;
    return int.Parse (obj.ToString ());

    в столбце хранится Integer...

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

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

    +144

    1. 1
    Response.Write ("<script>window.open (\"~/DownloadFile.aspx?FileID=" + e.id + "\")</script>");

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

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

    +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
    class SystemErrorCodes
    {
        public const Int32 ERROR_ACCESS_DENIED = 5;
        public const Int32 ERROR_ADAP_HDW_ERR = 57;
        public const Int32 ERROR_ALREADY_ASSIGNED = 85;
    // ещё две сотни подобных строк
    
        public string ToString(Int32 ERR)
        {
            switch (ERR)
            {
    
                case 0: return "The operation completed successfully.";
                case 1: return "Incorrect function.";
                case 10: return "The environment is incorrect.";
    // и снова две сотни таких строк
    
                default: return "unknown.";
            }
        }
    }

    http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx
    внизу страницы, заготовка класса для использования в C# системных кодов ошибок, получаемых в нативном коде вызовом GetLastError(), и их описаний :)
    И не лень было мартышке писать это?
    Всё гораздо проще: получение кода ошибки - Marshal.GetLastWin32Error()
    получение описания этого кода - new Win32Exception().Message

    koodeer, 16 Сентября 2010

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

    +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
    SqlCommand command = new 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 ();
    
    System.IO.Stream outStream = Response.OutputStream;
    
    Response.ContentType = "Application/octet-stream";
    Response.AppendHeader ("Connection", "keep-alive");
    
    Response.AppendHeader ("Content-Disposition", " attachment; filename = \"" + fName+"\"" );
    
    outStream.Write (data, 0, data.Length);
    Response.End ();

    продолжение http://govnokod.ru/4227

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

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