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

    +962

    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
    for (int i = 0; i < 4; i++)
    {
        if (!UseParam[i])
        {
            switch (i)
            {
                case 0:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания амперметра " + PS1_DeviceName_A.Text + " " + PS1.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            I1 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            I1 = GetCorrectElectricValue(CorrectKm[1] ?? 0, "I0_A", row["N"], row["M"]) * 1000;
                        I0_A.ErrorText = PS1_A.ErrorText = "Показание " + PS1_DeviceName_A.Text + " исключено из расчета";
                    }
                    break;
                case 1:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания вольтметра" + PS1_DeviceName_B.Text + " " + PS1.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            U1 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            U1 = GetCorrectElectricValue(CorrectKm[0] ?? 0, "U0_A", row["N"], row["M"]) * 1000;
                        U0_A.ErrorText = PS1_B.ErrorText = "Показание " + PS1_DeviceName_B.Text + " исключено из расчета";
                    }
                    break;
                case 2:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания амперметра" + PS2_DeviceName_A.Text + " " + PS2.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            I2 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            I2 = GetCorrectElectricValue(CorrectKm[3] ?? 0, "I0_B", row["N"], row["M"]) * 1000;
                        I0_B.ErrorText = PS2_A.ErrorText = "Показание " + PS2_DeviceName_A.Text + " исключено из расчета";
                    }
                    break;
                case 3:
                    if (AutoCalc || XtraMessageBox.Show("Неверные показания вольтметра" + PS2_DeviceName_B.Text + " " + PS2.Text + "\nИслючить из расчета?", "Проверка показаний", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    {
                        if (CorrectKm[i] == 0 || CorrectKm[i] == L)
                            U2 = (CorrectValue[i] ?? 0) * 1000;
                        else
                            U2 = GetCorrectElectricValue(CorrectKm[2] ?? 0, "U0_B", row["N"], row["M"]) * 1000;
                        U0_B.ErrorText = PS2_B.ErrorText = "Показание " + PS2_DeviceName_B.Text + " исключено из расчета";
                    }
                    break;
            }
        }
    }

    Красота

    invi, 16 Февраля 2012

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

    +960

    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 static void WriteErrLog(string FileName, string errors)
    {
        try
        {
            string name = Environment.CurrentDirectory + "\\log\\" + FileName.Replace("80020_", "");
            name = name.Replace(".xml", ".txt");
            if (File.Exists(name))
                name = name.Replace(".txt", "_" + DateTime.Now.ToString("yyyy-MM-dd hh_mm_ss") + ".txt");                
            using (StreamWriter f = new StreamWriter(name, true, Encoding.GetEncoding(1251)))
            {
                f.Write(errors);
            }
        }
        catch { }
    }

    Продолжаем...

    invi, 16 Февраля 2012

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

    +113

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    private static string GetStringParam(ref string str, string param)
    {
        string result = "";
        if (str.Contains(param))
        {
            result = str.Substring(str.IndexOf(param) + 1);
            str = str.Remove(str.IndexOf(param));
        }
        return result;
    }

    И еще

    invi, 16 Февраля 2012

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

    +113

    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
    public static string GetShortName(string name, int length)
    {
        StringBuilder shortname = new StringBuilder(name);
        string[] str = new string[] { "ПС", "ОАО" };
        for (int i = 0; i < str.Length; i++)
            if (shortname.ToString().Length > str[i].Length && shortname.ToString().Substring(0, str[i].Length).ToUpper() == str[i])
                shortname.Remove(0, str[i].Length);
    
        str = new string[] { "ТЭЦ", "ГЭС", "ГРЭС" };
        for (int i = 0; i < str.Length; i++)
            if (shortname.ToString().IndexOf(str[i], StringComparison.CurrentCultureIgnoreCase) > 0)
                shortname.Remove(1, shortname.ToString().IndexOf(str[i]) - 1);
        return (shortname.Length > length) ? shortname.ToString().Substring(0, length).Trim() : shortname.ToString().Trim();
    }

    Опять же, из того, что досталось в наследство)

    invi, 16 Февраля 2012

    Комментарии (0)
  5. VisualBasic / Говнокод #9440

    −90

    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
    L = InputBox("Введите номер вашего варианта", "Лабораторная работа №2")
    Label4.Caption = L
    
    If L > 50 Then
    MsgBox "Вы не ввели свой вариант, ввод варианта обязателен для корректной работы программы", vbExclamation, "Ошибка"
    L = InputBox("Введите номер вашего варианта", "Лабораторная работа №2")
    Label4.Caption = L
    End If
        If L > 50 Then
            MsgBox "Ошибка. Попробуйте запустить приложение снова и выполнить все действия", vbCritical, "Ошибка"
            End
    
    End If

    Третий раз не спрашиваем...

    vovams, 16 Февраля 2012

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

    +87

    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
    var
    x,y,R:real;
    l11,l12,l1,l21,l22,l2,l3,l41,l42,l4,l51,l52,l5,l6,l71,l72,l7:boolean;
    begin
    x:= StrToFloat(edit1.text);
    y:= StrToFloat(edit2.text);
    R:=StrToFloat(edit3.text);
    l11:=(y<x) and (x*x+y*y<R*R) and (y>0);
    l12:=(x*x+y*y<r*r) and (x<0)and (y>0);
    l1:=l11 or l12;
    l21:=(y>0) and (x*x+y*y<R*R)and (y>x);
    l22:= ( x*x+y*y<R*R)and (y>x) and (x<0);
    l2:= l21 or l22;
    l3:=(y<0) and ( x*x+y*y<R*R)and (y>x);
    l41:= (x>0) and ( x*x+y*y<R*R)and (y<x);
    l42:= (x<-1) and ( x*x+y*y>R*R)and (y>x);
    l4:= l41 or l42;
    l51:= (x>1) and ( x*x+y*y>R*R)and (y<x);
    l52:= (x>-1) and ( x*x+y*y>R*R)and (y<x);
    l5:= l51 or l52;
    l6:= (y>0) and ( x*x+y*y<R*R)and (y>x);
    l71:= (x>0) and (x*x+y*y>R*R) and (y<0);
    l72:= (y<0) and (x*x+y*y>R*R) and (y<x) and (x<0);
    l7:= l71 or l72;
    if l1= true then
    begin
    edit4.text:='T принадлежит 1 области';
    end
    else
    begin
    edit4.text:='T не принадлежит 1 области';
    end;
    if l2= true then
    begin
    edit4.text:='T принадлежит 2 области';
    end
    else
    begin
    edit4.text:='T не принадлежит 2 области'
    end;
    if l3= true then
    begin
    edit4.text:='T принадлежит 3 области'
    end
    else
    begin
    edit4.text:='T не принадлежит 3 области'
    end;
    if l4= true then
    begin
    edit4.text:='T принадлежит 4 области'
    end
    else
    begin
    edit4.text:='T не принадлежит 4 области'
    end;
    if l5= true then
    begin
    edit4.text:='T принадлежит 5 области'
    end
    else
    begin
    edit4.text:='T не принадлежит 5 области'
    end;
    if l6= true then
    begin
    edit4.text:='T принадлежит 6 области'
    end
    else
    begin
    edit4.text:='T не принадлежит 6 области'
    end;
    if l4= true then
    begin
    edit4.text:='T принадлежит 7 области'
    end
    else
    begin
    edit4.text:='T не принадлежит 7 области'
    end;
    end;
    
    end.

    ...

    Cyanide, 15 Февраля 2012

    Комментарии (12)
  7. PHP / Говнокод #9438

    +156

    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
    <?
    include "config/bd.php";
    
    class watermark1
    {
      function create_watermark( $main_img_obj, $text, $font, $r = 128, $g = 128, $b = 128, $alpha_level = 0 )
      {
       $width = imagesx($main_img_obj);
       $height = imagesy($main_img_obj);
       $angle =  -rad2deg(atan2((-$height),($width)));
       $text = " ".$text." ";
       $c = imagecolorallocatealpha($main_img_obj, $r, $g, $b, $alpha_level);
       $size = (($width+$height)/2)*2/strlen($text);
       $box  = imagettfbbox ( $size, $angle, $font, $text );
       $x = $width/2 - abs($box[4] - $box[0])/2;
       $y = $height/2 + abs($box[5] - $box[1])/2;
       imagettftext($main_img_obj,$size ,$angle, $x, $y, $c, $font, $text);
       return $main_img_obj;
      }
    }
    
    
    
    $myrow22 = mysql_query("select * from `content` where id_content=3");
    $row22 = mysql_fetch_array($myrow22);
    include "includes/head1.php";
    include "includes/leftm.php"; 
     
    $category_id = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 1;
    $myrow = mysql_query("SELECT * FROM `gallery` LEFT JOIN `gallery_files` `gf` ON `gallery`.id = gallery_id WHERE category_id = " . $category_id  . " ORDER BY `gf`.id");
     
    $items = array();
    $photos = array();
    while($row = mysql_fetch_array($myrow)) {
    	$items[ $row['gallery_id']] = $row;
    $photos[ $row['gallery_id']][] = $row['filename'];
    }
     
    echo '<div id=content>
    <p><table width=100% >
    <tr>';
    $i = 0;
    foreach ($items as $id => $item) {
            $i++;
            echo '<td>';
    
    
    
    
     
     
    
    	$photo = array_shift($photos[$id]); // только первая картинка
    $photo2='./uploads/text'.$photo;
    
    	$watermark = new watermark1();
    	$type=mime_content_type($photo);
    	
    if (($type != 'image/jpeg')and($type != 'image/png'))
    {
    }
    else
    {
    // определяем расширение переданного файла
    switch ($type)
    {
    case 'image/jpeg':
    $img = imagecreatefromjpg("./uploads/resized_$photo");
    break;
    case 'image/png':
    $img = imagecreatefrompng("./uploads/resized_$photo");
    break;
    }
    
    	$im=$watermark->create_watermark($img,”jeka911.wordpress.com”,'./1.ttf',0,0,255,120);
    	imagejpeg($im,$photo2);
    echo '<a href="infokuhni.php?id=' . $item['gallery_id'] . '" ><img src="'. $photo2 . '" /><br/><br/>';
    	echo '<font face="Georgia, Times New Roman, Times, serif">';	echo  $item['title'] . '</font><br/>';
    		echo '<font face="Times New Roman, Times, serif">Цена: ';	echo $item['price'] . ' рублей</font></a><br/><br>';
     
            echo '</td>';
            if (!($i % 4)) echo '</tr><tr>';
    }
    echo '</tr>
    </table>
    <p></div>';
     
    include "includes/foot.php";
    ?>

    bugaaa, 15 Февраля 2012

    Комментарии (1)
  8. PHP / Говнокод #9437

    +156

    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
    public static function ObjectToArray($obj, $filter_fields = true)
        {
            $a = array();
            $cv = array();
            if($filter_fields)
            {
                $cv = get_class_vars(get_class($obj));
            }
            else
            {
                $cv = get_object_vars($obj);
            }
            foreach($cv as $k => $v)
            {
                $a[$k] = $obj->$k;
            }
            return $a;
        }

    Написано n-ное количество лет назад. Делало из объекта ассоциативный массив, который передавался в метод, осуществляющий запись в БД :D
    А ведь все это можно было заменить на return (array)$obj

    nolka4, 15 Февраля 2012

    Комментарии (1)
  9. PHP / Говнокод #9436

    +152

    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
    <?
    include "config/bd.php";
    
    class watermark1
    {
      function create_watermark( $main_img_obj, $text, $font, $r = 128, $g = 128, $b = 128, $alpha_level = 100 )
      {
       $width = imagesx($main_img_obj);
       $height = imagesy($main_img_obj);
       $angle =  -rad2deg(atan2((-$height),($width)));
       $text = " ".$text." ";
       $c = imagecolorallocatealpha($main_img_obj, $r, $g, $b, $alpha_level);
       $size = (($width+$height)/2)*2/strlen($text);
       $box  = imagettfbbox ( $size, $angle, $font, $text );
       $x = $width/2 - abs($box[4] - $box[0])/2;
       $y = $height/2 + abs($box[5] - $box[1])/2;
       imagettftext($main_img_obj,$size ,$angle, $x, $y, $c, $font, $text);
       return $main_img_obj;
      }
    }
    
    
    
    $myrow22 = mysql_query("select * from `content` where id_content=3");
    $row22 = mysql_fetch_array($myrow22);
    include "includes/head1.php";
    include "includes/leftm.php"; 
     
    $category_id = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 1;
    $myrow = mysql_query("SELECT * FROM `gallery` LEFT JOIN `gallery_files` `gf` ON `gallery`.id = gallery_id WHERE category_id = " . $category_id  . " ORDER BY `gf`.id");
     
    $items = array();
    $photos = array();
    while($row = mysql_fetch_array($myrow)) {
    	$items[ $row['gallery_id']] = $row;
    $photos[ $row['gallery_id']][] = $row['filename'];
    }
     
    echo '<div id=content>
    <p><table width=100% >
    <tr>';
    $i = 0;
    foreach ($items as $id => $item) {
            $i++;
            echo '<td>';
    $watermark = new watermark1();
    $img = imagecreatefromjpeg(“' . $photo . '”);
    $im=$watermark->create_watermark($img,”jeka911.wordpress.com”,”1.ttf”,0,0,255,120);
    imagejpeg($im,”result.jpg”); 
     
     
     
    	$photo = array_shift($photos[$id]); // только первая картинка
    echo '<a href="infokuhni.php?id=' . $item['gallery_id'] . '" ><img src="./uploads/resized_' . $photo . '" /><br/><br/>';
    	echo '<font face="Georgia, Times New Roman, Times, serif">';	echo  $item['title'] . '</font><br/>';
    		echo '<font face="Times New Roman, Times, serif">Цена: ';	echo $item['price'] . ' рублей</font></a><br/><br>';
     
            echo '</td>';
            if (!($i % 4)) echo '</tr><tr>';
    }
    echo '</tr>
    </table>
    <p></div>';
     
    include "includes/foot.php";
    ?>

    bugaaa, 15 Февраля 2012

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

    +153

    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
    <?
    include "config/bd.php";
    $myrow22 = mysql_query("select * from `content` where id_content=3");
    $row22 = mysql_fetch_array($myrow22);
    include "includes/head1.php";
    include "includes/leftm.php"; 
     
    $category_id = isset($_GET['category_id']) ? (int)$_GET['category_id'] : 1;
    $myrow = mysql_query("SELECT * FROM `gallery` LEFT JOIN `gallery_files` `gf` ON `gallery`.id = gallery_id WHERE category_id = " . $category_id  . " ORDER BY `gf`.id");
     
    $items = array();
    $photos = array();
    while($row = mysql_fetch_array($myrow)) {
    	$items[ $row['gallery_id']] = $row;
    $photos[ $row['gallery_id']][] = $row['filename'];
    }
     
    echo '<div id=content>
    <p><table width=100% >
    <tr>';
    $i = 0;
    foreach ($items as $id => $item) {
            $i++;
            echo '<td>';
     
     
     
     
    	$photo = array_shift($photos[$id]); // только первая картинка
    echo '<a href="infokuhni.php?id=' . $item['gallery_id'] . '" ><img src="./uploads/resized_' . $photo . '" /><br/><br/>';
    	echo '<font face="Georgia, Times New Roman, Times, serif">';	echo  $item['title'] . '</font><br/>';
    		echo '<font face="Times New Roman, Times, serif">Цена: ';	echo $item['price'] . ' рублей</font></a><br/><br>';
     
            echo '</td>';
            if (!($i % 4)) echo '</tr><tr>';
    }
    echo '</tr>
    </table>
    <p></div>';
     
    include "includes/foot.php";
    ?>

    bugaaa, 15 Февраля 2012

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