📄 usccgxq.pas
字号:
end;
strsql:='delete from cgwl where cgxqdh='+''''+cgxqdH+'''';
adodel(adoquery3,strsql);
{
for i:=1 to length(gdhm) do
begin
if copy(gdhm,i,1)=',' then
cgdhm:=cgdhm+QuotedStr(',')
else
cgdhm:=cgdhm+copy(gdhm,i,1);
end; //从工程单号中取得工单号码
strsql:='delete llqk_detail where hthm in (select hthm from ddk where gdhm in('+''''+cgdhm+''''+'))';
adodel(adoquery3,strsql);
adoquery3.Close;
}
if not insertdate then //插入数据不成功
begin
messagebox(handle,'重新生成采购需求单号失败','信息',mb_ok+mb_iconinformation);
exit;
end;
end; //结束修改模式工单号码发生改变的处理
if adoquery5.State in[dsinsert] then
begin
if not insertdate then //插入数据不成功
begin
messagebox(handle,'重新生成采购需求单号失败','信息',mb_ok+mb_iconinformation);
exit;
end else begin
treeview1.Items.AddChild(node,trim(dbedit1.Text));
end;
end;
if (gdhm=trim(dbedit2.Text)) and (adoquery5.State in[dsedit]) then //如果当前为修改模式,且包含工单未发生改变
begin
try
strsql:='exec p_editcgwl '+''''+hthm+''''+','+''''+cgxqdh+'''';
adodel(adoquery3,strsql);
except
showmessage('更新领料计划或采购物料库时出错!');
adoquery3.Close;
exit;
end;
end;
adoquery5.Post;
messagebox(handle,'生成采购需求单号成功','信息',mb_ok+mb_iconinformation);
RzBitBtn1.Enabled:=true;
RzBitBtn2.Enabled:=true;
RzBitBtn3.Enabled:=false;
TreeView1.Enabled:=true;
end;
function tfrmsccgxq.insertdate():boolean;
var
wldm:string;
xql:longint;
begin
try
strsql:='exec p_wlxq @cgxqdh='+''''+trim(dbedit1.Text)+''''+',@gdhm='+''''+hthm+''''+
',@username='+''''+username+'''';
adodel(adoquery3,strsql);
result:=true;
{
STRSQL:='select wldm,sum(xql) as 需求量 from order_wlfp'+ //计算被选工单物料合计
' where gdhm in ('+''''+chthm+''''+') group by wldm';
adoexect(adoquery3,strsql);
//showmessage(strsql);
if not(adoquery3.Recordset.BOF and adoquery3.Recordset.EOF) then
begin
adoquery3.First;
while not adoquery3.Eof do
begin
adotable2.Append;
adotable2.FieldByName('wldm').AsString:=adoquery3.fieldbyname('wldm').AsString;
adotable2.FieldByName('xql').AsString:=adoquery3.fieldbyname('需求量').AsString;
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;
adoquery3.Next;
end;
adoquery3.Close;
result:=true;
end else begin
showmessage('你所输入的工单号不正确,请确认后重新输入');
adoquery3.Close;
result:=false;
exit;
end;
}
except
showmessage('生成物料需求出错!');
result:=false;
end;
adoquery3.Close;
{
try
strsql:='delete llqk_detail where hthm in (select hthm from ddk where gdhm in('+''''+chthm+''''+'))';
adodel(adoquery3,strsql);
strsql:='insert llqk_detail (hthm,gdhm,ylbm,wldm,xql,ylsl,wlsl,yfpsl,sysl,ldrq)'+
' select 合同号码,工程单号,用料部门,物料代码,用量,0,用量,0,0,货期 from view_wlxq where 工单号码 in ('+''''+chthm+''''+')'; //用来生成部门领料计划
adodel(adoquery3,strsql);
except //如果产生异常则删除所天家的明细
strsql:='delete from cgwl where cgxqdh='+''''+cgxqdh+'''';
adodel(adoquery3,strsql);
strsql:='delete llqk_detail where hthm in (select hthm from ddk where gdhm in('+''''+chthm+''''+'))';
adodel(adoquery3,strsql);
showmessage('生成领料计划时出错!');
result:=false;
end;
}
end;
procedure Tfrmsccgxq.RzBitBtn7Click(Sender: TObject);
begin
adoquery5.CancelUpdates;
RzBitBtn1.Enabled:=true;
RzBitBtn2.Enabled:=true;
RzBitBtn3.Enabled:=false;
TreeView1.Enabled:=true;
end;
procedure Tfrmsccgxq.RzBitBtn8Click(Sender: TObject);
begin
close;
end;
procedure Tfrmsccgxq.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (adoquery5.State in[dsinsert]) or (adoquery5.State in[dsedit]) then
begin
if messagebox(handle,'是否需要保存数据?','询问',mb_yesno+mb_iconquestion)=idyes then
begin
RzBitBtn3Click(self);
end else begin
RzBitBtn7Click(self);
end;
end;
action:=cafree;
end;
procedure Tfrmsccgxq.DBEdit2Enter(Sender: TObject);
begin
RzMenuToolbarButton1.Visible:=true;
end;
procedure Tfrmsccgxq.DBEdit2Exit(Sender: TObject);
begin
RzMenuToolbarButton1.Visible:=false;
end;
procedure Tfrmsccgxq.dtp1Change(Sender: TObject);
begin
csh;
end;
procedure Tfrmsccgxq.dtp2Change(Sender: TObject);
begin
csh;
end;
procedure Tfrmsccgxq.Edit1Change(Sender: TObject);
begin
strsql:='select * from view_cgwl where 采购需求单号='+''''+cgxqdh+''''+
'and 助记码 like'+''''+trim(edit1.text)+'%'+''''+'order by 助记码 ASC';
adoexect(adoquery1,strsql);
if adoquery1.Recordset.EOF and adoquery1.Recordset.BOF then
begin
strsql:='select * from view_cgwl where 采购需求单号='+''''+cgxqdh+''''+
'and 物料名称 like'+''''+'%'+trim(edit1.text)+'%'+''''+'order by 助记码 ASC';
adoexect(adoquery1,strsql);
end;
end;
procedure Tfrmsccgxq.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if adoquery1.FieldByName('用库存量').Value+adoquery1.FieldByName('采购数量').Value<adoquery1.FieldByName('需求数').Value then
begin
dbgrid1.Canvas.Brush.Color:=rgb(250,120,150);
end;
dbgrid1.DefaultDrawColumnCell(rect,datacol,column,[gdfixed,gdfocused,gdselected]);
end;
procedure Tfrmsccgxq.RzBitBtn9Click(Sender: TObject);
begin
if adoquery1.Recordset.EOF and adoquery1.Recordset.BOF then exit;
if (strtoint(txtykcl.Text)<>ykcl) and (adoquery1.FieldByName('已分配数量').value>0) then
begin
showmessage('该需求单已经分配了该物料数量,'+#10#13+'不能更改用库存量');
txtykcl.Text:=inttostr(ykcl);
txtcgsl.SetFocus();
exit;
end;
if strtoint(txtykcl.Text)+strtoint(txtcgsl.Text)<adoquery1.FieldByName('需求数').Value then
begin
showmessage('采购数量+用库存量不能少于实际需求数');
txtcgsl.SetFocus;
exit;
end;
if strtoint(txtykcl.Text)-ykcl>adoquery1.FieldByName('剩余库存').Value then
begin
showmessage('用库存量不能超过剩余库存数!');
exit;
end;
strsql:='select * from cgjh_main,cgjh_detail where cgjh_main.cgjhdh=cgjh_detail.cgjhdh and '+
'cgjh_detail.wldm='+''''+adoquery1.fieldbyname('物料代码').AsString+''''+'and cgjh_main.cgxqdh='+
''''+trim(dbedit1.Text)+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.EOF and adoquery3.Recordset.bof) then
begin
if messagebox(handle,'该物料已经被列入计划行列,系统建议不要再修改用库存量','警告',mb_yesno+mb_iconwarning)=idno then exit;
if cgsl>strtoint(txtcgsl.Text) then
begin
showmessage('改需求数量已实施,采购数量不能少于原先的数量!');
txtcgsl.Text:=inttostr(cgsl);
exit;
end;
end;
strsql:='select * from cgwl where cgxqdh='+''''+adoquery1.fieldbyname('采购需求单号').AsString+
''''+'and wldm='+''''+adoquery1.fieldbyname('物料代码').AsString+'''';
adoexect(adoquery4,strsql);
strsql:='select * from wldmk where wldm='+''''+adoquery1.fieldbyname('物料代码').AsString+'''';
adoexect(adoquery3,strsql); //adoquery3 用来修改相应物料的剩余库存,adoquery4用来修改采购计划
try
adoquery4.Edit;
adoquery3.Edit;
adoquery4.FieldByName('ykcl').Value:=strtoint(txtykcl.Text);
adoquery4.FieldByName('jhcgl').Value:=strtoint(txtcgsl.Text);
// adoquery4.FieldByName('xql').Value:=strtoint(edit3.Text);
adoquery3.FieldByName('sykc').Value:=adoquery3.FieldByName('sykc').Value-strtoint(txtykcl.Text)+ykcl;
adoquery3.FieldByName('yfpkc').Value:=adoquery3.FieldByName('yfpkc').Value+strtoint(txtykcl.Text)-ykcl;
adoquery4.Post;
adoquery3.Post;
except
showmessage('更新数据失败!');
exit;
end;
strsql:='update wldmk set node='+''''+trim(dbmemo2.Text)+''''+' where wldm='+''''+trim(dbedit5.Text)+'''';
adodel(adoquery3,strsql);
adoquery3.Close;
adoquery4.Close;
adoquery1.Close;
adoquery1.Open;
RzPageControl1.ActivePageIndex:=0;
end;
procedure Tfrmsccgxq.RzBitBtn10Click(Sender: TObject);
begin
RzPageControl1.ActivePageIndex:=0;
end;
procedure Tfrmsccgxq.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
cgxqdh:=trim(node.Text);
brouse;
end;
procedure Tfrmsccgxq.TabSheet2Enter(Sender: TObject);
var
zsys:longint;
begin
zsys:=0;
if not adoquery1.Active then exit;
if adoquery1.Recordset.EOF and adoquery1.Recordset.BOF then exit;
strsql:='select wldm,wlmc,wlys,wlsh,dw,gysdm,sjkc,sykc,yfpkc,pym,wlsh from wldmk where wlmc='+
''''+trim(adoquery1.fieldbyname('物料名称').AsString)+
''''+' and wlys='+''''+trim(adoquery1.fieldbyname('物料颜色').AsString)+'''';
adoexect(adoquery6,strsql);
while not adoquery6.Eof do
begin
zsys:=zsys+adoquery6.fieldbyname('sykc').Value;
adoquery6.Next;
end;
label22.Caption:='总剩余数量:'+inttostr(zsys)+' ';
ykcl:=ADOQUERY1.FIELDBYNAME('用库存量').Value;
cgsl:=ADOQUERY1.FIELDBYNAME('采购数量').Value;
txtykcl.Text:=ADOQUERY1.FIELDBYNAME('用库存量').AsString;
txtcgsl.Text:=adoquery1.fieldbyname('采购数量').AsString;
edit2.Text:=ADOQUERY1.FIELDBYNAME('剩余库存').AsString;
edit3.Text:=ADOQUERY1.FIELDBYNAME('需求数').AsString;
txtykcl.SetFocus;
end;
procedure Tfrmsccgxq.RzBitBtn6Click(Sender: TObject);
var
i:integer;
begin
if not qxjc(userid,'xqd_del') and (username<>trim(dbedit3.Text)) then exit;
if adoquery5.Recordset.eof and adoquery5.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;
strsql:='select * from cgwl where yfpsl>0 and cgxqdh='+''''+trim(dbedit1.Text)+'''';
adoexect(adoquery3,strsql);
if not(adoquery3.Recordset.EOF and adoquery3.Recordset.BOF) then
begin
showmessage('对不起!此需求单已分配库存,不能删除?');
exit;
end;
adoquery3.Close;
cgxqdh:=trim(dbedit1.Text);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -