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

    +133.8

    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
    public static XmlNode FindNodeXPath(XmlNode root, string xPath)
            {
                string[] paths = xPath.Split(new char[] { '/' });
                XmlNode node = root;
                for (int i = 0; i < paths.Length; i++)
                {
                    XmlNode childNode = null;
                    for (int j = 0; j < node.ChildNodes.Count; j++)
                    {
                        if (node.ChildNodes[j].Name == paths[i])
                        {
                            childNode = node.ChildNodes[j];
                            node = childNode;
                            break;
                        }
                    }
                    if (childNode == null)
                    {
                        return null;
                    }
                }
                return node;
            }
    
            public static XmlNode FindNodeXPath(XmlNode root, string nodeName, string xPath)
            {
                XmlNode node = FindNodeXPath(root, xPath);
                if (node != null)
                {
                    for (int i = 0; i < node.ChildNodes.Count; i++)
                    {
                        if (node.ChildNodes[i].Name == nodeName)
                        {
                            node = node.ChildNodes[i];
                        }
                    }
                }
                return node;
            }
    
            public static void UpdateBaseAddress(string url, string fileConfig)
            {
                // Create config file to create 
                XmlDocument xmlDom = new XmlDocument();
                xmlDom.Load(fileConfig);
                XmlNode root = xmlDom.DocumentElement;
                // Get XML node 
                XmlNode xmlNode = FindNodeXPath(root, "endpoint", "system.serviceModel/services/service");
                xmlNode.Attributes["address"].Value = url;
    
                xmlNode = FindNodeXPath(root, "add", "system.serviceModel/services/service/host/baseAddresses");
                xmlNode.Attributes["baseAddress"].Value = url;
    
                xmlDom.Save(fileConfig);
            }

    Виетнамский XPath эквивалент :)

    bugotrep, 15 Августа 2009

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

    +107.5

    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
    /// <summary>
            /// Check if this char is digit
            /// </summary>
            /// <param name="symbol">Some char</param>
            /// <returns>True if is digit</returns>
            private static bool IsDigit(char symbol)
            {
                List<char> digits = new List<char>();
                digits.Add('0');
                digits.Add('1');
                digits.Add('2');
                digits.Add('3');
                digits.Add('4');
                digits.Add('5');
                digits.Add('6');
                digits.Add('7');
                digits.Add('8');
                digits.Add('9');
                return digits.Contains(symbol);
            }

    так сказать код от велосипедиста, сделал свой IsDigit() хотя уже есть char.IsDigit()

    sv219, 13 Августа 2009

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

    +133.1

    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
    /// <summary>
    /// General handler for all buttons
    /// </summary>
    private void FormButtons_Click(object sender, EventArgs e)
    {
        Control control = (Control) sender;
    
        if (control.Handle == btnCreateInvoices.Handle)
            ExportOrders();
        else if (control.Handle == btnFirstUsageInvoices.Handle)
            ExportFirstUsageInvoices();
        else if (control.Handle == btnImportCustomers.Handle)
            ImportCustomers();
        else if (control.Handle == btnImportProdcuts.Handle)
            ImportProducts();
        else if // и так далее...
    }

    WinForms приложение, на все кнопки навешен 1 обработчик события OnClick.
    А внутри вот....

    vleschenko, 12 Августа 2009

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

    +142.9

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public Аккаунт НайтиУчётнуюЗаписьПользователя(string логин, string пароль)
    {
    	lock (_пользователи)
    		return _пользователи.Find(пользователь => пользователь.НеТыЛиЭто(логин, пароль));
    }

    Dimarius, 12 Августа 2009

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

    +138

    1. 1
    txtCollimator.parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none";

    Прапрапрадедушка можно уже не показывать.
    Дикая вложенность UserContol в ASP.Net дает о себе знать.

    vaceknt, 11 Августа 2009

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

    +133.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
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    for (int i = 0; i < gvOrderMain.RowCount - EditIndex; i++)
                                {
                                    float tempQuantity = GetRow(i).Quantity;
                                    int partyLen = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray().Length;
                                    for (int j = 0; j < partyLen; j++)
                                    {
                                        if (DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity > 0)
                                        {
                                            float CurSQuantity = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity.Value;
                                            if (tempQuantity > CurSQuantity)
                                            {
                                                Documents_Product dp = new Documents_Product();
                                                dp.PrimePriceExcVAT = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].PrimePriceExcVAT;
                                                dp.PrimePriceIncVAT = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].PrimePriceIncVAT;
                                                dp.Quantity = -1 * DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity;
                                                dp.OldQuantity = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity;
                                                dp.PartyNumber = DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].PartyNumber;
                                                DB.Documents_Products.InsertOnSubmit(dp);
                                                DB.SubmitChanges();
    
                                                Documents_ProductsOrder dro = new Documents_ProductsOrder();
                                                dro.PriceSum = GetRow(i).RealPrice * DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity;
                                                tempQuantity = tempQuantity - DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity.Value;
                                                DB.PrInStOrderByPartyNum(GetRow(i).ProductId, curStockId).ToArray()[j].Quantity = 0;
                                                DB.Documents_ProductsOrders.InsertOnSubmit(dro);
    
                                                DB.SubmitChanges();
    ..........

    Rudolf_Abel, 11 Августа 2009

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

    +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
    List<int> arr = new List<int>();
    List<int> tmpArr = new List<int>();
    
    for (int i = 0; i < arr.Count; i++)
    {
    	if (arr[i] > 100)
    	{
    	}
    	else
    		tmpArr.Add(arr[i]);
    }
    arr = tmpArr;

    Удаляем плохие элементы со списка или кто создал дурацкий for???

    62316e, 10 Августа 2009

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

    +137.1

    1. 1
    2. 2
    3. 3
    if (Skin == null || ((Skin != null && Skin.Value == null) || (Skin != null && Skin.Value != null && Skin.Value.Length == 0))) {
    				Skin = new LocalString("...");
    			}

    проверочко.. ^_^

    fade, 10 Августа 2009

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

    +126.2

    1. 1
    2. 2
    3. 3
    if (myBool.ToString() == "true")
    {
    }

    62316e, 10 Августа 2009

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

    +132.5

    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
    public Image ResultImage
            {
                get
                {
                    return GetCut();
                }
            }
    
            private Image GetCut()
            {
                Bitmap b1 = new Bitmap(border.Width, border.Height);
    
                Bitmap b = new Bitmap(pictureBox1.Image.GetThumbnailImage(pictureBox1.Width, pictureBox1.Height, new Image.GetThumbnailImageAbort(fff), IntPtr.Zero));
                int x = border.Location.X;
                int y = border.Location.Y;
    
                int x1 = border.Location.X + border.Width;
                int y1 = border.Location.Y + border.Height;
    
                for (int i = x; i < x1; i++)
                {
                    for (int j = y; j < y1; j++)
                    {
                        b1.SetPixel(i - x, j - y, b.GetPixel(i, j));
                    }
                }
                return b1;
            }
    
            public bool fff()
            {
                return false;
            }

    Вырезка прямоугольника из битмапа.

    guest, 08 Августа 2009

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