This is the Fortran code that I modified.
The problem is the code can not open the text file.
I am getting the following error:
The message is: RunCode: Fail to run.. At line 123 of file <unit = 90, file = 'cunnette_xyz.txt'> Fortran runtime error: End of file
The file is below in 4368 rows (decimals are the same for three columns):
602340.440000,129706.190000,28.892939
602340.880000,129706.390000,28.955128
602884.500000,128780.700000,29.876873
602884.380000,128781.190000,29.875114
602884.250000,128781.660000,29.885448
602884.130000,128782.150000,29.895996
602883.940000,128782.630000,29.899380
602883.810000,128783.120000,29.903221
602883.690000,128783.590000,29.907070
602883.560000,128784.080000,29.910931
602883.440000,128784.560000,29.914803
602883.310000,128785.050000,29.918684
602883.190000,128785.520000,29.922575
602883.060000,128786.010000,29.926479
602882.940000,128786.490000,29.930393
602882.810000,128786.980000,29.934317
602882.630000,128787.450000,29.938253
602882.500000,128787.940000,29.942202
.
.
.
the program is:
----------------------------
USE BIEF
USE DECLARATIONS_TELEMAC2D
IMPLICIT NONE
INTEGER LNG,LU, K, ITRAC,I, NSOM,J, NLINE, NDOWN
DOUBLE PRECISION, PARAMETER:: BATHY_RADIER_up= 29.84D0
DOUBLE PRECISION, PARAMETER:: DEPTH_up = 2.15D0
REAL A(5000),B(5000),C(5000)
DOUBLE PRECISION XPOLYD(14), YPOLYD(14), INPOLYD(14)
COMMON/INFO/LNG,LU
DOUBLE PRECISION XPOLY(6), YPOLY(6),COTE_RADIER_up
NSOM = 6
XPOLY(1) = 602883.13
XPOLY(2) = 602886.15
XPOLY(3) = 602887.15
XPOLY(4) = 602905.46
XPOLY(5) = 602902.52
XPOLY(6) = 602884.13
YPOLY(1) = 128779.99
YPOLY(2) = 128780.80
YPOLY(3) = 128777.12
YPOLY(4) = 128741.21
YPOLY(5) = 128739.75
YPOLY(6) = 128775.96
AT = 0.D0
CALL OS( 'X=0 ' , X=U )
CALL OS( 'X=0 ' , X=V )
IF(CDTINI(1:10).EQ.'COTE NULLE'.OR.
* CDTINI(1:14).EQ.'ZERO ELEVATION') THEN
CALL OS( 'X=C ' , H , H , H , 0.D0 )
CALL OS( 'X=X-Y ' , H , ZF , H , 0.D0 )
ELSEIF(CDTINI(1:14).EQ.'COTE CONSTANTE'.OR.
* CDTINI(1:18).EQ.'CONSTANT ELEVATION') THEN
CALL OS( 'X=C ' , H , H , H , COTINI )
CALL OS( 'X=X-Y ' , H , ZF , H , 0.D0 )
ELSEIF(CDTINI(1:13).EQ.'HAUTEUR NULLE'.OR.
* CDTINI(1:10).EQ.'ZERO DEPTH') THEN
CALL OS( 'X=C ' , H , H , H , 0.D0 )
ELSEIF(CDTINI(1:17).EQ.'HAUTEUR CONSTANTE'.OR.
* CDTINI(1:14).EQ.'CONSTANT DEPTH') THEN
CALL OS( 'X=C ' , H , H , H , HAUTIN )
ELSEIF(CDTINI(1:13).EQ.'PARTICULIERES'.OR.
* CDTINI(1:10).EQ.'PARTICULAR'.OR.
* CDTINI(1:07).EQ.'SPECIAL') THEN
COTE_RADIER_up = BATHY_RADIER_up + DEPTH_up
input for coordinates of the downstream
NDOWN = 14
XPOLYD(1) = 602883.13
XPOLYD(2) = 602886.15
XPOLYD(3) = 602864.47
XPOLYD(4) = 602837.90
XPOLYD(5) = 602821.91
XPOLYD(6) = 602649.77
XPOLYD(7) = 602634.35
XPOLYD(8) = 602345.08
XPOLYD(9) = 602326.07
XPOLYD(10) = 602619.31
XPOLYD(11) = 602638.33
XPOLYD(12) = 602811.64
XPOLYD(13) = 602831.52
XPOLYD(14) = 602857.16
YPOLYD(1) = 128779.99
YPOLYD(2) = 128780.80
YPOLYD(3) = 128867.74
YPOLYD(4) = 128936.74
YPOLYD(5) = 128953.95
YPOLYD(6) = 129105.43
YPOLYD(7) = 129143.43
YPOLYD(8) = 129713.38
YPOLYD(9) = 129708.26
YPOLYD(10) = 129136.41
YPOLYD(11) = 129094.72
YPOLYD(12) = 128941.16
YPOLYD(13) = 128931.09
YPOLYD(14) = 128865.81
DO 10 J=1,NPOIN
IF(INPOLY(X(J),Y(J),XPOLY,YPOLY,NSOM)) THEN
write(lu,*) 'upstream is recognized....'
H%R(J)=MAX(0.D0,COTE_RADIER_up-ZF%R(J))
U%R(J)=0.0D0
ELSE
PRINT *, 'opening file'
OPEN(unit =90, FILE = 'cunnette_xyz.txt', FORM ='FORMATTED')
PRINT *, 'read now'
READ (90, *)NLINE
PRINT *, 'DO now'
READ (90, *) A(K),B(K),C(K)
IF(INPOLY(X(J),Y(J),XPOLYD,YPOLYD,NDOWN)) THEN
DO K=1,NLINE
H%R(K)=0.45D0
U%R(K)=0.D0
ENDDO
ELSE
H%R(J)=0.0D0
U%R(J)=0.0D0
ENDIF
ENDIF
write(lu,*) 'downstream ....',K,H%r(K)
10 CONTINUE
ELSE
IF(LNG.EQ.1) THEN
WRITE(LU,*) 'CONDIN : CONDITION INITIALE NON PREVUE : ',CDTINI
ENDIF
IF(LNG.EQ.2) THEN
WRITE(LU,*) 'CONDIN: INITIAL CONDITION UNKNOWN: ',CDTINI
ENDIF
STOP
ENDIF
IF(NTRAC.GT.0) THEN
DO ITRAC=1,NTRAC
CALL OS( 'X=C ' , X=T%ADR(ITRAC)%P , C=TRAC0(ITRAC) )
ENDDO
ENDIF
CALL OS( 'X=C ' , VISC , VISC , VISC , PROPNU )
RETURN
END
Related
*[I found that the error occurred at line 57, z2 = w12.a1 + b12; with incompatible array size,
May I know how to fix it? Basically the data is from the simulation on MATLAB Simulink, so the size of the array changes as we increase the inputs from the original code which only have 1 input type][1]
%% load training data (use training_data.mat attached file)
% initialize number of nodes, weights, biases, errors and gradients.
%epochs and mini-batch size
clc
data = [out.dutycycle out.voltage out.current]
sample=1000;
labels = data(1:sample,1);
y = labels'; %output vector
images = data(1:sample,2:3);
images(:,1) = images(:,1)/400;
images(:,2) = images(:,2)/100;
images = images'; %Input vectors
hn1 = 80; %Number of neurons in the first hidden layer
hn2 = 60; %Number of neurons in the second hidden layer
%Initializing weights and biases
w12 = randn(hn1,1000).*sqrt(2/1000);
w23 = randn(hn2,hn1)*sqrt(2/hn1);
w34 = randn(1,hn2)*sqrt(2/hn2);
b12 = randn(hn1,1);
b23 = randn(hn2,1);
b34 = randn(1,1);
%learning rate
eta = 0.0058;
%Initializing errors and gradients
error4 = zeros(1,1);
error3 = zeros(hn2,1);
error2 = zeros(hn1,1);
errortot4 = zeros(1,1);
errortot3 = zeros(hn2,1);
errortot2 = zeros(hn1,1);
grad4 = zeros(1,1);
grad3 = zeros(hn2,1);
grad2 = zeros(hn1,1);
epochs = 50;
m = 10; %Minibatch size
%% Training phase
for k = 1:epochs %Outer epoch loop
batches = 1;
for j = 1:sample/m
error4 = zeros(1,1);
error3 = zeros(hn2,1);
error2 = zeros(hn1,1);
errortot4 = zeros(1,1);
errortot3 = zeros(hn2,1);
errortot2 = zeros(hn1,1);
grad4 = zeros(1,1);
grad3 = zeros(hn2,1);
grad2 = zeros(hn1,1);
for i = batches:batches+m-1 %Loop over each minibatch
%Feed forward
a1 = images(:,i);
z2 = w12.*a1 + b12;
a2 = elu(z2);
z3 = w23*a2 + b23;
a3 = elu(z3);
z4 = w34*a3 + b34;
a4 = elu(z4); %Output vector
%backpropagation
error4 = (a4-y(:,i)).*elup(z4);
error3 = (w34'*error4).*elup(z3);
error2 = (w23'*error3).*elup(z2);
errortot4 = errortot4 + error4;
errortot3 = errortot3 + error3;
errortot2 = errortot2 + error2;
grad4 = grad4 + error4*a3';
grad3 = grad3 + error3*a2';
grad2 = grad2 + error2*a1';
end
%Gradient descent
w34 = w34 - eta/m*grad4;
w23 = w23 - eta/m*grad3;
w12 = w12 - eta/m*grad2;
b34 = b34 - eta/m*errortot4;
b23 = b23 - eta/m*errortot3;
b12 = b12 - eta/m*errortot2;
batches = batches + m;
end
fprintf('Epochs:');
disp(k) %Track number of epochs
[images,y] = shuffle(images,y); %Shuffles order of the images for next epoch
end
disp('Training done!')
%note : create folder for this experiment and save the parameters.
% don't forget to keep the folder in matlab path!
save('wfour.mat','w34');
save('wthree.mat','w23');
save('wtwo.mat','w12');
save('bfour.mat','b34');
save('bthree.mat','b23');
save('btwo.mat','b12');
%% Testing phase
% load testing data with labels ... (use testing_data.mat attached file)
testsample = 100;
labels = test(1:testsample,1);
y = labels';
images = test(1:testsample,2:3);
images(:,1) = images(:,1)/400;
images(:,2) = images(:,2)/100;%copy
images = images';
we34 = matfile('wfour.mat');
w4 = we34.w34;
we23 = matfile('wthree.mat');
w3 = we23.w23;
we12 = matfile('wtwo.mat');
w2 = we12.w12;
bi34 = matfile('bfour.mat');
b4 = bi34.b34;
bi23 = matfile('bthree.mat');
b3 = bi23.b23;
bi12 = matfile('btwo.mat');
b2 = bi12.b12;
success = 0;
n = testsample;
for i = 1:n
out2 = elu(w2*images(:,i)+b2);
out3 = elu(w3*out2+b3);
out = elu(w4*out3+b4);
big = 0;
num = 0;
for k = 1:10
if out(k) > big
num = k-1;
big = out(k);
end
end
if labels(i) == num
success = success + 1;
end
end
fprintf('Accuracy: ');
fprintf('%f',success/n*100);
disp(' %');
%% ELU activation function
function fr = elu(x)
f = zeros(length(x),1);
for i = 1:length(x)
if x(i)>=0
f(i) = x(i);
else
f(i) = 0.2*(exp(x(i))-1);
end
end
fr = f;
end
%% derivative of the ELU activation function
function fr = elup(x)
f = zeros(length(x),1);
for i = 1:length(x)
if x(i)>=0
f(i) = 1;
else
f(i) = 0.2*exp(x(i));
end
end
fr = f;
end
%% SHuffle function
function [B,v] = shuffle(A,y)
cols = size(A,2);
P = randperm(cols);
B = A(:,P);
v = y(:,P);
end
Your help is much appreciated, thank you
MATLAB Error :
Arrays have incompatible sizes for this operation.
Error in ANN_PV_Array (line 57)
z2 = w12.*a1 + b12;
the summation to be written in a for loop is here
TCPC = csvread ( 'tcpc.csv' ) ;
TCPC ( : , 3) = TCPC ( : , 3 ) * (100000); %unit conversion
TCPC ( : , 5) = TCPC ( : , 5 ) * (1e-6); %unit conversion
%------------------------------------------------------------------------
% Within the outer loop we calculate Bii's Psat for all components
for i = 1 : n
W(i,i) = TCPC (SP(i),1) ;
TC(i,i) = TCPC (SP(i),2);
PC(i,i) = TCPC (SP(i),3);
ZC(i,i) = TCPC (SP(i),4);
VC(i,i) = TCPC (SP(i),5);
TR(i,i) = T/TC(i,i);
Bi(i,i) = (R*TC(i,i)/PC(i,i))*((.083-(.422/(TR(i,i)^(1.6))))+(W(i,i)*(.139-
((.0172/(TR(i,i)^4.2))))));
phisat(i) = exp((Bi(i,i)*P)/(R*T)) ;
for j = i+1 : n % Within the inner loop we calculate Bij's (mixed coefficients)
W(i,j) = (TCPC (SP(i),1) + TCPC (SP(j),1)) / 2 ;
TC(i,j) = sqrt((TCPC (SP(i),2) * (TCPC (SP(j),2)))) ;
ZC(i,j) = ((TCPC (SP(i),4) * (TCPC (SP(j),4))))/2 ;
VC(i,j) = (((TCPC (SP(i),5)^(1/3) * (TCPC (SP(j),5)^(1/3))))/2)^(3) ;
PC(i,j) = ((ZC(i,j) * R * (TC(i,j)))/VC(i,j)) ;
Bi(i,j) = ((R*TC(i,j))/PC(i,j))*((.083-(.422/(TR(i,i)^(1.6))))+(W(i,j)*(.139-
((.0172/(TR(i,i)^4.2))))));
Bi(j,i)=Bi(i,j); % as Bij=Bji we write the inner loop for j = i+1 : n and assigned
the values to rest
end
end
for i = 1 : n
B(i,i) = ((X(i))^2)*Bi(i,i);
a = sum(B(i,i));
for j = i+1 : n
B(i,j) = X(i)*X(j)*Bi(i,j);
B(j,i) = B(i,j);
b = sum(B(i,j)); c = sum(B(j,I));
end
end
Bfinal = a+b+c
%------------------------------------------------------------------------
% Having calculated all the second virial coefficients,
% we calculate the fugacity coefficients for all the components of the mixture
% use phi bar 1-3 and phi 1-3
for i = 1:n
for j = i+1 : n
phi(i,j) = exp((((-Bfinal+2*X(i)Bi(i) + 2X(j)))P)/(RT));
end
end
i got the same problem( develop with podofo in c++). after Insert multiple(2 times)digital signatures,i found there are 3 info——dictionary in the pdf file:
how to add two digital signature without invalidating the previous one?
thanks!
i open file in notepad++,and i found the different
the first: 97 0 obj<</Title(? G I S e r C l u bThR\n 2 0 1 4 0 7 2 0) /Author(edison qian) /Keywords(GISerClub) /Creator(? M i c r o s o f t ? W o r d 2 0 1 3)
/CreationDate(D:20150601200942+08'00') /ModDate(D:20150601200942+08'00') /Producer(? M i c r o s o f t ? W o r d 2 0 1 3) >>
the second: 97 0 obj<</Author(edison qian)/CreationDate(D:20150601200942+08'00')/Creator(? M i c r o s o f t ? W o r d 2 0 1 3)/Keywords(GISerClub)
/ModDate(D:20190426155330+08'00')/Producer(? M i c r o s o f t ? W o r d 2 0 1 3)/Title(? G I S e r C l u bThR\n 2 0 1 4 0 7 2 0)>>
the third: 97 0 obj<</Author(edison qian)/CreationDate(D:20150601200942+08'00')/Creator(? M i c r o s o f t ? W o r d 2 0 1 3)/Keywords(GISerClub)
/ModDate(D:20190426155428+08'00')/Producer(? M i c r o s o f t ? W o r d 2 0 1 3)/Title(? G I S e r C l u bThR\n 2 0 1 4 0 7 2 0)>>
my code:
bool pdfSign(PdfMemDocument* document,PdfOutputDevice* outputDevice,PKCS12* p12,RSA* rsa,int npage,PdfRect rect,int min_signature_size,const char* ImgFile/*,PdfDate& sigData*/)
{
PdfInfo* pInfo = document->GetInfo();
TKeyMap itm = pInfo->GetObject()->GetDictionary().GetKeys();
PdfObject* pobj = pInfo->GetObject()->GetDictionary().GetKey(PdfName("ModDate"));
PdfString modDate = pobj->GetString();
string sDate = modDate.GetString();
string sutf8Date = modDate.GetStringUtf8();
PdfOutlines* pOutLine = document->GetOutlines();
TKeyMap itm2 = pOutLine->GetObject()->GetDictionary().GetKeys();
const char *field_name = NULL;
bool field_use_existing = false;
int annot_page = npage;
//double annot_left = 80.0, annot_top = 70.0, annot_width = 150.0, annot_height = 150.0;
bool annot_print = true;
const char *reason = "I agree";
int result = 0;
PdfSignatureField *pSignField = NULL;
try
{
PdfSignOutputDevice signer( outputDevice );
PdfAcroForm* pAcroForm = document->GetAcroForm();
if( !pAcroForm )
PODOFO_RAISE_ERROR_INFO( ePdfError_InvalidHandle, "acroForm == NULL" );
if( !pAcroForm->GetObject()->GetDictionary().HasKey( PdfName( "SigFlags" ) ) ||
!pAcroForm->GetObject()->GetDictionary().GetKey( PdfName( "SigFlags" ) )->IsNumber() ||
pAcroForm->GetObject()->GetDictionary().GetKeyAsLong( PdfName( "SigFlags" ) ) != 3 )
{
if( pAcroForm->GetObject()->GetDictionary().HasKey( PdfName( "SigFlags" ) ) )
pAcroForm->GetObject()->GetDictionary().RemoveKey( PdfName( "SigFlags" ) );
pdf_int64 val = 3;
pAcroForm->GetObject()->GetDictionary().AddKey( PdfName( "SigFlags" ), PdfObject( val ) );
}
if( pAcroForm->GetNeedAppearances() )
{
#if 0 /* TODO */
update_default_appearance_streams( pAcroForm );
#endif
pAcroForm->SetNeedAppearances( false );
}
PdfString name;
PdfObject* pExistingSigField = NULL;
PdfImage image( document );
image.LoadFromFile( ImgFile );
double dimgWidth = image.GetWidth();
double dimgHeight = image.GetHeight();
char fldName[96]; // use bigger buffer to make sure sprintf does not overflow
sprintf( fldName, "PodofoSignatureField%" PDF_FORMAT_INT64, static_cast( document->GetObjects().GetObjectCount() ) );
name = PdfString( fldName );
PdfPage* pPage = document->GetPage( annot_page );
if( !pPage )
PODOFO_RAISE_ERROR( ePdfError_PageNotFound );
double dPageHeight = pPage->GetPageSize().GetHeight();
double dPageWidth = pPage->GetPageSize().GetWidth();
PdfRect annot_rect;
annot_rect = PdfRect( rect.GetLeft(),
pPage->GetPageSize().GetHeight() - rect.GetBottom() - rect.GetHeight(),
dimgWidth,
dimgHeight );
PdfAnnotation* pAnnot = pPage->CreateAnnotation( ePdfAnnotation_Widget, annot_rect );
if( !pAnnot )
PODOFO_RAISE_ERROR_INFO( ePdfError_OutOfMemory, "Cannot allocate annotation object" );
if( annot_print )
pAnnot->SetFlags( ePdfAnnotationFlags_Print );
else if( !field_name || !field_use_existing )
pAnnot->SetFlags( ePdfAnnotationFlags_Invisible | ePdfAnnotationFlags_Hidden );
PdfPainter painter;
try
{
painter.SetPage( /*&sigXObject*/pPage );
/* Workaround Adobe's reader error 'Expected a dict object.' when the stream
contains only one object which does Save()/Restore() on its own, like
the image XObject. */
painter.Save();
painter.Restore();
draw_annotation( *document, painter, image, annot_rect );
}
catch( PdfError & e )
{
if( painter.GetPage() )
{
try
{
painter.FinishPage();
}
catch( ... )
{
}
}
}
painter.FinishPage();
//pSignField = new PdfSignatureField( pAnnot, pAcroForm, document );
pSignField = new PdfSignatureField( pPage, annot_rect, document );
if( !pSignField )
PODOFO_RAISE_ERROR_INFO( ePdfError_OutOfMemory, "Cannot allocate signature field object" );
PdfRect annotSize( 0.0, 0.0, dimgWidth, dimgHeight );
PdfXObject sigXObject( annotSize, document );
pSignField->SetAppearanceStream( &sigXObject );
// use large-enough buffer to hold the signature with the certificate
signer.SetSignatureSize( min_signature_size );
pSignField->SetFieldName( name );
pSignField->SetSignatureReason( PdfString( reinterpret_cast( reason ) ) );
pSignField->SetSignatureDate( /*sigData*/PdfDate() );
pSignField->SetSignature( *signer.GetSignatureBeacon() );
pSignField->SetBackgroundColorTransparent();
pSignField->SetBorderColorTransparent();
// The outPdfFile != NULL means that the write happens to a new file,
// which will be truncated first and then the content of the srcPdfFile
// will be copied into the document, follwed by the changes.
//signer.Seek(0);
document->WriteUpdate( &signer, true );
if( !signer.HasSignaturePosition() )
PODOFO_RAISE_ERROR_INFO( ePdfError_SignatureError, "Cannot find signature position in the document data" );
// Adjust ByteRange for signature
signer.AdjustByteRange();
// Read data for signature and count it
// We seek at the beginning of the file
signer.Seek( 0 );
sign_with_signer( signer, g_x509, g_pKey );
signer.Flush();
}
catch( PdfError & e )
{
}
if( pSignField )
delete pSignField;
}
i use the code above two times, and the first signature is invalid.
how to add two digital signature without invalidating the previous one?
Painting on the right PdfCanvas
After analyzing the example pdf the reason why your second signature invalidated your first one became clear: In the course of signing you change the page content of the page with the widget annotation of the signature.
But changing the content of any page invalidates any previous signature! Cf. this answer for details on allowed and disallowed changes of signed documents.
Indeed:
PdfPainter painter;
try
{
painter.SetPage( /*&sigXObject*/pPage );
/* Workaround Adobe's reader error 'Expected a dict object.' when the stream
contains only one object which does Save()/Restore() on its own, like
the image XObject. */
painter.Save();
painter.Restore();
draw_annotation( *document, painter, image, annot_rect );
}
Apparently you here change something in the page content itself. When this code is executed while applying the second signature, the first signature is invalidated.
You confirmed in a comment:
i use '&sigXObject' instead of 'pPage ',All two signatures are working! but the red seal disappeared
Using the right coordinates
Concerning your observation that the red seal disappeared: You use the wrong coordinates for drawing the image on the annotation appearance!
You use coordinates for the page coordinate system, but you have to use the coordinates in the coordinate system given by the appearance's bounding box.
Thus, your
painter.DrawImage( annot_rect.GetLeft(), annot_rect.GetBottom(), &image );
is wrong, instead try something like
painter.DrawImage( 0, 0, &image );
as the bounding box of your appearance is is
[ 0 0 151 151 ]
i need to add correct indexes to a temp table to speed up a query. according to msdn i check the menu "Include Actual Execution Plan" and run the query in SSMC, after the execution i can see the query plan but there's no indication about the indexes to create.
in the table #Tax the fields l1,l2....l10 identify the position of the element within a hierarchical structure:
the dummy data in the sample is representing the following structure:
--node idleaf=1
----child idleaf=3 of 1
--------child idleaf=5 of 3
----child idleaf=4 of 1
--node idleaf=2
with the tremendous query i need to extract the list of all parents of each record starting form the top
ex:
this is the result of the query (omitting some field is not interesting for the sample)
idleaf,description,node_path
1 node idleaf=1 1_________
3 child idleaf=3 of 1 1_3________
5 child idleaf=5 of 3 1_3_5_______
4 child idleaf=4 of 1 1_4________
2 node idleaf=2 2_________
query:
Create Table #Tax (IdLeaf int,l1 int,l2 int ,l3 int ,l4 int ,l5 int ,l6 int
,l7 int ,l8 int ,l9 int ,l10 int ,Descrizione varchar(max), FlagDocumento bit)
INSERT INTO #Tax (IdLeaf,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,Descrizione,FlagDocumento)
VALUES (1,1,0,0,0,0,0,0,0,0,0,'node idleaf=1',1)
INSERT INTO #Tax (IdLeaf,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,Descrizione,FlagDocumento)
VALUES (2,2,0,0,0,0,0,0,0,0,0,'node idleaf=2',1)
INSERT INTO #Tax (IdLeaf,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,Descrizione,FlagDocumento)
VALUES (3,1,1,0,0,0,0,0,0,0,0,'child idleaf=3 of 1',1)
INSERT INTO #Tax (IdLeaf,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,Descrizione,FlagDocumento)
VALUES (4,1,2,0,0,0,0,0,0,0,0,'child idleaf=4 of 1',1)
INSERT INTO #Tax (IdLeaf,l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,Descrizione,FlagDocumento)
VALUES (5,1,1,1,0,0,0,0,0,0,0,'child idleaf=5 of 3',1)
SELECT Levels.IdLeaf , Levels.Descrizione,Levels.FlagDocumento,
CASE FlagDocumento WHEN 1 Then
ISNULL(CONVERT(varchar(10),Levels.Level1),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level2),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level3),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level4),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level5),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level6),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level7),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level8),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level9),'') + '_' +
ISNULL(CONVERT(varchar(10),Levels.Level10),'')
Else '' END AS NodePath,
CASE
When Levels.Level10>0 Then Levels.IdLeaf9
When Levels.Level9>0 Then Levels.IdLeaf8
When Levels.Level8>0 Then Levels.IdLeaf7
When Levels.Level7>0 Then Levels.IdLeaf6
When Levels.Level6>0 Then Levels.IdLeaf5
When Levels.Level5>0 Then Levels.IdLeaf4
When Levels.Level4>0 Then Levels.IdLeaf3
When Levels.Level3>0 Then Levels.IdLeaf2
When Levels.Level2>0 Then Levels.IdLeaf1
When Levels.Level1>0 Then null
END AS IdParent,
CASE
When Levels.Level10>0 Then 10
When Levels.Level9>0 Then 9
When Levels.Level8>0 Then 8
When Levels.Level7>0 Then 7
When Levels.Level6>0 Then 6
When Levels.Level5>0 Then 5
When Levels.Level4>0 Then 4
When Levels.Level3>0 Then 3
When Levels.Level2>0 Then 2
When Levels.Level1>0 Then 1
END AS TaxLevel
FROM
(
SELECT f10.*,
f1.IdLeaf AS IdLeaf1,
f2.IdLeaf AS IdLeaf2,
f3.IdLeaf AS IdLeaf3,
f4.IdLeaf AS IdLeaf4,
f5.IdLeaf AS IdLeaf5,
f6.IdLeaf AS IdLeaf6,
f7.IdLeaf AS IdLeaf7,
f8.IdLeaf AS IdLeaf8,
f9.IdLeaf AS IdLeaf9,
f10.IdLeaf AS IdLeaf10,
CONVERT(varchar(10), f1.IdLeaf) + '_' + CONVERT(varchar(10), f2.IdLeaf) + '_' + CONVERT(varchar(10), f3.IdLeaf) + '_' + CONVERT(varchar(10), f4.IdLeaf) + CONVERT(varchar(10), f5.IdLeaf) + CONVERT(varchar(10), f6.IdLeaf) + CONVERT(varchar(10), f7.IdLeaf) + CONVERT(varchar(10), f8.IdLeaf) + CONVERT(varchar(10), f9.IdLeaf) + CONVERT(varchar(10), f10.IdLeaf) + '_' AS NODE_PATH,
f1.IdLeaf AS 'Level1',
CASE WHEN f2.IdLeaf <> f1.IdLeaf THEN f2.IdLeaf END AS 'Level2',
CASE WHEN f3.IdLeaf <> f2.IdLeaf THEN f3.IdLeaf END AS 'Level3',
CASE WHEN f4.IdLeaf <> f3.IdLeaf THEN f4.IdLeaf END AS 'Level4',
CASE WHEN f5.IdLeaf <> f4.IdLeaf THEN f5.IdLeaf END AS 'Level5',
CASE WHEN f6.IdLeaf <> f5.IdLeaf THEN f6.IdLeaf END AS 'Level6',
CASE WHEN f7.IdLeaf <> f6.IdLeaf THEN f7.IdLeaf END AS 'Level7',
CASE WHEN f8.IdLeaf <> f7.IdLeaf THEN f8.IdLeaf END AS 'Level8',
CASE WHEN f9.IdLeaf <> f8.IdLeaf THEN f9.IdLeaf END AS 'Level9',
CASE WHEN f10.IdLeaf <> f9.IdLeaf THEN f10.IdLeaf END AS 'Level10'
FROM
(SELECT * FROM #Tax) f10
JOIN #Tax f9 ON f9.l1 = f10.l1
AND f9.l2 = f10.l2
AND f9.l3 = f10.l3
AND f9.l4 = f10.l4
AND f9.l5 = f10.l5
AND f9.l6 = f10.l6
AND f9.l7 = f10.l7
AND f9.l8 = f10.L8
AND f9.l9 = f10.l9
AND f9.l10 = 0
JOIN #Tax f8 ON f8.l1 = f10.l1
AND f8.l2 = f10.l2
AND f8.l3 = f10.l3
AND f8.l4 = f10.l4
AND f8.l5 = f10.l5
AND f8.l6 = f10.l6
AND f8.l7 = f10.l7
AND f8.l8 = f10.l8
AND f8.l9 = 0
AND f8.l10 = 0
JOIN #Tax f7 ON f7.l1 = f10.l1
AND f7.l2 = f10.l2
AND f7.l3 = f10.l3
AND f7.l4 = f10.l4
AND f7.l5 = f10.l5
AND f7.l6 = f10.l6
AND f7.l7 = f10.l7
AND f7.l8 = 0
AND f7.l9 = 0
AND f7.l10 = 0
JOIN #Tax f6 ON f6.l1 = f10.l1
AND f6.l2 = f10.l2
AND f6.l3 = f10.l3
AND f6.l4 = f10.l4
AND f6.l5 = f10.l5
AND f6.l6 = f10.l6
AND f6.l7 = 0
AND f6.l8 = 0
AND f6.l9 = 0
AND f6.l10 = 0
JOIN #Tax f5 ON f5.l1 = f10.l1
AND f5.l2 = f10.l2
AND f5.l3 = f10.l3
AND f5.l4 = f10.l4
AND f5.l5 = f10.l5
AND f5.l6 = 0
AND f5.l7 = 0
AND f5.l8 = 0
AND f5.l9 = 0
AND f5.l10 = 0
JOIN #Tax f4 ON f4.l1 = f10.l1
AND f4.l2 = f10.l2
AND f4.l3 = f10.l3
AND f4.l4 = f10.l4
AND f4.l5 = 0
AND f4.l6 = 0
AND f4.l7 = 0
AND f4.l8 = 0
AND f4.l9 = 0
AND f4.l10 = 0
JOIN #Tax f3 ON f3.l1 = f10.l1
AND f3.l2 = f10.l2
AND f3.l3 = f10.l3
AND f3.l4 = 0
AND f3.l5 = 0
AND f3.l6 = 0
AND f3.l7 = 0
AND f3.l8 = 0
AND f3.l9 = 0
AND f3.l10 = 0
JOIN #Tax f2 ON f2.l1 = f10.l1
AND f2.l2 = f10.l2
AND f2.l3 = 0
AND f2.l4 = 0
AND f2.l5 = 0
AND f2.l6 = 0
AND f2.l7 = 0
AND f2.l8 = 0
AND f2.l9 = 0
AND f2.l10 = 0
JOIN #Tax f1 ON f1.l1 = f10.l1
AND f1.l2 = 0
AND f1.l3 = 0
AND f1.l4 = 0
AND f1.l5 = 0
AND f1.l6 = 0
AND f1.l7 = 0
AND f1.l8 = 0
AND f1.l9 = 0
AND f1.l10 = 0
) Levels Order By L1,L2,L3,L4,L5,L6,L7,L8,L9,L10
I have a table in database.In that table , there is an unknown number of rows.I want to put
checkboxes but number of checkboxes should be equal to the Number of rows. Thus i tried to do it in while loop. I found number of rows which exists in table.It's rowNumber.Then , i did a while loop.At this point , there is a serial failure. Because when i clicked any checkbox , the row below is called with last m value.
cbox[m] = checkBox.new(checkX, txtY, sendRows[m], col,
Because after exiting while loop , m equals rowNumber. And when any checkboxes is clicked , it doesn't know which row is clicked because m = rowNumber. I tried many things but i can't do it. What should i do ?? Should i give up using loop? IF i give up using it how can do it?
Here is the code which i can't fixed
local m = 1
while(m<rowNumber)
cbox[m] = checkBox.new(checkX, txtY, sendRows[m], col,
function(this)
local state = this:getCheck()
if state then
print(m .. " checked")
gonder[m] = 1
else
print(m .. " does not checked")
gonder[m] = 0
end
end
)
screen:addChild(cbox[m])
cbox[m]:setCheck(settings.getMusicState())
txtY = txtY + gap
print ("gonder[m] = " .. gonder[m])
end
If the code is written as in the below,it runs correctly:
cbox[1] = checkBox.new(checkX, txtY, sendRows[1], col,
function(this)
local state = this:getCheck()
if state then
print(1.. " checked")
gonder[1] = 1
else
print(1 .. " does not checked")
gonder[1] = 0
end
end
)
screen:addChild(cbox[1])
cbox[1]:setCheck(settings.getMusicState())
txtY = txtY + gap
cbox[2] = checkBox.new(checkX, txtY, sendRows[2], col,
function(this)
local state = this:getCheck()
if state then
print(2.. " checked")
gonder[2] = 1
else
print(2 .. " does not checked")
gonder[2] = 0
end
end
)
screen:addChild(cbox[2])
cbox[2]:setCheck(settings.getMusicState())
txtY = txtY + gap
.
.
.
.
It is solved after changing the inside of while as this:
while( m<rowNumber + 1)
do
cbox[m] = checkBox.new(checkX, txtY, sendRows[m], col,
function(this)
end
)
screen:addChild(cbox[m])
txtY = txtY + gap
m = m + 1
end
And the important point is here. Here , we are sending what we want:
submitt:addEventListener("click",
function()
local mydata={}
local i=1
while (i<rowNumber+1) do
mydata[3*i-2]=cbox[i].checked--1. Holds whether it is true or false
mydata[3*i-1]=sendRows2[i]
mydata[3*i] = sendURL[i]
i=i+1
end
sceneManager:changeScene("results", 1, SceneManager.flipWithFade, easing.outBack,mydata)
stage:removeChild(submitt)--after clicked , the button disappears
end)