⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit2.pas

📁 program kehuji uses Forms, Unit1 in ..zxcUnit1.pas {Form1}, Unit2 in ..zxcUnit2.pas {Form2
💻 PAS
📖 第 1 页 / 共 3 页
字号:

  strtemp:='select sum(度数) as 大 from shui , info where 户号='''+combobox3.Text+''''+' and 楼栋='''+combobox2.Text+'''  and  采集时间 <= '''+time2+''''+' and 采集时间 >= all(select 采集时间  from shui  where 采集时间 <='''+time2+''')'+' and info.编号 = shui.户主编号';
 adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  statictext6.Caption:=inttostr(final-start)+'度';

  statictext7.Caption:='该用户总共耗水:';


  strtemp:='select sum(度数) as 小 from dian ,info where 户号='''+combobox3.Text+''''+' and 楼栋='''+combobox2.Text+''' and 采集时间 >= '''+time1+''''+' and 采集时间 <= all(select 采集时间  from dian  where 采集时间 >='''+time1+''')'+' and info.编号 = dian.户主编号';

  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  start:=strtoint(adoquery4.FieldByName('小').AsString);


  strtemp:='select sum(度数) as 大 from dian , info where 户号='''+combobox3.Text+''''+' and  楼栋='''+combobox2.Text+'''  and  采集时间 <= '''+time2+''''+' and 采集时间 >= all(select 采集时间  from dian  where 采集时间 <='''+time2+''')'+' and info.编号 = dian.户主编号';
 adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  statictext9.Caption:=inttostr(final-start)+'度';

  statictext8.Caption:='该用户总共耗电:';

strtemp:='select sum(度数) as 小 from mei ,info where 户号='''+combobox3.Text+''''+' and  楼栋='''+combobox2.Text+''' and 采集时间 >= '''+time1+''''+' and 采集时间 <= all(select 采集时间  from mei  where 采集时间 >='''+time1+''')'+' and info.编号 = mei.户主编号';

  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  start:=strtoint(adoquery4.FieldByName('小').AsString);


  strtemp:='select sum(度数) as 大 from mei , info where  户号='''+combobox3.Text+''''+' and 楼栋='''+combobox2.Text+'''  and  采集时间 <= '''+time2+''''+' and 采集时间 >= all(select 采集时间  from mei  where 采集时间 <='''+time2+''')'+' and info.编号 = mei.户主编号';
 adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  statictext11.Caption:=inttostr(final-start)+'度';

  statictext10.Caption:='该用户总共耗煤:';













  end;






end;











 // adoquery1.Filtered:=true;
//  adoquery2.Filtered:=true;
  //adoquery3.Filtered:=true;

  end;



 { if (checkbox1.Checked<>false)and(checkbox2.checked<>false)and(checkbox3.Checked<>false)and(checkbox4.Checked<>false)
  then
  begin
  if (checkbox1.Checked=true) and (checkbox4.Checked=true )
  then
  begin


  end;





  end;  }




{  if checkbox1.Checked=true and checkbox1.Checked =ture
  then
  begin
    adoquery1.Filter:='户主编号='''+combobox1.Text+''''+'and 采集时间 >='''+time1+''''+'and 采集时间 <='''+time2+'''';
//    adoquery1.Filtered:=true;
  end
  else
  begin
       if checkbox1.checked=true
       then
       begin
       adoquery1.Filter:='户主编号='''+combobox1.Text+'''';
       end
       else
       if


  end;







    adoquery1.Filter:='采集时间 >='''+time1+''''+'and 采集时间 <='''+time2+'''';
    if combobox2.Text<>''
    then
    begin
      adoquery1.Filter:=adoquery1.Filter+'and 楼栋='''+combobox2.Text+'''' ;
//      adotable1.Filtered:=true;
    end;
    if combobox3.Text<>''
    then
    begin
     adoquery1.Filter:=adoquery1.Filter+'and 户号='''+combobox3.Text+'''' ;
  //    table1.Filtered:=true;
    end;
  end;
  adoquery1.Filtered:=true;
{  if (DBEdit1.Text='')
  then
  begin
    showmessage('未找到相应的医务管理员');
  end;

 }


procedure TForm2.CheckBox1Click(Sender: TObject);
begin
if checkbox1.Checked=true
then
begin
checkbox2.Checked:=false;
checkbox3.Checked:=false;
checkbox2.Enabled:=false;
checkbox3.Enabled:=false;



end
else
begin
checkbox2.Enabled:=true;
checkbox3.Enabled:=true;

end;


end;

procedure TForm2.N1Click(Sender: TObject);
begin
unit3.Form3.Show;

end;

procedure TForm2.CheckBox5Click(Sender: TObject);
begin
if checkbox5.Checked=true
then
begin
checkbox4.Checked:=false;
checkbox4.Enabled:=false;
end
else
begin
checkbox4.Enabled:=true;
end;

end;

procedure TForm2.Timer1Timer(Sender: TObject);
var
time1:string;
time2:string;
temp1:string;
temp2:string;
temp3:string;
temp4:string;
nowtime:string;
timea:Tdatetime;
i:integer;
str:string;
str1:string;

strtemp:string;
start:integer;
final:integer;
total:integer;
count:integer;
tag:boolean;

begin

  tag:=false;
  strtemp:='select 编号 from info';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  count:=adoquery4.RecordCount;

  //timea:=strtodatetime('1990-01-03 0:00:00');

  timea:=date()-3;

  for i:=1 to  count
do
begin

  strtemp:='select min(度数) as 小 from shui where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
    adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  start:=strtoint(adoquery4.FieldByName('小').AsString);


  strtemp:='select max(度数) as 大 from shui where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  strtemp:='select 是否长住 from info where 编号='''+inttostr(i)+'''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  temp1:=adoquery4.FieldByName('是否长住').AsString;
  if (final-start<=0)and ( temp1='是')
  then
  begin
  temp2:='住户'+inttostr(i)+'水表警告';
  tag:=true;

  form4.Show;
  unit4.Form4.Memo1.Lines.Add(temp2);

  //showmessage( temp2);

  end;

  end;
    for i:=1 to  count
do
begin
  strtemp:='select min(度数) as 小 from dian where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
    adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  start:=strtoint(adoquery4.FieldByName('小').AsString);


  strtemp:='select max(度数) as 大 from dian where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  strtemp:='select 是否长住 from info where 编号='''+inttostr(i)+'''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  temp1:=adoquery4.FieldByName('是否长住').AsString;
  if (final-start<=0)and ( temp1='是')
  then
  begin
  temp2:='住户'+inttostr(i)+'电表警告';
  tag:=true;
  form4.Show;
   unit4.Form4.Memo1.Lines.Add(temp2);
 // showmessage( temp2);

  end;

  end;
    for i:=1 to  count
do
begin
  strtemp:='select min(度数) as 小 from mei where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
    adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  start:=strtoint(adoquery4.FieldByName('小').AsString);


  strtemp:='select max(度数) as 大 from mei where 采集时间 >= '''+datetimetostr(timea)+''''+' and 采集时间 <= '''+datetimetostr(date())+''''+'and 户主编号 ='''+inttostr(i)+'  ''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  final:=strtoint(adoquery4.FieldByName('大').AsString);

  strtemp:='select 是否长住 from info where 编号='''+inttostr(i)+'''';
  adoquery4.Close;
  adoquery4.SQL.Clear;
  adoquery4.SQL.Add(strtemp);
  adoquery4.ExecSQL;
  adoquery4.Open;
  adoquery4.First;
  temp1:=adoquery4.FieldByName('是否长住').AsString;
  if (final-start<=0)and ( temp1='是')
  then
  begin
  temp2:='住户'+inttostr(i)+'煤表警告';
  tag:=true;
  form4.Show;
   unit4.Form4.Memo1.Lines.Add(temp2);

  //showmessage( temp2);

  end;

end;


if tag=false
then
begin
showmessage('未发现异常');

end;


//timer1.Enabled:=false;
{total:=0;
adoquery1.Close;
adoquery1.Open;

adoquery1.FindFirst;
count:=adoquery1.RecordCount;

for i:=1 to count-1
do
begin
a:=adoquery1.FieldByName('度数').AsString;
total:=total+strtoint(a);
adoquery1.FindNext;
end;
a:=adoquery1.FieldByName('度数').AsString;
total:=total+strtoint(a);

statictext12.Caption:=inttostr(total);      }

end;

procedure TForm2.Button3Click(Sender: TObject);
begin
if jian =false
then
begin
timer1.Enabled:=true;
label1.Color:=clyellow;
jian:=true;
end
else if jian=true
then
begin
timer1.Enabled:=false;

label1.Color:=clwhite;
jian:=false;


end;






end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -