mrp_enter_automo.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 764 行 · 第 1/2 页

PAS
764
字号
    Act_Save.Enabled:=False;
     if flag=0 then
       begin
        Executesql(AdoQry_tmp,'update #tMpssInfoResult set tMpssreMainqty=case ss.reMainqty when 0 then null else ss.reMainqty end from #tMpssInfoResult,ss where #tMpssInfoResult.ssid=ss.ssid ',1);
       BookmArk:=Frm_Mrp_Enter_MrpInfo.AdoQry_Main.BookmArk;
       Frm_Mrp_Enter_MrpInfo.AdoQry_Main.ReQuery;
       Frm_Mrp_Enter_MrpInfo.AdoQry_Main.BookmArk:=BookmArk;
       end;
     if flag=1 then
       begin
        Executesql(AdoQry_tmp,'update #tMpssInfoResult1 set tMpssreMainqty=case ss.reMainqty when 0 then null else ss.reMainqty end from #tMpssInfoResult1,ss where #tMpssInfoResult1.ssid=ss.ssid ',1);
       BookmArk:=Frm_Mrp_Enter_MrpInfo1.AdoQry_Main.BookmArk;
       Frm_Mrp_Enter_MrpInfo1.AdoQry_Main.ReQuery;
       Frm_Mrp_Enter_MrpInfo1.AdoQry_Main.BookmArk:=BookmArk;
       end;
     if flag=2 then
       begin
        Executesql(AdoQry_tmp,'update #tMpssInfoResult2 set tMpssreMainqty=case ss.reMainqty when 0 then null else ss.reMainqty end from #tMpssInfoResult2,ss where #tMpssInfoResult2.ssid=ss.ssid ',1);
       BookmArk:=Frm_Mrp_Enter_MrpInfo2.AdoQry_Main.BookmArk;
       Frm_Mrp_Enter_MrpInfo2.AdoQry_Main.ReQuery;
       Frm_Mrp_Enter_MrpInfo2.AdoQry_Main.BookmArk:=BookmArk;
       end;
     if flag=3 then
       begin
        Executesql(AdoQry_tmp,'update #tmpdynssInfoResult set tMpssreMainqty=case ss.reMainqty when 0 then null else ss.reMainqty end from #tmpdynssInfoResult,ss where #tmpdynssInfoResult.ssid=ss.ssid ',1);
       BookmArk:=Frm_Mrp_Qry_DynamicMrpInfo.AdoQry_Main.BookmArk;
       Frm_Mrp_Qry_DynamicMrpInfo.AdoQry_Main.ReQuery;
       Frm_Mrp_Qry_DynamicMrpInfo.AdoQry_Main.BookmArk:=BookmArk;
       end;

    DispInfo('数据保存完毕!',3);
  Except
   on e:exception do
    begin
    If DbConnect.InTransaction Then
      DbConnect.RollBackTrans;
    recOrderror(self,AdoQry_tmp,e.message);
    Edt_MoNo.Text:='';
    DispInfo('保存数据失败,请重试!',1);
    Abort;
    end;
  end;
  InitForm(DBConnect,'ReadOnly',AdoQry_Head);
  InitControls;
  if(Status='Add')then
  begin
    if ExtendCaption then
    begin
      Caption:=FormCaption+'新增';
      Pnl_Title.Caption:=FormCaption+'新增';
    end;
    AdoQry_Head.Append;
  end
  else if(Status='PArtEdit')or(Status='AllEdit')then
  begin
    if ExtendCaption then
    begin
      Caption:=FormCaption+'修改';
      Pnl_Title.Caption:=FormCaption+'修改';
    end;
    AdoQry_Head.Edit;
  end
  else if(Status='ReadOnly')then
  begin
    if ExtendCaption then
    begin
      Caption:=FormCaption+'查询';
      Pnl_Title.Caption:=FormCaption+'查询';
    end;
  end;
  Act_Save.Enabled:=False;
 finally
  AdoQry_Body.BookmArk:=bodymArk;
 end;
end;

procedure TFrm_Mrp_Enter_AutoMo.FormActivate(Sender: TObject);
begin
  inherited;
  MEdt_MoDate.Text:=FormatDateTime('yyyy.mm.dd',Date);
end;

procedure TFrm_Mrp_Enter_AutoMo.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
  Frm_Entry_Detail:=TFrm_Mrp_Enter_AutoMo_D.Create(Self);
  SetFocus_Control:=Edt_DeptCode;
  Cmbx_StandardFlag.clear;
  Cmbx_StandardFlag.Items.Add('否');
  Cmbx_StandardFlag.Items.Add('是');
end;

procedure TFrm_Mrp_Enter_AutoMo.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
  Enablecontrols:='Edt_MoNo,Edt_DeptCode,Medt_Modate,Edt_MoRemArk,Edt_SysParamCode,Cmbx_StandardFlag,';
end;

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

end;

procedure TFrm_Mrp_Enter_AutoMo.Act_DeleteLineExecute(Sender: TObject);
var
  BookmArk:String;
  tmPMoLineno:integer;
  tmpno:integer;
begin
  if AdoQry_Body.fieldbyname('byProduct').asinteger=1 then
     begin
      DispInfo('您不能删除副产品!',3);
      abort;
     end;
  If DispInfo('确认真的要删除这行吗?',2)<>'y' Then
    Abort;
  BookMArk:=AdoQry_Head1.BookmArk;
  AdoQry_Head1.First;
  While Not AdoQry_Head1.Eof Do
  begin
    If (AdoQry_Head1.fieldbyname('SsID').AsInteger=AdoQry_Body.fieldbyname('LimItOut').AsInteger) Then
     begin
       AdoQry_Head1.Edit;
       AdoQry_Head1.fieldbyname('SScheck').AsInteger:=0;
       AdoQry_Head1.Post;
       Break;
     end;
    AdoQry_Head1.Next;
  end;
  AdoQry_Head1.BookmArk:=BookMArk;
  deletebyProduct(AdoQry_Body.fieldbyname('MoLineno').asinteger);
  AdoQry_Body.Delete;
  If  AdoQry_Body.RecordCount>0 Then
  begin
    BookmArk:=AdoQry_Body.BookmArk;
    AdoQry_Body.First;
    While Not AdoQry_Body.Eof Do
    begin
      if AdoQry_Body.fieldbyname('byProduct').asinteger<>1 then
      tmPMoLineno:=AdoQry_Body.fieldbyname('MoLineno').asinteger;
      AdoQry_Body.Edit;
      AdoQry_Body.fieldbyname('MoLineNo').AsInteger:=AdoQry_Body.RecNo;
      if AdoQry_Body.fieldbyname('ParentMoLineno').asinteger=tmPMoLineno then
       AdoQry_Body.fieldbyname('ParentMoLineno').asinteger:=tmpno;
      AdoQry_Body.Post;
      if AdoQry_Body.fieldbyname('byProduct').asinteger<>1 then
      tmpno:=AdoQry_Body.fieldbyname('MoLineno').asinteger;
      AdoQry_Body.Next;
    end;
    AdoQry_Body.BookmArk:=BookMArk;
  end;
end;

procedure TFrm_Mrp_Enter_AutoMo.Edt_SysParamCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  Try
    If (Key=120) Then
      CommonHint(Sender,AdoQry_Body,'SysParamValuec','销售类型描述','SysParamCode','销售类型代码',
              'SysParam',' SubString(SysParamCode,1,8)='''+'SaleType'+'''');
  Finally
    Edt_SysParamValuec.Text:=Lbl_SaleType.Caption;
  end;
end;

procedure TFrm_Mrp_Enter_AutoMo.Edt_SysParamCodeExit(Sender: TObject);
begin
  inherited;
  If Trim(TExtEdit(Sender).Text)='' Then
  begin
    DispInfo('销售类型代码不能为空!',3);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
  With AdoQry_Tmp Do
  begin
    Close;
    SQL.clear;
    SQL.Add('Select SysParamCode,SysParamValuec From SysParam '
            +' Where SysParamCode='''+TEdit(Sender).Text+'''');
    Open;
    If Eof Then
    begin
      DispInfo('销售类型代码错误,请重新输入',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end;
    if (Sender is TExtEdit)and(TExtEdit(Sender).DispLabel<>nil) then
       TExtEdit(Sender).DispLabel.Caption:=fieldbyname('SysParamValuec').AsString;
      Edt_SysParamValuec.Text:=Lbl_SaleType.Caption;
  end;
end;

procedure TFrm_Mrp_Enter_AutoMo.Act_PreviewExecute(Sender: TObject);
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能预览!',3);
    Abort;
  end;
  Frm_Mrp_Enter_Mo_P:=TFrm_Mrp_Enter_Mo_P.Create(Application);
  Frm_Mrp_Enter_Mo_P.SetDBConnect(DbConnect);
  Frm_Mrp_Enter_Mo_P.SetSysParam(UserCode,ModuleCode,MenuId,DateTimeToStr(Now));
  Frm_Mrp_Enter_Mo_P.GetHeadData(AdoQry_Body,Trim(Edt_MoNo.Text),Trim(MEdt_MoDate.Text),Trim(Edt_DeptCode.Text),Lbl_DeptName.Caption,Trim(Edt_SysParamValuec.Text),Trim(Edt_MoReMArk.Text),'Preview');
  Frm_Mrp_Enter_Mo_P:=Nil;
end;

procedure TFrm_Mrp_Enter_AutoMo.Act_PrintExecute(Sender: TObject);
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能打印!',3);
    Abort;
  end;
  Frm_Mrp_Enter_Mo_P:=TFrm_Mrp_Enter_Mo_P.Create(Application);
  Frm_Mrp_Enter_Mo_P.SetDBConnect(DbConnect);
  Frm_Mrp_Enter_Mo_P.SetSysParam(UserCode,ModuleCode,MenuId,DateTimeToStr(Now));
  Frm_Mrp_Enter_Mo_P.GetHeadData(AdoQry_Body,Trim(Edt_MoNo.Text),Trim(MEdt_MoDate.Text),Trim(Edt_DeptCode.Text),Lbl_DeptName.Caption,Trim(Edt_SysParamValuec.Text),Trim(Edt_MoReMArk.Text),'Print');
  Frm_Mrp_Enter_Mo_P:=Nil;
end;

procedure TFrm_Mrp_Enter_AutoMo.Act_QuitExecute(Sender: TObject);
begin
 Close;

end;

procedure TFrm_Mrp_Enter_AutoMo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
//  inherited;

end;

procedure TFrm_Mrp_Enter_AutoMo.Edt_DeptCodeExit(Sender: TObject);
var
  SqlText:String;
begin
//  If (ActiveControl.Name='DBGridEh1')  Then
  //  Exit;
  If Trim(TExtEdit(Sender).Text)='' Then
  begin
    DispInfo('受单部门代码不能为空!',3);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
  SqlText:=' Select * '
          +' From Dept '
          +' Where DeptCode='''+Trim(Edt_DeptCode.Text)+'''';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:=SqlText;
  AdoQry_Tmp.Open;
  If AdoQry_Tmp.Eof Then
  begin
    DispInfo('受单部门代码错误,请重新输入!',1);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
  Lbl_DeptName.Caption:=AdoQry_Tmp.fieldbyname('DeptName').AsString;
  Edt_DeptName.Text:=AdoQry_Tmp.fieldbyname('DeptName').AsString;
end;

procedure TFrm_Mrp_Enter_AutoMo.DataSourceDataChange(Sender: TObject;
  Field: TField);
begin
  inherited;
  Lbl_ItemFlag.Caption:=AdoQry_Body.fieldbyname('ItemCode').AsString+' '+AdoQry_Body.fieldbyname('ItemName').AsString;
end;

procedure TFrm_Mrp_Enter_AutoMo.Act_ExcelExecute(Sender: TObject);
begin
  //inherited;
  DbGridEhToExcel(DbGridEh1);
end;

procedure TFrm_Mrp_Enter_AutoMo.Act_ModifyExecute(Sender: TObject);
var Book:string;
begin
  Edt_DeptCode.OnExit(Edt_DeptCode);
  Edt_SysParamCode.OnExit(Edt_SysParamCode);
try
  If (AdoQry_Body.fieldbyname('MoLineStatus').AsInteger<>5) Or
     (AdoQry_Body.fieldbyname('MoQty').AsFloat<>AdoQry_Body.fieldbyname('MoNoFinishQty').AsFloat) or (AdoQry_Body.fieldbyname('byProduct').asinteger=1) Then
   begin
     DispInfo('本条记录不可以修改',3);
     Abort;
   end;
   Book:=AdoQry_Body.BookmArk;
  inherited;
finally
 AdoQry_Body.BookmArk:=Book;
end;

end;



procedure TFrm_Mrp_Enter_AutoMo.getbyProduct(ItemCode: string;qty:real;MoLinedate,mostArtdate:string);
var tmpAdoQry:TAdoQuery;
    tmPMoLineno:integer;

begin
  tmpAdoQry:=TAdoQuery.Create(Application);
  tmpAdoQry.EnableBCD:=False;
  try
    tmPMoLineno:=AdoQry_Body.RecordCount;
    with tmpAdoQry do
    begin
      Close;
      Connection:=dbconnect;
      sql.clear;
      sql.Text:='select Bom.ItemCode,    '
              +'        Item.ItemName, '
              +'        Bom.Bomqty,   '
              +'        Uom.UomName  '
              +' from Bom '
              +' join Item on Bom.ItemCode=Item.ItemCode '
              +' left outer join Uom on Item.UomCode=Uom.UomCode '
              +' where ite_ItemCode='+quotedstr(ItemCode)
               +' and BomItemType=4';
      Prepared;
      open;
      if recordCount=0 then exit;
      First;
        while not eof do
        begin
          AdoQry_Body.Append;
          AdoQry_Body.fieldbyname('MoLineNo').AsInteger:=AdoQry_Body.RecordCount+1;
          AdoQry_Body.fieldbyname('LimItOut').AsInteger:=99999999;
          AdoQry_Body.fieldbyname('ItemCode').AsString:=fieldbyname('ItemCode').AsString;
          AdoQry_Body.fieldbyname('ItemName').AsString:=fieldbyname('ItemName').AsString;
          AdoQry_Body.fieldbyname('UomName').AsString:=fieldbyname('UomName').AsString;
          AdoQry_Body.fieldbyname('SsQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoNoFinishQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoLineStatus').AsInteger:=5;
          AdoQry_Body.fieldbyname('MoLineDate').Asstring:=MoLinedate;
          AdoQry_Body.fieldbyname('MoStArtWorkDate').Asstring:=mostArtdate;
          AdoQry_Body.fieldbyname('byProduct').Asinteger:=1;
          AdoQry_Body.fieldbyname('ParentMoLineno').Asinteger:=tmPMoLineno;
          AdoQry_Body.Post;
           next;
        end;
         AdoQry_Body.First;
    end;

  finally
    tmpAdoQry.Free;
  end;

end;

procedure TFrm_Mrp_Enter_AutoMo.deletebyProduct(MoLineno: integer);
var tmPmArk:string;
    tmplineno:integer;
    Count:integer;
begin
   tmPmArk:=AdoQry_Body.BookmArk;
   Count:=AdoQry_Body.RecordCount;
  tmplineno:=AdoQry_Body.fieldbyname('MoLineno').asinteger;
  with AdoQry_Body do
    begin
      First;
      while Count>0  do
        begin
          if AdoQry_Body.fieldbyname('ParentMoLineno').asinteger=tmplineno then
            AdoQry_Body.Delete;
          next;
          Count:=Count-1;
        end;
    end;
  AdoQry_Body.BookmArk:=tmPmArk;
end;

end.

⌨️ 快捷键说明

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