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

    +111

    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
    /// <summary>
            /// Получает IPAdress к которому нужно подключиться
            /// </summary>
            private int Get_IPAdress_Server()
            {
                string Buf = "";
                for (int i = 0; i < Server_IP.Servers_IP.Length; i++ )
                {
                    try
                    {
                        TcpClient tc = new TcpClient(Server_IP.Servers_IP[i], Server_IP.Servers_Port[i]);
                        byte[] buffer = new byte[19];
                        NetworkStream nss = tc.GetStream();
                        nss.Read(buffer, 0, 19);
                        Buf = Encoding.ASCII.GetString(buffer).Trim();
                        Server_IPAdress = Buf.Substring(0, Buf.IndexOf(":"));
                        Server_Port = int.Parse(Buf.Substring(Buf.IndexOf(":") + 1, Buf.Length - Buf.IndexOf(":") - 1));
                        return 0;
                    }
                    catch (SocketException)
                    {
                    }
                }
                return -1;
            }

    Получаем индекс в коллекции где хранятся список серверов Первый доступный!

    Nigma143, 06 Августа 2010

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

    +112

    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
    private void _Login()
            {
                if (Get_IPAdress_Server() != 0)
                {
                    if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                    return;
                }
                try
                {
                    TcpClient MClient = new TcpClient(Server_IPAdress, Server_Port);
                    Sock = MClient.Client;
                    if (Sock == null)
                    {
                        if (Error_Connect_Method != null) Error_Connect_Method(this ,"Серевер недоступен!");
                        return;
                    }
                    mrim_packet_header Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_HELLO, 0, 0, 0, 0, 0, 0, 0);
                    byte[] Hello = Pack.Generat_Packet();
                    Sock.Send(Hello);
                    byte[] Buf = new byte[48];
                    Sock.Receive(Buf);
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_HELLO_ACK)
                    {
                        Sock.Close();
                        if (Error_Connect_Method != null) Error_Connect_Method(this, "Серевер недоступен!");
                    }
                    Ping_Timer = new System.Timers.Timer();
                    long j = 0;
                    Ping_Timer.Interval = mrim_packet_header.Get_UL(Buf.Skip(44).ToArray(), ref j) * 1000;
                    Ping_Timer.Elapsed += new System.Timers.ElapsedEventHandler(Send_Ping);
                    Ping_Timer.Start();
                    Pack = new mrim_packet_header(Msg.CS_MAGIC, Msg.PROTO_VERSION, seq, Msg.MRIM_CS_LOGIN2, 0, 0, 0, 0, 0, 0, 0);
                    Pack.Add_Date_LPS(new string[] {Login, Password });
                    Pack.Add_Date_UL(new long[] { Status });
                    Pack.Add_Date_LPS(new string[] { User_Agent });
                    byte[] Auth = Pack.Generat_Packet();
                    Sock.Send(Auth);
                    Buf = new byte[48];
                    Sock.Receive(Buf);
                    byte[] Date_Len;
                    byte[] Date;
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) != Msg.MRIM_CS_LOGIN_ACK)
                    {
                        Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                        Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                        int N = Sock.Receive(Date);
                        mrim.mrim_packet_header.Loger(Date, N);
                        if (Error_Connect_Method != null) Error_Connect_Method(this, Encoding.GetEncoding("windows-1251").GetString(Date));
                        return;
                    }
                    if (Complite_Connect_Method != null) Complite_Connect_Method(this);
                    Sock.Receive(Buf = new byte[44]);
                    if (BitConverter.ToUInt32(Buf.Skip(12).Take(4).ToArray(), 0) == Msg.MRIM_CS_USER_INFO)
                    {
                        Date_Len = new byte[4] { Buf[16], Buf[17], Buf[18], Buf[19] };
                        Date = new byte[BitConverter.ToUInt32(Date_Len, 0)];
                        int N = Sock.Receive(Date);
                        long M = 0;
                        long J = 0;
                        byte[] Buf_Text;
                        while (N > J)

    Мега авторизация на сервере mrim.mail.ru

    Nigma143, 06 Августа 2010

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

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    public static byte[] Length_Hex(long _Length)
            {
                byte[] Buf = { (byte)(_Length >> 0), (byte)(_Length >> 8), (byte)(_Length >> 16), (byte)(_Length >> 24) };
                return Buf;
            }

    Кривой велик

    Nigma143, 06 Августа 2010

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

    +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
    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
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
            {
                ComboBox
                    cb = sender as ComboBox;
                TextBox
                    tb = new TextBox();
    
                if (cb == comboBox1)
                {
                    tb = textBox7;
                }
                if (cb == comboBox2)
                {
                    tb = textBox6;
                }
                if (cb == comboBox12)
                {
                    tb = textBox2;
                }
                if (cb == comboBox3)
                {
                    tb = textBox8;
                }
                if (cb == comboBox4)
                {
                    tb = textBox9;
                }
                if (cb == comboBox5)
                {
                    tb = textBox10;
                }
                if (cb == comboBox6)
                {
                    tb = textBox11;
                }
                if (cb == comboBox7)
                {
                    tb = textBox12;
                }
                if (cb == comboBox8)
                {
                    tb = textBox13;
                }
                if (cb == comboBox11)
                {
                    tb = textBox14;
                }
    
                tb.Enabled = !(cb.SelectedIndex > 0);
                tb.Text = (cb.SelectedIndex > 0) ? "" : tb.Text;
            }

    David_M, 05 Августа 2010

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

    +116

    1. 1
    2. 2
    var result = resultDate.ToString("yyyy-MM-dd");
    result = result.Replace("-", "");

    zonder, 04 Августа 2010

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

    +111

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    /// ----------------------------------------------------------------------------- 
    /// <summary> 
    /// Page_Load runs when the control is loaded 
    /// </summary> 
    /// ----------------------------------------------------------------------------- 
    protected void Page_Load(object sender, System.EventArgs e)
    {
       ...
    }

    да ну!! серьезно что-ли???

    Coffeeholic, 04 Августа 2010

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

    +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
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    const string newObjectName = "Новый объект";
    
            // формирует имя нового объекта
            string BuildNewObjectName()
            {
                var namesTaken = from node in objectAdapters where node.Name.Contains(newObjectName) select node.Name;
    
                int n = 0;
    
                // ищем максимальное число в конце имени
                if (namesTaken.Any())
                    n = namesTaken.Aggregate(n, (acc, name) =>
                        {
                            int current;
                            return (int.TryParse(name.Split().Last(), out current) && current > acc) ? current : acc;
                        });
    
                // возвращаем следующее
                return newObjectName + " " + (n+1).ToString();
            }

    Получение имени для нового объекта. Смесь различных техник. Не читаемо.

    Lehox, 04 Августа 2010

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

    +113

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    if (((productOrder.DataSet).ProductOrder[0].RowState != DataRowState.Deleted) &&
                    (productOrder.DataSet).ProductOrder[0].IsOrderReferenceNull() &&
                    WebOrderType.IsIngestion() &&
                    (ingestOrder != null) && (ingestOrder.IngestOrder.Count > 0) &&
                    !(ingestOrder).IngestOrder[0].IsOrderReferenceNull()){
                    (productOrder.DataSet).ProductOrder[0].OrderReference =
                        (ingestOrder).IngestOrder[0].OrderReference;
                }

    Eugene, 04 Августа 2010

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

    +105

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    str_sql = " select convert(varchar(6),e.id) as  equipment_id,e.name as name,1 as is_check  " +
                              "         ,(select count(t2.id) from equipment t2 where t2.parent_id=e.id) count_child" +
                              " from equipment e " +
                              " where isnull(e.parent_id,0)=" + e.Node.Value +
                              "       and id in (select cod from f_DisplayEqipmentContract_nodes_2(" + str_contract + "))";

    а вот так мы собираем sql запрос

    madnezz, 02 Августа 2010

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

    +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
    List<ArestDates> dates = new List<ArestDates>();
       ...
       ...
      #region Sort by ArestDate
            
                for (int i = 1; i < dates.Count; i++)
                {
                    for (int j = i + 1; j <= dates.Count; j++)
                    {
                        if (dates[j - 1].ArestDate < dates[i - 1].ArestDate)
                        {
                            ArestDates ads = dates[j - 1];
    
                            dates[j - 1] = dates[i - 1];
                            dates[i - 1] = ads;
                        }
                    }
                }

    Крутая сортировка :) по заявлению автора :) вместо этого ---
    dates.Sort((x, y) => DateTime.Compare(x.ArestDate, y.ArestDate)); ???

    David_M, 02 Августа 2010

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