delphi查询日期数据


1在窗体显示的时候定义时间控件显示状态
DateTimePicker1.Date:=Date-30;
DateTimePicker2.Date:=Date
2.查询营业额
query1.close;
query1.sql.clear;
query1.sql.add('select*from月结算费用表 where 日期>:A and 日期<=:B');
query1.sql.add('order by 结帐编号 asc');
query1.ParamByName('A').AsDateTime:=DateTimePicker1.DateTime;
query1.ParamByName('B').AsDateTime:=DateTimePicker2.DateTime;
query1.open;
query2.close;
query2.sql.clear;
query2.sql.add('select sum(费用)from 月结算费用信息表 where 日期>=A and 日期<=:B');
query2.ParamByName('A').AsDateTime:=DateTimePicker1.DateTime;
query2.ParamByName('B').AsDateTime:=DateTimePicker2.DateTime;
query2.open;
lable1.caption:=Query2.Fields[0].AsString;
lable2.caption:=IntToStr(Query1.RecordCount);
Query2.close;

3.查询一天地
Query1.sql.add('select*from 入库where 日期=:A');
Query1.ParamByName('A').AsDateTime:=Date;

4.综合查询统计
var
  str_date, str_date1: string;
begin
  if chk_rkrq.Checked then
  begin
    DateTimeToString(str_date, 'yyyymmdd', dtp_ksrq.date);
    DateTimeToString(str_date1, 'yyyymmdd', dtp_jsrq.date);
    dy_ksrq := Copy(Trim(str_date), 1, 4) + '年' + Copy(Trim(str_date), 5, 2) +
      '月' + Copy(Trim(str_date), 7, 2) + '日';
    dy_jsrq := Copy(Trim(str_date1), 1, 4) + '年' + Copy(Trim(str_date1), 5, 2) +
      '月' + Copy(Trim(str_date1), 7, 2) + '日';
    with qry_jhxx do
    begin
      close;
      sql.Clear;
      sql.Add('select a.jhdh,a.ghsmc,a.hwzje,b.czyxm from j_jhzdxxb a,j_xtczyb b where a.czydm=b.czyid and a.jhdh like ''%' + trim(edt_jhdh.Text) + '%''');
      sql.Add(' and a.ghsmc like ''%' + trim(cbb_ghsmc.Text) +
        '%'' and substring(jhdh,3,8) between ''' + str_date + ''' and ''' +
        str_date1 + '''');
      open;
    end;
  end
  else
    if chk_rkrq.Checked = False then
    begin
      with qry_jhxx do
      begin
        close;
        sql.Clear;
        sql.Add('select a.jhdh,a.ghsmc,a.hwzje,b.czyxm from j_jhzdxxb a,j_xtczyb b where a.czydm=b.czyid and a.jhdh like ''%' + trim(edt_jhdh.Text) + '%''');
        sql.Add(' and a.ghsmc like ''%' + trim(cbb_ghsmc.Text) + '%''');
        open;
      end;
    end;
  stat_jhcx.Panels[0].Text := '查询信息记录数:' + inttostr(qry_jhxx.RecordCount)
    + '条。';

5.有记录就查,没就算了
 if ds_xx.DataSet.State = dsinactive then
  begin
    exit;
  end;
  if ds_xx.DataSet.RecordCount = 0 then
  begin
    exit;
  end;
  jxxxw.showmodal;



6.表格中字段为0就别打了
 if trim(dbgrd_czy.Columns.Grid.Fields[0].AsString) <> '' then
  begin
    edt_bh.Text := Trim(dbgrd_czy.DataSource.DataSet.fieldvalues['czyid']);
    edt_xm.Text := Trim(dbgrd_czy.DataSource.DataSet.fieldvalues['czyxm']);
    edt_bh.Enabled := False;
    edt_xm.Enabled := false;
    edt_qrmm.Enabled := false;
  end;

7.
if length(edt_bh.text) <> 5 then
  begin
    Application.MessageBox('编号必须为5位整数,请重新输入!', '操作员编号', MB_OK
      + MB_ICONWarning);
    edt_bh.SetFocus;
    exit;
  end;
  if Trim(edt_xm.Text) = '' then
  begin
    Application.MessageBox('姓名不能为空,请重新输入!', '操作员姓名', MB_OK +
      MB_ICONWarning);
    edt_xm.SetFocus;
    exit;
  end;
  if Trim(edt_mm.Text) = '' then
  begin
    Application.MessageBox('密码不能为空,请重新输入!', '操作员密码', MB_OK +
      MB_ICONWarning);
    edt_mm.SetFocus;
    exit;
  end;
  if Trim(edt_mm.Text) <> Trim(edt_qrmm.Text) then
  begin
    Application.MessageBox('二次输入密码不同,请重新输入!', '操作员密码', MB_OK
      + MB_ICONWarning);
    edt_mm.SetFocus;
    exit;
  end;
  if edt_bh.Enabled = True then
  begin
    if MessageBox(0,
      PChar('确定信息输入无误吗?确定点击“是”,取消点击“否”!'),
      '确认新增信息', MB_ICONQUESTION or MB_YESNO) = IDNO then
      exit;
    with qry_czy do
    begin
      Close;
      sql.Clear;
      sql.Add('insert into j_xtczyb (czyid,czyxm,czymm,czyzt,czyqx,czsj,czydm)');
      sql.Add(' values(''' + trim(edt_bh.Text) + ''',''' + trim(edt_xm.Text) +
        '''');
      sql.Add(',''' + Encrypt(trim(edt_mm.Text), 66) +
        ''',''0'',''00000000000'',CURRENT_TIMESTAMP,''' + dlidz
        + ''')');
      //inputbox(sql.text,sql.Text,sql.text);
      ExecSQL;
    end;
    with jmainw.qry_xtrz do
    begin
      close;
      sql.clear;
      sql.add('insert into j_syslog values(''' + dlidz + ''',''' + dlxmz +
        ''',CURRENT_TIMESTAMP,''新增操作员'')');
      execsql;
    end;
    Application.MessageBox('新增操作员成功!', '新增', MB_OK +
      MB_ICONINFORMATION);
    jczyglw.FormActivate(nil);
    btn_clear.Click;
    exit;
  end
  else
    if edt_qrmm.Enabled = True then
    begin
      if (Trim(edt_mm.Text) <> '') and (Trim(edt_qrmm.text) <> '') then
      begin
        if MessageBox(0, PChar('确定修改  ' + trim(edt_xm.Text) +
          '  的密码吗?确定点击“是”,取消点击“否”!'), '确认密码信息',
          MB_ICONQUESTION or MB_YESNO) = IDNO then
          exit;
        with qry_czy do
        begin
          close;
          sql.Clear;
          sql.Add('update j_xtczyb set czymm=''' + Encrypt(trim(edt_mm.Text), 66)
            + '''');
          sql.Add(',czsj=CURRENT_TIMESTAMP,czydm=''' + dlidz +
            ''' where czyid=''' + trim(edt_bh.Text) + '''');
          ExecSQL;
        end;
      end;
      with jmainw.qry_xtrz do
      begin
        close;
        sql.clear;
        sql.add('insert into j_syslog values(''' + dlidz + ''',''' + dlxmz +
          ''',CURRENT_TIMESTAMP,''修改操作员密码'')');
        execsql;
      end;
      Application.MessageBox('修改操作员密码成功!', '修改密码', MB_OK +
        MB_ICONINFORMATION);
      jczyglw.FormActivate(nil);
      btn_clear.Click;
      exit;
    end;
end;

8.
  with qry_ylxx do
    begin
      Close;
      sql.Clear;
      sql.Add('update ylcf set name=''' + trim(edt_ylmc.Text) + ''',zjm=''' +
        trim(edt_zjm.Text) + '''');
      SQL.Add(',yylb_id=''' + trim(yllb_idz) + '''  where code=''' +
        trim(edt_ylbh.Text) + '''');
      ExecSQL;
    end;
  except
    Exit;
  end;

你可能感兴趣的:(Delphi)