Question number in error log

RTAVIX

New member
Joined
Apr 6, 2018
Messages
4
Location
Brazil
Programming Experience
Beginner
Personal, I would like the following information, I have a validation, and in this validation I send a message in the application to the user that the cell G of the line should be filled, my code looks like this:
C#:
private void PreliminaryVerification(IEnumerable<DataRow> data)        {
            bool imported= false;
            foreach(var line in data)
            {
                //Verifies that no worksheets with the numSEP entered have not already been imported             
                if (!line.ItemArray[17].ToString().Equals(""))
                {
                    if (aplProcessInterested.listProcInterperCodSep(decimal.Parse(line.ItemArray[17].ToString())).Count != 0)
                    {
                        imported= true;
                        break;
                    }
                }
                else
                {
                    log.Append("The cell S" + (1) + " must be completed. <br>"); // [COLOR=#212121][FONT=arial]but this is wrong (1), because I am working with lines, I put in an illustrative way, how to solve this situation in this part of the code?[/FONT][/COLOR]
                    fileInvalidated = true;
                }
                
                if (!imported)
                {
                    //Validation of required fields                
                    if (line.ItemArray[6].ToString().Equals(""))
                    {
                        
                        log.Append("The cell G" + ( 1) + " must be completed <br>"); //Here the same situation as the previous comment
                        arquivoInvalidado = true;
                    }




But when compiling, and trying to import the file, the log message, it looks like this:Import Log:Cell G1 must be filled.

is not G1, it should appear for the user cell g of line 3 for example.


Please, if anyone can help me, thank you! :semi-twins:

But when compiling, and trying to import the file, the log message, it looks like this:Import Log:Cell G1 must be filled.
 
If you want a line number then use a `for` loop rather than a `foreach` loop. That way, you can use the loop counter as the line number. The loop counter will be zero-based, because it is an index, so if you want your line numbers to be 1-based then you will obviously need to add 1 to the loop counter to get the line number.
 
I'm having trouble firing the log for the user, in my previous code it was that way and it worked:I'm having trouble firing the log for the user, in my previous code it was that way and it worked:
C#:
[/FONT][/COLOR]
[FONT=inherit][COLOR=#000000][FONT=inherit]		[COLOR=#000088][FONT=inherit]private[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]void[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#660066][FONT=inherit]PreliminaryVerification[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000088][FONT=inherit]int[/FONT][/COLOR][COLOR=#000000][FONT=inherit] count[/FONT][/COLOR][COLOR=#666600][FONT=inherit],[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#660066][FONT=inherit]DataSet[/FONT][/COLOR][COLOR=#000000][FONT=inherit] ds[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR]

[/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]         
            [/FONT][/COLOR][COLOR=#000088][FONT=inherit]bool[/FONT][/COLOR][COLOR=#000000][FONT=inherit] imported[/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]false[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
            [/FONT][/COLOR][COLOR=#000088][FONT=inherit]for[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000088][FONT=inherit]int[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]5[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i [/FONT][/COLOR][COLOR=#666600][FONT=inherit]<[/FONT][/COLOR][COLOR=#000000][FONT=inherit] count[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit] i[/FONT][/COLOR][COLOR=#666600][FONT=inherit]++)[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
            [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#880000][FONT=inherit]//Verifies that no worksheets with the numSEP entered have not already been imported                [/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#000088][FONT=inherit]if[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit](![/FONT][/COLOR][COLOR=#000000][FONT=inherit]ds[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Tables[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]0[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Rows[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#000000][FONT=inherit]i[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ItemArray[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]17[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ToString[/FONT][/COLOR][COLOR=#666600][FONT=inherit]().[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Equals[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]""[/FONT][/COLOR][COLOR=#666600][FONT=inherit]))[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#000088][FONT=inherit]if[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]aplProcessInterested[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]listProcInterPorCodSep[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000088][FONT=inherit]decimal[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Parse[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]ds[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Tables[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]0[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Rows[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#000000][FONT=inherit]i[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ItemArray[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]17[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ToString[/FONT][/COLOR][COLOR=#666600][FONT=inherit]())).[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Count[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]!=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]0[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                        imported[/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]true[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                        [/FONT][/COLOR][COLOR=#000088][FONT=inherit]break[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#000088][FONT=inherit]else[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    log[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Append[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"The cell S"[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]i [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]" must be completed. <br>"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]);[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    arquivoInvalidado [/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]true[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][/FONT]
[COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#212121][FONT=arial]

And due to changes it turned out to be that way :concern::

C#:
[COLOR=#000000][FONT=inherit]        private[FONT=inherit] [/FONT][COLOR=#000088][FONT=inherit]void[/FONT][/COLOR][FONT=inherit] [/FONT][COLOR=#660066][FONT=inherit]PreliminaryVerification[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#660066][FONT=inherit]IEnumerable[/FONT][/COLOR][COLOR=#666600][FONT=inherit]<[/FONT][/COLOR][COLOR=#660066][FONT=inherit]DataRow[/FONT][/COLOR][COLOR=#666600][FONT=inherit]>[/FONT][/COLOR][FONT=inherit] data[/FONT][COLOR=#666600][FONT=inherit])[/FONT][/COLOR]

[/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
            [/FONT][/COLOR][COLOR=#000088][FONT=inherit]bool[/FONT][/COLOR][COLOR=#000000][FONT=inherit] imported[/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]false[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
            [/FONT][/COLOR][COLOR=#000088][FONT=inherit]foreach[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000088][FONT=inherit]var[/FONT][/COLOR][COLOR=#000000][FONT=inherit] line [/FONT][/COLOR][COLOR=#000088][FONT=inherit]in[/FONT][/COLOR][COLOR=#000000][FONT=inherit] data[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
            [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#880000][FONT=inherit]//Verifies that no worksheets with the numSEP entered have not already been imported               [/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#000088][FONT=inherit]if[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit](![/FONT][/COLOR][COLOR=#000000][FONT=inherit]line[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ItemArray[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]17[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ToString[/FONT][/COLOR][COLOR=#666600][FONT=inherit]().[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Equals[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]""[/FONT][/COLOR][COLOR=#666600][FONT=inherit]))[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#000088][FONT=inherit]if[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]aplProcessInterested[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#000000][FONT=inherit]listProcInterPorCodSep[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000088][FONT=inherit]decimal[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Parse[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#000000][FONT=inherit]line[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ItemArray[/FONT][/COLOR][COLOR=#666600][FONT=inherit][[/FONT][/COLOR][COLOR=#006666][FONT=inherit]17[/FONT][/COLOR][COLOR=#666600][FONT=inherit]].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]ToString[/FONT][/COLOR][COLOR=#666600][FONT=inherit]())).[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Count[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]!=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#006666][FONT=inherit]0[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                        imported[/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]true[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                        [/FONT][/COLOR][COLOR=#000088][FONT=inherit]break[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#000088][FONT=inherit]else[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]{[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    log[/FONT][/COLOR][COLOR=#666600][FONT=inherit].[/FONT][/COLOR][COLOR=#660066][FONT=inherit]Append[/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#008800][FONT=inherit]"The cell S"[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]([/FONT][/COLOR][COLOR=#006666][FONT=inherit]1[/FONT][/COLOR][COLOR=#666600][FONT=inherit])[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]+[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#008800][FONT=inherit]" must be completed. <br>"[/FONT][/COLOR][COLOR=#666600][FONT=inherit]);[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                    fileInvalidated[/FONT][/COLOR][COLOR=#666600][FONT=inherit]=[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#000088][FONT=inherit]true[/FONT][/COLOR][COLOR=#666600][FONT=inherit];[/FONT][/COLOR][COLOR=#000000][FONT=inherit]
                [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR][COLOR=#000000][FONT=inherit] [/FONT][/COLOR][COLOR=#666600][FONT=inherit]}[/FONT][/COLOR]

However, the log that was displayed to the user ended up incorrectly like this:


Import Log: In the system there is no execution stick associated with the comarca informed in line 1. Please correct the system. In the system there is no execution stick associated with the comarca informed in line 1. Please correct the system.

Here is the problem, but I do not know how to solve it:

log.Append("The cell S" + (1) + " must be completed. <br>");
 
The line you specified doesn't seem to make sense. This:
log.Append("The cell S"+(1)+" must be completed. <br>");

would produce the very same result as this:
log.Append("The cell S1 must be completed. <br>");

Obviously that's not what you want if you expect the row number. If you do expect the row number though, you have to actually have the row number stored somewhere. I would suggest going back to a 'for' loop because the inherently stores the row index in the loop counter. If you don't want to do that for some reason then you need an extra variable that you can simply increment each iteration of the loop.
 
From now on I would like to apologize for the duplicate topic, I am a beginner in the programming area, I have doubts on how to make your suggestion and apply in my code. Can you show me how to do this please?
I have no idea.

I have no ideaI have no ideaI have no ideaFrom now on I would like to apologize for the duplicate topic, I am a beginner in the programming area, I have doubts on how to make your suggestion and apply in my code. Can you show me how to do this?
 
I tried to pass the line, however it presents the following message to the user on the screen, incorrectly, see:

[FONT=&quot]Import Log:[/FONT]
[FONT=&quot]The CPF / CNPJ entered in the HSystem.Data.DataRow cell is in an incorrect format. Please correct the spreadsheet.[/FONT]
[FONT=&quot]The CPF / CNPJ entered in the HSystem.Data.DataRow cell is in an incorrect format. Please correct the spreadsheet.[/FONT]
[FONT=&quot]The CPF / CNPJ entered in the HSystem.Data.DataRow cell is in an incorrect format. Please correct the spreadsheet. [/FONT]
 

Latest posts

Back
Top Bottom