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

📄 unitmb.pas

📁 飞恒进销存(超市批发)管理系统V5.1(含源程序) 语言:Delphi 6/7 相关控件:FastReport 2.4以上, Ehlib 3.4以上 1.数据库为fhe2db_V51.da
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    if queryDetail.active then queryDetail.close;
    querydetail.sql.clear;
    queryDetail.sql.add(mySql);
  end;

  //if (not dataE2.bTwoUnit) and ( dbGrid1.columns[3].FieldName='disc')  then
  //  dbGrid1.Columns[3].Visible :=false;
  //是否用双单位
  DBComboBoxEh1.ReadOnly:=(not dataE2.bTwoUnit);
  if (nTableId in [0,1,2,10,11,12]) then
    DBGrid1.Columns[3].ReadOnly:=(not DataE2.bTwoUnit);
  // >=30 不用加计算字段,只对现有字段进行初始化
  if nTableId < 30 then
    AddCalcField(dataE2.queryDetail, 'total','D')
  else
    AddCalcField(dataE2.queryDetail, 'total','*');
  stinprice.Visible:=(nTableId in [0,1,2,10,11,12]);
  stQty.Visible:=(nTableId in [0,1,2,10,11,12]);
end;

//1:empty 2:have record 3:after click new or edit
procedure TmbForm.SetCommandStatus(nStatus:integer);
var
  bType:boolean;
begin
  bType:= nStatus<3;

  cmdAdd.Enabled :=bType;
  cmdDel.Enabled :=bType;
  cmdPrior.enabled:=bType;
  cmdNext.Enabled :=bType;
  cmdSearch.Enabled :=bType;
  cmdPrint.enabled:=bType;

  cmdSave.Enabled := not bType;
  cmdUndo.enabled := not bType;
  cmdDelLine.Enabled :=not bType;

  dbGrid1.ReadOnly := bType;

  cmdEdit.enabled:=(nStatus=2);
end;

procedure TmbForm.DBGrid1ColExit(Sender: TObject);
var
  seekvalue,sSqlTmp:string;
begin
  //2005-05-23
  if dbGrid1.selectedindex = 3 then
  begin
    DBComboBoxEh1.Items.Clear;
    DBComboBoxEh1.Visible := false;
  end;

  with DataE2 do
  if (dbGrid1.selectedindex = 0) and (dbGrid1.columns[0].FieldName='code')  then
  begin
    seekvalue:=queryDetail.fieldbyname('code').asstring;
    if ( seekvalue<>sOldCode ) and ( sCodeBuff<>'' ) then
    begin
      if length(seekvalue)>=10 then
        sSqlTmp:='select * from Goods where barcode= :code'
      else
        sSqlTmp:='select * from Goods where code= :code';
      if OpenTable(sSqlTmp,seekvalue) then
      begin
         sSchCode:=seekvalue;
         sSchUnits:=adoQuery1.fieldbyname('units').asstring;
         sSchUnit2:=adoQuery1.fieldbyname('unit2').asstring;
         nSchPerQty:=adoQuery1.fieldbyname('perqty').ascurrency;

         queryDetail.Edit;
         queryDetail.fieldbyname('goodsId').value:=adoQuery1.fieldbyname('goodsid').asinteger;
         queryDetail.fieldbyname('qty').value:=1;
         queryDetail.fieldbyname('name').value:=adoQuery1.fieldbyname('name').asstring;
         queryDetail.fieldbyname('perqty').value:=adoQuery1.fieldbyname('perqty').ascurrency;
         queryDetail.fieldbyname('units').value:=adoQuery1.fieldbyname('units').asstring;
         queryDetail.fieldbyname('disc').AsBoolean:=false;    //0是件,1是支
         if bOutUnit2 and (nTableId=11) then  //出仓零数价优先
         begin
           queryDetail.fieldbyname('units').value:=sSchunit2;
           queryDetail.fieldbyname('disc').AsBoolean:=True;
         end;
         if (nTableId in [0,1,2,10,11,12]) then
         begin
           nInprice:=adoQuery1.fieldbyname('inprice').ascurrency;
           nInprice2:=adoQuery1.fieldbyname('inprice2').ascurrency;
           GetStock(false);
           if bOutUnit2 then
             stInprice.Caption:=FloatToStr(nInprice2)+'/'+sSchUnit2+
               ' '+FloatToStr(adoQuery1.fieldbyname('speprice2').ascurrency)+'/'+sSchUnit2
           else
             stInprice.Caption:=FloatToStr(nInprice)+'/'+sSchUnits+
               ' '+FloatToStr(adoQuery1.fieldbyname('SpePrice').ascurrency)+'/'+sSchUnits;
           stQty.Caption:=FloatToStr(rQty)+sSchUnits+' '+FloatToStr(rQty1)+sSchUnit2;
         end;
         case nTableId of
           0,1,2,21,24,25,26,27: begin
             queryDetail.fieldbyname('price').value:=adoQuery1.fieldbyname('inprice').ascurrency;
             nSchPrice:=adoQuery1.fieldbyname('inprice').ascurrency;
             nSchPrice2:=adoQuery1.fieldbyname('inprice2').ascurrency;
           end;
           10,11,12,18: begin
             queryDetail.fieldbyname('price').value:=GetLastSalePrice(nCusId,adoQuery1.fieldbyname('goodsid').asinteger,queryDetail.fieldbyname('disc').AsBoolean);
             //2005-06-24 默认为批发价
             //if bBatchSale then //批发
             begin
               nSchPrice:=adoQuery1.fieldbyname('SpePrice').ascurrency;  //件
               nSchPrice2:=adoQuery1.fieldbyname('speprice2').ascurrency; //支
               //queryDetail.fieldbyname('price').value:=nSchPrice;
             //end else begin
             //  nSchPrice:=adoQuery1.fieldbyname('Saleprice').ascurrency;
             //  nSchPrice2:=adoQuery1.fieldbyname('saleprice2').ascurrency;
             end;
           end;
         end;
         //出仓时,计入成本价
         if ( nTableId=11 ) or ( nTableid= 12 ) or (nTableid=18) then
         begin
           nCost1:=adoQuery1.fieldbyname('inprice').ascurrency;
           nCost2:=adoQuery1.fieldbyname('inprice2').ascurrency;
           queryDetail.fieldbyname('cost').value:=nCost1;
           if bOutUnit2 and ( (nTableId=11) or (nTableid=18)) then  //出仓零数价优先
             queryDetail.fieldbyname('cost').value:=nCost2;
         end;
      end;
      adoQuery1.close;
    end; //<>soldcode
  end else if dbGrid1.columns[dbGrid1.selectedindex].FieldName='PRICE' then
  begin
    //出仓及退货时,计入成本价
    if ( nTableId=11 ) or ( nTableid= 12 ) or (nTableid=18) then
       if bZeroProfit and (abs(queryDetail.fieldbyname('price').value) < 0.001) then //出仓价为0不计利润成本
          queryDetail.fieldbyname('cost').value:=0
  end;
  if (dbGrid1.selectedindex = 4) and (dbGrid1.columns[4].FieldName='QTY') then
    if nTableId in [10,11,12] then
      GetStock(true);
  sCodeBuff:='';
end;

procedure TmbForm.cmdPriorClick(Sender: TObject);
begin
  ShowMasterInfo(true);
end;

procedure TmbForm.cmdNextClick(Sender: TObject);
begin
  ShowMasterInfo(false);
end;

procedure TmbForm.ShowMasterInfo(bPrior:boolean);
begin
  setCommandStatus(2);
  if bPrior and not cmdNext.enabled then
  begin
    cmdNext.Enabled:=true;
    cmdnext.ImageIndex:=12;
  end;

  with DataE2 do
  if GetPriorNext(bPrior,myTable,nBillId) then  //have a record
  begin
    nBillId:=adoquery1.fieldbyname('billId').asinteger;
    edtBillDate.date :=adoQuery1.fieldbyname('billdate').asdatetime;
    edtInvoNo.text :=adoQuery1.fieldbyname('InvoNo').asstring;

    ShowMasterSpecial(false);

    //open detail
    if queryDetail.active then queryDetail.close;
    queryDetail.parameters[0].value:=nBillId;
    queryDetail.open;
  end;

end;

//显示当前主表的特定内容
procedure TmbForm.ShowMasterSpecial(bAdd:boolean);
begin
// for override use;
end;


procedure TmbForm.cmdExitClick(Sender: TObject);
var
  sErrInfo:string;
begin
{  if cmdSave.enabled then
    if DataE2.queryDetail.RecordCount >0 then
    begin
      if application.messagebox(pchar('放弃保存录入的信息 ?  '),'确认',MB_OKCANCEL+MB_ICONQUESTION+MB_DEFBUTTON2)=IDOK then
        close
    end else close
  else}
    close;
end;

procedure TmbForm.cmdEditClick(Sender: TObject);
begin
  bNew:=false;
  sDelItemNo:=',';

  nOldStoreId:=nStoreId;
  nOldOutStoreId:=nOutStoreId;
  nOldEmployId:=nEmployId;
  sOldMasterMemo:=sMasterMemo;
  nOldCusid:=nCusId;  

  SetCommandStatus(3);
  DataE2.queryDetail.Edit;

  //
  with dataE2 do
  if queryDetail.Eof then
    nId:=1
  else  begin
    querydetail.Last;
    nId:=querydetail.fieldbyname('itemno').asinteger+1
  end;
end;

procedure TmbForm.cmdDelLineClick(Sender: TObject);
var
  iRow:Integer;
begin
  with DataE2.queryDetail do
  begin
    if not bNew then
      sDelItemno:=sDelItemNo+fieldbyname('itemno').asstring+',';

    iRow:=RecordCount;
    if iRow>0 then
      Delete;

    //刷新会造成删除显示不正确
    //Refresh;
  end;
end;

procedure TmbForm.cmdAddClick(Sender: TObject);
begin
  bNew:=true;
  sDelItemNo:=',';
  edtBillDate.Date :=date;
  oIsChecked:=false;

  InitInfo;
  SetCommandStatus(3);

  with DataE2 do
  begin
    nBillId:=GetBillId(myTable);
    if queryDetail.active then queryDetail.close;
    queryDetail.parameters[0].value:=nBillId;
    queryDetail.open;

    nId:=1;
    edtInvono.Text:=GetInvono(mytable,'SEE');
  end;

  ShowMasterSpecial(true);
end;

procedure TmbForm.UpdateBatchDetail(sStatus:TRecordStatusSet);
begin
  if nTableId mod 10 <>3 then
  with dataE2 do
  begin
    nGoodsid:=queryDetail.fieldbyname('goodsid').asinteger;
    nQty:=queryDetail.fieldbyname('qty').AsFloat;
    bDisc:=queryDetail.fieldbyname('Disc').asBoolean;
  end;

  if rsNew in sStatus then
  begin
    InsertDetail;
    //插入或修改 reference table for example: orderD,InstoreD ,onhand
    UpdateRefTbl;
    //订单表,收付款表不改库存
    if (nTableId mod 10 =0) or (nTableId mod 10 =3)  then exit else  UpdateOnhand(bDisc);
    //for I_Instore use only
    //if (nTableId = 1) then  UpdateGoodsInprice;
  end
  else  if ( rsModified in sStatus ) or ( nOldStoreId<>nStoreId ) or ( nOldOutStoreId<>nOutStoreId ) then
  begin
    if ( rsModified in sStatus ) or ( nOldOutStoreId<>nOutStoreId )then
      UpdateRefTblBack(1);

    //库存按出入仓方向先减
    if (nTableId mod 10 <>0) and (nTableId mod 10 <>3) then
      if nTableId=24 then
        updateOnHandBack(1,nOldOutStoreId,1)
      else
        updateOnHandBack(1,nOldStoreId,1);

    //for move onlye
    if nTableId =22 then updateOnHandBack(1,nOldOutStoreId,0);

    if ( rsModified in sStatus ) or ( nOldOutStoreId<>nOutStoreId ) then
      UpdateRefTbl;

    //订单表不改库存
    if (nTableId mod 10 <>0) and  (nTableId mod 10 <>3) then  UpdateOnhand(bDisc);

    UpdateDetail;
  end;
  //for I_Instore use only
  if (nTableId = 1) then  UpdateGoodsInprice; //2005-12-22修改进仓单不会更新进价
end;

procedure TmbForm.cmdSaveClick(Sender: TObject);
var
  sStatus:TRecordStatusset;
  sInvono,sSql:string;
begin
  if dataE2.bBakAccSet or (dataE2.hotelspe<1) or (DataE2.installdate < now) then
  begin
    application.messagebox(pchar('备份帐或演示帐不可以保存数据...  '),'提示',MB_OK);
    cmdUndoClick(sender);
    exit;
  end;
  edtMemo.SetFocus;

  if (edtName.Text='') and (edtName.Visible) then
    nCusId:=-1;
  if (nCusId< 0 )  then
  begin
    application.MessageBox('请选择供应商或客户  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  if (nStoreId< 0 )  then
  begin
    application.MessageBox('请选择仓库    ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  if (nEmployId< 0 )  then
  begin
    application.MessageBox('请选择业务员  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  SetCommandStatus(2);

  with  DataE2  do
  begin
   adoConstore.BeginTrans ;
   try
     queryDetail.DisableControls;
     queryDetail.First;
     while not queryDetail.eof do
     begin
       //如果编码有错就跳到下一行
       if (nTableId in [0,1,2,10,11,12]) then
       begin
         if (queryDetail.fieldbyname('Name').asstring<>'')
           and (queryDetail.fieldbyname('Units').asstring<>'') then
         begin
           sStatus:=queryDetail.RecordStatus;
           UpdateBatchDetail(sStatus);
           queryDetail.Next; end
         else queryDetail.Next;

⌨️ 快捷键说明

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