Robson Amaral

Robson Amaral

  • NA
  • 132
  • 17.3k

Questions regarding the use of the Windows Service

Aug 7 2018 10:35 PM
I have the following doubt, I have a windows service, and in it after reading the file I move that file to another folder, however if any barcode that exists inside that file is not registered in my database, I will not insert in another particular table, I am explaining only the process.
 
Now my doubt: In the log generated, I inform this barcode that was not inserted for this reason, but I would like to know how I could do to inform the responsible person, that the bar code was not inserted in the given table of the bank because it is not registered , is there a way to send an email informing this bar code and asking for it to register the same? how could I do the coding for the email?
  1. // InsertLog Method  
  2. private static void InsertLog (string row)  
  3. {  
  4.     // Create Log Folder, if it does not exist  
  5.     if (! Directory.Exists (LogFileLog))  
  6.     {
  7.         Directory.CreateDirectory (LogFileLog);  
  8.     }  
  9.   
  10.     // Create Log File, if it does not exist  
  11.     string FullPath = LogFileLog + "\\ Proofing Processing Log.txt";  
  12.     if (! File.Exists (FullPath))  
  13.     {
  14.         using (File.Create (FullPath));  
  15.     }  
  16.   
  17.     // Write to LOG file  
  18.     using (StreamWriter file = new StreamWriter (FullPath, true))  
  19.     {
  20.         file.WriteLine (line);  
  21.         file.Dispose ();  
  22.     }
  23. }  
  1. // Here I look for all proc_inter from the sdpj_proc_interest table  
  2. // that has the bar code read in the file, only for you to understand where I want to go.  
  3. GetCodProcInter (string CodBar)  
  4.         {  
  5.             using (DB db = new DB ())  
  6.             {  
  7.                 string SQL = string.Format (@ "SELECT T0.cod_proc_inter FROM sdpj_proc_inter T0 WHERE T0.cod_bars_banestes = '{0}'", CodBar);  
  8.                 var data = db.ExecuteCommandCommission (SQL);  
  9.   
  10.                 if (data.Read ())  
  11.                 {  
  12.            return data ["cod_proc_inter"]. ToString ();  
  13.                 }  
  14.             }  
  15.   
  16.             return "";  
  17.         }  
  1. // This method, I use to move the read files.  
  2. private static void MoveFile (string FileName)  
  3.         {  
  4.     try  
  5.             {  
  6.                 FileFilesImported + = "\\" + FileName;  
  7.                 FileFilesPpendents + = "\\" + FileName;  
  8.                 File.Move (FolderFiles, FileFilesImported);  
  9.             }  
  10.             catch (Exception)  
  11.             {  
  12.                 throw;  
  13.             }  
  14.   
  15.         }
  1. // In this method I go through all the lines, until I find the information that  
  2. // I need to read and write.  
  3.   
  4. private static void ProcessesFile (string FullPathFile, string FileName)  
  5.    {  
  6.             try  
  7.             {  
  8.   
  9.                 bool Move r = true;  
  10.   
  11.                 string [] StringLine = System.IO.File.ReadAllLines (FullPathFile);  
  12.                 string CodBars = "";  
  13.   
  14.                 for (int line = 0; line 
  15.                 {  
  16.                     string DateScheduling = "";  
  17.                     string DocumentValue = "";  
  18.                     string Protocol = "";  
  19.                     string Register = "";  
  20.                     string Emission = "";  
  21.  
  22.                     #regi on Retrieve Bar Code  
  23.   
  24.                     if (String [line] .Contains ("Bar Cod:"))  
  25.                     {  
  26.                         CodBars + = String [line] .Replace ("BarCode:""");  
  27.                         ln + = 2;  
  28.                     }  
  29.   
  30.   
  31.   
  32.                     if (CodBar! = "")  
  33.                     {  
  34.                         CodBar + = String [line];  
  35.                         CodBar = CodBar.Replace ("""");  
  36.                     }  
  37.  
  38.                     #endregion  
  39.   
  40.                     if (CodBar == "")  
  41.                         continue;  
  42.   
  43.                     line + = 6;  
  44.  
  45.                     #region Scheduling Date  
  46.   
  47.                     if (String [line] .Contains ("Delay:"))  
  48.                     {  
  49.                         DateScheduling + = String [line] .Replace ("Date.Scheduling:""").Replace ("""");  
  50.                     }  
  51.  
  52.                     #endregion  
  53.   
  54.                     line + = 2;  
  55.  
  56.                     #region Document Value  
  57.   
  58.                     if (StringLine [line] .Contains ("Document.Value:"))  
  59.                     {  
  60.                        DocumentValue + = String [line] .Replace ("Vlr.Documento:""") .Replace ("""");  
  61.                     }  
  62.  
  63.  
  64.                     #endr?egion  
  65.   
  66.                     line += 2;  
  67.  
  68.                     #region Protocol  
  69.   
  70.                     if (StringLine[line].Contains("Protocol:"))  
  71.                     {  
  72.                         Protocolo += StringLine[line].Replace("Protocol:""").Replace(" """);  
  73.                     }  
  74. ? 
  75.                     #endr?egion  
  76. ?  
  77.                     line ?+= 12;  
  78.  
  79.                     #region Register  
  80.   
  81.                     if (StringLine[line].Contains("Register:"))  
  82.                     {  
  83.                         Register += StringLine[line].Replace("Register:""");  
  84.                     }?  
  85.  
  86.                     #?endregion  
  87.   
  88.                     l?ine ??+= 2;  
  89.  
  90.                     #?region Emission  
  91.   
  92.                     i?f (StringLine[line].Contains("Emission.:"))  
  93.                     {  
  94.                      ?   E?mission += StringLine[line].Replace("Emission.:""");  
  95.                     }??  
  96. ?? 
  97.                     #?endr?egion  
  98. ?
  99.   
  100. // Search BarCode  
  101.                     string CodProcInter = GetCodProcInter (CodeBarra);  
  102.   
  103.                     if (! string.IsNullOrEmpty (CodProcInter))  
  104.                     {  
  105.                         if (! CodeBarAlreadyInserted (CodeBar))  
  106.                         {  
  107.                             // Insert Bar Code  
  108.                          bool inserted = BankInfo (CodProcInter, CodeBar, DateScheduling, DocumentValue, Protocol, Register, Emission);  
  109.                         }  
  110.                           
  111.                         {  
  112.                             // Bar Code Already Inserted  
  113.                          InsertLog ("\ n Already Exists ->" + CodBar);  
  114.                         }  
  115.                     }  
  116.                     else  
  117.                     {  
  118.                         // Barcode not available in table -> sdpj_proc_inter  
  119. // if it is not available, should I inform the responsible person, sending the barcode number to that person, how to do it?  
  120.                         Move = false;  
  121.                         InsertLog ("\ nCode Bar Not Available ->" + CodeBar);  
  122.                     }  
  123.   
  124.                     // Clear Variables  
  125.                     CodeBar = "";  
  126.                 }  
  127.   
  128.                 if  
  129.                 {  
  130.                     MoveFile (FileName);  
  131.                 }  
  132.   
  133.             }  
  134.             catch (Except ion)  
  135.             {  
  136.                 throw;  
  137.             }  
  138.         } 
In that part of the code my doubt lives.
  1. if (! string.IsNullOrEmpty (CodProcInter))  
  2.                     {  
  3.                         if (!CodeBarAlreadyinserted(CodeBar))  
  4.                         {  
  5.                          // Insert Bar Code  
  6.                          bool inserted = BankInfo (CodProcInter, CodBar, DateScheduling, DocumentValue, Protocol, Register, Emission);  
  7.                         }  
  8.                           
  9.                         {  
  10.                          // Bar Code Already Inserted  
  11.                             InsertLog ("\ n Already Exists ->" + CodeBar);  
  12.                         }  
  13.                     }  
  14.                     else  
  15.                     {  
  16.                         // Barcode not available in table -> sdpj_proc_inter  
  17. // if it is not available, should I inform the responsible person, sending the barcode number to that person, how to do it?  
  18.                         Move = false;  
  19.                         InsertLog ("\ nCode Bar Not Available ->" + CodeBar);  
  20.                     }

Answers (2)