A
Amos.mao
Unregistered / Unconfirmed
GUEST, unregistred user!
{<br>简单说明<br>1: Select psn.materysn,planshu from MRPplan where psn=xxx (xxx 为传入参数),对应数据集为rsq1<br> If rsq1.RecordCount>0 then<br> Begin<br> For I:=1 To rsq1.RecordCount Do<br> Begin<br> fstr:=rsq1.materysn<br> Select * From mrpplanpsn where materysn=fstr and psn=xxx (xxx 为传入参数),对应数据集为rst<br> If rst.RecordCount>0 Then 将对应 planshu 数量进行相加<br> Else <br> Begin<br> rst.Append //新写入对应内容<br> End;<br> <br> 进行BOM资料对应查找,rsq2.SQL.Add('select materysn from bom where fmaterysn=fstr)<br> If Rsq2.RecordCount Then SGmaterysn(Fstr;planshu) 进行循环<br> <br> End //For I:=1 To rsq1.RecordCount Do<br> End;<br> <br>1:由生产单MRPPlan 查找对应的资料 <br>2:计算制造该产品所需要的物料 计算依据为 毛需求量=生产批量*物料清单中的单位用量<br>3:将相关计算后的数据储存至MRP需求计算资料库 mrpplanpsn 中 <br>}<br><br><br>procedure TMRPNR.BtnGRClick(Sender: TObject); //毛需求<br><br>var<br> rsq1,rsq2:TADOQuery;<br> rst:TADODataSet;<br> tstr,remark:string;<br> i,n:integer;<br> planshu:double;<br>begin<br> <br> tmpPSN := CmbPsn.Text;<br> adoconnwrite.Close ;<br> adoconnwrite.ConnectionString:=strconnection;<br> adoconnwrite.Open ;<br> adoconnwrite.BeginTrans ;<br> try<br> rsq1:=TADOQuery.Create(self);<br> rst:=TADODataSet.Create(self);<br> rsq2:=TADOQuery.Create(self);<br> try<br> rsq2.Connection:=adoconnread;<br> rsq1.Connection:=adoconnread;<br> rsq1.SQL.Clear ; //MRPplan 为 生产单<br> rsq1.SQL.Add('select materysn,planshu,consigndate from MRPplan where psn='+''''+ Trim(tmpPSN)+''''+'');<br> rsq1.Prepared ;<br> rsq1.Open ;<br> n:=rsq1.RecordCount;<br> If n > 0 Then<br> begin<br> tmpDate:= rsq1.fieldbyname('consigndate').AsString ; //交货日期<br> rsq1.First ;<br> rst.Connection:=adoconnWrite;<br> For i:=1 To n do<br> Begin<br> fstr:=trim(rsq1.fieldbyname('Materysn').asstring); //<br> Planshu:= rsq1.fieldbyname('planshu').AsFloat ;<br> tstr:='select materysn,gr,fu,psn,consigndate,remark';<br> tstr:=tstr+ ' from mrpplanpsn';<br> tstr:=tstr+ ' where materysn='+''''+ Trim(fstr)+''''+'and psn='+''''+ Trim(CmbPsn.Text)+''''+'';<br> rst.Close ;<br> rst.CommandText:=tstr;<br> rst.Prepared ;<br> rst.Open ;<br> if (rst.RecordCount >0) then<br> begin<br> rst.Edit ;<br> rst.FieldByName('gr').AsFloat:=rst.FieldByName('gr').AsFloat+ planshu;<br> rst.FieldByName('remark').AsString:=rst.FieldByName('remark').AsString+','+ fstr;<br> rst.Post;<br> end<br> else<br> begin<br> rst.Append ;<br> rst.FieldByName('materysn').AsString :=trim(rsq1.fieldbyname('materysn').AsString) ;<br> rst.FieldByName('gr').AsCurrency :=planshu; //毛需求 初始数据批量数目MRPPlan的planshu (批量数)<br> rst.FieldByName('fu').AsCurrency :=0;<br> rst.FieldByName('psn').AsString :=trim(tmppsn);<br> rst.FieldByName('consigndate').AsDateTime :=strtodate(tmpdate); //交货日期<br> rst.FieldByName('remark').AsString:=fstr; //备注说明<br> rst.Post ;<br> end;<br> //if rst.RecordCount >0 then<br><br> rsq2.Close ;<br> rsq2.SQL.Clear ;<br> rsq2.SQL.Add('select materysn from bom where fmaterysn='+''''+Trim(rsq1.fieldbyname('materysn').AsString)+''''+'');<br> rsq2.Prepared ;<br> rsq2.Open ;<br> if rsq2.RecordCount >0 then SGmaterysn(rsq1.FieldByName('materysn').AsString, Planshu);<br><br> rsq1.Next ;<br> end;// For i:=1 To n do<br><br> tstr:='update mrpplantou';<br> tstr:= tstr+' set';<br> tstr:= tstr+' state='+''''+'3'+''''+'';<br> tstr:= tstr+' where psn='+''''+Trim(tmpPsn)+''''+'';<br><br> rsq2.Close ;<br> rsq2.SQL.Clear ;<br> rsq2.SQL.Add(tstr);<br> rsq2.Prepared ;<br> rsq2.ExecSQL ;<br> end;//If n > 0 Then<br><br> adoconnwrite.CommitTrans ;<br> adoconnwrite.Close;<br> finally<br> Screen.Cursor:=crDefault;<br> rsq1.Free ;<br> rsq2.Free ;<br> rst.Free ;<br> end;<br><br> except<br> messagedlg('保存过程中出现错误,未保存!',mtinformation,[mbok],0);<br> adoconnwrite.RollbackTrans ;<br> end;<br> adoconnwrite.Close ;<br> Animate1.Active:=false;<br> Animate1.Visible :=false;<br><br>Display_rs2; //显示 Mrp需求 mrpplanpsn 计算的相关信息<br>//end; //If n > 0 Then<br>end;<br><br><br>procedure TMRPNR.SGmaterysn(Fmaterysn:string;planshuouble);<br>var<br> rsq1,rsq2:TADOQuery;<br> rst:TADODataSet;<br> i,n:integer;<br> remark:String;<br>begin<br> rsq1:=TADOQuery.Create(self);<br> rsq2:=TADOQuery.Create(self);<br> rst:=TADODataSet.Create(self);<br> try<br> rst.Connection :=AdoConnWrite;<br> rsq2.Connection :=adoconnread;<br> rsq1.Connection :=adoconnread;<br> rsq1.SQL.Clear;<br> rsq1.SQL.Add('select materysn,useshu from bom where fmaterysn='+''''+ Trim(Fmaterysn)+''''+' and useshu>'+''''+'0'+''''+'');<br> rsq1.Prepared ;<br> rsq1.Open ;<br> n :=rsq1.RecordCount ;<br> If n > 0 Then<br> begin<br> rsq1.First ;<br> For i:= 1 To n do<br> begin<br> rst.Close ;<br> rst.CommandText :='select materysn,gr,fu,psn,consigndate,remark from mrpplanpsn where materysn='+''''+ Trim(rsq1.fieldbyname('Materysn').AsString)+''''+' and psn='+''''+Trim(tmpPsn)+''''+'';<br> rst.Prepared ;<br> rst.Open ;<br> If rst.RecordCount > 0 Then<br> begin<br> rst.edit;<br> rst.FieldByName('gr').AsFloat:=rst.FieldByName('gr').AsFloat+planshu*rsq1.fieldbyname('useshu').AsFloat;<br> rst.FieldByName('remark').AsString:=rst.FieldByName('remark').AsString+','+ fstr;<br> rst.Post ;<br> end<br> Else<br> begin<br> rst.Append ;<br> rst.FieldByName('materysn').AsString:=trim(rsq1.FieldByName('materysn').asstring);<br> rst.FieldByName('gr').AsFloat:= Planshu * rsq1.fieldbyname('useshu').AsFloat;<br> rst.FieldByName('fu').AsFloat:= 0;<br> rst.FieldByName('psn').AsString:= Trim(tmpPSN);<br> rst.FieldByName('consigndate').AsDateTime:= strtodate(tmpDate);<br> rst.FieldByName('remark').AsString:=fstr;<br><br> rst.Post ;<br> end; // If rst.RecordCount > 0 Then<br> rsq2.Close ;<br> rsq2.SQL.Clear ;<br> rsq2.SQL.Add('select materysn from bom where fmaterysn='+''''+Trim(rsq1.fieldbyname('materysn').AsString)+''''+'');<br> rsq2.Prepared ;<br> rsq2.Open ;<br> if rsq2.RecordCount >0 then<br> SGmaterysn(rsq1.FieldByName('materysn').AsString, Planshu * rsq1.fieldbyname('useshu').asfloat);<br> rsq1.Next ;<br> end; //For i:= 1 To n do<br> end;//If n > 0 Then<br> finally<br> rsq1.Free ;<br> rsq2.Free ;<br> rst.Free ;<br> end;<br> end;