V
victor9871
Unregistered / Unconfirmed
GUEST, unregistred user!
procedure TFrm_A_Sale.CreateReport;var TempCity,TempCode,TempIn,TempOut,TempCityIn,TempCityOut,n,nIn,nout :string; i,j :integer;begin DBGridEh1.Columns.Clear; Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'delete from T_FieldShow where TableName=''TempDetail'''); try Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'drop table T_TempDetail'); Except end; Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES (''IDD'',''序号'',0,50,''TempDetail'',0)'); Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES (''Goodsname'',''设备名称'',1,200,''TempDetail'',0)'); Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES (''SortCount'',''总数量'',1,50,''TempDetail'',1)'); Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES (''SortCountIn'',''保内'',1,50,''TempDetail'',1)'); Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES (''SortCountOut'',''保外'',1,50,''TempDetail'',1)'); try Frm_Data.ExecDataSet(Frm_Data.Qry_Temp,'Create table T_TempDetail (IDD Integer NULL,Goodsname varchar(100),SortCount float,SortCountIn float,SortCountOut float)'); Except end; for i := 0 to CheckListBox1.Items.Count - 1 do begin if CheckListBox1.Checked then begin TempCity:=CheckListBox1.Items; TempCityIn:=TempCity+'|保内'; TempCityOut:=TempCity+'|保外'; TempIn:='TempIn'+inttostr(i); TempOut:='TempOut'+inttostr(i); try Frm_Data.ExecDataSet(Frm_Data.Qry_Sql,'ALTER table T_TempDetail Add '+TempIn+' float,'+TempOut+' float'); Except end; Frm_Data.ExecDataSet(Frm_Data.Qry_Sql,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES ('''+TempIn+''','''+TempCityIn+''',1,50,''TempDetail'',1)'); Frm_Data.ExecDataSet(Frm_Data.Qry_Sql,'Insert Into T_FieldShow(field,name,show,width,TableName,SumField) VALUES ('''+TempOut+''','''+TempCityOut+''',1,50,''TempDetail'',1)'); if Combo_gys.Text='' then Frm_Data.OpenDataSet(Frm_Data.Qry_Str,'select DISTINCT goodsname from view1 where [model]='''+TempCity+'''') else Frm_Data.OpenDataSet(Frm_Data.Qry_Str,'select DISTINCT goodsname,name from view1 where [name]='''+Combo_gys.Text+''' and [model]='''+TempCity+''''); Frm_Data.Qry_Str.First; For j:=1 to Frm_Data.Qry_Str.RecordCount do begin TempCode:=Frm_Data.Qry_Str.FieldByName('Goodsname').AsString; n:='0'; nIn:='0'; nOut:='0'; Frm_Data.OpenDataSet(Frm_Data.Qry_FieldShow,'select Goodsname,SortCount,SortCountIn,SortCountOut from T_TempDetail where Goodsname='''+TempCode+''''); if Frm_Data.Qry_FieldShow.RecordCount=0 then begin Frm_Data.ExecDataSet(Frm_Data.Qry_Sql,'Insert Into T_TempDetail(Goodsname) VALUES ('''+TempCode+''')'); end; Frm_Data.OpenDataSet(Frm_Data.Qry_TempIn,'select [Number] from view1 where [model]='''+TempCity+''' and Goodsname='''+TempCode+''' and buyDate>='''+DateToStr(Date1.Date)+'''');//保内 Frm_Data.OpenDataSet(Frm_Data.Qry_TempOut,'select [Number] from view1 where [model]='''+TempCity+''' and Goodsname='''+TempCode+''' and buyDate<='''+DateToStr(Date1.Date)+'''');//保外 Frm_Data.ExecDataSet(Frm_Data.Qry_TempBill,'Update T_TempDetail set '+TempIn+'='+inttostr(Frm_Data.Qry_TempIn.RecordCount)+','+TempOut+'='+inttostr(Frm_Data.Qry_TempOut.RecordCount)+' where [Goodsname]='''+TempCode+''''); if Frm_Data.Qry_FieldShow.FieldByName('SortCount').AsString='' then n:=inttostr(strtoint+Frm_Data.Qry_TempIn.RecordCount+Frm_Data.Qry_TempOut.RecordCount) else n:=inttostr(strtoint+Frm_Data.Qry_TempIn.RecordCount+Frm_Data.Qry_TempOut.RecordCount+Frm_Data.Qry_FieldShow.FieldByName('SortCount').AsInteger); //某货品的总数 if Frm_Data.Qry_FieldShow.FieldByName('SortCountIn').AsString='' then nIn:=inttostr(strtoint(nIn)+Frm_Data.Qry_TempIn.RecordCount) else nIn:=inttostr(strtoint(nIn)+Frm_Data.Qry_TempIn.RecordCount+Frm_Data.Qry_FieldShow.FieldByName('SortCountIn').AsInteger); if Frm_Data.Qry_FieldShow.FieldByName('SortCountOut').AsString='' then nOut:=inttostr(strtoint(nOut)+Frm_Data.Qry_TempOut.RecordCount) else nOut:=inttostr(strtoint(nOut)+Frm_Data.Qry_TempOut.RecordCount+Frm_Data.Qry_FieldShow.FieldByName('SortCountOut').AsInteger); Frm_Data.ExecDataSet(Frm_Data.Qry_Sql,'Update T_TempDetail set [SortCount]='+n+',[SortCountIn]='+nIn+',[SortCountOut]='+nOut+' where [Goodsname]='''+TempCode+''''); Frm_Data.Qry_Str.Next; end; end; //-------------------------------------- end; Frm_Data.OpenDataSet(Frm_Data.Qry_Str,'select * from T_FieldShow where show=1 and TableName=''TempDetail'' order by ID'); Frm_Data.Qry_Str.First; For i:=0 to Frm_Data.Qry_Str.RecordCount-1 do begin TempCode:=Frm_Data.Qry_Str.FieldByName('ID').AsString; Frm_Data.ExecDataSet(Frm_Data.Qry_TempBill,'Update T_FieldShow set [ShowID]='+inttostr(i)+' where [ID]='+TempCode+''); Frm_Data.Qry_Str.Next; end; Frm_Data.OpenDataSet(Frm_Data.Qry_Str,'select * from T_TempDetail order by Goodsname'); Frm_Data.Qry_Str.First; For i:=1 to Frm_Data.Qry_Str.RecordCount do begin TempCode:=Frm_Data.Qry_Str.FieldByName('Goodsname').AsString; Frm_Data.ExecDataSet(Frm_Data.Qry_TempBill,'Update T_TempDetail set [IDD]='+inttostr(i)+' where Goodsname='''+TempCode+''''); Frm_Data.Qry_Str.Next; end; Frm_Data.OpenDataSet(Qry_Count,'select * from T_TempDetail order by Goodsname'); Frm_main.AddToGridEh(DBGridEh1,Qry_Count,'TempDetail');end;