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

📄 mrp_enter_mo.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                +' And MoLineNo='''+AdoQry_Body.fieldbyname('MoLineNO').AsString+''''
                +' And MoLineStatus=5';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
        If Cmbx_StandardFlag.ItemIndex=1 Then
         if ((AdoQry_Body.fieldbyname('byProduct').asinteger<>1) and (AdoQry_Body.fieldbyname('MoLinestatus').asinteger=5)) then
          begin
          Executesql(AdoQry_tmp,'delete from mnItemList where mono='+quotedstr(Trim(edt_Mono.text))+' and MoLineno='+inttostr(AdoQry_Body.fieldbyname('MoLineno').asinteger),1);
          If Not (AutoBuildOrder(DbConnect,Trim(Edt_MoNo.Text),Trim(AdoQry_Body.fieldbyname('ItemCode').AsString),
             IntToStr(AdoQry_Body.fieldbyname('MoLineNo').AsInteger),'Add','Mo',AdoQry_Body.fieldbyname('MoQty').AsFloat)) Then //自动产生领料单
             Abort;
          end;
        AdoQry_Body.Next;
      end;
    end;
    saveMoLineHistory1(dbconnect,deletedMoLine,userCode,2);
    deleteMoLine;
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;
    DispInfo('数据保存成功!',3);
  Except
   on e:exception do
    begin
    DbConnect.RollBackTrans;
    recOrderror(self,AdoQry_tmp,e.message);
    Edt_MoNo.Text:='';
    DispInfo('保存数据失败,请重试!',1);
    Abort;
    end;
  end;
  with AdoQry_Head do
  begin
    fieldbyname('MoNo').AsString:=Trim(Edt_MoNo.Text);
    fieldbyname('DeptCode').AsString:=Trim(Edt_DeptCode.Text);
    fieldbyname('DeptName').AsString:=Lbl_DeptName.Caption;
    fieldbyname('Modate').AsDatetime:=Strtodatetime(Medt_Modate.Text);
    fieldbyname('MoReMArk').AsString:=Trim(Edt_MoRemArk.Text);
    fieldbyname('SysParamCode').AsString:=Trim(Edt_SysParamCode.Text);
    fieldbyname('SysParamValuec').AsString:=Trim(Edt_SysParamValuec.Text);
    fieldbyname('StandardFlag').AsInteger:=Cmbx_StandardFlag.ItemIndex;
  end;
end;

procedure TFrm_Mrp_Enter_Mo.Act_SaveExecute(Sender: TObject);
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能保存!',1);
    Abort;
  end;
  inherited;
end;

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

end;

procedure TFrm_Mrp_Enter_Mo.Act_DeleteLineExecute(Sender: TObject);
var
  BookMArk:String;
  tmPMoLineno:integer;
  tmpno:integer;
begin
 // inherited;
{  If  AdoQry_Body.RecordCount>0 Then
  begin
    BookMArk:=AdoQry_Body.BookmArk;
    AdoQry_Body.First;
    While Not AdoQry_Body.Eof Do
    begin
      AdoQry_Body.Edit;
      AdoQry_Body.fieldbyname('MoLineNo').AsInteger:=AdoQry_Body.RecNo;
      AdoQry_Body.Post;
      AdoQry_Body.Next;
    end;
    AdoQry_Body.BookmArk:=BookMArk;
  end; }
  if AdoQry_Body.fieldbyname('byProduct').asinteger=1 then
     begin
      DispInfo('您不能删除副产品!',3);
      abort;
     end;
  if getstatus(AdoQry_Body.fieldbyname('mono').asstring,AdoQry_Body.fieldbyname('MoLineno').asinteger)<>5 then
     begin
       DispInfo('这行生产订单行状态不是准备状态,不可删除!',3);
       abort;
     end;
  If DispInfo('确认真的要删除这行吗?',2)<>'y' Then
    Abort;
  BookMArk:=AdoQry_Body.BookmArk;
  deletebyProduct(AdoQry_Body.fieldbyname('MoLineno').asinteger);
  deletedMoLine:=deletedMoLine+','+quotedstr(AdoQry_Body.fieldbyname('mono').asstring+inttostr(AdoQry_Body.fieldbyname('MoLineno').asinteger));
  AdoQry_Body.Delete;
  If  AdoQry_Body.RecordCount>0 Then
  begin
   if status='Add' 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;
  act_Save.Enabled:=True;
end;

procedure TFrm_Mrp_Enter_Mo.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_Mo.Edt_SysParamCodeExit(Sender: TObject);
begin
  inherited;
 If Trim(TExtEdit(Sender).Text)='' Then
  begin
    DispInfo('销售类型代码不能为空!',1);
    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_Mo.Act_PreviewExecute(Sender: TObject);
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能预览!',1);
    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_Mo.Act_PrintExecute(Sender: TObject);
begin
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能打印!',1);
    Abort;
  end;
  If Frm_Mrp_Enter_Mo_P<>Nil Then
  begin
    Frm_Mrp_Enter_Mo_P.QR.Destroy;
    Frm_Mrp_Enter_Mo_P.Close;
  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');
end;

procedure TFrm_Mrp_Enter_Mo.FormActivate(Sender: TObject);
begin
  inherited;
  Edt_MoNo.Enabled:=False;
end;

procedure TFrm_Mrp_Enter_Mo.Edt_DeptCodeExit(Sender: TObject);
var
  SqlText:String;
begin
//  If (ActiveControl.Name='DBGridEh') Or (ActiveControl.Name='ControlBar')  Then
 //   Exit;
  If Trim(TExtEdit(Sender).Text)='' Then
  begin
    DispInfo('受单部门代码不能为空!',1);
    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_Mo.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_Mo.Act_ExcelExecute(Sender: TObject);
begin
  //inherited;
  DbGridEhToExcel(DbGridEh);
end;

procedure TFrm_Mrp_Enter_Mo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
 If AdoQry_Body.RecordCount=0 Then
   Act_Save.Enabled:=False;
  inherited;

end;

procedure TFrm_Mrp_Enter_Mo.Act_ModifyExecute(Sender: TObject);
var Book:string;
begin
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_Mo.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
           begin
            deletedMoLine:=deletedMoLine+','+quotedstr(AdoQry_Body.fieldbyname('mono').asstring+inttostr(AdoQry_Body.fieldbyname('MoLineno').asinteger));
            AdoQry_Body.Delete;
            end;
          next;
          Count:=Count-1;
        end;
    end;
  AdoQry_Body.BookmArk:=tmPmArk;
end;


function  TFrm_Mrp_Enter_Mo.getstatus(mono:string;MoLineno:integer):integer;
 begin
   Result:=999;
   Executesql(AdoQry_tmp,'select MoLinestatus from MoLine where mono='+quotedstr(mono)+' and MoLineno='+inttostr(MoLineno),0);
   Result:=AdoQry_tmp.fieldbyname('MoLinestatus').asinteger;
 end;

procedure TFrm_Mrp_Enter_Mo.deleteMoLine;
 begin
  Executesql(AdoQry_tmp,'delete from mnItemList where mono+convert(varchAr,MoLineno) in ('+deletedMoLine+')',1);
  Executesql(AdoQry_tmp,'delete from MoLine where mono+convert(varchAr,MoLineno) in ('+deletedMoLine+')',1);

 end;
end.

⌨️ 快捷键说明

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