1. C++ / Говнокод #6280

    +163

    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
    class CStateShortMap
    {
    public:
      CStateShortMap(int id, TDateTime time, TZReadOnlyQuery* query);
      void Load(TZReadOnlyQuery* query, TDateTime time);
      int GetTypeSize() const { return Items.size(); }
      char GetType(int idx)
      {
        return Items[idx].first;
      }
      std::vector< std::vector<CStateShortItem> >& GetItems(char type)
      {
        for(int i=0; i < Items.size(); i++)
        {
          if( Items[i].first == type )
            return Items[i].second;
        }
        return Items[0].second;
      }
    private:
      const int Id;
      std::vector< std::pair<char, std::vector< std::vector<CStateShortItem> > > > Items;
    };
    
    CStateShortMap::CStateShortMap(int id, TDateTime time, TZReadOnlyQuery* query)
     : Id(id)
    {
      Load( query, time );
    }
    
    void CStateShortMap::Load(TZReadOnlyQuery* query, TDateTime time)
    {
      Items.clear();
      String sql;
      sql.sprintf( "select map.id_, equipment.type_"
                   " from map left join equipment on map.equipment_id=equipment.id_"
                   " where map.station_id=%d order by equipment.type_", Id );
      query->SQL->Text = sql;
      query->Open();
      vector< pair<int, char> > mapId;
      while( !query->Eof )
      {
        mapId.push_back( pair<int, char>(query->FieldByName( "id_" )->AsInteger, query->FieldByName( "type_" )->AsString[1]) );
        query->Next();
      }
      Items.clear();
      for(int i=0; i<mapId.size(); i++)
      {
        sql.sprintf( "select status.color, status.name_, map.number_equipment, equipment_status.status_id, equipment_status.begin_, equipment_status.plan_end_"
                     " from equipment_status left join map on equipment_status.map_id=map.id_"
                     " left join status on equipment_status.status_id=status.id_"
                     " where equipment_status.map_id=%d and begin_<='%s' order by equipment_status.begin_ desc limit 1",
                     mapId[i].first, time.FormatString("yyyy-mm-dd hh:nn:ss") );   //equipment_status.id_
        query->SQL->Text = sql;
        query->Open();
        if( query->Eof ) continue;
        int id[] = { 0, 1, 1, 1, 1, 2, 3, 1, 1, 1 };
        int j;
        for(j=0; j<Items.size(); j++)
          if( Items[j].first==mapId[i].second )
            break;
        if( j!=Items.size() )
          Items[j].second[id[query->FieldByName( "status_id" )->AsInteger]].push_back( CStateShortItem( query ) );
        else
        {
          Items.push_back( std::pair<char, std::vector< std::vector<CStateShortItem> > >( mapId[i].second, std::vector< std::vector<CStateShortItem> >() ) );
          Items[ Items.size()-1 ].second.resize( 4 );
          Items[ Items.size()-1 ].second[ id[query->FieldByName( "status_id" )->AsInteger] ].push_back( CStateShortItem( query ) );
        }
      }
      for(int i=0; i<Items.size(); i++)
      {
        sort( Items[i].second[0].begin(), Items[i].second[0].end() );
        sort( Items[i].second[1].begin(), Items[i].second[1].end() );
        sort( Items[i].second[2].begin(), Items[i].second[2].end() );
        sort( Items[i].second[3].begin(), Items[i].second[3].end() );
      }
    }

    старый проект на борландбыдлере, найденный на новой работе

    Запостил: ni3_inv, 08 Апреля 2011

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

    Добавить комментарий