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

    +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
    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
    [Serializable()]
    	public class Vendor
    	{
    		#region Constructors
    
    		public Vendor(long vendorID)
    		{
    			LoadData(vendorID);
    		}
    
    		internal Vendor(Vendor argVendor)
    		{
    			if (argVendor != null)
    			{
    				this.ID = argVendor.ID;
    				this.VendorName = argVendor.VendorName;
    				this.Account = argVendor.VendorAccount;
    				this.EIN = argVendor.VendorEIN;
    				this.Address = argVendor.VendorAddress;
    				this.City = argVendor.VendorCity;
    				this.State = argVendor.VendorState;
    				this.PostalCode = argVendor.VendorZip;
    				this.Phone = argVendor.VendorPhone;
    				this.ContactName = argVendor.VendorContact;
    				this.VendorCode = argVendor.VendorCode;
    				this.Country = argVendor.VendorCountry;
    				this.FaxNumber = argVendor.VendorFax;
    				this.Email = argVendor.Email;
    			}
    		}
    		#endregion
    
    		public void LoadData(long vendorID)
    		{
    			POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
    			var ven = (from v in db.Vendors
    					   where v.ID == vendorID
    					   select v).SingleOrDefault();
    			if (ven != null)
    			{
                    populateMe(ven);
    			}
    		}
            public void LoadDataByVendorCode(string argVendorCode)
            {
                POMRepositoryDataClassesDataContext db = new POMRepositoryDataClassesDataContext();
                var ven = (from v in db.Vendors
                           where v.VendorCode == argVendorCode
                           select v).Take(1).SingleOrDefault();
                if (ven != null)
                {
                    populateMe(ven);
                }
            }
            private void populateMe(Vendor ven)
            {
                this.ID = ven.ID;
                this.VendorName = ven.VendorName;
                this.Account = ven.VendorAccount;
                this.EIN = ven.VendorEIN;
                this.Address = ven.VendorAddress;
                this.City = ven.VendorCity;
                this.State = ven.VendorState;
                this.PostalCode = ven.VendorZip;
                this.Phone = ven.VendorPhone;
                this.ContactName = ven.VendorContact;
                this.VendorCode = ven.VendorCode;
                this.Country = ven.VendorCountry;
    	    this.FaxNumber = ven.VendorFax;
    	    this.Email = ven.Email;
            }
    }

    No comments!!!

    Arterius, 16 Марта 2011

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

    +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
    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
    Type window = core.getTypeCreationWindowFromType( this.currentType );
                if (window != null)
                {
                    var cr_window = Activator.CreateInstance( window );
                    if (window == typeof( forms.showWindow ))
                    {
                        ((forms.showWindow)cr_window).setTitle( "Добавить новую позицию" );
                        ((forms.showWindow)cr_window).setType( this.chldrenType );
                        ((forms.showWindow)cr_window).fill( );
                        ((forms.showWindow)cr_window).setSelectionMode( );
                        if (this.isExlusivePositionResolve == true) 
                        {
                            // var new_item = Activator.CreateInstance( this.chldrenType );
                            //new_item = (types.ICovertiablePersist<this.chldrenType>)core.instance().ge
    
                            ((forms.showWindow)cr_window).selectedItem += ( forms.showWindow form ) =>
                            {
                                var new_item = Activator.CreateInstance( this.chldrenType );
                                ///new_item = core.instance().getObject(this, form.selected_id);
    
                                int parent_object_id = -1; // Это номер связанного с 
                                                           //выриьбаемым обектом объекта, 
                                                           //тоесть если окно выбора было 
                                                           //кастомизированна и тип выбираемы 
                                                           //х щзначений другой нежели целевой 
                                                           //то мы ищем звязь между обектом ородите и дитя !!!
                                FieldInfo[] fields = this.chldrenType.GetFields( );
                                
                                int id = ((types.persistent)new_item).id;
                                bool isExists = false;
                                for (int i = 0; i < this.dgv_grid.RowCount; i++) 
                                {
                                    int id_s;
                                    int.TryParse( this.dgv_grid.Rows[i].Cells["id"].Value.ToString( ),out id_s );
                                    if (id_s == id) 
                                    {
                                        int count;
                                        int.TryParse( this.dgv_grid.Rows[i].Cells["count"].Value.ToString( ), out count );
                                        this.dgv_grid.Rows[i].Cells["count"].Value = count++;
                                        isExists = true;
                                    }
                                }
                                if (isExists == false) 
                                {
                                    this.addOnePosition( new_item );
                                }
                            };
                        }
                    }
                    else 
                    {
                        ((Form)cr_window).FormClosed += ( object sender, FormClosedEventArgs e ) => {
                            this.fill( );
                        };                   
                    }
                    ((System.Windows.Forms.Form)cr_window).Show( );
                }
                else
                {
                    MessageBox.Show( "Объекты такого типа создавать запрещено" );
                }

    Нашел его миленкого. Переписываю ))) А коменн то комент

    glilya, 15 Марта 2011

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

    +140

    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
    try
    {
    	client.SendData(xml);
    }
    catch(Exception e)
    {
    	string s = e.ToString();
    	if(s.Substring(0,80)=="System.InvalidOperationException: Operation not allowed on non-connected sockets")
    	{
    		client.tcpclient.Close();
    		clients.Remove(client.SessionId);
    	}
    	else if (s.Substring(0,71)=="System.IO.IOException: Unable to write data to the transport connection")
    	{
    		client.tcpclient.Close();
    		clients.Remove(client.SessionId);
    	}
    	else
    	{
    		client.tcpclient.Close();
    		clients.Remove(client.SessionId);
    	}
    }

    нестандартное определение типа исключения
    найдено в примерах кода кандидата на работу

    mozg_raka, 15 Марта 2011

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

    +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
    public class BasisTariffing : IFormattable
    {
    	public override bool Equals(object obj) {
    		BasisTariffing subject = obj as BasisTariffing;
    		if (subject == null) {
    			return false;
    		}
    		return ((Profession == null && subject.Profession == null) || (Profession != null && subject.Profession != null && Profession.Equals(subject.Profession))) &&
    			((BasisRateOf == null && subject.BasisRateOf == null) || (BasisRateOf != null && subject.BasisRateOf != null && BasisRateOf.Equals(subject.BasisRateOf))) &&
    			((BasisRating1Main == null && subject.BasisRating1Main == null) || (BasisRating1Main != null && subject.BasisRating1Main != null && BasisRating1Main.Equals(subject.BasisRating1Main))) &&
    			((BasisRating1Add == null && subject.BasisRating1Add == null) || (BasisRating1Add != null && subject.BasisRating1Add != null && BasisRating1Add.Equals(subject.BasisRating1Add))) &&
    			((BasisRating2Main == null && subject.BasisRating2Main == null) || (BasisRating2Main != null && subject.BasisRating2Main != null && BasisRating2Main.Equals(subject.BasisRating2Main))) &&
    			((BasisRating2Add == null && subject.BasisRating2Add == null) || (BasisRating2Add != null && subject.BasisRating2Add != null && BasisRating2Add.Equals(subject.BasisRating2Add))) &&
    			((BasisRating3Main == null && subject.BasisRating3Main == null) || (BasisRating3Main != null && subject.BasisRating3Main != null && BasisRating3Main.Equals(subject.BasisRating3Main))) &&
    			((BasisRating3Add == null && subject.BasisRating3Add == null) || (BasisRating3Add != null && subject.BasisRating3Add != null && BasisRating3Add.Equals(subject.BasisRating3Add))) &&
    			((BasisRating4Main == null && subject.BasisRating4Main == null) || (BasisRating4Main != null && subject.BasisRating4Main != null && BasisRating4Main.Equals(subject.BasisRating4Main))) &&
    			((BasisRating4Add == null && subject.BasisRating4Add == null) || (BasisRating4Add != null && subject.BasisRating4Add != null && BasisRating4Add.Equals(subject.BasisRating4Add))) &&
    			((BasisRating5Main == null && subject.BasisRating5Main == null) || (BasisRating5Main != null && subject.BasisRating5Main != null && BasisRating5Main.Equals(subject.BasisRating5Main))) &&
    			((BasisRating5Add == null && subject.BasisRating5Add == null) || (BasisRating5Add != null && subject.BasisRating5Add != null && BasisRating5Add.Equals(subject.BasisRating5Add))) &&
    			((BasisRating6Main == null && subject.BasisRating6Main == null) || (BasisRating6Main != null && subject.BasisRating6Main != null && BasisRating6Main.Equals(subject.BasisRating6Main))) &&
    			((BasisRating6Add == null && subject.BasisRating6Add == null) || (BasisRating6Add != null && subject.BasisRating6Add != null && BasisRating6Add.Equals(subject.BasisRating6Add))) &&
    			((BasisRating7Main == null && subject.BasisRating7Main == null) || (BasisRating7Main != null && subject.BasisRating7Main != null && BasisRating7Main.Equals(subject.BasisRating7Main))) &&
    			((BasisRating7Add == null && subject.BasisRating7Add == null) || (BasisRating7Add != null && subject.BasisRating7Add != null && BasisRating7Add.Equals(subject.BasisRating7Add))) &&
    			((BasisRating8Main == null && subject.BasisRating8Main == null) || (BasisRating8Main != null && subject.BasisRating8Main != null && BasisRating8Main.Equals(subject.BasisRating8Main))) &&
    			((BasisRating8Add == null && subject.BasisRating8Add == null) || (BasisRating8Add != null && subject.BasisRating8Add != null && BasisRating8Add.Equals(subject.BasisRating8Add)));
    	}
    
    	public override int GetHashCode() {
    		return ((Profession != null) ? Profession.GetHashCode() : 0) ^
    			((BasisRateOf != null) ? BasisRateOf.GetHashCode() : 0) ^
    			((BasisRating1Main != null) ? BasisRating1Main.GetHashCode() : 0) ^
    			((BasisRating1Add != null) ? BasisRating1Add.GetHashCode() : 0) ^
    			((BasisRating2Main != null) ? BasisRating2Main.GetHashCode() : 0) ^
    			....................................
    	}
    }

    Как вам перегрузочка? И это только часть кода *сущности*, больше просто не вместилось =)

    Guid, 15 Марта 2011

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

    +123

    1. 1
    2. 2
    3. 3
    if (!(IsPostBack == true))
    
    // далее везде, см. ссылку

    Реальный индус (Thoothukudi, Tamil Nadu, India) в реальном вопросе на StackOverflow (http://stackoverflow.com/questions/5295149/) наложил натуральную кучу говна.

    abatishchev, 14 Марта 2011

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

    +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
    public class XXX
    {
        private Object m_ForLock = new object();
        private String m_Path = "";
        public XXX(String Path)
        {
            lock (m_ForLock)
            {
                 m_Path = Path;
            }
         }
    }

    javros, 05 Марта 2011

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

    +120

    1. 1
    2. 2
    3. 3
    4. 4
    string tmpS;
    //идут всякие монипуляции с этой строкой
    //. . .
    tmpS.Remove(0, tmpS.Length);

    Реальный код из коммерческого продукта.

    inser, 04 Марта 2011

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

    +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
    private const string constDefFeedLimitValue = "5";
    private string feedLimit = constDefFeedLimitValue;
    private int feedLmt;
    
    protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
            {
                try
                {
                    feedLmt = Convert.ToInt32(feedLimit);
                }
                catch (Exception)
                {
                    feedLmt = 0;
                }
                ...
            }

    Автор из Киева, имеет статус MVP.

    Alexander, 03 Марта 2011

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

    +119

    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
    Microsoft.Win32.RegistryKey Fregistry =
                    Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE")
                    .OpenSubKey("Microsoft").OpenSubKey("Windows").OpenSubKey("CurrentVersion")
                    .OpenSubKey("Installer").OpenSubKey("UserData")
                    .OpenSubKey("S-1-5-18").OpenSubKey("Products");
                string []Names = Fregistry.GetSubKeyNames() ;
                string uninstall = "";
                string ApplicationName = "Adobe Reader 7.0.8";
                for (int i = 0; i < Names.Length; i++)
                {
                    Microsoft.Win32.RegistryKey FTemp = Fregistry.OpenSubKey(Names[i]).OpenSubKey("InstallProperties");
                    if (FTemp.GetValue("DisplayName").ToString() == ApplicationName)
                    {
                        object obj = FTemp.GetValue("UninstallString");
                        if (obj == null)
                            uninstall = "";
                        else
                            uninstall = obj.ToString();
                        i = Names.Length; 
                    }
                }
     
                System.Console.WriteLine(uninstall);
                System.Diagnostics.Process FProcess = new System.Diagnostics.Process();
                string temp = "/x{" + uninstall.Split("/".ToCharArray())[1].Split("I{".ToCharArray())[2];
                FProcess.StartInfo.FileName = uninstall.Split("/".ToCharArray())[0];
                FProcess.StartInfo.Arguments = temp;
                FProcess.StartInfo.UseShellExecute = false;
                FProcess.Start();
                System.Console.Read();

    qbasic, 03 Марта 2011

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

    +131

    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
    static public int IIF(bool condition, int a, int b)
            {
                int x = 0;
                if (condition)
                {
                    x = a;
                }
                else
                {
                    x = b;
                }
                return x;
            }
    
            static public bool IIF(bool condition, bool a, bool b)
            {
                bool x = false;
                if (condition)
                {
                    x = a;
                }
                else
                {
                    x = b;
                }
                return x;
            }
    
            static public Single IIF(bool condition, Single a, Single b)
            {
                float x = 0;
                if (condition)
                {
                    x = a;
                }
                else
                {
                    x = b;
                }
                return x;
            }
    
            static public Double IIF(bool condition, double a, double b)
            {
                double x = 0;
                if (condition)
                {
                    x = a;
                }
                else
                {
                    x = b;
                }
                return x;
            }
    
            static public decimal IIF(bool condition, decimal a, decimal b)
            {
                decimal x = 0;
                if (condition)
                {
                    x = a;
                }
                else
                {
                    x = b;
                }
                return x;
            }

    inser, 03 Марта 2011

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