Пример подготовки файла для отчета в GRmanager
Принцип следующий создаем модуль выполняющий запрос к источнику
данных и вызываем Genrep для построения отчета
Ниже приведен пример такого модуля для приложения "Вектор"
local sCon
kw = .f. && Код возврата
* подключение
if TYPE("lnConn") <> 'N'
sCon= _rep.GetConnection('vector') && получаем строку соединения из таблички rep\connects
if empty(sCon)
return
endif
PUBLIC lnConn
lnConn = - 1
lnConn= SQLSTRINGCONNECT(sCon,.t.)
endif
if lnConn< 0
messagebox("Проверьте параметры соединеия c базой данных")
return
endif
set safety off
m.kw = .f.
* парамеры для сохранения
IF TYPE("sPar") <> 'O'
PUBLIC sPar
sPar = CreateObject("Custom")
sPar.AddProperty('dep',1)
sPar.AddProperty('fob',1)
sPar.AddProperty('fac',0)
sPar.AddProperty('nabor',0)
sPar.AddProperty('dis',0)
sPar.AddProperty('typ',0)
sPar.AddProperty('sem',0)
ENDIF
oform = _ParForm
lNameForm = oform.Caption
oform.release
*----------------------------------------------------------------------------------------------
* Запросы
*----------------------------------------------------------------------------------------------
lresult = SQLEXEC(lnConn, "select DepartmentID as ncode, left(DepartmentName,100) as nname from vwListOrganizationDepartment" , "cur_dep")
if lresult = -1
_REP.get_error()
return
ENDIF
lresult = SQLEXEC(lnConn, "select facultyID ncode, left(facultyName,100) nname from vwListFaculty" , "cur_fac")
if lresult = -1
_REP.get_error()
return
endif
lresult = SQLEXEC(lnConn, "select FormID as ncode ,left(FormName,100) as nname from vwListFormEducation " , "cur_form")
if lresult = -1
_REP.get_error()
return
ENDIF
lresult = SQLEXEC(lnConn, "select distinct semester ncode,(CASE WHEN semester <10 THEN '0' ELSE '' END) + convert(char(2),semester) + ' семестр. '+' Курс '+ convert(char(2),course) nname from vwListRecruitment_Course_Semester" , "cur_sem")
if lresult = -1
_REP.get_error()
return
ENDIF
*----------------------------------------------------------------------------------------------
* Параметры
*----------------------------------------------------------------------------------------------
oform = CREATEOBJECT("_wout")
oform.Caption= lNameForm
oform.SetCmd('Далее')
pDep = CREATEOBJECT('oParametr','Подразделение:','cur_dep', 'ncode', 'nname', sPar.dep)
oform.AddParameter(pDep)
pFac = CREATEOBJECT('oParametr','Факультет:','cur_fac', 'ncode', 'nname',sPar.fac)
oform.AddParameter(pFac)
pForm = CREATEOBJECT('oParametr','Форма:','cur_form', 'ncode', 'nname', sPar.fob)
oform.AddParameter(pForm)
pSem = CREATEOBJECT('oParametr','Текущий Семестр:','cur_sem', 'ncode', 'nname',sPar.sem)
oform.AddParameter(pSem )
*----------------------------------------------------------------------------------------------
* Окно ввода параметров
*----------------------------------------------------------------------------------------------
oform.Show(1)
IF m.kw = .f. THEN
return
ENDIF
m.kw = .f.
* получили параметры
lDepId = pDep.val_code
lFacId = pFac.val_code
lFormID = pForm.val_code
lSemID = pSem.val_code
n_Sem = pSem.val_name
if lDepId = 0 or lFormID = 0 or lFacId = 0 or lSemId = 0
return
ENDIF
sPar.dep =lDepId
sPar.fob =lFormID
sPar.fac =lFacId
sPar.sem =lSemID
lUsl = " WHERE (DepartmentID = "+str(lDepID)+") AND (FacultyID = "+str(lFacID)+ ") AND (FormID = "+str(lFormID)+ " ) AND (SemID = "+str(lSemID)+ ") "
*----------------------------------------------------------------------------------------------
* Запрос 2
*----------------------------------------------------------------------------------------------
lresult = SQLEXEC(lnConn, "select distinct gr ncode, gr nname from vp_students " + lUsl, "cur_gr")
if lresult = -1
_REP.get_error()
return
ENDIF
s = " SELECT SpecializationID ncode, left(SpecializationName,30) as nname "
s = s +" FROM vwlistSpecialization "
s = s +" WHERE (SpecializationID IN "
s = s +" (SELECT DISTINCT SpecializationID FROM vwlistEducationFaculty "
s = s +" WHERE (FacultyID IN (SELECT FacultyID FROM vwlistFaculty WHERE FacultyID = "+str(lFacID)+")))) "
lresult = SQLEXEC(lnConn, s ,"cur_spez")
if lresult = -1
_REP.get_error()
return
ENDIF
m.kw =.f.
sNameForm = pForm.val_name
*----------------------------------------------------------------------------------------------
* Параметры 2
*----------------------------------------------------------------------------------------------
oform = CREATEOBJECT("_wout")
oform.Caption= lNameForm
pGroup = CREATEOBJECT('oParametr','Группа :','cur_gr', 'ncode', 'nname','')
oform.AddParameter(pGroup)
pSpez = CREATEOBJECT('oParametr','Специализация :','cur_spez', 'ncode', 'nname','')
oform.AddParameter(pSpez)
ltKur = right(alltrim(n_sem),1)
pKur = CREATEOBJECT('oParametr','Курс :','', '', '',ltKur)
oform.AddParameter(pKur)
pName = CREATEOBJECT('oParametr','Дата строкой:','', '', '',' c "01" июля 2011 г. по "30" июля 2011 г.')
oform.AddParameter(pName )
*----------------------------------------------------------------------------------------------
* Форма 2
*----------------------------------------------------------------------------------------------
m.kw = .f.
oform.Show(1)
IF m.kw = .f. THEN
return
ENDIF
lGroup = alltrim(pGroup.val_code)
lUslGr = ""
if !empty(lGroup)
lUslGr = lUslGr + " AND (Gr = '"+lGroup+"') "
endif
lSpezID = pSpez.val_code
if !empty(lSpezID )
lUslGr = lUslGr + " AND (SpezID= "+str(lSpezID) +") "
endif
lSem = pSem.val_name
lKur = pKur.val_name
lGod = "" &&pGod.val_name
lData = pName.val_name
*messagebox(lSem)
*----------------------------------------------------------------------------------------------
* Основной запрос групп
*---------------------------------------------------------------------------------------------
s=""
s= s+ " select *, "
s= s+ " 'zach' = (select top 1 AgreementDocumentNumber from dbo.AgreementStudentDocument a(nolock) where a.TypeDocumentID=14 and a.StudentID=ag.StudentID and a.RecStatus <> 'del'), "
s= s+ " 'tel' = (select top 1 left(TelephoneNumber,150) from vwTelephonePerson where PersonID = ag.StudentID ) "
s= s+ " from vp_students ag"
s= s+ lUsl + lUslGr
s= s+ " order by gr, sfio "
lStr = s
*-------------------------------------------
* Выгружаем в temp.dbf
*-------------------------------------------
lresult = SQLEXEC(lnConn, lStr , "cur_tmp")
if lresult = -1
_REP.get_error()
return
else
if used("cur_tmp")
SELECT lSemID as Sem, lKur as Kurs, lGod as God , lData as DT, cur_tmp.* FROM cur_tmp INTO TABLE temp.dbf
USE IN temp
endif
endif
kw = .t.
* После окончания исполняемого кода производтся вызов шаблона Genrep
* по имени ?local sCon
kw = .f. && Код возврата
* подключение
if TYPE("lnConn") <> 'N'
sCon= _rep.GetConnection('vector') && получаем строку соединения из таблички rep\connects
if empty(sCon)
return
endif
PUBLIC lnConn
lnConn = - 1
lnConn= SQLSTRINGCONNECT(sCon,.t.)
endif
if lnConn< 0
messagebox("Проверьте параметры соединеия c базой данных")
return
endif
set safety off
m.kw = .f.
* парамеры для сохранения
IF TYPE("sPar") <> 'O'
PUBLIC sPar
sPar = CreateObject("Custom")
sPar.AddProperty('dep',1)
sPar.AddProperty('fob',1)
sPar.AddProperty('fac',0)
sPar.AddProperty('nabor',0)
sPar.AddProperty('dis',0)
sPar.AddProperty('typ',0)
sPar.AddProperty('sem',0)
ENDIF
oform = _ParForm
lNameForm = oform.Caption
oform.release
*----------------------------------------------------------------------------------------------
* Запросы
*----------------------------------------------------------------------------------------------
lresult = SQLEXEC(lnConn, "select DepartmentID as ncode, left(DepartmentName,100) as nname from vwListOrganizationDepartment" , "cur_dep")
if lresult = -1
_REP.get_error()
return
ENDIF
lresult = SQLEXEC(lnConn, "select facultyID ncode, left(facultyName,100) nname from vwListFaculty" , "cur_fac")
if lresult = -1
_REP.get_error()
return
endif
lresult = SQLEXEC(lnConn, "select FormID as ncode ,left(FormName,100) as nname from vwListFormEducation " , "cur_form")
if lresult = -1
_REP.get_error()
return
ENDIF
lresult = SQLEXEC(lnConn, "select distinct semester ncode,(CASE WHEN semester <10 THEN '0' ELSE '' END) + convert(char(2),semester) + ' семестр. '+' Курс '+ convert(char(2),course) nname from vwListRecruitment_Course_Semester" , "cur_sem")
if lresult = -1
_REP.get_error()
return
ENDIF
*----------------------------------------------------------------------------------------------
* Параметры
*----------------------------------------------------------------------------------------------
oform = CREATEOBJECT("_wout")
oform.Caption= lNameForm
oform.SetCmd('Далее')
pDep = CREATEOBJECT('oParametr','Подразделение:','cur_dep', 'ncode', 'nname', sPar.dep)
oform.AddParameter(pDep)
pFac = CREATEOBJECT('oParametr','Факультет:','cur_fac', 'ncode', 'nname',sPar.fac)
oform.AddParameter(pFac)
pForm = CREATEOBJECT('oParametr','Форма:','cur_form', 'ncode', 'nname', sPar.fob)
oform.AddParameter(pForm)
pSem = CREATEOBJECT('oParametr','Текущий Семестр:','cur_sem', 'ncode', 'nname',sPar.sem)
oform.AddParameter(pSem )
*----------------------------------------------------------------------------------------------
* Окно ввода параметров
*----------------------------------------------------------------------------------------------
oform.Show(1)
IF m.kw = .f. THEN
return
ENDIF
m.kw = .f.
* получили параметры
lDepId = pDep.val_code
lFacId = pFac.val_code
lFormID = pForm.val_code
lSemID = pSem.val_code
n_Sem = pSem.val_name
if lDepId = 0 or lFormID = 0 or lFacId = 0 or lSemId = 0
return
ENDIF
sPar.dep =lDepId
sPar.fob =lFormID
sPar.fac =lFacId
sPar.sem =lSemID
lUsl = " WHERE (DepartmentID = "+str(lDepID)+") AND (FacultyID = "+str(lFacID)+ ") AND (FormID = "+str(lFormID)+ " ) AND (SemID = "+str(lSemID)+ ") "
*----------------------------------------------------------------------------------------------
* Запрос 2
*----------------------------------------------------------------------------------------------
lresult = SQLEXEC(lnConn, "select distinct gr ncode, gr nname from vp_students " + lUsl, "cur_gr")
if lresult = -1
_REP.get_error()
return
ENDIF
s = " SELECT SpecializationID ncode, left(SpecializationName,30) as nname "
s = s +" FROM vwlistSpecialization "
s = s +" WHERE (SpecializationID IN "
s = s +" (SELECT DISTINCT SpecializationID FROM vwlistEducationFaculty "
s = s +" WHERE (FacultyID IN (SELECT FacultyID FROM vwlistFaculty WHERE FacultyID = "+str(lFacID)+")))) "
lresult = SQLEXEC(lnConn, s ,"cur_spez")
if lresult = -1
_REP.get_error()
return
ENDIF
m.kw =.f.
sNameForm = pForm.val_name
*----------------------------------------------------------------------------------------------
* Параметры 2
*----------------------------------------------------------------------------------------------
oform = CREATEOBJECT("_wout")
oform.Caption= lNameForm
pGroup = CREATEOBJECT('oParametr','Группа :','cur_gr', 'ncode', 'nname','')
oform.AddParameter(pGroup)
pSpez = CREATEOBJECT('oParametr','Специализация :','cur_spez', 'ncode', 'nname','')
oform.AddParameter(pSpez)
ltKur = right(alltrim(n_sem),1)
pKur = CREATEOBJECT('oParametr','Курс :','', '', '',ltKur)
oform.AddParameter(pKur)
pName = CREATEOBJECT('oParametr','Дата строкой:','', '', '',' c "01" июля 2011 г. по "30" июля 2011 г.')
oform.AddParameter(pName )
*----------------------------------------------------------------------------------------------
* Форма 2
*----------------------------------------------------------------------------------------------
m.kw = .f.
oform.Show(1)
IF m.kw = .f. THEN
return
ENDIF
lGroup = alltrim(pGroup.val_code)
lUslGr = ""
if !empty(lGroup)
lUslGr = lUslGr + " AND (Gr = '"+lGroup+"') "
endif
lSpezID = pSpez.val_code
if !empty(lSpezID )
lUslGr = lUslGr + " AND (SpezID= "+str(lSpezID) +") "
endif
lSem = pSem.val_name
lKur = pKur.val_name
lGod = "" &&pGod.val_name
lData = pName.val_name
*----------------------------------------------------------------------------------------------
* Основной запрос групп
*---------------------------------------------------------------------------------------------
s=""
s= s+ " select *, "
s= s+ " 'zach' = (select top 1 AgreementDocumentNumber from dbo.AgreementStudentDocument a(nolock) where a.TypeDocumentID=14 and a.StudentID=ag.StudentID and a.RecStatus <> 'del'), "
s= s+ " 'tel' = (select top 1 left(TelephoneNumber,150) from vwTelephonePerson where PersonID = ag.StudentID ) "
s= s+ " from vp_students ag"
s= s+ lUsl + lUslGr
s= s+ " order by gr, sfio "
lStr = s
*-------------------------------------------
* Выгружаем в temp.dbf
*-------------------------------------------
lresult = SQLEXEC(lnConn, lStr , "cur_tmp")
if lresult = -1
_REP.get_error()
return
else
if used("cur_tmp")
SELECT lSemID as Sem, lKur as Kurs, lGod as God , lData as DT, cur_tmp.* FROM cur_tmp INTO TABLE temp.dbf
USE IN temp
endif
endif
kw = .t.
* После окончания исполняемого кода производтся вызов шаблона Genrep
* по имени файла исходного кода
файла исходного кода
|