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

📄 uselectpartedit.pas

📁 天涯進銷存系統
💻 PAS
字号:
unit uSelectPartEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, LBCtrls, LBDBCtrls, jpeg, ExtCtrls, LBMorphVCLBase,
  LBMorphButton;

type
  TfrmSelectPartEdit = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    QuantityEdit: TLBNumberEdit;
    PriceEdit: TLBNumberEdit;
    CessEdit: TLBNumberEdit;
    AgioEdit: TLBNumberEdit;
    Panel4: TPanel;
    Panel6: TPanel;
    Panel3: TPanel;
    Image2: TImage;
    SysCloseButton: TLBMorphButton;
    LBButton1: TLBButton;
    LBButton2: TLBButton;
    WindowCaption: TLabel;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure QuantityEditExit(Sender: TObject);
    procedure PriceEditExit(Sender: TObject);
    procedure AgioEditExit(Sender: TObject);
    procedure CessEditExit(Sender: TObject);
    procedure QuantityEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure CessEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    isSelect : Boolean;
  end;

var
  frmSelectPartEdit: TfrmSelectPartEdit;

implementation

uses uDataMo, uPublicvar, uConst, uSelectPart;

{$R *.dfm}

procedure TfrmSelectPartEdit.FormShow(Sender: TObject);
begin
  isSelect:=BillIsEdit;
  case SelectPartType of
  1,2,3: {2.为采购订货}
    PriceEdit.Value:=dmData.sdsSelectPart.FieldByName('StockPrice').asfloat;
  4,5: {销售单、销售订货单}
    begin
      PriceEdit.Value:=dmData.sdsSelectPart.FieldByName('SalePrice').asfloat;
      //如果已选择客户,则单价为该客户的最后销售单价
      if OpposingCode<>'' then
      begin
        OpenData('select price from Partsoutputbody '+
                 'where billcode=(select max(billcode) from'+
                 ' Partsoutputhand where Outputtype='''+'1'''+' and ClientCode='+#39+OpposingCode+#39+') '+
                 ' and PartCode='+#39+dmData.sdsSelectPart.FieldByName('Code').asstring+#39,
                 dmData.sdsPublic);
        PriceEdit.Value:=dmData.sdsPublic.FieldByName('Price').asfloat;
      end;
    end;
  6:
    begin
      PriceEdit.Value:=dmData.sdsSelectPart.FieldByName('Price').asfloat;
      QuantityEdit.Text:=FloatToStr(dmData.sdsSelectPart.FieldByName('Quantity').asfloat-
                          dmData.sdsSelectPart.FieldByName('REIMBURSEQRY').asfloat);
    end;
  end;  
end;

procedure TfrmSelectPartEdit.Button1Click(Sender: TObject);
var
  Agiosum, CessSum: Extended;
begin
  if Trim(QuantityEdit.Text)='' then
  begin
    Application.MessageBox('请输入数量。',Hintinfo,$30);
    QuantityEdit.SetFocus;
    Exit;
  end;
  if StrToFloat(QuantityEdit.Text)<=0 then
  begin
    Application.MessageBox('数量不能小于或等于“0”',Hintinfo,$30);
    QuantityEdit.SetFocus;
    Exit;
  end;
  if Trim(PriceEdit.Text)='' then PriceEdit.Text:='0';
  if Trim(AgioEdit.Text)='' then AgioEdit.Text:='0';
  if Trim(CessEdit.Text)='' then CessEdit.Text:='0';
  if SelectPartType=6 then
  begin
    if Trim(QuantityEdit.Text)='' then QuantityEdit.Text:='0';
    if StrToFloat(QuantityEdit.Text)>(dmData.sdsSelectPart.FieldByName('Quantity').asfloat-
                        dmData.sdsSelectPart.FieldByName('REIMBURSEQRY').asfloat) then
    begin
      Application.MessageBox('退货数量不可大于未退数量。',Hintinfo,$30);
      QuantityEdit.SetFocus;
      Exit;
    end;
  end;
  if SelectPartType=5 then
  begin
    if Trim(QuantityEdit.Text)='' then QuantityEdit.Text:='1';
    if StrToFloat(QuantityEdit.Text)>dmData.sdsSelectPart.FieldByName('BillQuantity').asfloat then
      if Application.MessageBox('数量不足,是否继续?',Hintinfo,$24)=idNo then
      begin
        QuantityEdit.SetFocus;
        Exit;
      end;
  end;    
  if SelectPartType=5 then
  begin
    if Trim(PriceEdit.Text)='' then PriceEdit.Text:='1';
    if StrToFloat(PriceEdit.Text)<dmData.sdsSelectPart.FieldByName('CostPrice').asfloat then
      if Application.MessageBox('销售价低于成本价,是否继续?',Hintinfo,$24)=idNo then
      begin
        PriceEdit.SetFocus;
        Exit;
      end;
  end;
  if (StrToFloat(AgioEdit.Text)>=10)or(StrToFloat(AgioEdit.Text)<0) then
  begin
    Application.MessageBox('折扣率只能是小于“10”和大于“0”之间的数字。',Hintinfo,$30);
    AgioEdit.SetFocus;
  end;
  if StrToFloat(CessEdit.Text)<0 then
  begin
    Application.MessageBox('税率只能是大于“0”的数字。',Hintinfo,$30);
    CessEdit.SetFocus;
  end;
  with SelectPartCds do
  begin
    if (FieldByName('BILLCODE').asstring<>'') and (not BillisEdit) then Edit
    else
    begin
      Append;
      FieldByName('BILLCODE').asstring:='新单据';
      FieldByName('ID').asinteger:=SelectPartCds.RecordCount+1;
    end;  
    if SelectPartType=6 then
    begin
      isReimburese:=True;
      FieldByName('PARTCODE').asstring:=dmData.sdsSelectPart.FieldByName('PartCode').asstring;
      FieldByName('PARTNAME').asstring:=dmData.sdsSelectPart.FieldByName('PartName').asstring;
      FieldByName('REIMBURSEQRY').asfloat:=dmData.sdsSelectPart.FieldByName('Quantity').asfloat-
                                           dmData.sdsSelectPart.FieldByName('REIMBURSEQRY').asfloat;
      FieldByName('OrderID').asstring:=dmData.sdsSelectPart.FieldByName('ID').asstring;
    end
    else
    begin
      FieldByName('PARTCODE').asstring:=dmData.sdsSelectPart.FieldByName('Code').asstring;
      FieldByName('PARTNAME').asstring:=dmData.sdsSelectPart.FieldByName('Name').asstring;
    end;
    FieldByName('BORNCODE').asstring:=dmData.sdsSelectPart.FieldByName('BORNCODE').asstring;
    FieldByName('CARMODEL').asstring:=dmData.sdsSelectPart.FieldByName('CARMODEL').asstring;
    FieldByName('PRODUCING').asstring:=dmData.sdsSelectPart.FieldByName('PRODUCING').asstring;
    FieldByName('UNITS').asstring:=dmData.sdsSelectPart.FieldByName('UNITS').asstring;
    FieldByName('DepotPlace').asstring:=dmData.sdsSelectPart.FieldByName('DepotPlace').asstring;
    FieldByName('Quantity').asfloat:=StrToFloat(QuantityEdit.Text);
    FieldByName('Price').asfloat:=PriceEdit.Value;
    //如果不是商品移仓单
    if SelectPartType<>7 then
    begin
      FieldByName('Agio').asfloat:=StrToFloat(AgioEdit.Text);
      FieldByName('Cess').asfloat:=StrToFloat(CessEdit.Text);
      if FieldByName('Agio').asfloat>0 then
        Agiosum:=FieldByName('Price').asfloat*
       (FieldByName('Quantity').asfloat*
       (FieldByName('Agio').asfloat/10))
      else
        Agiosum:=FieldByName('Price').asfloat*
        FieldByName('Quantity').asfloat;
      if FieldByName('Cess').asfloat>0 then
         CessSum:=Agiosum*(FieldByName('Cess').asfloat/100)
      else
        CessSum:=0;
        FieldByName('TotalSum').asfloat:=Agiosum+CessSum;
    end
    else
      FieldByName('TotalSum').asfloat:=FieldByName('Price').asfloat*
        FieldByName('Quantity').asfloat;
    BillSum:=BillSum+FieldByName('TotalSum').asfloat;
    if PartSum>0 then
    begin
      BillSum:=BillSum-PartSum;
      PartSum:=0;
    end;
    Post;
  end;
  isSelect:=True;
  Close;  
end;

procedure TfrmSelectPartEdit.Button2Click(Sender: TObject);
begin
  isSelect:=False;
  Close;
end;

procedure TfrmSelectPartEdit.QuantityEditExit(Sender: TObject);
begin
  if SelectPartType=6 then
  begin
    if Trim(QuantityEdit.Text)='' then QuantityEdit.Text:='0';
    if StrToFloat(QuantityEdit.Text)>(dmData.sdsSelectPart.FieldByName('Quantity').asfloat-
                        dmData.sdsSelectPart.FieldByName('REIMBURSEQRY').asfloat) then
    begin
      Application.MessageBox('退货数量不可大于未退数量。',Hintinfo,$30);
      QuantityEdit.SetFocus;
      Exit;
    end;
  end;
  if SelectPartType=5  then
  begin
    if Trim(QuantityEdit.Text)='' then QuantityEdit.Text:='1';
    if StrToFloat(QuantityEdit.Text)>dmData.sdsSelectPart.FieldByName('BillQuantity').asfloat then
      if Application.MessageBox('数量不足,是否继续?',Hintinfo,$24)=idNo then
      begin
        QuantityEdit.SetFocus;
      end;
  end;
end;

procedure TfrmSelectPartEdit.PriceEditExit(Sender: TObject);
begin
  if SelectPartType=5 then
  begin
    if Trim(PriceEdit.Text)='' then PriceEdit.Text:='1';
    if StrToFloat(PriceEdit.Text)<dmData.sdsSelectPart.FieldByName('CostPrice').asfloat then
      if Application.MessageBox('销售价低于成本价,是否继续?',Hintinfo,$24)=idNo then
      begin
        PriceEdit.SetFocus;
        Exit;
      end;
  end;
end;

procedure TfrmSelectPartEdit.AgioEditExit(Sender: TObject);
begin
  if Trim(AgioEdit.Text)='' then  AgioEdit.Text:='0';
  if (StrToFloat(AgioEdit.Text)>=10)or(StrToFloat(AgioEdit.Text)<0) then
  begin
    Application.MessageBox('折扣率只能是小于“10”和大于“0”之间的数字。',Hintinfo,$30);
    AgioEdit.SetFocus;
    Exit;
  end;
end;

procedure TfrmSelectPartEdit.CessEditExit(Sender: TObject);
begin
  if Trim(CessEdit.Text)='' then  CessEdit.Text:='0';
  if StrToFloat(CessEdit.Text)<0 then
  begin
    Application.MessageBox('税率只能是大于“0”的数字。',Hintinfo,$30);
    CessEdit.SetFocus;
    Exit;
  end;
end;

procedure TfrmSelectPartEdit.QuantityEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then  Perform(WM_NEXTDLGCTL,0,0);
end;

procedure TfrmSelectPartEdit.CessEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then Button1Click(Nil);
end;

procedure TfrmSelectPartEdit.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then Close;
end;

procedure TfrmSelectPartEdit.Image2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Handle, wm_SysCommand ,$F012, 0);
end;

end.

⌨️ 快捷键说明

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