тут еще мог напороть с массивом: if qChart2.FieldByName('rc_smenavol_volumenum').AsInteger = mproduct[i] then begin
Полный код: [more]
procedure TfTypes.ChangeReservFiltr;
var bar_ser:TBarSeries;
mseries:array of TFastLineSeries;
mproduct:array of integer;
count_product,i,j:integer;
value_found: Boolean;
begin
if not bInit then
begin
with qReservoirsState do
begin
if Active then Close;
ParamByName('obj').AsInteger:=ID_AZS;
ParamByName('date_from').AsDate:=cxdedReservFrom.Date;
ParamByName('date_to').Asdate:=cxdedReservTo.Date;
Prepare;
Open;
end;
with qReservoirsStatus do
begin
if Active then Close;
ParamByName('obj').AsInteger:=ID_AZS;
ParamByName('date_from').AsDate:=cxdedReservFrom.Date;
ParamByName('date_to').Asdate:=cxdedReservTo.Date;
Prepare;
Open;
end;
with qryShiftListRes do
begin
if Active then Close;
ParamByName('obj').AsInteger:=ID_AZS;
ParamByName('date_from').AsDate:=cxdedReservFrom.Date;
ParamByName('date_to').Asdate:=cxdedReservTo.Date;
Prepare;
Open;
end;
//////////////////////////////////////////////////////////////////////////
with qCharts do
begin
if Active then Close;
ParamByName('obj').AsInteger:=ID_AZS;
ParamByName('date_from').AsDate:=cxdedReservFrom.Date;
ParamByName('date_to').Asdate:=cxdedReservTo.Date;
Prepare;
Open;
end;
with qChart2 do
begin
if Active then Close;
ParamByName('obj').AsInteger:=ID_AZS;
ParamByName('date_from').AsDate:=cxdedReservFrom.Date;
ParamByName('date_to').Asdate:=cxdedReservTo.Date;
Prepare;
Open;
end;
//Строим график
dbChart1.View3D:=false;
dbChart1.Legend.Visible:=true;
dbChart1.Legend.ColorWidth:=0;
dbChart1.Legend.ShadowSize:=1;
dbChart1.Legend.Alignment:=laRight;
dbChart1.Legend.ColorWidth:=15;
dbChart1.SeriesList.Clear; //Очищаю график
dbchart1.Refresh;
begin
//dbChart1.Title.Text.Add('График отклонения фактического движения за смену от расчетного');
//Подсчитываю количество линий:
count_product:=0;
while not(qCharts.Eof) do begin
inc(count_product);
SetLength(mproduct,count_product);
mproduct[count_product-1]:=qCharts.FieldByName('rc_smenavol_volumenum').AsInteger;
qCharts.Next;
end;
//Строю график
qChart2.Open;
for i:=0 to count_product-1 do begin
SetLength(mseries,dbChart1.SeriesList.Count+1);
mseries[dbChart1.SeriesList.Count]:=TFastLineSeries.Create(dbChart1);
mseries[dbChart1.SeriesList.Count].LinePen.Width:=2;
dbChart1.AddSeries(mseries[dbChart1.SeriesList.Count]);
qChart2.First();
for j := Trunc(cxdedReservFrom.Date) to trunc(strtodate('07.03.2010')) do begin
while trunc(qChart2.FieldByName('rc_sd_begindate').AsDateTime) < j do
//begin
qChart2.Next();
value_found := False;
//end;
//showmessage(DateToStr(j));
while trunc(qChart2.FieldByName('rc_sd_begindate').AsDateTime) = j do begin
if qChart2.FieldByName('rc_smenavol_volumenum').AsInteger = mproduct[i] then begin
if cxRadioGroup1.ItemIndex = 0 then //График фактического отклонения движения за смену от расчетного
mseries[dbChart1.SeriesList.Count-1].Add(qChart2.FieldByName('otklon_fakdvforsmena').AsInteger,datetostr(trunc((qChart2.FieldByName('rc_sd_begindate').Asdatetime))))
else //График фактического остатка от нарастающего расчетного
mseries[dbChart1.SeriesList.Count-1].Add(qChart2.FieldByName('otklon_fakrestfromincrease').AsInteger,datetostr(trunc((qChart2.FieldByName('rc_sd_begindate').Asdatetime))));
value_found := True;
end;
qChart2.Next();
end;
if not value_found then
mseries[dbChart1.SeriesList.Count-1].Add(0,datetostr(trunc((qChart2.FieldByName('rc_sd_begindate').Asdatetime))));
end;
end;
end;
end;
end;
[/more]
Запросы:
[more]
Подсчет количества резервуаров:
select distinct t.rc_smenavol_product, t.rc_smenavol_volumenum from berlio.RC_SMENAVOL t, berlio.rc_smenadates m, roman.Producttypes n
where rc_smenavol_header = rc_smenadates
and m.rc_sd_begindate >=
ate_from and m.rc_sd_enddate <=
ate_to
and m.rc_sd_object =
bj
and t.rc_smenavol_product = n.producttypes
and producttypes_productgroup in (1,2)
order by t.rc_smenavol_volumenum
Выборка записей:
SELECT DISTINCT "PT"."producttypes_productname",
"PT"."producttypes_color",
"V"."RC_SMENAVOL",
"V"."rc_smenavol_volumenum",
"V"."rc_smenavol_header",
"V"."rc_smenavol_bookbegsmena",
"V"."rc_smenavol_bookendsmena",
"V"."rc_smenavol_litrtrkofvolume",
"V"."rc_smenavol_begsmena",
"V"."rc_smenavol_endsmena",
"V"."rc_smenavol_deltavolume",
"V"."rc_smenavol_litrinput",
"V"."rc_smenavol_product",
"V"."rc_smenavol_bookendsmena" as "rc_smenavol_bookendsmena_increasing",
s.rc_smenadates,
s.rc_sd_iterator,
s.rc_sd_begindate,
s.rc_sd_enddate,
s.rc_sd_name,
(rc_smenavol_bookbegsmena - rc_smenavol_bookendsmena) AS "bookrealisation",
(rc_smenavol_endsmena - rc_smenavol_begsmena - (rc_smenavol_litrinput - bookrealisation)) as otklon_fakdvforsmena, (rc_smenavol_endsmena - rc_smenavol_bookendsmena) as otklon_fakrestfromincrease
FROM ( "Berlio"."RC_SMENAVOL" AS V JOIN "Berlio"."RC_SMENADATES" AS S ON ("V"."rc_smenavol_header" = "S"."RC_SMENADATES") ) JOIN "Roman"."PRODUCTTYPES" AS PT ON ("V"."rc_smenavol_product" = "PT"."PRODUCTTYPES")
WHERE rc_sd_object =
bj AND s.rc_sd_begindate >=
ate_from AND s.rc_sd_enddate <=
ate_to
ORDER BY V."rc_smenavol_volumenum", s."rc_sd_begindate"
[/more]