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

📄 ireturn.pas

📁 飞恒进销存(超市批发)管理系统V5.1(含源程序) 语言:Delphi 6/7 相关控件:FastReport 2.4以上, Ehlib 3.4以上 1.数据库为fhe2db_V51.da
💻 PAS
字号:
unit IReturn;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Unitmb, StdCtrls, Grids, DBGridEh, Buttons, ComCtrls, ExtCtrls,
  ToolWin, Menus, ImgList,adodb, FR_Ctrls,db, Mask, DBCtrls, dbcgrids,
  DBCtrlsEh;

type
  TIReturnForm = class(TmbForm)
    edtPaytype: TfrComboEdit;
    edtNo: TfrComboEdit;
    lblNo: TLabel;
    rgpPayStyle: TRadioGroup;
    procedure FormCreate(Sender: TObject);
    procedure edtPaytypeButtonClick(Sender: TObject);
    procedure edtNoButtonClick(Sender: TObject);
    procedure cmdSaveClick(Sender: TObject);
    procedure rgpPayStyleClick(Sender: TObject);
    procedure cmdEditClick(Sender: TObject);
    procedure DBGrid1DblClick(Sender: TObject);
  private
    { Private declarations }
    nBankId,nPayTypeid:integer;
    nOldBankId,nOldPayTypeid:integer;
    sOldChkNo:string;
    procedure InitInfo;override;
    procedure InsertDetail;override;
    procedure InsertMaster(sInvono:string);override;
    procedure UpdateMaster;override;
    procedure ShowMasterSpecial(bAdd:boolean);override;
  public
    { Public declarations }
  end;

var
  IReturnForm: TIReturnForm;

implementation

uses datamodule1, report2, selPaytype, SelectGoods;

{$R *.dfm}

procedure TIReturnForm.InitInfo;
begin
  inherited;
  nStoreId:=-1;
end;

procedure TIReturnForm.InsertDetail;
var
  sSql:string;
begin
  with dataE2 do
  begin
    if nTableid = 2 then
      sSql:='( :billid, :itemno, :goodsid, :units, :qty, :price,0, :disc, :xBillId, :xItemNo, :memo1)'
    else
      sSql:='( :billid, :itemno, :goodsid, :units, :qty, :price,0, :disc, :xBillId, :xItemNo, :memo1, :cost)';
    adoCmd.commandtext:='insert into '+myTable+'D values '+sSql;
    adoCmd.parameters[0].value:=nBillId;
    adoCmd.parameters[1].value:=queryDetail.fieldbyname('itemno').asinteger;
    adoCmd.parameters[2].value:=nGoodsId;
    adoCmd.parameters[3].value:=queryDetail.fieldbyname('units').asstring;
    adoCmd.parameters[4].value:=nQty;
    adoCmd.parameters[5].value:=queryDetail.fieldbyname('price').ascurrency;
    adoCmd.parameters[6].value:=queryDetail.fieldbyname('disc').asboolean;// asinteger;
    adoCmd.parameters[7].value:=queryDetail.fieldbyname('xBillId').asinteger;
    adoCmd.parameters[8].value:=queryDetail.fieldbyname('xItemNo').asinteger;
    adoCmd.parameters[9].value:=queryDetail.fieldbyname('memo1').asstring;
    if nTableid=12 then
      adoCmd.parameters[10].value:=queryDetail.fieldbyname('cost').asCurrency;
    adoCmd.execute;
  end;
end;

procedure TIReturnForm.InsertMaster(sInvoNo:string);
begin
  with dataE2 do
    InsertIReturn(nBillid,nCusid,nEmployid,nStoreid,nPayTypeid,nBankId,rgpPayStyle.itemindex,edtBillDate.date,edtInvoNo.text,'',edtmemo.text,myTable);
end;

procedure TIReturnForm.UpdateMaster;
var
  sSql:string;
  i:integer;
begin
  sMasterMemo:=trim(edtMemo.text);

  //dynamic sql sentence
  i:=0;
  with dataE2 do
  begin
    adoCmd.CommandText:='update '+mytable+' set ';

    if  nEmployId <> nOldEmployId then
    begin
      adoCmd.CommandText :=adoCmd.CommandText +' Employid= :employid ';
      adoCmd.Parameters[i].value:=nEmployId;
      inc(i);
    end;

    if  nCusId <> nOldCusId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      if nTableid < 10 then
        adoCmd.CommandText :=adoCmd.CommandText +' vendorId= :cusid '
      else
        adoCmd.CommandText :=adoCmd.CommandText +' ClientId= :cusid ';
      adoCmd.Parameters[i].value:=nCusId;
      inc(i);
    end;

    if  nOldStoreId <> nStoreid then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' Storeid= :stroeId ';
      adoCmd.Parameters[i].value:=nStoreId;
      inc(i);
    end;

    if  sMasterMemo <> sOldMasterMemo then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' Memo= :Memo ';
      adoCmd.Parameters[i].value:=sMastermemo;
      inc(i);
    end;

    if  nBankId <> nOldBankId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' BankId= :BankId ';
      adoCmd.Parameters[i].value:=nBankId;
      inc(i);
    end;

    if  nPayTypeId <> nOldPayTypeId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' PayTypeid= :Paytypeid ';
      adoCmd.Parameters[i].value:=nPaytypeId;
      inc(i);
    end;

    if  nOutStoreId <> nOldOutStoreId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' IsRCash= :IsRCash ';
      adoCmd.Parameters[i].value:= (nOutstoreId=1);
      inc(i);
    end;

    if i>0 then
    begin
      adoCmd.CommandText :=adoCmd.CommandText +' where BillId= :Billid ';
      adoCmd.parameters[i].value:=nBillid;
      adoCmd.Execute ;
    end;
  end; //dataE2
end;

procedure TIReturnForm.FormCreate(Sender: TObject);
begin
  inherited;
  if nTableid=12 then
  begin
    LblFormName.Caption :='销售退货单';
    caption:=lblFormName.caption;
    lblName.caption:='客  户';

    rgpPayStyle.Caption :='付款类型';
    lblOther.Caption:='付款方式';
    lblNo.Caption:='付款帐号';
  end;

end;

procedure TIReturnForm.ShowMasterSpecial(bAdd:boolean);
var
  s,sSql:string;
begin
  with DataE2 do
  if not bAdd then
  begin
    nStoreId:=adoquery1.fieldbyname('storeId').asinteger;
    nEmployId:=adoquery1.fieldbyname('EmployId').asinteger;
    nPayTypeid:=adoquery1.fieldbyname('PayTypeid').asinteger;
    nBankId:=adoquery1.fieldbyname('BankId').asinteger;
    sMasterMemo:=trim(adoquery1.fieldbyname('Memo').asstring);

    //用来保存是收付款类型:付现款 或  冲应收付款
    if adoquery1.fieldbyname('IsRCash').asBoolean then
      nOutStoreId:=1
    else nOutStoreId:=0;

    rgpPayStyle.ItemIndex :=nOutStoreId;
    
    if nTableid=2 then
    begin
      nCusId:=adoquery1.fieldbyname('VendorId').asinteger;
      sSql:= 'select * from vendor where vendorId= :vendorid'; end
    else begin
      nCusId:=adoquery1.fieldbyname('ClientId').asinteger;
      sSql:= 'select * from client where clientId= :clientd';
    end;

    s:='';
    if tblStore.Locate('storeid',nstoreId,[loPartialKey])
      then s:=tblStore.fieldbyname('name').asstring;
    edtStore.text:=s;

    s:='';
    if OpenTable('select * from employ where EmployId= :employid',nEmployid) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtEmp.text:=s;

    adoQuery1.close;

    s:='';
    if OpenTable(sSql,nCusid) then
      s:=adoquery1.fieldbyname('ShortName').asstring;
    edtName.text:=s;

    s:='';
    if OpenTable('select * from bank where bankId= :bankid',nBankid) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtNo.Text:=s;
    adoQuery1.close;

    s:='';
    if OpenTable('select * from Paytype where PaytypeId= :Paytypeid',nPaytypeId) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtPaytype.text:=s;
    adoQuery1.close;
  end
  else begin  //add emptye record,so clear last infomation
    //edtStore.Text:='';
    //edtEmp.Text:='';
    //edtPaytype.Text:='';
    //edtNo.text:='';

    s:='';
    nStoreId:=1;
    if tblStore.Locate('storeid',nstoreId,[loPartialKey])
      then s:=tblStore.fieldbyname('name').asstring;
    edtStore.text:=s;

    s:='';
    nEmployId:=1;
    if OpenTable('select * from employ where EmployId= :employid',nEmployid) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtEmp.text:=s;

    s:='';
    if rgpPayStyle.ItemIndex =1 then
      nBankid:=1;
    if OpenTable('select * from bank where bankId= :bankid',nBankid) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtNo.text:=s;

    s:='';
    if rgpPayStyle.ItemIndex =1 then
      npayTypeId:=1;
    if OpenTable('select * from Paytype where PaytypeId= :Paytypeid',nPaytypeId) then
      s:=adoquery1.fieldbyname('name').asstring;
    edtPaytype.text:=s;
    adoQuery1.close;
  end;
end;

procedure TIReturnForm.edtPaytypeButtonClick(Sender: TObject);
begin
  //inherited;
  if not cmdSave.Enabled then exit;

  dlgselPayType.Newsql:='select Paytypeid as id,name from paytype ';
  dlgSelpaytype.Top :=self.top+(sender as TComboBox).Top +81;//toolbar1.height+edtInstore.Height+20 ;
  dlgSelpaytype.Left :=self.Left+(sender as TComboBox).left+4 ;
  if dlgselPayType.showmodal=mrok then
  with dataE2 do
  begin
    (sender as TComboBox).Text :=dlgselPayType.xName;
    nPayTypeId:=dlgSelPaytype.xid;
  end;

end;

procedure TIReturnForm.edtNoButtonClick(Sender: TObject);
begin
  //inherited;
  if not cmdSave.Enabled then exit;
  dlgselPayType.Newsql:='select Bankid as id,name from bank ';
  dlgSelpaytype.Top :=self.top+(sender as TComboBox).Top +81;//toolbar1.height+edtInstore.Height+20 ;
  dlgSelpaytype.Left :=self.Left+(sender as TComboBox).left+4 ;
  if dlgselPayType.showmodal=mrok then
  with dataE2 do
  begin
    (sender as TComboBox).Text :=dlgselPayType.xName;
    nBankId:=dlgSelPaytype.xid;
  end;

end;

procedure TIReturnForm.cmdSaveClick(Sender: TObject);
begin
  if (nPayTypeId< 0 )  then
  begin
    application.MessageBox('请选择收付款类型  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  if (nBankId< 0 )  then
  begin
    application.MessageBox('请选择收付款帐户  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  nOutStoreId:=rgpPayStyle.itemindex;
  
  inherited;
end;

procedure TIReturnForm.rgpPayStyleClick(Sender: TObject);
var
  bVisible:boolean;
begin
  inherited;
  bVisible:= rgpPayStyle.ItemIndex =1;
  lblOther.visible:=bvisible;
  lblNo.Visible:=bVisible;
  edtPaytype.Visible :=bVisible;
  edtNo.Visible :=bVisible;

  if rgpPayStyle.ItemIndex =1 then
  begin
    nBankId:=-1;
    npayTypeId:=-1;
    //表示退现款
    nOutStoreId:=-1;end
  else begin
    nBankId:=100;
    npayTypeId:=100;
    nOutstoreId:=1;
  end;
end;

procedure TIReturnForm.cmdEditClick(Sender: TObject);
begin
  inherited;
  nOldBankId:=nBankId;
  nOldPaytypeId:=nPaytypeId;
end;

procedure TIReturnForm.DBGrid1DblClick(Sender: TObject);
begin
  inherited;
  if cmdSave.Enabled then
  begin
    if SelectGoodsForm.NewStatus='O' then
    if nCusid=-1 then
    begin
      Application.MessageBox('请选择客户!','提示',64);
      exit;
    end
    else SelectGoodsForm.NewCusId:=nCusId;
    if (dbGrid1.selectedindex = 0) and (dbGrid1.columns[0].FieldName='code')  then
      SelectGoodsForm.ShowModal;
  end;
end;

end.

⌨️ 快捷键说明

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