📄 usccgxq.pas
字号:
hthm:=trim(dbedit2.Text);
chthm:='';
for i:=1 to length(hthm) do
begin
if copy(hthm,i,1)=',' then
chthm:=chthm+QuotedStr(',')
else
chthm:=chthm+copy(hthm,i,1); //将工单号码转换为SQL格式
end;
if messagebox(handle,'是否真的要删除该采购需求单?','询问',
mb_yesno+mb_iconquestion)=idyes then
begin
strsql:='select * from cgwl where cgxqdh='+''''+cgxqdh+''''+'and ykcl<>0'; //检测是否已经有物料分配库存
adoexect(adoquery3,strsql);
adoquery3.First;
while not adoquery3.Eof do begin
strsql:='update wldmk set sykc=sykc+'+adoquery3.fieldbyname('ykcl').AsString+
',yfpkc=yfpkc-'+adoquery3.fieldbyname('ykcl').AsString+
' where wldm='+''''+trim(adoquery3.fieldbyname('wldm').AsString)+'''';
adodel(adoquery4,strsql);
adoquery3.Next;
end;
adoquery3.Close;
adoquery4.Close;
try
strsql:='update ddk set yclwl=0 where gdhm in ('+''''+chthm+''''+')';
adodel(adoquery3,strsql);
adoquery5.Delete;
strsql:='delete from cgwl where cgxqdh='+''''+cgxqdh+'''';
adodel(adoquery3,strsql);
TreeView1.Selected.Delete;
except
showmessage('删除采购需求单'+cgxqdh+'出错');
end;
end;
end;
procedure Tfrmsccgxq.txtykclChange(Sender: TObject);
begin
if strtoint(txtykcl.Text)-adoquery1.FieldByName('用库存量').Value>adoquery1.FieldByName('剩余库存').Value then begin
showmessage('用库存量不能超过剩余库存数!');
txtykcl.SetFocus;
exit;
end;
{
if strtoint(txtykcl.Text)>adoquery1.FieldByName('需求数').Value then begin
showmessage('用库存量不能超过需求数量!');
txtykcl.Text:=trim(adoquery1.fieldbyname('需求数').AsString);
txtykcl.SetFocus;
exit;
end;
}
if strtoint(txtykcl.Text)>=adoquery1.FieldByName('需求数').Value then
txtcgsl.Text:='0'
else
txtcgsl.Text:=inttostr(adoquery1.fieldbyname('需求数').Value-strtoint(txtykcl.Text));
end;
procedure Tfrmsccgxq.RzMenuToolbarButton1Click(Sender: TObject);
begin
strsql:='select * from cgjh_main where cgxqdh='+''''+trim(dbedit1.Text)+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.EOF and adoquery3.Recordset.BOF) then
begin
showmessage('对不起!该需求单号已经实施,不能更改工单号码!');
exit;
end;
if (not (adoquery5.State in [dsedit])) and (not (adoquery5.State in [dsinsert])) then exit;
strhthm:=trim(dbedit2.Text);
frmhtlb:=tfrmhtlb.Create(self);
frmhtlb.ShowModal;
dbedit2.Text:=strhthm;
strhthm:='';
end;
procedure Tfrmsccgxq.txtykclKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8] ) then
key:=#0;
end;
procedure Tfrmsccgxq.txtcgslKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in['0'..'9',#8] ) then
key:=#0;
end;
procedure Tfrmsccgxq.RzBitBtn11Click(Sender: TObject);
var
num:longint;
num1:longint;
num2:longint;
num3:longint;
strsql1:string;
begin
if not qxjc(userid,'company') then exit;
if not qxjc(userid,'xqd_edit') and (username<>trim(dbedit3.Text)) then exit;
strsql:='select * from cgjh_main where cgxqdh='+''''+trim(dbedit1.Text)+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.EOF and adoquery3.Recordset.BOF) then
begin
showmessage('对不起!该需求单号已经实施,不能再进行自动分配!');
exit;
end;
if not adoquery1.Active then exit;
if adoquery1.Recordset.eof and adoquery1.Recordset.BOF then exit;
strsql:='select * from cgjh_main where cgxqdh='+''''+trim(dbedit1.Text)+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.EOF and adoquery3.Recordset.BOF) then
begin
showmessage('对不起!此需求单已被实施,不能再重新分配?');
exit;
end;
application.ProcessMessages;
Panel5.Visible:=true;
timer1.Enabled:=true;
adoquery1.First;
while not adoquery1.Eof do
begin
num:=adoquery1.fieldbyname('剩余库存').value-adoquery1.fieldbyname('需求数').value+adoquery1.fieldbyname('用库存量').value;
num1:=adoquery1.fieldbyname('需求数').value;
num2:=adoquery1.fieldbyname('剩余库存').value;
num3:=adoquery1.fieldbyname('用库存量').value;
if num>=0 then
begin
strsql:='update wldmk set sykc='+inttostr(num)+
',yfpkc=sjkc-'+inttostr(num)+ ' where wldm='+
''''+trim(adoquery1.fieldbyname('物料代码').AsString)+'''';
strsql1:='update cgwl set ykcl=xql,jhcgl=0 where wldm='+''''+
trim(adoquery1.fieldbyname('物料代码').AsString)+''''+
' and cgxqdh='+''''+trim(dbedit1.Text)+'''';
end else begin
strsql:='update wldmk set sykc=0'+
',yfpkc=sjkc where wldm='+
''''+trim(adoquery1.fieldbyname('物料代码').AsString)+'''';
strsql1:='update cgwl set ykcl=ykcl+'+inttostr(num2)+',jhcgl=xql-'+inttostr(num3)+'-'+
inttostr(num2)+' where wldm='+''''+trim(adoquery1.fieldbyname('物料代码').AsString)+''''+
' and cgxqdh='+''''+trim(dbedit1.Text)+'''';
end;
adodel(adoquery3,strsql);
adodel(adoquery3,strsql1);
adoquery1.Next;
end;
adoquery3.Close;
Panel5.Visible:=false;
Timer1.Enabled:=false;
showmessage('自动分配库存成功!');
end;
procedure Tfrmsccgxq.Timer1Timer(Sender: TObject);
begin
Panel5.Caption:=trim(Panel5.Caption)+'. ';
i:=i+1;
if i>6 then
begin
Panel5.Caption:='正在处理数据,请稍后 ';
i:=0;
end;
end;
procedure Tfrmsccgxq.RzBitBtn5Click(Sender: TObject);
begin
form3.frDBDataSet1.dataset:=adoquery1;
form3.frDBDataSet2.dataset:=adoquery5;
form3.frReport1.DoublePass := True;
form3.frReport1.Clear;
form3.frReport1.LoadFromFile(strpath+'/report/cgjhd.frf');
form3.frReport1.Preview := Form3.frPreview1;
if form3.frReport1.PrepareReport then
begin
form3.frReport1.ShowPreparedReport;
end;
form3.ShowModal;
end;
procedure Tfrmsccgxq.RzBitBtn4Click(Sender: TObject);
begin
form3.frReport1.DoublePass := True;
form3.frReport1.Clear;
form3.frReport1.LoadFromFile(strpath+'/report/cgjhd.frf');
form3.frReport1.DesignReport;
end;
procedure Tfrmsccgxq.N1Click(Sender: TObject);
begin
strsql:='select * from cgwl,cgjh_detail,cgjh_main where cgwl.cgxqdh=cgjh_main.cgxqdh'+
' and cgjh_detail.cgjhdh=cgjh_main.cgjhdh and cgjh_detail.wldm='+
''''+trim(adoquery1.fieldbyname('物料代码').AsString)+'''';
adoexect(adoquery3,strsql);
if adoquery3.Recordset.EOF and adoquery3.Bof then
begin
strsql:='update wldmk set sykc=sykc+'+adoquery1.fieldbyname('用库存量').AsString+
',yfpkc=yfpkc-'+adoquery1.fieldbyname('用库存量').AsString+
' where wldm='+''''+trim(adoquery1.fieldbyname('物料代码').AsString)+'''';
adodel(adoquery3,strsql);
strsql:='delete from cgwl where wldm='+''''+trim(adoquery1.fieldbyname('物料代码').AsString)+''''+
'and cgxqdh='+''''+trim(dbedit1.Text)+'''';
adodel(adoquery3,strsql);
adoquery3.Close;
adoquery1.Close;
adoquery1.Open;
end else begin
showmessage('该物料已生成采购计划,不能删除?');
adoquery3.Close;
exit;
end;
end;
procedure Tfrmsccgxq.N2Click(Sender: TObject);
begin
wldm:='';
frmwllb.ShowModal;
if wldm='' then exit;
strsql:='select * from cgwl where cgxqdh='+''''+trim(dbedit1.Text)+''''+' and'+
' wldm='+''''+trim(wldm)+'''';
adoexect(adoquery2,strsql);
if not(adoquery2.Recordset.eof and adoquery2.Recordset.BOF) then
begin
showmessage('此物料在该需求单上已经存在');
exit;
end;
adotable2.Append;
adotable2.FieldByName('wldm').AsString:=wldm;
adotable2.FieldByName('xql').Value:=0;
adotable2.FieldByName('cgxqdh').AsString:=cgxqdh;
adotable2.FieldByName('jhcgl').Value:=0;
adotable2.FieldByName('ykcl').Value:=0;
adotable2.FieldByName('jhsl').Value:=0;
adotable2.FieldByName('dgsl').Value:=0;
adotable2.FieldByName('yssl').Value:=0;
adotable2.FieldByName('wssl').Value:=0;
adotable2.FieldByName('yfpsl').Value:=0;
adotable2.FieldByName('sysl').Value:=0;
adotable2.Post;
end;
procedure Tfrmsccgxq.Edit4KeyPress(Sender: TObject; var Key: Char);
var
i:integer;
begin
if key=#13 then
begin
strsql:='select * from cgwl_mail where gdhm like '+''''+'%'+trim(edit4.Text)+'%'+'''';
adoexect(adoquery3,strsql);
if adoquery3.Recordset.EOF and adoquery3.Recordset.BOF then
begin
showmessage('该工单尚未生成需求');
exit;
end;
for i:=0 to treeview1.Items.Count-1 do
begin
if trim(adoquery3.fieldbyname('cgxqdh').AsString)=trim(treeview1.Items[i].Text) then
begin
treeview1.Items[i].Selected:=true;
exit;
end;
end;
treeview1.Items.AddChild(node,trim(adoquery3.fieldbyname('cgxqdh').AsString));
treeview1.Items[i].Selected:=true;
end;
if key=#27 then
begin
GroupBox2.Visible:=false;
treeview1.Enabled:=true;
end;
end;
procedure Tfrmsccgxq.findClick(Sender: TObject);
begin
GroupBox2.Visible:=true;
edit4.SetFocus;
end;
procedure Tfrmsccgxq.RzBitBtn12Click(Sender: TObject);
begin
if adoquery6.Recordset.eof and adoquery6.Recordset.BOF then exit;
form3.frDBDataSet1.dataset:=adoquery6;
form3.frDBDataSet2.dataset:=adoquery1;
form3.frReport1.DoublePass := True;
form3.frReport1.Clear;
form3.frReport1.LoadFromFile(strpath+'/report/gyssywl.frf');
frVariables['username']:=username;
frVariables['wldm']:=trim(dbedit5.Text);
form3.frReport1.Preview := Form3.frPreview1;
if form3.frReport1.PrepareReport then
begin
form3.frReport1.ShowPreparedReport;
end;
form3.ShowModal;
end;
procedure Tfrmsccgxq.txtykclDblClick(Sender: TObject);
begin
if adoquery1.FieldByName('需求数').value>=adoquery1.FieldByName('剩余库存').Value then
txtykcl.Text:=adoquery1.FieldByName('剩余库存').AsString
else
txtykcl.Text:=adoquery1.FieldByName('需求数').AsString;
end;
procedure Tfrmsccgxq.DBGrid1TitleClick(Column: TColumn);
begin
dgridpx(adoquery1,DBGrid1,Column);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -