fout.pas.~291~

来自「delphi2007开发的汽车配件进销存系统.实用级的源码.」· ~291~ 代码 · 共 648 行 · 第 1/2 页

~291~
648
字号
  procedure delrec;
  var
    s:string;
  begin
    s:=dm.qry5.FieldByName('xsdh').Value;
    with DM.connqry do begin
       Close;
       with sql do begin
         Clear;
         Add('delete xsd where xsdh=:p_xsdh');
       end;
       Parameters.ParamByName('p_xsdh').Value:=s;
       dm.qry5.Close;
       ExecSQL;
       DM.qry5.Open;
     end; 
  end;
begin
  if dm.qry5.RecordCount>0 then  begin
    if dm.qry8.RecordCount<=0 then begin
     if Application.MessageBox('你确定要删除这条信息吗?', '提示信息',
        MB_OKCANCEL+MB_ICONQUESTION) = IDOK then
        delrec;
     end
     else begin
       //有清单的记录
       if Application.MessageBox('这条记录是有清单记录的,如果删除将不能再与清'
          +'单关联,确认删除吗?', '提示信息', MB_OKCANCEL
          +MB_ICONQUESTION) = IDOK then
          delrec;
     end
  end
  else
    ShowMessage('请不要和我开玩笑,表中已无记录可删除了!');
end;

procedure Tfrmout.cxButton7Click(Sender: TObject);
begin
  frmkhgl.ShowModal;
end;

procedure Tfrmout.cxButton8Click(Sender: TObject);
begin
  if (dm.qry8.State= dsEdit) or (dm.qry8.State = dsInsert) then
     dm.qry8.Post;

  //DBGridEh1.ReadOnly:=true;

  cxbutton8.Enabled:=false;
  cxbutton2.Enabled:=false;
  cxbutton4.Enabled:=true;
end;

procedure Tfrmout.cxTextEdit1Click(Sender: TObject);
begin
  cxTextEdit1.clear;
end;

{------------------------------------
    查询符合条件的记录
------------------------------------}
procedure Tfrmout.cxTextEdit1KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  with dm.qry3 do begin
    active:=false;
    with sql do begin
      Clear;
      add('select spxx.*,kcxx.sl as kcsl from spxx ,kcxx where spxx.bm=kcxx.bm'
          +' and (spxx.bm like :pbm or spxx.pm like :ppm or spxx.gg like :pgg)');
    end;
    Parameters.ParamByName('pbm').value:='%'+ cxTextEdit1.Text+'%';
    Parameters.ParamByName('ppm').value:='%'+ cxTextEdit1.Text+'%';
    Parameters.ParamByName('pgg').value:='%'+ cxTextEdit1.Text+'%';
    Active:=true;
  end;
end;

procedure Tfrmout.cxTextEdit2Click(Sender: TObject);
begin
  cxTextEdit2.Clear;
end;

procedure Tfrmout.cxTextEdit2KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  with dm.qry5 do begin
    active:=false;
    with sql do begin
      Clear;
      Add('select a.*,b.dwmc,b.ch from xsd a,dwgl b where a.dwbm=b.dwbm ');
      add(' and (a.xsdh like :p_xsdh or b.ch like :p_ch or b.dwmc like :p_dwmc)');
      Add(' order by a.xsdh desc');
    end;
    Parameters.ParamByName('p_xsdh').value:='%'+ cxTextEdit2.Text+'%';
    Parameters.ParamByName('p_ch').value:='%'+ cxTextEdit2.Text+'%';
    Parameters.ParamByName('p_dwmc').value:='%'+ cxTextEdit2.Text+'%';
    Active:=true;
  end;
end;

procedure Tfrmout.DBGridEh1CellClick(Column: TColumnEh);
begin
  if DM.qry8.RecordCount>0 then
     cxButton4.Enabled:=True
  else
     cxButton4.Enabled:=False;  
end;

procedure Tfrmout.DBGridEh1ColExit(Sender: TObject);
begin
//计算表中的数据je=sl*dj
  dm.qry8.edit;
  if (dm.qry8.fieldbyname('sl').AsFloat > 0)  and
     (dm.qry8.fieldbyname('dj').asfloat > 0) then begin
       dm.qry8.fieldbyname('je').Value:= dm.qry8.fieldbyname('sl').AsFloat *
       dm.qry8.fieldbyname('dj').asfloat
     end;
end;

procedure Tfrmout.DBGridEh1Columns2UpdateData(Sender: TObject; var Text: string;
  var Value: Variant; var UseText, Handled: Boolean);
begin
  //showmessage('a');
end;

procedure Tfrmout.DBGridEh1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumnEh; State: TGridDrawState);
begin
  if Column.Index = 0 then
    if DBGridEh1.SumList.RecNo <> -1 then
      DBGridEh1.Canvas.TextRect(Rect, Rect.Left + 3, Rect.Top + 2,
        IntToStr(DBGridEh1.SumList.RecNo));

  //showmessage('a');
end;

procedure Tfrmout.DBGridEh1DrawDataCell(Sender: TObject; const Rect: TRect;
  Field: TField; State: TGridDrawState);
begin
//  if (gdFocused in State) then
//    if (Field.FieldName = cxDBLookupComboBox2.DataBinding.DataField ) then
//    begin
//      cxDBLookupComboBox2.Left := Rect.Left + dbgrideh1.Left;
//      cxDBLookupComboBox2.Top :=Rect.Top+dbgrideh1.top;
//      cxDBLookupComboBox2.Width := Rect.Right - Rect.Left;
//      cxDBLookupComboBox2.Height := Rect.Bottom - Rect.Top;
//      cxDBLookupComboBox2.Visible := True;
//    end;
end;

procedure Tfrmout.DBGridEh1Exit(Sender: TObject);
begin
  cxbutton4.Enabled:=false;
end;

procedure Tfrmout.DBGridEh1KeyPress(Sender: TObject; var Key: Char);
begin
  //以回车代TAB键
  if  key = #13 then
  begin
    keybd_event(vk_tab,0,0,0);
    keybd_event(vk_tab,0,keyeventf_keyup,0);
  end;
end;

procedure Tfrmout.DBGridEh2DblClick(Sender: TObject);
begin
  frmoutadd.ShowModal;
end;

procedure Tfrmout.RefreshTable;
begin
    //测试过程中出现非常诡异的事情,当以":参数"的形式出递的暑假
    //总是无法出递成功,总是提示没有定义@P1
    //取销售单的明细
  try
    with dm.qry8 do begin
      close;
      with sql do begin
        clear;
        add('select * from ');
        add(trim(dm.qry5.FieldByName('xsdh').value));
      end;
      open;
      cxlabel3.Caption := trim(dm.qry5.FieldByName('xsdh').value);
    end;

    if trim(dm.qry5.FieldByName('jzbz').value)='Y' then
      cxButton5.Enabled := false
    else
      cxButton5.Enabled := true;  

    //取客户信息
    with dm.qry7 do begin
      close;
      with sql do begin
        clear;
        add('select * from dwgl where dwbm=:p_dwbm');
      end;
      Parameters.ParamByName('p_dwbm').Value :=trim(dm.qry5.FieldByName('dwbm').value);
      open;
    end;
  except
    
  end;
end;

procedure Tfrmout.DBGridEh3CellClick(Column: TColumnEh);
begin
  cxbutton6.Enabled :=true;
  RefreshTable;
end;

procedure Tfrmout.DBGridEh3Enter(Sender: TObject);
begin
  RefreshTable;
end;

procedure Tfrmout.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if Application.MessageBox('退出本页?', '提示信息', MB_OKCANCEL +
    MB_ICONQUESTION) = IDOK then
  begin
    Action:=caHide;
  end;
end;

procedure Tfrmout.FormCreate(Sender: TObject);
begin
  //初始化表表
  DBGridEh1.Columns[0].Title.caption:='序号';
  DBGridEh1.Columns[1].Title.caption:='销售代码';
  DBGridEh1.Columns[2].Title.caption:='编码';
  DBGridEh1.Columns[3].Title.caption:='品名';
  DBGridEh1.Columns[4].Title.caption:='规格';
  DBGridEh1.Columns[5].Title.caption:='产地';
  DBGridEh1.Columns[6].Title.caption:='数量';
  DBGridEh1.Columns[7].Title.caption:='进价';
  DBGridEh1.Columns[8].Title.caption:='单价';
  DBGridEh1.Columns[9].Title.caption:='金额';

  DBGridEh2.Columns[0].Title.caption:='货位';
  DBGridEh2.Columns[1].Title.caption:='编码';
  DBGridEh2.Columns[2].Title.caption:='品名';
  DBGridEh2.Columns[3].Title.caption:='规格';
  DBGridEh2.Columns[4].Title.caption:='产地';
  DBGridEh2.Columns[5].Title.caption:='单位';
  DBGridEh2.Columns[6].Title.caption:='进价';
  DBGridEh2.Columns[7].Title.caption:='单价';
  DBGridEh2.Columns[8].Title.caption:='库存数量';

  DBGridEh3.Columns[0].Width:=80;

  //按钮状态
  cxbutton6.Enabled :=false;
  cxbutton8.Enabled:=false;
  cxbutton4.Enabled:=false;//打印

  with dm.qry8 do begin
    Close;
    with sql do begin
      Clear;
      add('select * from TMP_xsdmx ');
    end;
    Active:=true;

    //if DM.qry8.RecordCount<=0 then begin
      //取销售单号
      s_xsdh:=FormatDateTime('"XS"YYMMDDHHMMss',now);
      cxLabel3.Caption:= s_xsdh;
    //end;

  end;
end;



end. 








{ 代码临时存放区

//  with dm.connqry do begin
//    close;
//    //先写单号到临时表
//    with sql do begin
//      clear;
//      add('update Tmp_xsdmx set xsdh=:P_s_xsdh');
//    end;
//    Parameters.ParamByName('p_s_xsdh').Value:=s_xsdh ;
//    ExecSQL;
    //将临时表写入到正式表
//    with sql do begin
//      clear;
//      add('insert into xsdmx(xsdh,bm,pm,gg,cd,sl,dj,je) ');
//      add('select xsdh,bm,pm,gg,cd,sl,dj,je from Tmp_xsdmx ');
//    end;
//    ExecSQL;
//  end;

  //先清空临时表,然后连接
//  with dm.qry8 do begin
//    Close;
//    with sql do begin
//      clear;
//      add('delete from TMP_xsdmx');
//    end;
//    ExecSQL;
//    with sql do begin
//      Clear;
//      add('select * from xsdmx where xsdh=:p_xsdh ');
//    end;
//    Parameters.ParamByName('p_xsdh').Value:=s_xsdh;
//    Active:=true;
//  end;
}

⌨️ 快捷键说明

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