📄 ustockquery.~pas
字号:
begin
queryitem:='';
if (DBLookupComboBox1.Text<>'') and (DBLookupComboBox1.KeyValue<>99999997) then
QueryItem:=QueryItem+' and ent_instack.unit_id='+inttostr(DBLookupComboBox1.KeyValue);
if (DBLookupComboBox2.Text<>'') and (DBLookupComboBox2.KeyValue<>99999998) then
QueryItem:=QueryItem+' and ent_instack.site_id='+inttostr(DBLookupComboBox2.KeyValue);
if (DBLookupComboBox3.Text<>'') and (DBLookupComboBox3.KeyValue<>99999999) then
QueryItem:=QueryItem+' and ent_instack.depot_id='+inttostr(DBLookupComboBox3.KeyValue);
if combobox5.Text <> '' then
begin
fdpidquery.ParamByName('unit_id').AsInteger :=dblookupcombobox1.KeyValue ;
fdpidquery.ParamByName('site_id').AsInteger :=dblookupcombobox2.KeyValue ;
fdpidquery.ParamByName('depot_id').AsInteger :=dblookupcombobox3.KeyValue ;
fdpidquery.ParamByName('foodposition_name').AsString :=combobox5.Text ;
fdpidquery.Close;
fdpidquery.Open;
// if fdpidquery.RecordCount =1 then
QueryItem:=QueryItem+' and ent_instack.foodposition_id='+inttostr(fdpidquery.fieldbyname('foodposition_id').AsInteger ) ;
end;
// QueryItem:=QueryItem+' and ent_fdposition_info.name='''+edit1.Text+'''';
if CheckBox1.Checked=True then
QueryItem:=QueryItem+' and in_time between '''+FormatDateTime('YYYY-MM-DD',DateTimePicker1.DateTime)+''' and '''+FormatDateTime('YYYY-MM-DD',DateTimePicker2.DateTime)+'''';
if CheckBox2.Checked=True then
QueryItem:=QueryItem+' and reap_year between '+ComboBox3.Text+' and '+ComboBox4.Text;
if (DBLookupComboBox4.Text<>'') and (DBLookupComboBox4.KeyValue<>'不指定') then
QueryItem:=QueryItem+' and attribute='''+DBLookupComboBox4.KeyValue+'''';
if (DBLookupComboBox6.Text<>'') and (DBLookupComboBox6.KeyValue<>'不指定') then
QueryItem:=QueryItem+' and attachment='''+DBLookupComboBox6.KeyValue+'''';
if (DBLookupComboBox5.Text<>'') and (DBLookupComboBox5.KeyValue<>'不指定') then
QueryItem:=QueryItem+' and in_food='''+DBLookupComboBox5.KeyValue+'''';
if (Edit2.Text<>'') then
if ((ComboBox1.ItemIndex=3) or (ComboBox1.ItemIndex=0)) then
QueryItem:=QueryItem+' and storage='+edit2.Text
else if ComboBox1.ItemIndex=1 then
QueryItem:=QueryItem+' and storage>'+Edit2.Text
else
QueryItem:=QueryItem+' and storage<'+Edit2.Text;
if (Edit3.Text<>'') then
if ((ComboBox2.ItemIndex=3) or (ComboBox2.ItemIndex=0)) then
QueryItem:=QueryItem+' and price='+edit3.Text
else if ComboBox2.ItemIndex=1 then
QueryItem:=QueryItem+' and price>'+Edit3.Text
else
QueryItem:=QueryItem+' and price<'+Edit3.Text;
if edit4.Text <> '' then
QueryItem:=QueryItem+' and prod_area='''+edit4.Text+'''';
// if (ComboBox5.Text<>'') and (ComboBox5.Text <>'不指定') then
// QueryItem:=QueryItem+' and fq_class='''+ComboBox5.text+'''';
// if (Edit5.Text<>'') then
// if ((ComboBox6.ItemIndex=3) or (ComboBox6.ItemIndex=0)) then
// QueryItem:=QueryItem+' and FQ_MOISTURE='+edit5.Text
// else if ComboBox6.ItemIndex=1 then
// QueryItem:=QueryItem+' and FQ_MOISTURE>'+Edit5.Text
// else
// QueryItem:=QueryItem+' and FQ_MOISTURE<'+Edit5.Text;
// if (Edit7.Text<>'') then
// if ((ComboBox7.ItemIndex=3) or (ComboBox7.ItemIndex=0)) then
// QueryItem:=QueryItem+' and FQ_IMPURITY='+edit7.Text
// else if ComboBox7.ItemIndex=1 then
// QueryItem:=QueryItem+' and FQ_IMPURITY>'+Edit7.Text
// else
// QueryItem:=QueryItem+' and FQ_IMPURITY<'+Edit7.Text;
// if (Edit6.Text<>'') then
// if ((ComboBox8.ItemIndex=3) or (ComboBox8.ItemIndex=0)) then
// QueryItem:=QueryItem+' and FQ_ITEM2='+edit6.Text
// else if ComboBox8.ItemIndex=1 then
// QueryItem:=QueryItem+' and FQ_ITEM2>'+Edit6.Text
// else
// QueryItem:=QueryItem+' and FQ_ITEM2<'+Edit6.Text;
StockQuery.SQL.Clear;
if QueryItem<>'' then
StockQuery.SQL.Add(s+QueryItem+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id') else
stockquery.SQL.Add(s+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id');
StockQuery.DisableControls;
try
StockQuery.Open;
except
Application.MessageBox('查询库存时出错!','系统错误',MB_OK+MB_ICONERROR);
Exit;
end;
total:=0;
for i:=1 to stockquery.RecordCount do
// stockquery.First ;
// while not stockquery.Eof do
begin
total:=total+stockquery.fieldbyname('库存数量').AsFloat;
stockquery.Next ;
end;
statictext1.Caption :=floattostr(total);
StockQuery.EnableControls;
end;
procedure Tfstockquery.EditBitBtnClick(Sender: TObject);
var total:real;
i:integer;
begin
if global.g_user.UnitID=0 then
dblookupcombobox1.KeyValue :=99999997
else
dblookupcombobox1.KeyValue :=global.g_user.UnitID;
dblookupcombobox2.KeyValue :=99999998;
dblookupcombobox3.KeyValue :=99999999;
checkbox1.Checked :=false;
checkbox2.Checked :=false;
edit4.Text :='';
dblookupcombobox4.KeyValue :='不指定';
dblookupcombobox5.KeyValue :='不指定';
dblookupcombobox6.KeyValue :='不指定';
combobox1.ItemIndex:=3;
edit2.Text :='';
edit2.Enabled :=false;
combobox2.ItemIndex:=3;
edit3.Text :='';
edit3.Enabled :=false;
StockQuery.SQL.Clear;
StockQuery.SQL.Add(s+' order by ent_instack.unit_id,ent_instack.site_id,ent_instack.depot_id,ent_instack.foodposition_id');
try
StockQuery.Open;
except
Application.MessageBox('查询库存时出错!','系统错误',MB_OK+MB_ICONERROR);
Exit;
end;
total:=0;
for i:=1 to stockquery.RecordCount do
// stockquery.First ;
// while not stockquery.Eof do
begin
total:=total+stockquery.fieldbyname('库存数量').AsFloat;
stockquery.Next ;
end;
statictext1.Caption :=floattostr(total);
end;
procedure Tfstockquery.BitBtn1Click(Sender: TObject);
var
i,j,k:integer;
PositionTempMax,PositionTempMin,PositionTempAvr,PositionTempTotal,DepotInTempAvr,DepotInTempTotal:double;
begin
PositionTempMax:=-100;
PositionTempMin:=100;
PositionTempAvr:=0;
PositionTempTotal:=0;
DepotInTempAvr:=0;
DepotInTempTotal:=0;
j:=0;
k:=0;
if (StockQuery.FieldByName('foodPosition_id').IsNull)
or (StockQuery.FieldByName('Depot_id').IsNull)
or (StockQuery.FieldByName('Site_id').IsNull)
or (StockQuery.FieldByName('Unit_id').IsNull) then
begin
showmessage('您选中的记录为空记录,或货位信息不全!,请重新选择!');
exit;
end;
FrmTempResult:=TFrmTempResult.Create(fstockQuery);
FrmTempResult.LblUnit.Caption:=IntToStr(StockQuery.FieldByName('Unit_id').AsInteger);
FrmTempResult.LblSite.Caption:=IntToStr(StockQuery.FieldByName('Site_id').AsInteger);
FrmTempResult.LblDepot.Caption:=IntToStr(StockQuery.FieldByName('Depot_id').AsInteger);
FrmTempResult.LblPosition.Caption:=IntToStr(StockQuery.FieldByName('FoodPosition_id').AsInteger);
FrmTempResult.TblTemp.Active:=false;
FrmTempResult.TblTemp.Filtered:=false;
FrmTempResult.TblTemp.Filter:='lkid='+intToStr(StockQuery.FieldByName('Unit_id').AsInteger)+
' and kd='+intToStr(StockQuery.FieldByName('Site_id').AsInteger)+
' and cf='+intToStr(StockQuery.FieldByName('Depot_id').AsInteger)+
' and hw='+intToStr(StockQuery.FieldByName('FoodPosition_id').AsInteger);
FrmTempResult.TblTemp.Filtered:=true;
FrmTempResult.TblTemp.Active:=true;
if FrmTempResult.TblTemp.RecordCount<1 then
begin
showmessage('没有相应的货位温度信息!');
end
else
begin
FrmTempResult.TblTemp.First;
for i:=1 to FrmTempResult.TblTemp.RecordCount do
begin
if (FrmTempResult.TblTemp.FieldByName('bz').AsInteger=2)then
begin
//showmessage('温度传感器:'+intToStr(FrmTempResult.TblTemp.FieldByName('tt').AsInteger)+'不正常!');
FrmTempResult.TblTemp.Next;
continue;
end;
if FrmTempResult.TblTemp.FieldByName('bz').AsInteger=1 then //货位温度
begin
PositionTempTotal:=PositionTempTotal+FrmTempResult.TblTemp.FieldByName('wsd').AsFloat;
j:=j+1;
if FrmTempResult.TblTemp.FieldByName('wsd').AsFloat>PositionTempMax then
PositionTempMax:=FrmTempResult.TblTemp.FieldByName('wsd').AsFloat;
if FrmTempResult.TblTemp.FieldByName('wsd').AsFloat<PositionTempMin then
PositionTempMin:=FrmTempResult.TblTemp.FieldByName('wsd').AsFloat;
end;
FrmTempResult.TblTemp.Next;
end;
end;
if j<>0 then
begin
PositionTempAvr:=PositionTempTotal/j;
FrmTempResult.LblPositionTempAvr.Caption:=FloatToStr(round(PositionTemPAvr*1000)/1000);
FrmTempResult.LblPositionTempMiN.Caption:=FloatToStr(PositionTemPMin);
FrmTempResult.LblPositionTempMax.Caption:=FloatToStr(PositionTemPMax);
end;
//以下取得仓库的室内外温度信息及仓库的湿度信息
FrmTempResult.TblTemp.Active:=false;
FrmTempResult.TblTemp.Filtered:=false;
FrmTempResult.TblTemp.Filter:='lkid='+intToStr(StockQuery.FieldByName('Unit_id').AsInteger)+
' and kd='+intToStr(StockQuery.FieldByName('Site_id').AsInteger)+
' and cf='+intToStr(StockQuery.FieldByName('Depot_id').AsInteger)+
' and bz<>1'; //仓库的室内外温度信息及仓库的湿度信息
FrmTempResult.TblTemp.Filtered:=true;
FrmTempResult.TblTemp.Active:=true;
if FrmTempResult.TblTemp.RecordCount<1 then
begin
showmessage('没有相应的仓库温湿度信息!');
end
else
begin
FrmTempResult.TblTemp.First;
for i:=1 to FrmTempResult.TblTemp.RecordCount do
begin
if (FrmTempResult.TblTemp.FieldByName('bz').AsInteger=4) then
begin
//showmessage('室内温度传感器:'+intToStr(FrmTempResult.TblTemp.FieldByName('tt').AsInteger)+'不正常!');
FrmTempResult.TblTemp.Next;
continue;
end;
if (FrmTempResult.TblTemp.FieldByName('bz').AsInteger=6) then
begin
// showmessage('室外温度传感器不正常!');
// FrmTempResult.LblDepotTempO.Caption:= '';
FrmTempResult.TblTemp.Next;
continue;
end;
if (FrmTempResult.TblTemp.FieldByName('bz').AsInteger=12) then
begin
//showmessage('湿度传感器不正常!');
//FrmTempResult.LblMoisture.Caption:='';
FrmTempResult.TblTemp.Next;
continue;
end;
if FrmTempResult.TblTemp.FieldByName('bz').AsInteger=3 then //仓库室内温度
begin
DepotInTempTotal:=DepotInTempTotal+FrmTempResult.TblTemp.FieldByName('wsd').AsFloat;
k:=k+1;
end;
if FrmTempResult.TblTemp.FieldByName('bz').AsInteger=5 then //仓库室外温度
FrmTempResult.LblDepotTempO.Caption:=floatToStr(FrmTempResult.TblTemp.FieldByName('wsd').AsFloat);
if FrmTempResult.TblTemp.FieldByName('bz').AsInteger=11 then //仓库湿度
FrmTempResult.LblMoisture.Caption:=floatToStr(FrmTempResult.TblTemp.FieldByName('wsd').AsFloat);
FrmTempResult.TblTemp.Next;
end;
end;
if k<>0 then
begin
DepotInTempAvr:=DepotInTempTotal/k;
FrmTempResult.LblDepotTempI.Caption:= FloatToStr(round(DepotInTemPAvr*1000)/1000);
end;
//else
//begin
//showmessage('没有有效的仓库温度信息!!');
//FrmTempResult.LblDepotTempI.Caption:='';
//end;
{ if FrmTempResult.LblMoisture.Caption='' then
showmessage('没有有效的仓库湿度信息!');
if FrmTempResult.LblDepotTempO.Caption='' then
showmessage('没有有效的库外温度信息!');
if FrmTempResult.LblDepotTempI.Caption='' then
showmessage('没有有效的库内温度信息!');
if FrmTempResult.LblPositionTempMin.Caption='' then
showmessage('没有有效货位温度信息!'); }
FrmTempResult.ShowModal;
end;
procedure Tfstockquery.BitBtn2Click(Sender: TObject);
begin
createreport;
// freereport;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -