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

📄 uqueryf.pas

📁 图书管理系统 用于进行图书的管理
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  ComboBox1.ItemIndex := 0;
  try
    Query := TQuery.Create(nil);
    Query.DatabaseName := DBName;
    Query.SQL.Add('select * from Class');
    Query.Open;
    while not Query.Eof do
    begin
      ComboBox2.Items.Add(Query.FieldByName('ClassName').AsString);
      ListBox1.Items.Add(Query.FieldByName('ClassID').AsString);
      Query.Next;
    end;
    ComboBox2.ItemIndex := -1;
    Query.Close;
    Query.Free;
  except
    ComboBox2.Items.Clear;
    ListBox1.Items.Clear;
  end;
  ComboBox2.MaxLength := UserIDLength;
  Edit2.MaxLength := UserIDLength;
  Edit3.MaxLength := UserIDLength;
end;

procedure TQueryF.LandView;
var
  Query : TQuery;
begin
  ListView3.Items.Clear;
  Query := TQuery.Create(nil);
  Query.DatabaseName := DBName;

  SetLandSQL(Query);
  try
    if RadioButton11.Checked and RadioButton8.Checked then
    begin
      Query.ParamByName('MaxDate').AsDateTime := Date-StrToInt(MinEdit.Text);
      Query.ParamByName('MinDate').AsDateTime := Date-StrToInt(MaxEdit.Text);
      if StrToInt(MinEdit.Text)>StrToInt(MaxEdit.Text) then
        Exit;
    end
    else SetLandParam(Query,Edit3.Text);
  except
    MessageDlg('设置参数错误',mtError,[mbok],0);
    Query.Free;
    Exit;
  end;
  Query.Open;

  while not Query.Eof do
  begin
    with ListView3.Items.Add do
    begin
      Caption := Query.FieldByName('UserID').AsString;
      SubItems.Add(Query.FieldByName('Name').AsString);
      if Query.FieldByName('Sex').AsString = '1' then
        SubItems.Add('女')
      else SubItems.Add('男');
      SubItems.Add(Query.FieldByName('Des').AsString);
      SubItems.Add(Query.FieldByName('Code').AsString);
      SubItems.Add(Query.FieldByName('LandDate').AsString);
      SubItems.Add(FloatToStr(Date-Query.FieldByName('LandDate').AsDateTime));
      SubItems.Add(Query.FieldByName('IDCard').AsString);
      if Date-Query.FieldByName('LandDate').AsDateTime >OutDay then
        SubItems.Add(FloatToStr((Date-Query.FieldByName('LandDate').AsDateTime-OutDay)*FineDay))
      else SubItems.Add('0')
    end;
    Query.Next;
  end;
  StaticText6.Caption:= '共'+IntToStr(Query.RecordCount)+'条记录';
  Query.Close;
  Query.Free;
end;

procedure TQueryF.SetLandParam(var Query: TQuery; Param: string);
begin
  if RadioButton7.Checked then
    if CheckBox3.Checked then
      Query.ParamByName('UserID').AsString := Param+'%'
    else Query.ParamByName('UserID').AsString := Param;
  if RadioButton8.Checked and RadioButton10.Checked then
    Query.ParamByName('LandDate').AsDateTime := Date-StrToInt(Param);
end;

procedure TQueryF.SetLandSQL(var Query: TQuery);
begin
  Query.SQL.Clear;
  if RadioButton7.Checked then
    Query.SQL.Add('select Owner.UserID,Name , Sex, IDCard, Des ,LandDate, Code from Owner,Userb,Groupb '+
                  ' where Owner.UserID like :UserID and Userb.UserID = Owner.UserID '+
                  ' and Userb.GroupID=Groupb.GroupID order by Owner.UserID');
  if RadioButton10.Checked and RadioButton8.Checked then
    case ComboBox1.ItemIndex of
      0 :  Query.SQL.Add('select Owner.UserID,Name , Sex, IDCard, Des ,LandDate, Code from Owner,Userb,Groupb '+
                  ' where Userb.UserID = Owner.UserID and Userb.GroupID=Groupb.GroupID'+
                  ' and Owner.LandDate < :LandDate order by Owner.UserID');
      1 :  Query.SQL.Add('select Owner.UserID,Name , Sex, IDCard, Des ,LandDate, Code from Owner,Userb,Groupb '+
                  ' where Userb.UserID = Owner.UserID and Userb.GroupID=Groupb.GroupID'+
                  ' and Owner.LandDate > :LandDate order by Owner.UserID');
      2 :  Query.SQL.Add('select Owner.UserID,Name , Sex, IDCard, Des ,LandDate, Code from Owner,Userb,Groupb '+
                  ' where Userb.UserID = Owner.UserID and Userb.GroupID=Groupb.GroupID'+
                  ' and Owner.LandDate = :LandDate order by Owner.UserID');
    end;
  if RadioButton11.Checked and RadioButton8.Checked then
    Query.SQL.Add('select Owner.UserID,Name , Sex, IDCard, Des ,LandDate, Code from Owner,Userb,Groupb '+
                  ' where Userb.UserID = Owner.UserID and Userb.GroupID=Groupb.GroupID'+
                  ' and Owner.LandDate < :MaxDate and Owner.LandDate > :MinDate order by Owner.UserID');
end;

procedure TQueryF.Button4Click(Sender: TObject);
begin
  try
    LandView;
  except
    MessageDlg('查询失败',mtError,[mbok],0);
  end;
end;

procedure TQueryF.RadioButton1Click(Sender: TObject);
begin
  ComboBox2.Style := csSimple;
  ComboBox2.Text := '';
  CheckBox1.Enabled := True;
  ComboBox2.MaxLength := UserIDLength;
end;

procedure TQueryF.RadioButton2Click(Sender: TObject);
begin
  ComboBox2.Style := csSimple;
  ComboBox2.Text := '';
  CheckBox1.Enabled := True;
  ComboBox2.MaxLength := 0;
end;

procedure TQueryF.RadioButton3Click(Sender: TObject);
begin
  ComboBox2.Style := csSimple;
  ComboBox2.Text := '';
  CheckBox1.Enabled := True;
  ComboBox2.MaxLength := 0;
end;

procedure TQueryF.RadioButton4Click(Sender: TObject);
begin
  ComboBox2.Style := csSimple;
  ComboBox2.Text := '';
  CheckBox1.Enabled := True;
  ComboBox2.MaxLength := 0;
end;

procedure TQueryF.RadioButton9Click(Sender: TObject);
begin
  ComboBox2.Style := csDropDownList;
  ComboBox2.ItemIndex := 0;
  CheckBox1.Enabled := False;
  ComboBox2.MaxLength := 0;
end;

procedure TQueryF.RadioButton5Click(Sender: TObject);
begin
  Edit2.MaxLength := UserIDLength;
end;

procedure TQueryF.RadioButton6Click(Sender: TObject);
begin
  Edit2.MaxLength := 0;
end;

procedure TQueryF.RadioButton10Click(Sender: TObject);
begin
  ComboBox1.Enabled := True;
  ComboBox1.Color := clWindow;
  CheckBox3.Enabled := False;
  Edit3.MaxLength := 0;
  Edit3.Visible :=True;
  Panel1.Visible := False;
end;

procedure TQueryF.RadioButton11Click(Sender: TObject);
begin
  ComboBox1.Enabled := False;
  ComboBox1.Color := clBtnFace;
  CheckBox3.Enabled := False;
  Panel1.Visible := True;
  Edit3.Visible := False;
end;

procedure TQueryF.ComboBox2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = 13 then
    Button2Click(Sender);
end;

procedure TQueryF.PrintLandUser(Printing : boolean);

  function FormatStr(s : string; StrLength :integer):string;
  var
    Temp : string;
    i : integer;
  begin
    Temp := '';
    try
      for i := 1 to StrLength do
        Temp := Temp +' ';
      for i:= 1 to Length(s) do
        Temp[(StrLength-Length(s))div 2 +i] := s[i];
      Result := Temp;
    except
      Result := s;
    end;
  end;



var
  PrintList : TStringList;
  i : integer;
  LinesCount : integer;
  PriUserID : string;
  f : TextFile;
begin
  if Printing = False then
    if (not SaveDialog1.Execute) then
      Exit;
  PrintList := TStringList.Create;
  LinesCount := 0;
  if ListView3.Items.Count >0 then
    PriUserID := ListView3.Items[0].Caption
  else PriUserID := '';
  i := 0;
  while i <= ListView3.Items.Count-1 do
  begin
    if LinesCount = 0 then
    begin
      PrintList.Add('   <'+ListView3.Items[i].Caption+':'+
                    ListView3.Items[i].SubItems.Strings[0]+
                    '>没归还图书清单');
      Inc(LinesCount);
      PrintList.Add('                     打印时间:'+DateToStr(Date));
      Inc(LinesCount);
      PrintList.Add('');
      Inc(LinesCount);
      PrintList.Add('  图书号  |  借出时间  | 持有时间/天 |  罚金/元  ');
      Inc(LinesCount);
      PrintList.Add('----------------------------------');
      Inc(LinesCount);
    end;
    if PriUserID = ListView3.Items[i].Caption then
    begin
      PrintList.Add(FormatStr(ListView3.Items[i].SubItems.Strings[3],14)+'|'+
                    FormatStr(ListView3.Items[i].SubItems.Strings[4],16)+'|'+
                    FormatStr(ListView3.Items[i].SubItems.Strings[5],16)+'|'+
                    FormatStr(ListView3.Items[i].SubItems.Strings[7],16));
      Inc(LinesCount);
      Inc(i);
      if LinesCount > PrintLinesCount then
        PrintList.Add(#12);
    end
    else begin
      PriUserID := ListView3.Items[i].Caption;
      PrintList.Add('');
      PrintList.Add('   <'+ListView3.Items[i].Caption+':'+
                    ListView3.Items[i].SubItems.Strings[0]+
                    '>没归还图书清单');
      Inc(LinesCount);
      PrintList.Add('                     打印时间:'+DateToStr(Date));
      Inc(LinesCount);
      PrintList.Add('');
      Inc(LinesCount);
      PrintList.Add('  图书号  |  借出时间  | 持有时间/天 |  罚金/元  ');
      Inc(LinesCount);
      PrintList.Add('----------------------------------');
      Inc(LinesCount);
      Inc(LinesCount);// := 0;
    end;
  end;
  if Printing = False then
  try
    PrintList.SaveToFile(SaveDialog1.FileName);
  except
    MessageDlg('不能创建打印文件'+SaveDialog1.FileName,
               mtError,[mbok],0);
  end;
  if Printing =True then
  begin
    AssignPrn(f);
    try
      Rewrite(f);
      for i := 0 to PrintList.Count-1 do
        Writeln(f,PrintList[i]);
      CloseFile(f);
    except
      MessageDlg('打印失败',mtError,[mbok],0);
      CloseFile(f);
    end;
  end;
  PrintList.Free;
end;

procedure TQueryF.ListView1DblClick(Sender: TObject);
begin
  ViewF := TViewF.Create('查询图书基本信息列表',ListView1,self);
end;

procedure TQueryF.ListView2DblClick(Sender: TObject);
begin
  ViewF := TViewF.Create('查询一般用户列表',ListView2,self);
end;

procedure TQueryF.ListView3DblClick(Sender: TObject);
begin
  ViewF := TViewF.Create('查询图书借阅者情况列表',ListView3,self);
end;

procedure TQueryF.Button8Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
    SaveListView(ListView1,'--- 图书基本信息列表 ---',SaveDialog1.FileName);
end;

procedure TQueryF.Button9Click(Sender: TObject);
begin
  PrintListView(ListView1,'--- 图书基本信息列表 ---');
end;

procedure TQueryF.Button7Click(Sender: TObject);
begin
  PrintLandUser(True);
end;

procedure TQueryF.Button5Click(Sender: TObject);
begin
  PrintLandUser(False);
end;

procedure TQueryF.Button10Click(Sender: TObject);
begin
  if SaveDialog1.Execute then
    SaveListView(ListView2,'--- 一般用户列表 ---',SaveDialog1.FileName);
end;

procedure TQueryF.Button6Click(Sender: TObject);
begin
  PrintListView(ListView2,'--- 一般用户列表 ---');
end;

end.

⌨️ 快捷键说明

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