- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 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() );
}
}
TarasB 08.04.2011 09:49 # 0
iddqd 08.04.2011 15:01 # 0
а вообще этот кусок кода показывает, что у автора в голове творится жуткая каша. знания вроде есть, а представлений о том, что где уместно использовать - нет.
guest 08.04.2011 19:16 # −6
NemoReturns 08.04.2011 19:30 # −9
guest 13.04.2011 17:54 # 0