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

    +7

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    public bool IsInRange(string ip, string cidrMask)
    {
                string[] parts = cidrMask.Split('/');
                int iIp = IPAddress.Parse(parts[0].Trim()).GetHashCode();
                int iCidr = IPAddress.Parse(ip.Trim()).GetHashCode();
                int iCidrMask = IPAddress.HostToNetworkOrder(-1 << (32 - int.Parse(parts[1].Trim())));
                return ((iIp & iCidrMask) == (iCidr & iCidrMask));
    }

    Финт ушами - превращение IPv4 в Int32 через вызов GetHashCode

    leon_mz, 14 Октября 2015

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

    +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
    ....
            SetFormPopup("/" & pageName & ".htm")
            pageName = pageName.Replace("(", "-")
            pageName = pageName.Replace(")", "-")
            pageName = pageName.Replace("&", "-")
            pageName = pageName.Replace(",", "-")
            pageName = pageName.Replace("""", "-")
            pageName = pageName.Replace("'", "-")
            pageName = pageName.Replace("_", "-")
            pageName = pageName.Replace("?", "-")
            pageName = pageName.Replace(".-", "-")
            pageName = pageName.Replace("-------", "-")
            pageName = pageName.Replace("------", "-")
            pageName = pageName.Replace("-----", "-")
            pageName = pageName.Replace("----", "-")
            pageName = pageName.Replace("---", "-")
            pageName = pageName.Replace("--", "-")
            pageName = pageName.Trim("-")
            ....

    skydev, 06 Октября 2015

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

    +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
    using DocsTaskInfo = System.Collections.Generic.KeyValuePair<int, bool>;
    using DocAndContentType = System.Collections.Generic.KeyValuePair<int, string>;
    using DocAndContentTypeToCount = System.Collections.Generic.Dictionary<System.Collections.Generic.KeyValuePair<int, string>, System.Collections.Generic.KeyValuePair<int, bool>>;
    //...
    private void DocsCountInternal(RefNetDbContainerDirect db, int docType, string contentType,  int status, int count, bool Checked = true){/*...*/}
    //...
    private DocAndContentTypeToCount[] _docCheckTasks;
    private RefNetDbContainerDirect _dbForCheck;
    private void ClearAllDocCounts(RefNetDbContainerDirect dbForCheck)
            {
                _dbForCheck = dbForCheck;
                _docCheckTasks = Enumerable.Repeat(new DocAndContentTypeToCount(), 2).ToArray();
                    //new DocAndContentTypeToCount[2] { new DocAndContentTypeToCount(), new DocAndContentTypeToCount() };
            }
    private void DocsCount(RefNetDbContainerDirect db, int docType, string contentType, int status, int count, bool Checked = true)
            {
                var taskHistory = _docCheckTasks[status];
                var taskKey = new DocAndContentType(docType, contentType);
                var taskInfo = new DocsTaskInfo(count, Checked);
                if(taskHistory.ContainsKey(taskKey))
                    _exceptions.Add(new Exception(string.Format(
                                     "CheckDocsTask with (_.idDocType == {0}) && (_.contentType == \"{1}\") && (_.status == {2}) ) already contained",
                                     docType, contentType, status)));
                taskHistory.Add(taskKey, taskInfo);
            }
    private void CheckAllDocCounts()
            {
                if (AllDocumentsMadeByServer)
                {
                    //1
                    var taskKeys = _docCheckTasks.SelectMany(_ => _.Keys)/*.Distinct()*/.ToArray();
                    foreach (var taskKey in taskKeys)
                    {
                        DocAndContentType key = taskKey;
                        foreach (var statusedTask in _docCheckTasks.Where(statusedTask => !statusedTask.ContainsKey(key)))
                            statusedTask.Add(taskKey, new DocsTaskInfo(0, true));
                    }
                    taskKeys.Select(_ => new
                    {
                        docAndContentType = _,
                        count = _docCheckTasks[0][_].Key + _docCheckTasks[1][_].Key,
                        Checked = _docCheckTasks[0][_].Value && _docCheckTasks[1][_].Value
                    }).ForEach(_ => DocsCountInternal(_dbForCheck, _.docAndContentType.Key, _.docAndContentType.Value, 1, _.count, _.Checked));
            }
                else
                    //0 и 1
                    foreach(var statusedTask in _docCheckTasks.Select((tasks, status) => new {tasks, status}))
                        foreach (var task in statusedTask.tasks)
                            DocsCountInternal(_dbForCheck, task.Key.Key, task.Key.Value, statusedTask.status, task.Value.Key, task.Value.Value);
                _docCheckTasks = null;
                _dbForCheck = null;
            }

    Автору я бы посоветовал утопиться, но как посоветуете отрефакторить?
    Планировалось, что чувак вызывает ClearAllDocCounts, затем много раз метод DocsCount, а потом CheckAllDocCounts.

    USB, 02 Октября 2015

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

    +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
    public class UnionDocumentJournalController : BaseDocumentJournalController
    <UnionDocumentJournalFilterViewModel, UnionDocumentJournalEntityViewModel, UnionDocumentJournalDataViewModel,
     UnionDocumentDataProvider, UnionDocumentDataManager, UnionLegalEntityDocumentsJournalViewModelMapper>
     {  }
    
    public class UnionDocumentJournalFilterViewModel : BaseJournalFilterViewModel<UnionDocumentJournalEntityViewModel>
    {
    ...
    }
    
    public class UnionDocumentJournalEntityViewModel : LegalEntityDocumentJournalEntityViewModel
    {
    ...
    }
    
    public class UnionDocumentJournalDataViewModel : BaseJournalDataViewModel<UnionDocumentJournalEntityViewModel>
     {  }
    
    public class UnionDocumentDataManager :
     DocumentDataManager
     <UnionDocumentDataProvider, UnionDocumentJournalFilterViewModel, UnionDocumentJournalEntityViewModel>
     {
    ...
    }
    
    public class UnionLegalEntityDocumentsJournalViewModelMapper :
     LegalEntityDocumentsJournalViewModelMapper<UnionDocumentJournalEntityViewModel, UnionDocumentJournalDataViewModel>
     {
    ...
    }

    Горе от ума

    banderror, 30 Сентября 2015

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

    +4

    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
    private void button2_Click(object sender, EventArgs e)
            {
     
            int n1 = Convert.ToInt16(textBox1.Text);
            int n2 = Convert.ToInt16(textBox4.Text);
            int n3 = Convert.ToInt16(textBox7.Text);
            int n4 = Convert.ToInt16(textBox10.Text);
            int n5 = Convert.ToInt16(textBox13.Text);
            int n6 = Convert.ToInt16(textBox16.Text);
            int n7 = Convert.ToInt16(textBox19.Text);
            int n8 = Convert.ToInt16(textBox22.Text);
     
            int b1 = Convert.ToInt16(textBox2.Text);
            int b2 = Convert.ToInt16(textBox5.Text);
            int b3 = Convert.ToInt16(textBox8.Text);
            int b4 = Convert.ToInt16(textBox11.Text);
            int b5 = Convert.ToInt16(textBox14.Text);
            int b6 = Convert.ToInt16(textBox17.Text);
            int b7 = Convert.ToInt16(textBox20.Text);
            int b8 = Convert.ToInt16(textBox23.Text);
     
            int c1 = Convert.ToInt16(textBox3.Text);
            int c2 = Convert.ToInt16(textBox6.Text);
            int c3 = Convert.ToInt16(textBox9.Text);
            int c4 = Convert.ToInt16(textBox12.Text);
            int c5 = Convert.ToInt16(textBox15.Text);
            int c6 = Convert.ToInt16(textBox18.Text);
            int c7 = Convert.ToInt16(textBox21.Text);
            int c8 = Convert.ToInt16(textBox24.Text);
     
            int ii, S2, S1, ti, ip, iip, iis, dp, ds, n;
                /*Индекс инфляции ii=S2/S1,
                *Темп инфляции ti=ii-1
                *простых процентов iip=((1+n*ip)*ii-1)/n
                 * для сложных iis=(1+is)nii(1/n)-1
                 * Реальная доходность простые% dp=(n*iip+1-ii)/ii
                 * Реальная доходность сложные% ds=(1+iis)/ii(1/n)-1
                 * сумма всей корзины S1 и S2
                 */
            S1 = n1 * b1 + n2 * b2 + n3 * b3 + n4 * b4 + n5 * b5 + n6 * b6 + n7 * b7 + n8 * b8;// сумма S1
            S2 = n1 * c1 + n2 * c2 + n3 * c3 + n4 * c4 + n5 * c5 + n6 * c6 + n7 * c7 + n8 * c8;// сумма S2
     
            ii = S2 / S1; // индекс инфляции
     
            ti = ii - 1; // темп инфляции
                
                n= n1+n2+n3+n4+n5+n6+n7+n8; // n= общее кол-во товаров и услуг
                iip = ((1 + n * ip) * ii - 1) / n;

    Diman3241, 28 Сентября 2015

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

    +4

    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
    StringBuilder errorMessage = new StringBuilder();
    int i = 0, j = 0;
    bool outcome = true;
    double value;
    string[] label = new string[] { label1.Text, label2.Text, label4.Text };
    
    textBox1.Text = textBox1.Text.Trim();
    textBox2.Text = textBox2.Text.Trim();
    textBox3.Text = textBox3.Text.Trim();
    
    foreach (string field in (new string[] { textBox1.Text, textBox2.Text, textBox3.Text }))
    {
    	try
    	{
    		if (field.Length == 0)
    			throw new Exception("отсутствует значение.\n");
    
    		if (j == 2)
    			value = int.Parse(field, NumberStyles.Integer);
    		else
    			value = double.Parse(field, NumberStyles.Float);
    
    		if (value <= 0)
    			throw new Exception("значение должно быть строго больше нуля.\n");
    
    		if (j == 2)
    		{
    			try
    			{
    				dateTimePicker1.Value.Date.AddMonths((int)value);
    			}
    			catch (Exception)
    			{
    				throw new Exception("превышено максимальное значение типа System.DateTime, " + DateTime.MaxValue.ToShortDateString() + ".\n" +
    									"Срок вклада не может превышать " + 
    									((DateTime.MaxValue.Year - dateTimePicker1.Value.Date.Year) * 12 +
    									DateTime.MaxValue.Month - dateTimePicker1.Value.Date.Month).ToString() + " мес. " + "от указанной даты оформления, " + dateTimePicker1.Value.Date.ToShortDateString() + ".\n");
    			}
    		}
    	}
    	catch (Exception e)
    	{
    		errorMessage.Append((++i).ToString() + ". " + label[j] + ": ");
    
    		switch (e.GetType().ToString())
    		{
    			case "System.FormatException":
    				errorMessage.AppendLine("неверный формат числа.\n");
    				break;
    
    			case "System.OverflowException":
    				{
    					if (j < 2)
    					{
    						errorMessage.AppendLine("значение не может быть обработано вещественным типом System.Double.");
    						errorMessage.AppendLine("Значение типа должно быть строго больше нуля, в промежутке (0; " + double.MaxValue.ToString() + "].\n");
    					}
    					else
    					{
    						errorMessage.AppendLine("значение не может быть обработано целочисленным типом System.Int32.");
    						errorMessage.AppendLine("Значение типа должно быть строго больше нуля, в промежутке (0; " + int.MaxValue.ToString() + "].\n");
    					}
    					break;
    				}
    
    			default:
    				errorMessage.AppendLine(e.Message);
    				break;
    		}
    
    		outcome = false;
    	}
    
    	j++;
    }

    Мастер исключений 80-го уровня.
    Хорошо, хоть не по мессаджам их разделяет.

    yamamoto, 28 Сентября 2015

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

    −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
    public interface IApplicationUserManager { }
    
        public class ApplicationUserManager : UserManager<ApplicationUser, long>, IApplicationUserManager
        {
            private static ApplicationUserManager applicationUserManager;
            public static bool IsUserInRole(long userId, string roleName)
            {
                return applicationUserManager.UserInRole(userId, roleName);
            }
    
            public ApplicationUserManager(IAccountService accountService)
                : base(new ApplicationUserStore())
            {
                this.accountService = accountService;
                applicationUserManager = this;
            }
         }

    Проверяй, проверяй мои роли полностью...

    FreedomHex, 24 Сентября 2015

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

    +6

    1. 1
    2. 2
    3. 3
    4. 4
    if (value is Int32)
    {
        Int32 prio = Int32.Parse(value.ToString());
    }

    l1pton17, 20 Сентября 2015

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

    +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
    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
    string[] array=new string[10];
    array[0] = "?";
    array[1] = "?";
    array[2] = "?";
    array[3] = "?";
    array[4] = "?";
    array[5] = "?";
    array[6] = "?";
    array[7] = "?";
    array[8] = "?";
    
    ....
    
    if (DS.Tables[0].Rows[i][3].ToString() == "1")
    {
    checkBox20.Checked = true;
    }
    if (DS.Tables[0].Rows[i][4].ToString() == "1")
    {
    checkBox23.Checked = true;
    }
    if (DS.Tables[0].Rows[i][5].ToString() == "1")
    {
    checkBox22.Checked = true;
    }
    if (DS.Tables[0].Rows[i][6].ToString() == "1")
    {
    checkBox25.Checked = true;
    }
    if (DS.Tables[0].Rows[i][7].ToString() == "1")
    {
    checkBox24.Checked = true;
    }
    if (DS.Tables[0].Rows[i][8].ToString() == "1")
    {
    checkBox27.Checked = true;
    }
    if (DS.Tables[0].Rows[i][9].ToString() == "1")
    {
    checkBox11.Checked = true;
    }
    
    ...
    
    if (checkBox17.Checked)
    {
    array[0] = "application/";
    }
    if (checkBox18.Checked)
    {
    array[1] = "audio/";
    }
    if (checkBox21.Checked)
    {
    array[2] = "example/";
    }
    if (checkBox20.Checked)
    {
    array[3] = "image/";
    }
    if (checkBox23.Checked)
    {
    array[4] = "message/";
    }
    if (checkBox22.Checked)
    {
    array[5] = "model/";
    }
    if (checkBox25.Checked)
    {
    array[6] = "multipart/";
    }
    if (checkBox24.Checked)
    {
    array[7] = "text/";
    }
    if (checkBox27.Checked)

    Дали на рецензию одну научную работу...

    sgerman, 18 Сентября 2015

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

    +3

    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
    public SomeLongNameSpace.PolicyPremiumReturnType ProcessPremiums(
                        int userID, 
                        int divisionID, 
                        string ObjectCode, 
                        int iPolicyID, 
                        int iBulkEndorsementID, 
                        System.Data.DataTable dtClientPremiums, 
                        System.Data.DataTable dtClientPremiumInterests, 
                        System.Data.DataTable dtRiskCommissions, 
                        System.Data.DataTable dtBrokerages, 
                        System.Data.DataTable dtDiscounts, 
                        System.Data.DataTable dtApportionments, 
                        System.Data.DataTable dtUWGroups, 
                        System.Data.DataTable dtUWGroupSettings, 
                        System.Data.DataTable dtUWGroupPremiums, 
                        System.Data.DataTable dtRiskDeclarations, 
                        System.Data.DataTable dtRiskDeclarationsInterests, 
                        int clientPaymentIntervalDays, 
                        int uwDefaultPaymentIntervalDays, 
                        int uwPaymentIntervalDays, 
                        System.Data.DataTable dtSchedulesLimitDetails, 
                        XII.Integration.GlobalXB.v1_4.PolicyGL.CommissionProcessingFlags commissionProcessingFlags, 
                        bool isOverrideWarranties, 
                        string transactionDescription, 
                        string TechnicalContactName, 
                        bool isCreateDeclarationWithoutInterests, 
                        int clientRPPaymentIntervalDays,
                        System.Data.DataTable deferredPayments)
            {
                return base.Channel.ProcessPremiums(userID, divisionID, ObjectCode, iPolicyID, iBulkEndorsementID, dtClientPremiums, dtClientPremiumInterests, dtRiskCommissions, dtBrokerages, dtDiscounts, dtApportionments, dtUWGroups, dtUWGroupSettings, dtUWGroupPremiums, dtRiskDeclarations, dtRiskDeclarationsInterests, clientPaymentIntervalDays, uwDefaultPaymentIntervalDays, uwPaymentIntervalDays, dtSchedulesLimitDetails, commissionProcessingFlags, isOverrideWarranties, transactionDescription, TechnicalContactName, isCreateDeclarationWithoutInterests, clientRPPaymentIntervalDays, deferredPayments);
            }

    few params

    g10829780, 18 Сентября 2015

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