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

    −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
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    public void CreateContract( string session_id, string sOrganizationCode, string sOrganizationName, string sContractNumber, string sClientCode, string sClientName, 
    double dSum , string sCurrencyCode, string sCurrencyName, double dSumUSD, string sdateContractDate, string sdateContractDueDate, string sResponsibleCode,
    string sResponsibleName, string sCuratorCode, string sCuratorName, string sContractType, string sProjectCode, string sDocName	, out int nDocNumber, out string sURL,
    string sSuperiorContract, string sProtocolNum, string sProcurementType, string sTRU){
                    nDocNumber = 0;
    		sURL = string.Empty;
                  BusinessObject business_object = LoadBusinessObject(session_id);
    
               if (business_object == null)
                goto end_of_method;
    try
    		{
    			business_object.CreateContract(sOrganizationCode, sOrganizationName,sContractNumber,sClientCode,sClientName,dSum,sCurrencyCode,sCurrencyName,
                                                    dSumUSD,sdateContractDate,sdateContractDueDate,sResponsibleCode,sResponsibleName,sCuratorCode,sCuratorName,sContractType,
                                                    sProjectCode,sDocName,ref nDocNumber,ref sURL, sSuperiorContract,sProtocolNum,sProcurementType,sTRU);
    		}
    catch(Exception e)
    		{ //...}
    
        end_of_method:
                 //а дальше код пишет логи)
    }

    Вот такое вот бывает...

    algore, 16 Декабря 2015

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

    0

    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
    DateTime minDate = DateTime.MinValue;
    
    if (IsSaving)
        return mPrognozStartDate;
    
    if (Children.Count > 0)
    {
        var childrens = Children.Cast<BaseDesignObject>().Where(p => p.PrognozStartDate != DateTime.MinValue);
        if (childrens.Count() > 0)
        {
            minDate = childrens.Min(t => t.PrognozStartDate);
        }
    
        return minDate;
    }
    else
    {
        return mPrognozStartDate;
    }

    При наличии детей выдаем минимальную дату, если их нет то собственную...

    Enelar, 15 Декабря 2015

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

    +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
    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
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    public static CategoryAttribute Build(string category_name, string attribute_type, string attribute_name, object attribute_value)
            {
                try
                {
                    CategoryAttribute document_attribute;
    
                    switch(attribute_type)
                    {
                        case "string":
                        case "double_as_string":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.String);
                            break;
                        case "string_as_date":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.DateTime);
                            break;
                        case "int":
                        case "double_as_int":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.Integer);
                            break;
                        case "double":
                            document_attribute = new CategoryAttribute(category_name, attribute_name, TypeEnum.Double);
                            break;
                        default:
                            throw new ApplicationException("Не верно настроен тип данных атрибута '" + attribute_name + "' категории '" + category_name + "'.");
                    }
    
                    if (attribute_value == null)
                        return document_attribute;// атрибут остался неопределенным
    
                  switch (document_attribute.Type)
                  {
                      case TypeEnum.String:
                            {
                                switch (attribute_type)
                                {
                                    case "string":
                                        {
                                            if (!(attribute_value is string))
                                                throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                               + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                               attribute_type + "'.");
    
                                            document_attribute.sValue = attribute_value as string;
                                        } break;
                                    case "double_as_string":
                                        {
                                            if (!(attribute_value is double))
                                                throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                               + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                               attribute_type + "'.");
    
                                            document_attribute.sValue = ((double)attribute_value).ToString();
                                        } break;
                                }
                            }
                            break;
                            case TypeEnum.Integer:
                            {
                                switch (attribute_type)
                                {
                                    case "int":
                                    {
                                        if (!(attribute_value is int))
                                            throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                           + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                           attribute_type + "'.");
    
                                        document_attribute.iValue = (int)attribute_value;
                                    }   break;
                                    case "double_as_int":
                                    {
                                        if (!(attribute_value is double))
                                            throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                                                           + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" +
                                                                           attribute_type + "'.");
    
                                        document_attribute.iValue = (int)(double)attribute_value;
                                    }   break;
                                }
                            }
                            break;
                          case TypeEnum.Double:
                            {
                                if (!(attribute_value is float || attribute_value is double || attribute_value is int || attribute_value is long))
                                    throw new ApplicationException("Тип данных '" + attribute_value.GetType() + "' входного значения атрибута '" + attribute_name
                                        + "' категории '" + category_name + "' не может быть приведен к требуему типу данных '" + attribute_type + "'.");
    
                                document_attribute.dValue = (double)attribute_value;
                            }
                            break;
                    }
    
                    return document_attribute;
    
                    catch (Exception e)
                       {
                         //...
                       }
                  }

    Создание объекта типа CategoryAttribute.

    algore, 15 Декабря 2015

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

    +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
    namespace ConsoleApplication
    {
        public static class Program
        {
            private static void Main( string[] args )
            {
                new Random().Next( -100, 100 )
                    .Execute( x => Console.Write( $"{x} это " ) )
                    .IfElse( x => x % 2 == 0, () => Console.Write( "четное " ), () => Console.Write( "нечетное " ) )
                    .Execute( () => Console.Write( "число " ) )
                    .IfElse( x => x > 0, () => Console.Write( "больше " ), () => Console.Write( "меньше " ) )
                    .Execute( () => Console.Write( "нуля" ) )
                    .Execute( () => Console.WriteLine() );
            }
        }
    }

    вывод в консоли (прим.): "-88 это четное число меньше нуля"

    Адские экстеншены

    anweledig, 14 Декабря 2015

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

    +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
    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
    if (dlgOpen.ShowDialog() != DialogResult.OK) return;
    
                txtLog.Clear();
                string customXMLFileName = dlgOpen.FileName;
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(customXMLFileName);
               
                foreach (XmlNode node in xmlDoc.DocumentElement.ChildNodes)
                {
                   
                    if (node.Name == "Surfaces")
                       {
    
                        foreach (XmlNode childNode in node.ChildNodes)
                        {
                            txtLog.AppendText(childNode.Name.ToString() + Environment.NewLine);
    
                            foreach (XmlNode _childNode in childNode.ChildNodes)
                            {
                                if (_childNode.Name == "SourceData")
                                {
                                    foreach (XmlNode __childNode in _childNode.ChildNodes)
                                    {
                                        txtLog.AppendText(__childNode.Name.ToString() + Environment.NewLine);
                                        if (__childNode.Name == "Breaklines")
                                        {
                                            foreach (XmlNode ___childNode in __childNode.ChildNodes)
                                            {
                                                txtLog.AppendText(___childNode.Name.ToString() + Environment.NewLine);
                                                XmlNode dataNode = ___childNode.LastChild;
                                                string txtData = dataNode.InnerText;
                                                txtLog.AppendText(txtData + Environment.NewLine);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                   }
                }

    Невнимательное чтение MSDN привело к такому плачевному результату. А всего лишь хотелось прочитать значение дочерних нод Breaklines....
    GetElementsByTagName в помощь....

    Thrasher1980, 12 Декабря 2015

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

    +8

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    public static class StringExtensions
        {
            public static bool IsNulldOrEmpty(this string str)
            {
                return string.IsNullOrEmpty(str);
            }
        }

    why

    antoanelenkov, 12 Декабря 2015

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

    +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
    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
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using Excel;
    using FPCLib.Models.Broadcasts;
    
    namespace ExcelReadTests.Model.Путевка
    {
        public class MyExcel : IDisposable
        {
            private readonly DataTable table;
    
            public MyExcel(string putevkaFileName)
            {
                table = ReadToTable(putevkaFileName);
            }
    
    		  internal DataTable ReadToTable(string excelFileName)
            {
                var stream = File.Open(excelFileName, FileMode.Open, FileAccess.Read);
                var excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
    
                return excelReader.AsDataSet().Tables[0];
            }
    
            public bool IsTvc()
            {
                if (table.Columns.Count == 10)
                    return true;
                return false;
            }
    
            public bool IsFriday()
            {
                if (table.Columns.Count == 16)
                    return true;
                return false;
            }
    		
          
            public List<Broadcast> GetBroadcastsFriday()
            {
                var broadcasts = new List<Broadcast>();
                for (var i = 0; i < table.Rows.Count; i++)
                {
                    if (table.Rows[i][0].ToString().Length > 1)
                    {
                        broadcasts.Add(new Broadcast
                        {
                            Time = new Time(table.Rows[i][0].ToString()),
                            Title = table.Rows[i][1].ToString(),
                            File = table.Rows[i][3].ToString(),
                            Type = table.Rows[i][7].ToString(),
                            Id = table.Rows[i][2].ToString(),
                            Length = new Time(table.Rows[i][4].ToString())
                        });
                    }
                }
    
                return broadcasts;
            }
    
            public List<Broadcast> GetBroadcastsTvc()
            {
                var broadcasts = new List<Broadcast>();
                for (var i = 0; i < table.Rows.Count; i++)
                {
                    broadcasts.Add(new Broadcast
                    {
                        Time = new Time(table.Rows[i][0].ToString()),
                        Title = table.Rows[i][2].ToString().Trim(),
                        File = table.Rows[i][6].ToString().Trim(),
                        Type = table.Rows[i][9].ToString().Trim(),
                        Id = table.Rows[i][1].ToString().Trim(),
                        Length = new Time(table.Rows[i][5].ToString())
                    });
                }
    
                return broadcasts;
            }
    		
    		  public void Dispose()
            {
            }
          
        }
    }

    вот так открываю эксельку
    DataTable ReadToTable(string excelFileName)

    по количеству столбцов, определяю ее источник)
    public bool IsTvc()
    public bool IsFriday()



    и даже поддерживаю интерфейс IDisposable))

    yolozesoja, 08 Декабря 2015

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

    +2

    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
    public static string _GetValueFromConfigFile(string sKey)
            {
                string sReturnValue = _scNullString;
                string filePath = System.IO.Directory.GetCurrentDirectory() + @"\App.config";
                // FOR TDOCS
                //string filePath = @"D:\hosting\4856094\html\Bin\App.config";
    
                XmlDocument doc = new XmlDocument();
                XmlNode rootNode;
                XmlNode xmlNode;
    
                try
                {
                    doc.Load(filePath);
    
                    rootNode = doc.DocumentElement;
                    xmlNode = rootNode.SelectSingleNode("descendant::add[@key='" + sKey + "']");
                    if (xmlNode != null) sReturnValue = xmlNode.Attributes["value"].Value;
    
                    return sReturnValue;
                    //return "";
                }
                catch// (Exception Ex)
                {
                    //_ErrorDetail = Ex.Message;
                    return _scNullString;
                }
            }

    Very helpful method to get data from app.config :)
    Жаль что для web не работает :(

    Note:
    public const string _scNullString = "";

    iec, 02 Декабря 2015

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

    +2

    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
    if(itemsCount <= 2)
    		{
    			if(iteration == 1)
    			{
    				dragItemPos = new Vector3(-20, -55, 0);
    			}else if(iteration == 2){
    				dragItemPos = new Vector3(145, 75, 0);
    			}
    		}else if(itemsCount == 3){
    			if(iteration == 1)
    			{
    				dragItemPos = new Vector3(60, -170, 0);
    			}else if(iteration == 2){
    				dragItemPos = new Vector3(245, -45, 0);
    			}else if(iteration == 3){
    				dragItemPos = new Vector3(20, 90, 0);
    			}
    		}else if(itemsCount == 4){
    			if(iteration == 1)
    			{
    				dragItemPos = new Vector3(60, -170, 0);
    			}else if(iteration == 2){
    				dragItemPos = new Vector3(245, -45, 0);
    			}else if(iteration == 3){
    				dragItemPos = new Vector3(-80, 2, 0);
    			}else if(iteration == 4){
    				dragItemPos = new Vector3(140, 160, 0);
    			}
    		}
    		else{
    			if(iteration == 1)
    			{
    				dragItemPos = new Vector3(60, -170, 0);
    			}else if(iteration == 2){
    				dragItemPos = new Vector3(245, -45, 0);
    			}else if(iteration == 3){
    				dragItemPos = new Vector3(-100, -45, 0);
    			}else if(iteration == 4){
    				dragItemPos = new Vector3(25, 95, 0);
    			}else if(iteration == 5){
    				dragItemPos = new Vector3(190, 180, 0);
    			}
    		}

    Определяем позиции объекта по их количеству и по номеру итерации. Массивы? не не слышал.

    kschingiz, 27 Ноября 2015

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

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    public static bool CheckBoxValue(bool Checked)
            {
                return Conversions.ToBoolean(Interaction.IIf(Checked, true, false));
            }

    inickvel, 26 Ноября 2015

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