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

📄 mainform.pas

📁 本图书管理系统一sql server为数据库开发平台
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  Randomize;
  result:='0000000000';
  repeat
    code:=codeclass+FormatDateTime('yyyymmdd',date)+'N'+inttostr(random(9999));
    with query do
    begin
      close;
      sql.Clear;
      sql.Add('select * from '+table+' where recordid=:rd');
      parameters.ParamByName('rd').Value:=code;
      open;
    end;
  until query.RecordCount<1;
  result:=code;
end;

procedure TMain.StaticText11Click(Sender: TObject);
begin
  if data.SellQuery.Active then
  begin
    dropselltemptable;
    resetEdit;
    edit1.Clear;
    label6.Caption:='0元';
  end;
end;

procedure TMain.resetEdit;
begin
//  edit1.Clear;
  edit4.Clear;
  edit3.Text:='10';
  edit5.Text:='0.0';
  edit6.Text:='1';
  edit7.Text:='0.0';
  memo1.Clear;
  edit1.SetFocus;
end;

procedure TMain.ApplicationEvents1ShortCut(var Msg: TWMKey;
  var Handled: Boolean);
begin
  if (msg.CharCode=13) and ((GetKeyState(VK_RCONTROL) and ($F0000000))<>0)then
  begin
    if (pagecontrol1.ActivePage=TabSheet1)then
      StaticText10Click(statictext10)
    else if (pagecontrol1.ActivePage=TabSheet2) then
      StaticText16Click(statictext16);
  end;
end;

procedure TMain.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  if (key=#13) and (trim(edit1.text)<>'') and (label3.Caption<>'')then
  begin
    with data.SellQuery do
    begin //with
      close;
      sql.Clear;
      sql.Add('update '+label3.Caption+' set sellcount=:sellcount,rebate=:rebate,pricesum=:PriceSum,Memo=:Memo ');
      sql.Add('  where Barcode=:barcode');
      parameters.ParamByName('Barcode').Value:=edit1.Text;
      parameters.ParamByName('sellcount').Value:=strtoint(edit6.Text);
      parameters.ParamByName('rebate').value:=strtofloat(edit3.Text);
      parameters.ParamByName('pricesum').value:=strtofloat(edit7.Text);
      parameters.ParamByName('Memo').value:=memo1.Text;
      execsql;
    end;    // with
    resetEdit;
    edit1.Clear;
    tableopen(data.SellQuery,label3.Caption);
  end;
end;

procedure TMain.StaticText10Click(Sender: TObject);
begin
  if data.SellQuery.Active then
  begin         //if active
    try
      with data.PublicQuery do
      begin                   //with publicquery
        sql.Add('insert into SellRecord (RecordID,Bookbarcode,BookName,sellCount,rebate,SellDate,PriceSum,worker,Memo)');
        sql.Add('select '+''''+label3.Caption+''''+',barcode,BookName,sellCount,rebate,getdate(),PriceSum,'+''''+main.userPurview.username+''''+',Memo from '+label3.Caption);
        execsql;
      end;              //with publicquery
      resetEdit;
      edit1.Clear;
      Label6.Caption:='0元';
      myshowmessage(#13+'购买结束,谢谢!!');
    finally
      dropselltemptable;
    end;
  end;   // if active
  data.SellQuery.Close;
  data.PublicQuery.Close;
  label3.Caption:='';
  edit1.SetFocus;
end;

procedure Tmain.dropselltemptable;
begin
  with data.SellQuery do
  begin
    Close;
    sql.Clear;
    sql.Add('drop table '+label3.Caption);
    execsql;
    close;
  end;
  label3.Caption:='';
end;

procedure Tmain.droplendtemptable;
begin
  with data.lendQuery do
  begin
    Close;
    sql.Clear;
    sql.Add('drop table '+label9.Caption);
    execsql;
    close;
  end;
  label9.Caption:='';
end;

procedure Tmain.dropbacktemptable;
begin
  with data.backQuery do
  begin
    Close;
    sql.Clear;
    sql.Add('drop table '+label7.Caption);
    execsql;
    close;
  end;
  label7.Caption:='';
end;

procedure TMain.Edit2KeyPress(Sender: TObject; var Key: Char);
var
  allownum:integer;
begin
//借阅
  if not (key in ['0'..'9',char(VK_Back),#13]) then
  key:=#0;
  if (key=#13) and (trim(edit2.Text)<>'')then
  begin
    with data.PublicQuery do
      begin //  with b
      close;
      sql.Clear;
      sql.Add('select * from lendcardkind,lendcardinfo where  Kindname=cardkind and cardid = :cardid');
      parameters.ParamByName('cardid').Value:=edit8.Text;
      open;
      allownum:=fieldbyname('allownum').AsInteger;
      close;
      sql.Clear;
      sql.Add('select * from lendrecord where lendcard=:lendcard and ynback=0');
      parameters.ParamByName('lendcard').Value:=edit8.Text;
      open;
      if recordcount >= allownum then
      begin
        myshowmessage('此卡借阅书籍已经达到规定数量!不能继续.');
        edit8.Clear;
        edit2.Clear;
        exit;
      end;
      close;
      sql.Clear;
      sql.Add('select * from booksave where barcode =:barcode');
      parameters.ParamByName('barcode').Value:=edit2.Text;
      open;
      if RecordCount<1 then
      begin
      myshowmessage('对不起!库存中没有此书!');
      edit2.Clear;
      edit2.SetFocus;
      exit;
      end;
      edit9.Text:=fieldbyname('bookname').AsString;
      edit10.Text:=floattostr(fieldbyname('price').AsFloat);
      if label9.Caption<>'' then
      begin           //ifnull
        close;
        sql.Clear;
        sql.Add('select * from '+label9.Caption);
        open;
        if recordcount >= allownum then
        begin
          myshowmessage('此卡借阅书籍已经达到规定数量!不能继续.');
          exit;
        end;
      end// if null
      else
      begin
        repeat       //create temp table
          label9.Caption:=codecreate(data.PublicQuery,'JY','LendRecord');
          close;
          sql.Clear;
          sql.Add('select * from sysobjects where name=:name');
          parameters.ParamByName('name').Value:=label9.Caption;
          open;
        until (recordcount<1);
        close;
        sql.Clear;
        sql.Add('create table '+label9.Caption);
        sql.Add(' ([Barcode] [varchar] (20),');
        sql.Add('[BookName] [varchar] (30),[LendCard] [varchar] (30),');
        sql.Add('[Memo] [varchar] (255))');
        execsql;  //create temp table
      end;    //else nuu
      close;           // insert lendtemp new book
      sql.Clear;
      sql.Add('insert into '+label9.Caption+' values(:barcode,:Bookname,:lendcard,:memo)');
      parameters.ParamByName('Barcode').Value:=edit2.Text;
      parameters.ParamByName('Bookname').Value:=edit9.Text;
      parameters.ParamByName('lendcard').value:=edit8.Text;
      parameters.ParamByName('memo').value:='无';
      execsql;             // inhert lendtemp
      end;  //with e
    tableopen(data.lendquery,label9.Caption);
    edit2.Clear;
    edit9.Clear;
    edit10.Clear;
    memo2.Clear;
  end;
end;

procedure TMain.DBGrid2CellClick(Column: TColumn);
begin
  if data.lendQuery.Active then
  begin
    with data.lendQuery do
    begin
      edit2.Text:=fieldbyname('Barcode').AsString;
      edit9.Text:=fieldbyname('Bookname').AsString;
      edit8.Text:=fieldbyname('lendcard').AsString;
      memo2.Text:=fieldbyname('memo').AsString;
    end;
  edit8.SetFocus;
  end;
end;

procedure TMain.Edit8KeyPress(Sender: TObject; var Key: Char);
begin
  if (key=#13) and (trim(edit8.Text)<>'')then
  begin
    with data.PublicQuery do
    begin
      close;
      sql.Clear;
      sql.Add('select * from lendcardinfo where cardid=:cardid');
      parameters.ParamByName('cardid').Value:=edit8.Text;
      open;
      if (recordcount<1)or (fieldbyname('usesing').asinteger=0) then
      begin
        myshowmessage('此卡不存在,或以停用!!');
        edit8.Clear;
        edit8.SetFocus;
        exit;
      end;
      edit2.SetFocus;
    end;
  end;
end;

procedure TMain.StaticText16Click(Sender: TObject);
begin
//  借阅
  if data.lendQuery.Active then
  begin         //if active
    try
      with data.PublicQuery do
      begin                   //with publicquery
        while not data.lendQuery.eof do
        begin                          // while b
          Close;
          sql.Clear;
          sql.Add('insert into lendRecord (RecordID,Bookbarcode,BookName,lendcard,lendDate,worker,ynback,Memo)');
          sql.Add('values(:RecordID,:Bookbarcode,:BookName,:lendcard,:lendDate,:worker,:ynback,:Memo)');
          parameters.ParamByName('recordID').Value:=label9.Caption;
          parameters.ParamByName('bookbarcode').Value:=data.lendQuery.fieldbyname('barcode').AsString;
          parameters.ParamByName('BookName').Value:=data.lendQuery.fieldbyname('bookname').AsString;
          parameters.ParamByName('lenddate').Value:=date;
          parameters.ParamByName('lendcard').Value:=data.lendQuery.fieldbyname('lendcard').AsString;
          parameters.ParamByName('ynback').Value:=0;
          parameters.ParamByName('worker').Value:=userPurview.username;
          parameters.ParamByName('Memo').Value:=data.lendQuery.fieldbyname('Memo').AsString;
          execsql;
          data.lendQuery.next;
        end;                            //while e
      end;              //with publicquery
      myshowmessage(#13+'借阅结束,谢谢!');
    Finally
      droplendtemptable;
    end;
  end;   // if active
  data.lendQuery.Close;
  data.PublicQuery.Close;
  label6.Caption:='';
  edit8.Clear;
  edit2.Clear;
  edit9.Clear;
  edit10.Clear;
  memo2.Clear;
end;

procedure TMain.StaticText15Click(Sender: TObject);
begin
  if data.lendQuery.Active then
  begin
    droplendtemptable;
    edit8.Clear;
    edit2.Clear;
    edit9.Clear;
    edit10.Clear;
    memo2.Clear;
    label6.Caption:='';
  end;
end;

procedure TMain.Edit14KeyPress(Sender: TObject; var Key: Char);
begin
  if (key=#13) and (trim(edit14.Text)<>'')then
  begin
    with data.PublicQuery do
    begin
      close;
      sql.Clear;
      sql.Add('select * from lendcardinfo where cardid=:cardid');
      parameters.ParamByName('cardid').Value:=edit14.Text;
      open;
      if recordcount<1 then
      begin
        myshowmessage('此卡不存在,或以注销!!');
        edit14.Clear;
        edit14.SetFocus;
        exit;
      end
      else
        edit13.SetFocus;
    end;
  end;
end;

function Tmain.Dateadd(Vardate:Tdatetime;varmonth:integer):Tdatetime;
begin
  result:=EncodeDate((strtoint(formatdatetime('yyyy',vardate))+(strtoint(formatdatetime('mm',vardate))+varmonth) div 13),((strtoint(formatdatetime('mm',vardate))+varmonth) div 13+(strtoint(formatdatetime('mm',vardate))+varmonth) mod 13),strtoint(formatdatetime('dd',vardate)))
end;

procedure TMain.Edit13KeyPress(Sender: TObject; var Key: Char);
  procedure clearedit;
  begin
    edit11.Clear;
    edit12.Clear;
    edit13.Clear;
    edit15.Clear;
    checkbox1.Checked:=false;
    memo3.Clear;
    Edit13.SetFocus;
  end;

var
 lenddate:TDatetime;
begin
//还阅
  if not (key in ['0'..'9',char(VK_Back),#13]) then
    key:=#0;
  if (key=#13) and (trim(edit13.Text)<>'')and (trim(edit14.Text)<>'')then
  begin        //# 13
    with data.PublicQuery do
    begin //  with b
      close;
      sql.Clear;
      sql.Add('select * from Lendrecord where bookbarcode =:barcode and lendcard=:lendcard and ynback=0');
      parameters.ParamByName('barcode').Value:=edit13.Text;
      parameters.ParamByName('lendcard').Value:=edit14.Text;
      open;
      if recordcount < 1 then
      begin     // if record  b
        myshowmessage('没有该书借阅记录!!');
        edit13.Clear;
        edit13.SetFocus;

⌨️ 快捷键说明

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