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

📄 fmbizmulu.pas

📁 小型库存管理,希望有帮助,小型库存管理,希望有帮助
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      end ;
  end ;
  cdsDetail.FieldByName('fItemBuyPrice').AsFloat:=0;
  cdsDetail.FieldByName('fItemSellPrice').AsFloat:=0;
  cdsDetail.FieldByName('fQty').Asinteger:=0;
end;

{金额计算}
procedure TFMBizMul.cdsDetailCalcFields(DataSet: TDataSet);
begin
  inherited;
  case aPriceType of
   0: cdsDetail.FieldByName('fAmt').AsFloat :=0;
   1: cdsDetail.FieldByName('fAmt').AsFloat :=cdsDetail.FieldByName('fBuyPrice').AsFloat * cdsDetail.FieldByName('fQty').AsFloat ;
   2: cdsDetail.FieldByName('fAmt').AsFloat :=cdsDetail.FieldByName('fSellPrice').AsFloat * cdsDetail.FieldByName('fQty').AsFloat ;
   3: begin
       cdsDetail.FieldByName('fAmt').AsFloat :=cdsDetail.FieldByName('fBuyPrice').AsFloat * cdsDetail.FieldByName('fQty').AsFloat ;
      end ;
  end ;
end;

{明细新增}
procedure TFMBizMul.nAddClick(Sender: TObject);
var
  bNew :boolean ;
begin
  if not cdsMain.Active then exit ;
  if cdsMain.FieldByName('fBillNo').AsString='' then exit ;
  if cdsMain.FieldByName('fState').AsInteger>1 then
   begin
     MessageBox(handle,'该单据已经不能再修改.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  if not (cdsMain.State in [dsInsert,dsEdit]) then exit ;
  if cdsDetail.RecordCount =0 then
       bNew :=true
   else
     if trim(cdsDetail.FieldByName('fProductName').AsString)='' then
         bNew :=false
      else
         bNew :=true ;
  if not bNew then exit ;
  if cdsDetail.State in [dsInsert,dsEdit] then cdsDetail.Post ;
  cdsDetail.Append  ;
  cdsDetailfProductNo.FocusControl ;
end;

{删除明细}
procedure TFMBizMul.nDelClick(Sender: TObject);
begin
  if not cdsMain.Active then exit ;
  if cdsMain.FieldByName('fBillNo').AsString='' then exit ;
  if cdsMain.FieldByName('fState').AsInteger>1 then
   begin
     MessageBox(handle,'该单据已经不能再修改.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  if not (cdsMain.State in [dsInsert,dsEdit]) then exit ;
  if cdsDetail.State in [dsInsert,dsEdit] then cdsDetail.Post ;
  if messagebox(handle,'确定删除此笔明细记录吗?','确认',MB_OKCANCEL+MB_ICONINFORMATION)<>IDOK then exit;
  cdsDetail.Delete  ;
end;

{头档新增}
procedure TFMBizMul.cdsMainNewRecord(DataSet: TDataSet);
begin
  inherited;
  cdsMain.FieldByName(aKeyField).AsString :=GetNextId(aMainTable,aKeyField);
  cdsMain.FieldByName(aBillNo).AsString :=GeneratID ;
  cdsMain.FieldByName('fState').Asinteger :=1;
  cdsMain.FieldByName('fCreUser').AsString :=aUserId;
  cdsMain.FieldByName('fAccDate').AsString :=FormatDateTime('YYYY'+DateSeparator+'MM'+DateSeparator+'DD',Date()) ;
  dbAccDate.Date :=Date();
end;

{审核}
procedure TFMBizMul.btnCheckClick(Sender: TObject);
var
  Save_Cursor:TCursor;
begin
  inherited;
  if not cdsMain.Active then exit ;
  if cdsMain.FieldByName('fBillNo').AsString='' then exit ;
  if cdsMain.State in [dsInsert,dsEdit] then exit ;
  if cdsMain.FieldByName('fState').AsInteger >1 then
   begin
     MessageBox(handle,'该单据已经不能再审核.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  if messagebox(handle,PChar('确定审核:'+cdsMain.FieldByName('fBillNo').AsString+'吗?注意审核后不能在修改.'),'确认',MB_OKCANCEL+MB_ICONINFORMATION)<>IDOK then exit;

  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crSQLWait;
   cdsMain.Edit ;
   cdsMain.FieldByName('fState').AsString :='3';
   cdsMain.Post ;

   CalStock(cdsMain.fieldByName(aKeyField).AsString);
  Screen.Cursor := Save_Cursor;
  MessageBox(handle,'审核完毕.','提示',MB_OK+MB_ICONINFORMATION);
end;

{作废}
procedure TFMBizMul.btnBlankClick(Sender: TObject);
begin
  inherited;
  if not cdsMain.Active then exit ;
  if cdsMain.FieldByName('fBillNo').AsString='' then exit ;
  if cdsMain.State in [dsInsert,dsEdit] then exit ;
  if cdsMain.FieldByName('fState').AsInteger >1 then
   begin
     MessageBox(handle,'该单据已经不能再作废.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  if messagebox(handle,PChar('确定作废:'+cdsMain.FieldByName('fBillNo').AsString+'吗?注意作废后不能在修改.'),'确认',MB_OKCANCEL+MB_ICONINFORMATION)<>IDOK then exit;
  cdsMain.Edit ;
  cdsMain.FieldByName('fState').AsString :='2';
  cdsMain.Post ;

  MessageBox(handle,'作废完毕.','提示',MB_OK+MB_ICONINFORMATION);
end;

{修改}
procedure TFMBizMul.btnModifyClick(Sender: TObject);
begin
  if cdsMain.FieldByName('fState').AsInteger >1 then
   begin
     MessageBox(handle,'该单据已经不能再修改.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  inherited;
  dbfBillNo.ReadOnly :=true ;
end;

{删除}
procedure TFMBizMul.btnDeleteClick(Sender: TObject);
var
  strBillId :string ;
begin
  strBillId :=cdsMain.FieldByName(aKeyField).AsString ;
  if cdsMain.FieldByName('fState').AsInteger >1 then
   begin
     MessageBox(handle,'该单据已经不能再删除.','提示',MB_OK+MB_ICONWARNING);
     exit ;
   end ;
  inherited;
  CheckDB(strBillId);

  if cdsMain.fieldByname(aKeyField).AsString<>'' then
   begin
     cdsDetail.Active :=false ;
     cdsDetail.CommandText :='select * from '+aDetailTable+ ' where '+aKeyField+'='+cdsMain.fieldByname(aKeyField).AsString;
     cdsDetail.Active :=true ;
   end ;
end;

procedure TFMBizMul.FormCreate(Sender: TObject);
begin
  PAddType :=1 ;  aNumType :=0;  aZeroStock :=0;
  inherited;
  cdsState.Active :=false ; cdsState.Active :=true ;
  cdsUser.Active :=false ; cdsUser.Active :=true ;
  cdsItem.Active :=false ; cdsItem.Active :=true ;
  PubPanel.Enabled :=false ;

  dbAccDate.Date :=Date();
end;

procedure TFMBizMul.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  cdsState.Active :=false ;
  cdsUser.Active :=false ;
  cdsItem.Active :=false ;
  inherited;
end;

{保存}
procedure TFMBizMul.btnSaveClick(Sender: TObject);
begin
  if not CheckHead then  abort ;
  if not CheckDetail then  abort ;
  cdsMain.FieldByName('fAccDate').AsString :=UFormatDate(DateToStr(dbAccDate.Date));
  inherited;
  btnCheck.Enabled :=true ;
  btnBlank.Enabled :=true ;
end;

{取消 判断是否是新增的取消,是要删除明细档的资料}
procedure TFMBizMul.btnCancleClick(Sender: TObject);
var
  strBillId :string ;
begin
  strBillId :=cdsMain.FieldByName(aKeyField).AsString ;
  inherited;
  CheckDB(strBillId);
  btnCheck.Enabled :=true ;
  btnBlank.Enabled :=true ;
end;

{产品明细}
procedure TFMBizMul.cdsDetailfProductNoSetText(Sender: TField;
  const Text: String);
begin
  inherited;
  if trim(Text)='' then exit ;
  if cdsItem.Locate('fProductNo',Text,[]) then
   begin
    cdsDetail.FieldByName('fProductId').AsString:=cdsItem.fieldbyname('fProductId').AsString;
    cdsDetail.FieldByName('fProductName').AsString:=cdsItem.fieldbyname('fProductName').AsString;
    cdsDetail.FieldByName('fSpec').AsString:=cdsItem.fieldbyname('fSpec').AsString;
    cdsDetail.FieldByName('fSaleUnit').AsString:=cdsItem.fieldbyname('fSaleUnit').AsString;
    cdsDetail.FieldByName('fQty').AsFloat:=cdsItem.fieldbyname('fStockDown').asfloat;
    cdsDetail.FieldByName('fItemBuyPrice').AsFloat:=cdsItem.fieldbyname('fBuyPrice').AsFloat;
    cdsDetail.FieldByName('fItemSellPrice').AsFloat:=cdsItem.fieldbyname('fSellPrice').AsFloat;
     case aPriceType of
     1:  cdsDetail.FieldByName('fBuyPrice').AsFloat:=cdsItem.fieldbyname('fBuyPrice').AsFloat;
     2:  cdsDetail.FieldByName('fSellPrice').AsFloat:=cdsItem.fieldbyname('fSellPrice').AsFloat;
     3: begin
          cdsDetail.FieldByName('fBuyPrice').AsFloat:=cdsItem.fieldbyname('fBuyPrice').AsFloat;
          cdsDetail.FieldByName('fSellPrice').AsFloat:=cdsItem.fieldbyname('fSellPrice').AsFloat;
        end ;
    end ;
   end
  else begin
   MessageBox(handle,'该产品没有对应的资料.','提示',MB_OK+MB_ICONWARNING);
  end;
end;

{弹出窗口选择产品}
procedure TFMBizMul.GridDetailfProductNoButtonClick(Sender: TObject;
  AbsoluteIndex: Integer);
begin
  inherited;
  if not (cdsMain.State in [dsInsert,dsEdit]) then exit ;
  if Application.FindComponent('FmSearch')=nil then
     FmSearch:=TFmSearch.create(self);
  FmSearch.Caption :='产品资料查询' ;
  FmSearch.UTableName :='ts_item';
  FMSearch.UFieldName :='fProductNo';
  FmSearch.USQL :='select * from ts_item where 1=1 ' ;

  if FmSearch.ShowModal=mrOK then
   begin
     if trim(FmSearch.UValue)<>'' then
      begin
        cdsDetail.FieldByName('fProductNo').AsString :=FmSearch.UValue ;
        cdsDetailfProductNoSetText(nil,FmSearch.UValue);
      end ;
   end;
end;

procedure TFMBizMul.btnAddClick(Sender: TObject);
begin
  inherited;
  dbfBillNo.ReadOnly :=true ;
end;

procedure TFMBizMul.GridDetailExit(Sender: TObject);
begin
  inherited;
  if cdsdetail.State in [dsInsert,dsEdit] then cdsDetail.Post ;
end;

procedure TFMBizMul.GridDetailKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  inherited;
  if not (cdsMain.State in [dsInsert,dsEdit]) then
   begin
     Key :=0;
     Shift :=[];
   end ;
end;

procedure TFMBizMul.GridDetailKeyPress(Sender: TObject; var Key: Char);
begin
  inherited;
  if not (cdsMain.State in [dsInsert,dsEdit]) then Key :=#0;
end;

procedure TFMBizMul.cdsDetailBeforePost(DataSet: TDataSet);
begin
  if not CheckDetail then  abort ;
  inherited;
end;

end.

⌨️ 快捷键说明

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