Robson Amaral

Robson Amaral

  • NA
  • 132
  • 17.3k

Doubts about using IF and else

Aug 29 2018 10:20 PM
I need to create a condition that if the barcode does not exist in the sdpj_proc_inter table, I have to move it to a processed folder with a slope, would anyone have any examples of how I could be doing this condition?
 
 
  1. public class ReadingTxt    
  2.     {    
  3.         static Thread _ThreadVerification;    
  4.     
  5.         static string FoldersFile = "C: \ CommonIndex \ ProofPants";    
  6.         static string FileFilesImported = @ "C: \ Provisional Import \ ProofImported";    
  7.         static string FolderLogLog = @ "C: \ CommonComports \ Log";    
  8.     
  9.         public static void Read ()    
  10.         {    
  11.             // creation of the verification thread and its execution    
  12.             _ThreadVerification = new Thread;    
  13.             _ThreadVerification.Start ();    
  14.         }    
  15.     
  16.               
  17. // will check whether or not to execute the method every 1 hour    
  18.         private static void CheckTime ()    
  19.         {    
  20.             while (true)    
  21.             {    
  22.                 if (DateTime.Now.Hour == 10) // If it is 07:00 AM in the morning    
  23.                 {    
  24.                     InsertLog ("");    
  25.                     InsertLog ("\ n HOME ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());    
  26.     
  27.                     try    
  28.                     {    
  29.                         DirectoryInfo dirPending = new DirectoryInfo (PendingPlacesFolder);    
  30.     
  31.                         // list files in the current directory    
  32.                         foreach (FileInfo file in dirPending.GetFiles ())    
  33.                         {    
  34.                             if (file.Extension == ".cpv")    
  35.                             {    
  36.                                 Process File (file.FullName, file.Name);    
  37.                             }    
  38.                         }    
  39.     
  40.                     }    
  41.     
  42.                      catch (Exception)    
  43.                     {    
  44.                         throw;    
  45.                     }    
  46.                     finally    
  47.                     {    
  48.                         InsertLog ("\ n FIM ::" + DateTime.Now.ToShortDateString () + "" + DateTime.Now.ToShortTimeString ());    
  49.                     }    
  50.                 }    
  51.     
  52.                 Thread.Sleep (3600000); // 3,600,000 milliseconds equals 1 hour (Standby)    
  53.             }    
  54.         }    
  55.  //And here is the method used to read the data I need in each line of the file:  
  56.    
  57. private static void ProcessFile (string FullPathFile, string FileName)    
  58.         {    
  59.             try    
  60.             {    
  61.     
  62.                 bool Move = true;    
  63.                 string [] StringLine = System.IO.File.ReadAllLines (FullPathFile);    
  64.                 string CodBar = "";    
  65.     
  66.                 for (int line = 0; line <StringLine.Length; line ++)    
  67.                 {    
  68.                     string DateScheduling = "";    
  69.                     string DocumentValue = "";    
  70.                     string Protocol = "";    
  71.                     string Record = "";    
  72.                     string Emission = "";    
  73.   
  74.                     #region Retrieve the Barcode    
  75.     
  76.                     if (String [line] .Contains ("Bar Cod:"))    
  77.                     {    
  78.                         CodBar + = String [line] .Replace ("Cod. Bars:""");    
  79.                         line + = 2;    
  80.                     }    
  81.                     if (CodBar! = "")    
  82.                     {    
  83.                         CodBar + = String [line];    
  84.                         CodBar = CodBar.Replace ("""");    
  85.                     }    
  86.   
  87.                     #endregion    
  88.     
  89.                     if (CodBar == "")    
  90.                         continues;    
  91.     
  92.                     line + = 6;    
  93.   
  94.                     #region Scheduling Date    
  95.     
  96.                     if (String [line] .Contains ("Delay:"))    
  97.                     {    
  98.                         DateScheduling + = String [line] .Replace ("Dt.Scheduling:""") .Replace ("""");    
  99.                     }    
  100.   
  101.                     #endregion    
  102.     
  103.                     line + = 2;    
  104.   
  105.                     #region Document Value    
  106.     
  107.                     if (String [line] .Contains ("Vlr.Document:"))    
  108.                     {    
  109.                         DocumentValue + = String [line] .Replace ("Vlr.Document:""") .Replace ("""");    
  110.                     }    
  111.   
  112.                     #endregion    
  113.     
  114.                     line + = 2;    
  115.   
  116.                     #region Protocol    
  117.     
  118.                     if (StringLine[line].Contains("Protocol:"))    
  119.                     {    
  120.                         Protocol += StringLine[line].Replace("Protocol:""").Replace(" """);    
  121.                     }    
  122.   
  123.                     #endregion    
  124.     
  125.                     line += 12;    
  126.   
  127.                     #region Register    
  128.     
  129.                     if (StringLine[line].Contains("Register:"))    
  130.                     {    
  131.                         Register += StringLine[line].Replace("Register:""");    
  132.                     }    
  133.   
  134.                     #endregion    
  135.     
  136.                     line += 2;    
  137.   
  138.                    #region Emission    
  139.     
  140.                     if (String [line] .Contains ("Emission:"))    
  141.                     {    
  142.                         Emission + = String [line] .Replace ("Emission:""");    
  143.                     }    
  144.   
  145.                     #endregion    
  146.     
  147.                     // Search Bar Code, here I access another method that I use the barcode of the files to check if it is in the table of the procInter database, from here down everything works ok.    
  148.                     string CodProcInter = GetCodProcInter (CodBar)    
  149.     
  150.                         
  151. if (! string.IsNullOrEmpty (CodProcInter))    
  152.                     {    
  153.                         if (! CodBarInserted (CodBar))    
  154.                         {    
  155.                             // Insert Bar Code    
  156.                             bool inserted = BankInfo (CodProcInter, CodBar, DateScheduling , DocumentValue, Protocol, Register, Emission);    
  157.                         }    
  158.                         else    
  159.                         {    
  160.                             // Bar Code Already Inserted    
  161.                             Move = false;    
  162.                             InsertLog ("\ n Already Exists ->" + CodBar);    
  163.                         }    
  164.                     }    
  165.                     else    
  166.                     {    
  167.                         // Barcode not available in table -> sdpj_proc_inter    
  168.                         Move = false;    
  169.                         InsertLog ("\ nCode Bar Not Available ->" + CodBar);    
  170.                     }    
  171.     
  172.                     / Clear Variables    
  173.                     CodBar = "";    
  174.                 }    
  175.     
  176.                 if    
  177.                 {    
  178.                     MoveFile (FileName);    
  179.                 }    
  180.     
  181.             }    
  182.             catch (Exception ex)    
  183.             {    
  184.                 throw;    
  185.             }    
  186.         }   
 
Here is my code that I read from the file and validate whether the barcode exists or not in the sdpj_proc_inter table of the database, existing I process the file, insert in the database and generate a service log and move the file to the folder processed. But I would like to know how I could do to this condition if it does not exist I generate the log stating that it does not exist, even in the log part all ok but the problem is how will I implement a condition to move that file to the processed if this barcode does not exist there in the database. How could I do it? 

Answers (1)