📄 sfc_mnrequest_b1.pas
字号:
unit Sfc_MnRequest_B1;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, DBCtrls, StdCtrls, ActnList, AdODB, Grids, DBGridEh,
ExtCtrls, ComCtrls, ToolWin, ExtPrintReport, ExtEdit, Mask,dbgrids, jpeg,variants;
Type
TFrm_Sfc_MnRequest_B1 = Class(TFrm_Base_Entry_Body)
Extpr: TExtPrintReport;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
cmbbx_WhCode: TComboBox;
cmbbx_WhPositionCode: TComboBox;
lbl_Dept: TLabel;
medt_Date: TMaskEdit;
lbl_Mono: TLabel;
lbl_MoLineno: TLabel;
lbl_Item: TLabel;
Extedt_Billno: TExtEdit;
Extedt_memo: TExtEdit;
CheckBox1: TCheckBox;
cmbbx_WhEmployee: TComboBox;
Label7: TLabel;
CheckBox2: TCheckBox;
cmbbx_Shift: TComboBox;
Panel1: TPanel;
Label13: TLabel;
DBText2: TDBText;
AdoQry_SwAp: TAdoQuery;
DataSource1: TDataSource;
Panel2: TPanel;
DBText1: TDBText;
Label8: TLabel;
Label14: TLabel;
lbl_qty: TLabel;
Label15: TLabel;
Label16: TLabel;
lbl_Noqty: TLabel;
CheckBox3: TCheckBox;
Label17: TLabel;
cmbx_WipWaster: TComboBox;
procedure DBGridEhKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure AdoQry_BodyBeforePost(DataSet: TDataSet);
procedure DBGridEhColExit(Sender: TObject);
procedure Act_autoExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender:TObject);
procedure AdoQry_BodyAfterPost(DataSet: TDataSet);
procedure cmbbx_WhPositionCodeExit(Sender: TObject);
procedure CheckBox1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure cmbbx_WhCodeExit(Sender: TObject);
procedure Act_NewExecute(Sender: TObject);
procedure DBGridEhExit(Sender: TObject);
procedure Extedt_BillnoChange(Sender: TObject);
procedure medt_DateChange(Sender: TObject);
procedure DataSourceDataChange(Sender: TObject; Field: TField);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure cmbbx_WhCodeChange(Sender: TObject);
procedure cmbbx_WhPositionCodeChange(Sender: TObject);
procedure Act_SaveExecute(Sender: TObject);
procedure DateCheck(Sender: TObject);
procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure cmbbx_WhEmployeeExit(Sender: TObject);
procedure CheckBox2Click(Sender: TObject);
procedure AdoQry_BodyAfterInsert(DataSet: TDataSet);
procedure AdoQry_SwApBeforePost(DataSet: TDataSet);
procedure AdoQry_SwApAfterInsert(DataSet: TDataSet);
procedure AdoQry_SwApAfterPost(DataSet: TDataSet);
procedure AdoQry_SwApBeforeEdit(DataSet: TDataSet);
procedure DataSource1DataChange(Sender: TObject; Field: TField);
procedure DBGridEh1GetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure DBGridEh1Exit(Sender: TObject);
procedure AdoQry_BodyBeforeEdit(DataSet: TDataSet);
procedure DBGridEh1ColExit(Sender: TObject);
procedure DBGridEh1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure CheckBox3Click(Sender: TObject);
procedure CheckBox3Exit(Sender: TObject);
procedure cmbx_WipWasterChange(Sender: TObject);
private
IOType,oldmoRequestlineqty,oldswApmoRequestqty,oldbodymoRequestqty:real;
swApflag,MoLinestatus:integer;
bodyItemListid,BillTypeCode,oldwhCode,oldWhPosition,oldEmployee:string;
IsAfterprint:boolean;
WipWaster:integer;
procedure checkbodyIOType;
procedure checkswApIOType;
procedure checkcoCurrentqty;
procedure updatebodymoRequestqty;
procedure checkswAp;
procedure InitCmbbx_WhPositionCode(whCode:string);
procedure InitCmbbx_WhEmployee(whCode:string);
procedure showdbgrid;
procedure initprint;
procedure updateswApmoRequestqty;
{ Private declarations }
public
tmp_Status:string;
procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;//设置各种状态下那些控件Enable
procedure InitControls; Override;//初始化Form上所有控件
procedure SaveData; Override;
{ Public declarations }
end;
var
Frm_Sfc_MnRequest_B1: TFrm_Sfc_MnRequest_B1;
implementation
uses Sys_Global, Sfc_MnRequest1,Inv_Global,Sfc_MnOut_NotSave_P, Sfc_MnOut_P;
{$R *.DFM}
procedure TFrm_Sfc_MnRequest_B1.InitCmbbx_WhPositionCode(whCode:string);
begin
//初始化货位,根据当前传入的仓库号码,选出不是待检货位及不是拉式货位的货位
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select WhPositionCode,WhPositionName '+
' from WhPosition '+
' where whCode='''+whCode+''''+
' and WhPositionType<>1 '+
' and BackFlushWhP=0 '+
' Order by WhPositionCode ');
open;
cmbbx_WhPositionCode.clear;
if not Eof then
begin
First;
while not Eof do
begin
cmbbx_WhPositionCode.Items.Add(fieldbyname('WhPositionCode').asstring+' '+fieldbyname('WhPositionName').asstring);
Next;
end;
end;
end;
cmbbx_WhPositionCode.Itemindex:=0;
end;
procedure TFrm_Sfc_MnRequest_B1.InitCmbbx_WhEmployee(whCode:string);
begin
//初始化仓管员,从物料主文件中选出当前仓库的缺省仓管员,可以为空
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select distinct i.wh_EmployeeCode,e.EmployeeName '+
' from Item i,Employee e '+
' where whCode='''+whCode+''''+
' and i.wh_EmployeeCode is not null '+
' and i.wh_EmployeeCode=e.EmployeeCode '+
' Order by i.wh_EmployeeCode');
open;
cmbbx_WhEmployee.clear;
cmbbx_WhEmployee.Items.Add('');
if not Eof then
begin
First;
while not Eof do
begin
cmbbx_WhEmployee.Items.Add(fieldbyname('wh_EmployeeCode').asstring+' '+fieldbyname('EmployeeName').asstring);
Next;
end;
cmbbx_WhEmployee.Itemindex:=0;
end;
end;
end;
procedure TFrm_Sfc_MnRequest_B1.Showdbgrid;
var
sql_text,tmp_WhEmployee,tmp_DeptCode,tmpfields,oncheckpositionCode:string;
begin
//取待检货位的代码
with AdoQry_tmp do
begin
Close;
sql.text:='select WhPositionCode from WhPosition where WhPositionType=1 '+
'and whCode='+QuotedStr(getCode(cmbbx_WhCode.text));
open;
oncheckpositionCode:=fieldbyname('WhPositionCode').asstring;
end;
//取数据显示于DBGRID
//根据仓库代码,货位代码决定选出数据表中的英文字段名,用于下面的SQL语名组合
tmpfields:=getInvfield(AdoQry_tmp,getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text),'CurrentInv');
//如果仓库管理员为空或不为空情况下的SQL语名中仓管员条件组合
if cmbbx_WhEmployee.text<>'' then
tmp_WhEmployee:=' and i.wh_EmployeeCode='''+getCode(cmbbx_WhEmployee.text)+''''
else
tmp_WhEmployee:='';
//按部门过滤条件的组合
if checkbox2.Checked then
tmp_DeptCode:=' and (m.DeptCode in ('''+getCode(lbl_Dept.Caption)+''','''+copy(getCode(lbl_Dept.Caption),1,length(getCode(lbl_Dept.Caption))-2)+''')) '
else
tmp_DeptCode:='';
{
数据的取法:
1。创建一个存放数据的临时表
2。从生产计划中的MNItemList中取出满足条件的记录,存放在临时表中
先取不是替代件的记录,后取替代虚项,而实际的替代件放在第二DBGRID中显示。
3。由于取出来的数据要根据父,子代码在DBGRID中显示结构虚项及替代虚项,因此用CUOSOR
对数据进行构造,只要是对两个状态标志字段STATUS,STATUS1进行付值。
STATUS STATUS1
A A
A1 A
A1 A
B B
B1 B
这样出来后,Order BY 后就得到显示的结果,用红色字体显示结构虚项
蓝色字体显示替代虚项
}
try
Executesql(AdoQry_tmp,'drop table #tmp1,#Sfcmo',1);
except
end;
//显示库存不为零的数据
if checkbox1.checked =True then
begin
//如果领料单中有虚项
sql_text:=
'set noCount on '+
' create table #tmp1(Bomlevel int,mono varchAr(16),MoLineno int ,ItemCode varchAr(16) ,'+
'ite_ItemCode varchAr(16) null,BilllineremArk varchAr(250) null,'+
'Bomqty float null,BomScrAp_Percent float null,moCtrlqty float null,'+
'MoRealqty float null,moRequestqty float null,alterNative int,'+
'ItemListid int,Parentid int,Batchno varchAr(16)) '+
' insert #tmp1(Bomlevel,mono,MoLineno,ItemCode,ite_ItemCode,BilllineremArk,Bomqty,BomScrAp_Percent,moCtrlqty,MoRealqty,moRequestqty,alterNative,ItemListid,Parentid) '+
' select case when m.Parentid=0 then m.Parentid else -1 end ,m.mono,'+
'm.MoLineno,'+
'm.ItemCode,'+
'm.ite_ItemCode,'+
'm.BilllineremArk,'+
'b.Bomqty, '+
'b.BomScrAp_Percent,'+
'm.moCtrlqty,'+
'm.MoRealqty,'+
'm.moRequestqty,'+
'm.alterNative,'+
'm.ItemListid,'+
'm.Parentid '+
' from mnItemList m '+
' join Bom b on m.ite_ItemCode=b.ite_ItemCode and m.ItemCode=b.ItemCode '+
' where m.mono='''+lbl_Mono.Caption+''' '+
' and m.MoLineno='+lbl_MoLineno.Caption+
//' and m.alterNative=0 '+
// ' and m.moCtrlqty>0 '+
tmp_DeptCode+
' while exists(select Bomlevel from #tmp1 where Bomlevel<0) '+
' begin ' +
' update #tmp1 ' +
' set Bomlevel=tt.Bomlevel+1 ' +
' from #tmp1,#tmp1 tt ' +
' where #tmp1.ite_ItemCode=tt.ItemCode ' +
' and tt.Bomlevel>=0 ' +
' end ' +
//把代换项加入到临时表中
{ ' insert #tmp1(mono,MoLineno,ItemCode,ite_ItemCode,BilllineremArk,moCtrlqty,MoRealqty,moRequestqty,alterNative,ItemListid,Parentid) '+
' select m.mono,'+
'm.MoLineno,'+
'm.ItemCode,'+
'm.ite_ItemCode,'+
'm.BilllineremArk,'+
'm.moCtrlqty,'+
'm.MoRealqty,'+
'm.moRequestqty,'+
'm.alterNative,'+
'm.ItemListid,'+
'm.Parentid'+
' from mnItemList m '+
' where m.mono='''+lbl_Mono.Caption+''' '+
' and m.MoLineno='+lbl_MoLineno.Caption+
' and m.alterNative=1 '+
' and m.moCtrlqty>0 '+
tmp_DeptCode+
' insert #tmp1(mono,MoLineno,ItemCode) '+
' select distinct mono,MoLineno,ite_ItemCode from #tmp1 '+
' where ite_ItemCode<>'''''+
' and alterNative=0 '+
' and ite_ItemCode<>'''+getCode(lbl_Item.Caption)+''''+
' select distinct ite_ItemCode into #tmp2 '+
' from #tmp1 '+
' where ite_ItemCode<>'''''+
' and alterNative=0 '+
' and ite_ItemCode<>'''+getCode(lbl_Item.Caption)+''''+
' declAre Item_Cursor cursor for select ite_ItemCode from #tmp2 '+
' open Item_Cursor '+
' declAre @tmp_ItemCode varchAr(16) '+
' declAre @m int '+
' set @m=65 '+
' fetch Item_Cursor into @tmp_ItemCode '+
' while @@fetch_Status=0 '+
' begin '+
' update #tmp1 set status=chAr(@m),status1=chAr(@m) where ItemCode=@tmp_ItemCode '+
' update #tmp1 set status=chAr(@m)+''1'' where ite_ItemCode=@tmp_ItemCode '+
' set @m=@m+1 '+
' fetch Item_Cursor into @tmp_ItemCode '+
' end '+
' Close Item_Cursor '+
' deallocate Item_Cursor '+}
' select * into #Sfcmo from ( '+
' select t.Bomlevel,t.mono,'+
't.MoLineno,'+
't.ItemListid,'+
't.Parentid,'+
't.ItemCode,'+
'space(t.Bomlevel*2)+t.ItemCode as tmpItemCode,'+
't.ite_ItemCode,'+
{ 'case '+
' when (status1 is not null and alterNative=0) then ''+''+t.ItemCode '+
' when (status1 is null and alterNative=1) then ''-''+t.ItemCode '+
' else t.ItemCode end tmpItemCode,'+}
'i.ItemName,'+
'i.wh_EmployeeCode+'+''' '''+'+e.EmployeeName as wh_EmployeeCode,'+
'i.ItemCode2,'+
'u.UomName,'+
't.BilllineremArk,'+
't.Bomqty, '+
't.BomScrAp_Percent, '+
'round(t.moCtrlqty,0) as moCtrlqty,'+
't.MoRealqty,'+
't.moRequestqty, '+
't.alterNative,'+
'isnull(c.'+tmpfields+',0.00) as onhandInv,'+
'isnull(c1.onCheckInv,0.00) as onCheckInv,'+
't.Batchno '+
// 't.status '+
'from #tmp1 t'+
' join Item i '+
' on t.ItemCode=i.ItemCode '+
// ' and i.whCode='''+getCode(cmbbx_WhCode.text)+''' '+
tmp_WhEmployee+
' left join Uom u '+
' on i.UomCode=u.UomCode '+
' join CurrentInv c '+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -