pm_enter_ssvendorassigninfo2_b.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 278 行

PAS
278
字号
unit Pm_Enter_SsVendorAssignInfo2_B;
//
Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, Mask, ExtEdit, DBCtrls, ExtPrintReport, jpeg;

Type
  TFrm_Pm_Enter_SsVendorAssignInfo2_B = Class(TFrm_Base_Entry_Body)
    Label3: TLabel;
    lbl_Qty: TLabel;
    AdoQry_BodyVendorCode: TStringField;
    AdoQry_BodyVendorName: TStringField;
    AdoQry_BodyItemCode: TStringField;
    AdoQry_BodyItemName: TStringField;
    AdoQry_BodyAssignQty: TFloatField;
    AdoQry_BodyHavePrice: TIntegerField;
    Label1: TLabel;
    lbl_ItemFlag: TLabel;
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DateCheck(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_QuitExecute(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormActivate(Sender: TObject);
    procedure AdoQry_BodyAfterPost(DataSet: TDataSet);
    procedure AdoQry_BodyBeforeEdit(DataSet: TDataSet);
  private
    { Private declarations }
  public
    flag:integer;
    ToDate:String;          //日期
    ItemCode : String;      //物料代码
    ItemName :String;
    SsReleaseDate : String; //计划约定交货日
    DueDate : String; //计划约定开工日
    qty:Double;       //总分配量
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
    procedure GetalterItem(var AdoQry:TAdoQuery;ite_ItemCode:string);
    { Public declarations }
    { Public declarations }
  end;

var
  Frm_Pm_Enter_SsVendorAssignInfo2_B: TFrm_Pm_Enter_SsVendorAssignInfo2_B;
implementation

uses  Sys_Global;

{$R *.DFM}


function checksymbol(Source:string;disptext:string):boolean;   //检查输入中是否有单引号
var
  i:integer;
  s:string;
begin
  s:=Trim(Source);
  for i:=1 to length(s) do
    if s[i]='''' then
    begin
      DispInfo(disptext+'中不能使用单引号!',1);
      Result:=False;
      exit;
    end;
  Result:=True;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.GetalterItem(var AdoQry:TAdoQuery;ite_ItemCode:string);
var
  SqlText:String;
  NoPriceQty,PriceQty : Double;  
begin
  AdoQry_Tmp.Connection:=AdoQry.Connection;
  AdoQry_Body.Connection:=AdoQry.Connection;
  DbConnect:=AdoQry.Connection;
  AdoQry_Head:=AdoQry;
  lbl_ItemFlag.Caption := ItemCode+' '+ItemName;
  SqlText := ' select VendorItemAssign.VendorCode,     '
             +'       Vendor.VendorName, '
             +'    VendorItemAssign.ItemCode,           '
             +'       Item.ItemName , '
             +'    VendorItemAssign.AssignRate/100.0*'+lbl_Qty.Caption+' As AssignQty,  '
             +'    case when IsNull(tmp.PcNo,'''')<>'''' then 1   '
             +'         else 0                                '
             +'    end HavePrice                              '
             +'  Into #TmPAssign '
             +'  from VendorItemAssign                      '
             +'   left join (select Pc.VendorCode,            '
             +'                     PcLine.*                  '
             +'                from PcLine                    '
             +'                join Pc on PcLine.PcNo=Pc.PcNo '
             +'               where ItemCode='+QuotedStr(ItemCode)
             +'                 and PcStArtDate<='+QuotedStr(SSReleaseDate)
             +'                 and PcendDate>='+QuotedStr(SSReleaseDate)
             +'                 and PcLineStatus=1) tmp        '
             +'   on VendorItemAssign.VendorCode=Tmp.VendorCode  '
             +'    and VendorItemAssign.ItemCode=Tmp.ItemCode    '
             +'   left join Vendor on VendorItemAssign.VendorCode=Vendor.VendorCode '
             +'   left join Item on VendorItemAssign.ItemCode=Item.ItemCode '
             +'    where VendorItemAssign.ItemCode='+QuotedStr(ItemCode);
  ExecuteSql(AdoQry_Tmp,SqlText,1);
  ExecuteSql(AdoQry_Tmp,'select Sum(case when HavePrice=0 then IsNull(AssignQty,0) '
                        +'               else 0 '
                        +'          end) as NoPriceQty ,'
                        +'      Sum(case when HavePrice=1 then IsNull(AssignQty,0) '
                        +'               else 0 '
                        +'          end) as PriceQty '
                        +' from #TmPAssign      ',0);
  NoPriceQty := AdoQry_Tmp.fieldbyname('NoPriceQty').AsFloat;
  PriceQty := AdoQry_Tmp.fieldbyname('PriceQty').AsFloat;
  ExecuteSQl(AdoQry_Tmp,'update #TmPAssign '
            +'   set AssignQty=0.0 '
            +' where HavePrice=0 ',1);
  If (PriceQty<>0.0) and (NoPriceQty<>0.0) then 
  ExecuteSQl(AdoQry_Tmp,'update #TmPAssign '
                       +'   set AssignQty=AssignQty+AssignQty/'+FloatToStr(PriceQty)+'*'+FloatToStr(NoPriceQty) 
                       +' where HavePrice=1 ',1);
  ExecuteSql(AdoQry_Body,'select * from #TmPAssign ',0);
  DataSource.DataSet:=AdoQry_Body;
  dataSource.DataSet.First;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.Act_SaveExecute(Sender: TObject);
var
  SqlText:String;
  I:integer;
  BookmArk:string;
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能保存!',3);
    Abort;
  end;
  If AdoQry_Body.State in [dsEdit,DsInsert] then AdoQry_Body.Post;
  ExecuteSql(AdoQry_Tmp,'select Sum(IsNUll(AssignQty,0.0)) as PriceQty from #TmPAssign',0);
  If AdoQry_Tmp.fieldbyname('PriceQty').AsFloat<>Qty then 
  begin
    DispInfo('总分配量必须等于计划量!',1);
    Abort;
  end;  

  try
    DbConnect.beginTrans;
    AdoQry_Body.First;
    While (Not AdoQry_Body.Eof) and (AdoQry_Body.fieldbyname('AssignQty').AsFloat>0)do begin
      SqlText := 'insert into  PurchaseApplyAssign  '
                +'      (ToDate,ItemCode,VendorCode,SSQty,PlanQty, '
                +'       SSReleaseDate,PlanDueDate,PlanReleaseDate, '
                +'       CreateEmployeeCode,CreateDate, '
                +'       EdItEmployeeCode,EditDate) '
                +'Values('+QuotedStr(ToDate)+','
                          +quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+','
                          +QuotedStr(AdoQry_Body.fieldbyname('VendorCode').AsString)+','
                          +FloatToStr(AdoQry_Body.fieldbyname('AssignQty').AsFloat)+','
                          +FloatToStr(AdoQry_Body.fieldbyname('AssignQty').AsFloat)+','
                          +quotedstr(SSReleaseDate)+','
                          +quotedstr(DueDate)+','
                          +quotedstr(SSReleaseDate)+','
                          +QuotedStr(UserCode)+','
                          +'GetDate(),'
                          +quotedstr(UserCode)+','
                          +'GetDate()'
                          +')';
      ExecuteSql(AdoQry_Tmp,SqlText,1);
      AdoQry_Body.Next;
    end;
    sqltext:='update PurchaseApply '
            +' set IsAssign=1  '
            +' where ToDate='+QuotedStr(ToDate)
            +'   and ItemCode='+QuotedStr(ItemCode)
            +'   and SSReleaseDate='+QuotedStr(SsReleaseDate);
    Executesql(AdoQry_tmp,sqltext,1);
    ExecuteSql(AdoQry_Tmp,'update #TmpVendorAssignInfo '
                          +'  set IsAssign=1, '
                          +'      TmpField=0  '
                          +' where ToDate='+QuotedStr(ToDate)
                          +'   and ItemCode='+Quotedstr(ItemCode)
                          + '  and SsReleaseDate='+quotedStr(SsReleaseDate)
                          ,1);
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;
    DispInfo('数据保存完毕!',3);
  Except
    If DbConnect.InTransaction Then
      DbConnect.RollBackTrans;
    DispInfo('保存数据失败,请重试!',1);
    Abort;
  end;
  Act_Save.Enabled:=False;
  self.Close;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
//  Frm_Entry_Detail:=TFrm_Mrp_Enter_AssignAlterNative2_D.Create(Self);
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.DateCheck(Sender: TObject);
begin
  If (ActiveControl.Name='DBGridEh1') Or (ActiveControl.Name='ControlBar')  Then
    Exit;
  inherited;

end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.Act_DeleteLineExecute(Sender: TObject);
begin
  if AdoQry_Body.RecordCount=0 then exit;
  If DispInfo('确认真的要删除这行吗?',2)<>'y' Then
    Abort;
  AdoQry_Body.Delete;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.Act_QuitExecute(Sender: TObject);
begin
  Close;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.Act_ExcelExecute(Sender: TObject);
begin
  //inherited;
  DbGridEhToExcel(DbGridEh);
end;






procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  try
    ExecuteSql(AdoQry_Tmp,'drop table #TmPAssign',1);
  except
  end;

end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.FormActivate(
  Sender: TObject);
begin
  inherited;
  Act_Save.Enabled := True;
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.AdoQry_BodyAfterPost(
  DataSet: TDataSet);
begin
  inherited;
  ExecuteSql(AdoQry_Tmp,'update #TmPAssign '
                       +'   set AssignQty='+FloatToStr(AdoQry_Body.fieldbyname('AssignQty').AsFloat)
                       +' where VendorCode='+QuotedStr(AdoQry_Body.fieldbyname('VendorCode').AsString),1);
end;

procedure TFrm_Pm_Enter_SsVendorAssignInfo2_B.AdoQry_BodyBeforeEdit(
  DataSet: TDataSet);
begin
  inherited;
  If AdoQry_Body.fieldbyname('HavePrice').AsInteger=0 then Abort;
end;

end.

⌨️ 快捷键说明

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