Robson Amaral

Robson Amaral

  • NA
  • 132
  • 15.7k

Popular one dataTable and get index of the line

May 12 2018 2:10 PM
How do I populate my dataTable in the mue method import and grab the index
from the correct line from my initated file from line 6? Here's my code:
 
  1. protected void Page_Load (object sender, EventArgs, and)  
  2.   
  3.  {  
  4.      
  5.  }  
  6.   
  7.    
  8.   
  9.   protected void import_Click (object sender, EventArgs and)  
  10.   
  11.         {  
  12.            
  13.            
  14.            DataTable Data = new DataTable ();  
  15.   
  16. if (selectFileContent! = null)  
  17.   
  18.                     {  
  19.   
  20.                         string Excel = AppDomain.CurrentDomain.BaseDirectory + select File.FileName;  
  21.   
  22.                         select File.SaveAs (Excel);  
  23.   
  24.                         Data = Excel Data (Excel);  
  25.   
  26.    
  27.   
  28.                         var recordsValid = ((DataTable) Data) .Rows.OfType <DataRow> (). Skip (5);  
  29.   
  30.                         // Delete the last line  
  31.   
  32.                         recordsValid = RecordsValid.Take (RecordsValid.Count () - 1);  
  33.   
  34.                         // read 100 out of 100 records  
  35.   
  36. int amount_for_page = 100;  
  37.   
  38.                         int total_of_page;  
  39.   
  40.                         // Count valid records  
  41.   
  42.                         int qtd_total_registers = recordsValids.Count ();  
  43.   
  44.                         // Perform mathematical calculations for total pages.  
  45.   
  46.                         total_of_pages = (int) Math.Ceiling ((double) qtd_total_records / amount_by_page);  
  47.   
  48.                         if (recordsValid.Count ()> 0)  
  49.   
  50.                         {  
  51.   
  52.                             bool layoutValid = CheckLayout (Data);  
  53.   
  54.   
  55.   
  56. if (! layoutValid)  
  57.   
  58.                                 ClientScript.RegisterStartupScript (typeof (string), "Error""<script> alert ('Non-standard file layout defined for import.') </ Script>");  
  59.   
  60.    
  61.   
  62.                             else  
  63.   
  64.                             {  
  65.   
  66.                                 // Basic validation required for import. PS: NumLinhas-1 because the file has the last line with total, which is useless to import.  
  67.   
  68.                                 VerificationPreliminary (valid records);  
  69.   
  70.    
  71.   
  72.                                 // Start the repetition routine to read all the lines, starting in cell B6  
  73.   
  74.                                 if (!  
  75.   
  76.                                 {  
  77.   
  78.                                     this.ValidateDuplicityInterested ();  
  79.   
  80.                                     // Creating Parallel Tasks  
  81.   
  82.                                     List <System.Threading.Tasks.Task> TasksParallel = new List <System.Threading.Tasks.Task> ();  
  83.   
  84.   
  85. for (int j = 0; j <total_of_pages; j ++)  
  86.   
  87.                                     {  
  88.   
  89.    
  90.   
  91.                                         var page = j;  
  92.   
  93.                                         // read the 100 lines  
  94.   
  95.                                         var linesPerPage = recordsResults.Skip (page * quantity_by_page) .Take (quantity_by_page);  
  96.   
  97.    
  98.   
  99.                                         // Breaking into 10 threads, I will break the list with the extension created below  
  100.   
  101.                                         var data_rows_divididos = linesPerPagina.SplitList (10);  
  102.   
  103.    
  104.   
  105.                                         foreach (var linesDivided in data_rows_divided)  
  106.   
  107.                                         {  
  108.   
  109.                                             // I ADD TO MY PARALLEL TASK LIST  
  110.   
  111.                                             TasksParalelas.Add (TableTransform (split lines, j, userLog));  
  112.   
  113.                                         }  
  114.   
  115.                                     }  
  116.   
  117.   
  118. // START THE PARALLEL TASKS  
  119.   
  120.                                     foreach (var task in TasksParallel)  
  121.   
  122.                                         task.Start ();  
  123.   
  124.    
  125.   
  126.                                     // NOW I EXPECT ALL JOBS TO COMPLETE  
  127.   
  128.                                     System.Threading.Tasks.Task.WaitAll (TasksParalelas.ToArray ());  
  129.   
  130.     }  
  131. }  
  132.   
  133. private System.Threading.Tasks.Task Processing table (IEnumerable <DataRow> dataparam, int i, UserLibrary user)  
  134.   
  135.         {  
  136.   
  137.             // userLogin = appLogin.LoginPorLogin (GetUserAuthenticated ().));  
  138.   
  139.               
  140.   
  141.             Action <object> processing = (data) =>  
  142.   
  143.             {  
  144.   
  145.                
  146. NHibernate.Context.ThreadStaticSessionContext.Bind (NhibernateHelper.HelpThreading (). OpenSession ());  
  147.   
  148.   
  149.   
  150.   
  151. foreach (var line in (IEnumerable <DataRow>) data)  
  152.   
  153.                 {  
  154.   
  155.                      
  156.   
  157.                     
  158.   
  159.                     List <Process> listProcessOpen = new List <Process> ();  
  160.   
  161.                     Process process = null;  
  162.   
  163.                     Interested interested = new Interested ();  
  164.   
  165.    
  166.   
  167.                     // search for the process by the previous or current judicial number  
  168.   
  169.                     if (! line.ItemArray [1] .ToString ().) Equals (""))  
  170.   
  171.                         process = aplProcess.consultPerNProcessOER (line.ItemArray [1] .ToString ());  
  172.   
  173.                     if (process == null)  
  174.   
  175.                     {  
  176.   
  177.                         if (! line.ItemArray [2] .ToString ().) Equals (""))  
  178.   
  179.                             process = aplProcess.consultPerNProcessOER (line.ItemArray [2] .ToString ());  
  180.   
  181.                     }  
  182.   
  183.   
  184. // find the person interested by cpf / cnpj  
  185.   
  186.                     if (line.ItemArray [7] .ToString (). Length == 14)  
  187.   
  188.                         interested = aplInterado.ConsultaPorCPF (AuxiliarCPF_CNPJ.DesformataCPF (line.ItemArray [7] .ToString ()));  
  189.   
  190.    
  191.   
  192.                     if (line.ItemArray [7] .ToString (). Length == 18)  
  193.   
  194.                         interested = apl  
  195. Interested.ConsultPerCPF (HelpCPF_CNPJ.DesformatCNPJ (line.ItemArray [7] .ToString ()));  
  196.   
  197.   
  198.   
  199.   
  200. if (process! = null)  
  201.   
  202.                     {  
  203.   
  204.                         // if the process is not null I search all procinter related to it  
  205.   
  206.                         List <ProcessInterest> listprocinter = ProcessInterested.consultProcesso(process.Code);  
  207.   
  208.                         if (listprocinter.Exists (o => o.interest == interested))  
  209.   
  210.   
  211. //  
  212. I can not get the index of the interested one of the correct line here, here lives the problem, therefore I thought of popular the dataTable in the beginning and to pass the index here direct, however I do not know how to do.  
  213. log.Append ("The interested" + process.Interested.Name + ", entered in the line" + (i + 1) + "was added again to the process" + process.NumProcesso + "");  
  214.   
  215.   
  216.   
  217.   
  218. else  
  219.   
  220.                     {  
  221.   
  222.                         // New Process - 6.3  
  223.   
  224.                         process = new Process ();  
  225.   
  226.                         process.Interested = interested;  
  227.   
  228.             }  
  229.         }  
  230.     }  
  231. }