Advertisement
Guest User

FORM1

a guest
Feb 16th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 106.64 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Net;
  4. using System.Net.Mail;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Xml;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using System.Configuration;
  15. using System.Text.RegularExpressions;
  16. using MES_Import_AOI_Results.Properties;
  17. using System.Security.Principal;
  18. using System.Security.Permissions;
  19. using System.Runtime.InteropServices;
  20. using System.Diagnostics;
  21. using TsLib;
  22. using TSV_Crypt_PW;
  23.  
  24. namespace MES_Import_AOI_Results
  25. {
  26.     public enum Glob_RC
  27.     {
  28.         I_O = 0,
  29.         ST_PASS_fehlt = 1,
  30.         ST_FAIL_fehlt = 2,
  31.         ST_REPAIR_fehlt = 3,
  32.         User_ID_fehlt = 4,
  33.         Dev_stage_ID_fehlt = 5,
  34.         Keine_SerialNums_gefunden = 6,
  35.         Val_PCBNum_fehlt = 7,
  36.         Val_Machine_Serial_fehlt = 8,
  37.         Val_Progr_Name_fehlt = 9,
  38.         Val_Insp_user_fehlt = 10,
  39.         Val_First_user_fehlt = 11,
  40.         Val_Sec_user_fehlt = 12,
  41.         Val_Insp_Dat_fehlt = 13,
  42.         Val_First_Op_Dat_fehlt = 14,
  43.         Val_Sec_Op_Dat_fehlt = 15,
  44.         Val_Insp_Res_fehlt = 16,
  45.         Val_First_Op_Res_fehlt = 17,
  46.         Val_Sec_Op_Res_fehlt = 18,
  47.         Val_Insp_NG_Count_fehlt = 19,
  48.         Val_First_Op_NG_Count_fehlt = 20,
  49.         Val_Sec_Op_NG_Count_fehlt = 21,
  50.         Val_Insp_NG_Parts_fehlt = 22,
  51.         Val_First_Op_NG_Parts_fehlt = 23,
  52.         Val_Sec_Op_NG_Parts_fehlt = 24,
  53.         Val_Parts_Ref_fehlt = 25,
  54.         Val_NGReason_fehlt = 26,
  55.         Val_PinNo_fehlt = 27,
  56.         Val_Dummy_fehlt = 28,
  57.         ST_IN_PROGRESS_fehlt = 29,
  58.         Val_Res_First_OP_fehlt = 30,
  59.         Val_Res_Sec_OP_fehlt = 31,
  60.         Quell_Verzeichnis_Good_fehlt = 32,
  61.         Quell_Verzeichnis_Judge_fehlt = 33,
  62.         None
  63.     }
  64.  
  65.     public partial class Form1 : Form
  66.     {
  67.         private Config m_Config;
  68.         private TsLogFile m_TsLogFile;
  69.         private DbAccess m_DbAccess;
  70.         private List<DB_AOI_Data_MES> AOI_Data_MES;
  71.         private DB_AOI_ScanResultData_MES AOI_ScanResultData_MES;
  72.         private List<MES_DB_Laser_SerialNum> Laser_ResultData;
  73.  
  74.         private DBReturn_Errors Proc_Errors;
  75.         public System.Data.SqlClient.SqlConnection connection;
  76.         public static string pw_uv;
  77.         public static string NW_pw_quelle;
  78.         public static string NW_pw_ziel;
  79.         public static string file_name;
  80.  
  81.         /// <summary>
  82.         /// Konstruktor
  83.         /// </summary>
  84.         public Form1()
  85.         {
  86.             InitializeComponent();
  87.             try
  88.             {
  89.                 Init();
  90.             }
  91.             catch (Exception ex)
  92.             {
  93.                 MessageBox.Show(ex.Message, "Software-Fehler");
  94.             }
  95.         }
  96.  
  97.  
  98.         /// <summary>
  99.         /// Prüfung auf numerisch über regulären Ausdruck
  100.         /// </summary>
  101.         static bool IsNumericString(string strAlphanum)
  102.         {
  103.             System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(@"^[0-9]+$");
  104.             return pattern.IsMatch(strAlphanum.Trim());
  105.         }
  106.  
  107.  
  108.         /// <summary>
  109.         /// Initialisierung
  110.         /// </summary>
  111.         private void Init()
  112.         {
  113.             try
  114.             {
  115.                 m_Config = new Config();
  116.                 m_TsLogFile = new TsLogFile();
  117.                 m_DbAccess = new DbAccess(m_Config);
  118.                 AOI_Data_MES = new List<DB_AOI_Data_MES>();
  119.                 AOI_ScanResultData_MES = new DB_AOI_ScanResultData_MES();
  120.                 Laser_ResultData = new List<MES_DB_Laser_SerialNum>();
  121.  
  122.                 byte[] key = { 66, 122, 26, 24, 156, 86, 182, 98, 48, 176, 46, 126, 101, 66, 32, 146 };
  123.                 byte[] iv = { 44, 58, 41, 33, 77, 142, 165, 42, 73, 84, 32, 69, 24, 76, 37, 56 };
  124.  
  125.                 string Pw = m_Config.Pwd;
  126.                 List<string> ret_val = TSV_Crypt.Crypt_PW(Pw, key, iv);
  127.  
  128.                 if (ret_val[0] != null && ret_val[0].Length > 0)
  129.                 {
  130.                     m_TsLogFile.WriteLine("For use to setup config: \"" + ret_val[0] + "\".");
  131.                 }
  132.                 pw_uv = ret_val[1];
  133.  
  134.                 string NW_Pw_Quelle = m_Config.NW_PW_Quelle;
  135.                 List<string> NW_Quelle_ret_val = TSV_Crypt.Crypt_PW(NW_Pw_Quelle, key, iv);
  136.  
  137.                 if (NW_Quelle_ret_val[0] != null && NW_Quelle_ret_val[0].Length > 0)
  138.                 {
  139.                     m_TsLogFile.WriteLine("For use to setup config for NW_Quelle: \"" + NW_Quelle_ret_val[0] + "\".");
  140.                 }
  141.                 NW_pw_quelle = NW_Quelle_ret_val[1];
  142.  
  143.                 string NW_Pw_Ziel = m_Config.NW_PW_Ziel;
  144.                 List<string> NW_Ziel_ret_val = TSV_Crypt.Crypt_PW(NW_Pw_Ziel, key, iv);
  145.  
  146.                 if (NW_Ziel_ret_val[0] != null && NW_Ziel_ret_val[0].Length > 0)
  147.                 {
  148.                     m_TsLogFile.WriteLine("For use to setup config for NW_Ziel: \"" + NW_Ziel_ret_val[0] + "\".");
  149.                 }
  150.                 NW_pw_ziel = NW_Ziel_ret_val[1];
  151.                
  152.                 bool eine_mail = false;   // nur eine Mail senden
  153.  
  154.                 MailMessage message = new MailMessage();
  155.  
  156.                 message.From = new MailAddress(m_Config.MAIL_From);
  157.                 message.To.Add(m_Config.MAIL_To);
  158.                 if (m_Config.MAIL_CC.Length > 0)
  159.                 {
  160.                     message.CC.Add(m_Config.MAIL_CC);
  161.                 }
  162.                 message.Subject = m_Config.MAIL_Betreff;
  163.  
  164.                 int glob_rc = 0;    // globaler RC  I.O.
  165.  
  166.                 if (m_Config.NW_LW_Quelle.Length > 0)
  167.                 {
  168.                     //                      Exists Quelle?
  169.                     if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good))
  170.                     {
  171.                         MapNetworkDriveDisconnect(m_Config.NW_LW_Quelle);
  172.                         MapNetworkDriveConnect(m_Config.NW_LW_Quelle, "\\\\smd-vogtland1\\d$", m_Config.NW_User_Quelle, NW_pw_quelle);
  173.                         System.Threading.Thread.Sleep(100);
  174.                         eine_mail = true;
  175.                         message.Body += "Das Quell-Laufwerk existierte nicht und wurde wiederhergestellt. \r\n\r\n";
  176.                     }
  177.                 }
  178.  
  179.                 if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good))
  180.                 {
  181.                     eine_mail = true;
  182.                     message.Body += "Das Quell-Verzeichnis \"Good\" existiert nicht! \r\n\r\n";
  183.                     glob_rc = Convert.ToInt32(Glob_RC.Quell_Verzeichnis_Good_fehlt);
  184.                 }
  185.  
  186.                 if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Judge))
  187.                 {
  188.                     eine_mail = true;
  189.                     message.Body += "Das Quell-Verzeichnis \"Judge\" existiert nicht! \r\n\r\n";
  190.                     glob_rc = Convert.ToInt32(Glob_RC.Quell_Verzeichnis_Judge_fehlt);
  191.                 }
  192.  
  193.                 //                      Exists Archiv-Ziel?
  194.                 if (!System.IO.Directory.Exists(m_Config.NW_LW_Ziel + m_Config.FileDirectory_ARCHIV))
  195.                 {
  196.                     MapNetworkDriveDisconnect(m_Config.NW_LW_Ziel);
  197.                     MapNetworkDriveConnect(m_Config.NW_LW_Ziel, "\\\\sic-vogtland1\\d", m_Config.NW_User_Ziel, NW_pw_ziel);
  198.                     System.Threading.Thread.Sleep(100);
  199.                     eine_mail = true;
  200.                     message.Body += "Das Ziel-Laufwerk existierte nicht und wurde wierehergestellt. \r\n\r\n";
  201.                 }
  202.  
  203. //                MapNetworkDriveDisconnect(m_Config.NW_LW_Quelle);
  204. //                MapNetworkDriveDisconnect(m_Config.NW_LW_Ziel);
  205.  
  206. //                MapNetworkDriveConnect(m_Config.NW_LW_Quelle, "\\\\smd-vogtland1\\d$", m_Config.NW_User_Quelle, NW_pw_quelle);
  207. //                MapNetworkDriveConnect(m_Config.NW_LW_Ziel, "\\\\sic-vogtland1\\d", m_Config.NW_User_Ziel, NW_pw_ziel);
  208.  
  209.                 if (m_DbAccess.TestDbAccess())
  210.                 {
  211.                     bool Fehler = false;
  212.  
  213.                     try
  214.                     {
  215.                         this.Width = int.Parse(m_Config.DisplayWidth);
  216.                         this.Height = int.Parse(m_Config.DisplayHeight);
  217.                         lbFiles.Width = this.Width - 30;
  218.                         SLBDatabaseConection.Text = m_Config.Server + "/" + m_Config.User + " (connected)";
  219.  
  220.                         bool datei_verarb = false;
  221.                         bool datei_error = false;
  222.                         int max = 100;         // maximale Anzahl Serialnummern pro Nutzen
  223.                         int s = 0, e = 0, z = 0, a = 0, n = 0;              // s => start    e => ende    z => zahl     a => anzahl
  224.                         int ordern = 0;
  225.  
  226.                         Settings setting = new Settings();
  227.                         connection = DbAccess.Open_MES(true);
  228.  
  229.                         string act_Directory;
  230.  
  231.                         //                      Exists Fehler-Verzeichnis?
  232.                         if (!System.IO.Directory.Exists(m_Config.FileDirectory_ERROR))
  233.                         {
  234.                             System.IO.Directory.CreateDirectory(m_Config.FileDirectory_ERROR);
  235.                         }
  236.  
  237.                         int status_pass = 0;
  238. //                        int status_fail = 0;
  239.                         int status_repair = 0;
  240.                         int status_in_progress = 0;
  241.  
  242.                         //                      Status PASS
  243.                         int look_up_status_pass = DbAccess.Look_up_Status_PASS_MES(connection, "PASS");
  244.  
  245.                         if (look_up_status_pass == 0)
  246.                         {
  247.                             // Fehler
  248.                             status_pass = 0;
  249.                             glob_rc = Convert.ToInt32(Glob_RC.ST_PASS_fehlt);
  250.                         }
  251.                         else
  252.                         {
  253.                             status_pass = look_up_status_pass;
  254.                         }
  255.  
  256. //                      Status FAIL  wird zur Zeit hier nicht verwendet
  257. //                        if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  258. //                        {
  259. //                            int look_up_status_fail = DbAccess.Look_up_Status_PASS_MES(connection, "FAIL");
  260.  
  261. //                            if (look_up_status_fail == 0)
  262. //                            {
  263.                                 // Fehler
  264. //                                status_fail = 0;
  265. //                                glob_rc = Convert.ToInt32(Glob_RC.ST_FAIL_fehlt);
  266. //                            }
  267. //                            else
  268. //                            {
  269. //                                status_fail = look_up_status_fail;
  270. //                            }
  271. //                        }
  272.  
  273.                         //                      Status REPAIR
  274.                         if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  275.                         {
  276.                             int look_up_status_repair = DbAccess.Look_up_Status_PASS_MES(connection, "REPAIR");
  277.  
  278.                             if (look_up_status_repair == 0)
  279.                             {
  280.                                 // Fehler
  281.                                 status_repair = 0;
  282.                                 glob_rc = Convert.ToInt32(Glob_RC.ST_REPAIR_fehlt);
  283.                             }
  284.                             else
  285.                             {
  286.                                 status_repair = look_up_status_repair;
  287.                             }
  288.                         }
  289.  
  290.                         //                      Status IN_PROGRESS
  291.                         if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  292.                         {
  293.                             int look_up_status_in_progress = DbAccess.Look_up_Status_PASS_MES(connection, "IN PROGRESS");
  294.  
  295.                             if (look_up_status_in_progress == 0)
  296.                             {
  297.                                 // Fehler
  298.                                 status_in_progress = 0;
  299.                                 glob_rc = Convert.ToInt32(Glob_RC.ST_IN_PROGRESS_fehlt);
  300.                             }
  301.                             else
  302.                             {
  303.                                 status_in_progress = look_up_status_in_progress;
  304.                             }
  305.                         }
  306.  
  307.                         int look_up_value_name;
  308.  
  309.                         string value_name_PCBNum;
  310.  
  311.                         //                      value name PCBNum
  312.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Laser PCB number");
  313.  
  314.                         if (look_up_value_name != 0)
  315.                         {
  316.                             // Fehler
  317.                             value_name_PCBNum = "";
  318.                             glob_rc = Convert.ToInt32(Glob_RC.Val_PCBNum_fehlt);
  319.                         }
  320.                         else
  321.                         {
  322.                             value_name_PCBNum = DBReturn_Names.Quality_ID;
  323.                         }
  324.  
  325.                         string vn_Machine_Serial;
  326.  
  327.                         //                      value name Machine_Serial
  328.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Machine Serial");
  329.  
  330.                         if (look_up_value_name != 0)
  331.                         {
  332.                             // Fehler
  333.                             vn_Machine_Serial = "";
  334.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Machine_Serial_fehlt);
  335.                         }
  336.                         else
  337.                         {
  338.                             vn_Machine_Serial = DBReturn_Names.Quality_ID;
  339.                         }
  340.  
  341.                         string vn_Progr_Name;
  342.  
  343.                         //                      value name Progr_Name
  344.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Programm Name");
  345.  
  346.                         if (look_up_value_name != 0)
  347.                         {
  348.                             // Fehler
  349.                             vn_Progr_Name = "";
  350.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Progr_Name_fehlt);
  351.                         }
  352.                         else
  353.                         {
  354.                             vn_Progr_Name = DBReturn_Names.Quality_ID;
  355.                         }
  356.  
  357.                         string vn_Insp_user;
  358.  
  359.                         //                      value name _Insp_user
  360.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection User");
  361.  
  362.                         if (look_up_value_name != 0)
  363.                         {
  364.                             // Fehler
  365.                             vn_Insp_user = "";
  366.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_user_fehlt);
  367.                         }
  368.                         else
  369.                         {
  370.                             vn_Insp_user = DBReturn_Names.Quality_ID;
  371.                         }
  372.  
  373.                         string vn_First_user;
  374.  
  375.                         //                      value name First_user
  376.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First User");
  377.  
  378.                         if (look_up_value_name != 0)
  379.                         {
  380.                             // Fehler
  381.                             vn_First_user = "";
  382.                             glob_rc = Convert.ToInt32(Glob_RC.Val_First_user_fehlt);
  383.                         }
  384.                         else
  385.                         {
  386.                             vn_First_user = DBReturn_Names.Quality_ID;
  387.                         }
  388.  
  389.                         string vn_Sec_user;
  390.  
  391.                         //                      value name Sec_user
  392.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second User");
  393.  
  394.                         if (look_up_value_name != 0)
  395.                         {
  396.                             // Fehler
  397.                             vn_Sec_user = "";
  398.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_user_fehlt);
  399.                         }
  400.                         else
  401.                         {
  402.                             vn_Sec_user = DBReturn_Names.Quality_ID;
  403.                         }
  404.  
  405.                         string vn_Insp_Res;
  406.  
  407.                         //                      value name Insp_Res
  408.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection Result");
  409.  
  410.                         if (look_up_value_name != 0)
  411.                         {
  412.                             // Fehler
  413.                             vn_Insp_Res = "";
  414.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_Res_fehlt);
  415.                         }
  416.                         else
  417.                         {
  418.                             vn_Insp_Res = DBReturn_Names.Quality_ID;
  419.                         }
  420.  
  421.                         string vn_First_Op_Res;
  422.  
  423.                         //                      value name First_Op_Res
  424.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator Result");
  425.  
  426.                         if (look_up_value_name != 0)
  427.                         {
  428.                             // Fehler
  429.                             vn_First_Op_Res = "";
  430.                             glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_Res_fehlt);
  431.                         }
  432.                         else
  433.                         {
  434.                             vn_First_Op_Res = DBReturn_Names.Quality_ID;
  435.                         }
  436.  
  437.                         string vn_Sec_Op_Res;
  438.  
  439.                         //                      value name Sec_Op_Res
  440.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator Result");
  441.  
  442.                         if (look_up_value_name != 0)
  443.                         {
  444.                             // Fehler
  445.                             vn_Sec_Op_Res = "";
  446.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_Res_fehlt);
  447.                         }
  448.                         else
  449.                         {
  450.                             vn_Sec_Op_Res = DBReturn_Names.Quality_ID;
  451.                         }
  452.  
  453.                         string vn_Insp_NG_Count;
  454.  
  455.                         //                      value name Insp_NG_Count
  456.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection NG Count");
  457.  
  458.                         if (look_up_value_name != 0)
  459.                         {
  460.                             // Fehler
  461.                             vn_Insp_NG_Count = "";
  462.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_NG_Count_fehlt);
  463.                         }
  464.                         else
  465.                         {
  466.                             vn_Insp_NG_Count = DBReturn_Names.Quality_ID;
  467.                         }
  468.  
  469.                         string vn_First_Op_NG_Count;
  470.  
  471.                         //                      value name First_Op_NG_Count
  472.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator NG Count");
  473.  
  474.                         if (look_up_value_name != 0)
  475.                         {
  476.                             // Fehler
  477.                             vn_First_Op_NG_Count = "";
  478.                             glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_NG_Count_fehlt);
  479.                         }
  480.                         else
  481.                         {
  482.                             vn_First_Op_NG_Count = DBReturn_Names.Quality_ID;
  483.                         }
  484.  
  485.                         string vn_Sec_Op_NG_Count;
  486.  
  487.                         //                      value name Sec_Op_NG_Count
  488.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator NG Count");
  489.  
  490.                         if (look_up_value_name != 0)
  491.                         {
  492.                             // Fehler
  493.                             vn_Sec_Op_NG_Count = "";
  494.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_NG_Count_fehlt);
  495.                         }
  496.                         else
  497.                         {
  498.                             vn_Sec_Op_NG_Count = DBReturn_Names.Quality_ID;
  499.                         }
  500.  
  501.                         string vn_Insp_NG_Parts;
  502.  
  503.                         //                      value name Insp_NG_Parts
  504.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection NG Parts");
  505.  
  506.                         if (look_up_value_name != 0)
  507.                         {
  508.                             // Fehler
  509.                             vn_Insp_NG_Parts = "";
  510.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_NG_Parts_fehlt);
  511.                         }
  512.                         else
  513.                         {
  514.                             vn_Insp_NG_Parts = DBReturn_Names.Quality_ID;
  515.                         }
  516.  
  517.                         string vn_First_Op_NG_Parts;
  518.  
  519.                         //                      value name First_Op_NG_Parts
  520.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator NG Parts");
  521.  
  522.                         if (look_up_value_name != 0)
  523.                         {
  524.                             // Fehler
  525.                             vn_First_Op_NG_Parts = "";
  526.                             glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_NG_Parts_fehlt);
  527.                         }
  528.                         else
  529.                         {
  530.                             vn_First_Op_NG_Parts = DBReturn_Names.Quality_ID;
  531.                         }
  532.                        
  533.                         string vn_Sec_Op_NG_Parts;
  534.  
  535.                         //                      value name Sec_Op_NG_Parts
  536.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator NG Parts");
  537.  
  538.                         if (look_up_value_name != 0)
  539.                         {
  540.                             // Fehler
  541.                             vn_Sec_Op_NG_Parts = "";
  542.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_NG_Parts_fehlt);
  543.                         }
  544.                         else
  545.                         {
  546.                             vn_Sec_Op_NG_Parts = DBReturn_Names.Quality_ID;
  547.                         }
  548.  
  549.                         string vn_Parts_Ref;
  550.  
  551.                         //                      value name Parts_Ref
  552.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Parts Reference Number");
  553.  
  554.                         if (look_up_value_name != 0)
  555.                         {
  556.                             // Fehler
  557.                             vn_Parts_Ref = "";
  558.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Parts_Ref_fehlt);
  559.                         }
  560.                         else
  561.                         {
  562.                             vn_Parts_Ref = DBReturn_Names.Quality_ID;
  563.                         }
  564.  
  565.                         string vn_NGReason;
  566.  
  567.                         //                      value name NGReason
  568.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "NG Reason");
  569.  
  570.                         if (look_up_value_name != 0)
  571.                         {
  572.                             // Fehler
  573.                             vn_NGReason = "";
  574.                             glob_rc = Convert.ToInt32(Glob_RC.Val_NGReason_fehlt);
  575.                         }
  576.                         else
  577.                         {
  578.                             vn_NGReason = DBReturn_Names.Quality_ID;
  579.                         }
  580.  
  581.                         string vn_PinNo;
  582.  
  583.                         //                      value name PinNo
  584.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Pin Number");
  585.  
  586.                         if (look_up_value_name != 0)
  587.                         {
  588.                             // Fehler
  589.                             vn_PinNo = "";
  590.                             glob_rc = Convert.ToInt32(Glob_RC.Val_PinNo_fehlt);
  591.                         }
  592.                         else
  593.                         {
  594.                             vn_PinNo = DBReturn_Names.Quality_ID;
  595.                         }
  596.  
  597.                         string vn_Dummy;
  598.  
  599.                         // value name Dummy Record
  600.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Dummy Record used as");
  601.  
  602.                         if (look_up_value_name != 0)
  603.                         {
  604.                             // Fehler
  605.                             vn_Dummy = "";
  606.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Dummy_fehlt);
  607.                         }
  608.                         else
  609.                         {
  610.                             vn_Dummy = DBReturn_Names.Quality_ID;
  611.                         }
  612.  
  613.                         string vn_Res_First;
  614.  
  615.                         // value name Result First OP
  616.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Result First OP");
  617.  
  618.                         if (look_up_value_name != 0)
  619.                         {
  620.                             // Fehler
  621.                             vn_Res_First = "";
  622.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Res_First_OP_fehlt);
  623.                         }
  624.                         else
  625.                         {
  626.                             vn_Res_First = DBReturn_Names.Quality_ID;
  627.                         }
  628.  
  629.                         string vn_Res_Sec;
  630.  
  631.                         // value name Result Sec OP
  632.                         look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Result Sec OP");
  633.  
  634.                         if (look_up_value_name != 0)
  635.                         {
  636.                             // Fehler
  637.                             vn_Res_Sec = "";
  638.                             glob_rc = Convert.ToInt32(Glob_RC.Val_Res_Sec_OP_fehlt);
  639.                         }
  640.                         else
  641.                         {
  642.                             vn_Res_Sec = DBReturn_Names.Quality_ID;
  643.                         }
  644.  
  645.                         if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  646.                         {
  647.  
  648.                             for (n = 0; n < 2; n++)        // Durchlauf durch 2 Quellverzeichnisse
  649.                             {
  650.                                 if (n == 0)
  651.                                 {
  652. // wenn das Programm als Import der AOI läuft, ist dieses Verzeichnis mit Daten aus "PREJUDGE" besetzt, läuft es als Import der Daten der angegliederten "RepairStation" ist dieses Verzeichnis ein leeres Verzeichnis => "Leerverzeichnis" !!!!!
  653.  
  654.                                     act_Directory = m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good;           // PREJUDGE  => nur "OK"
  655.                                 }
  656.                                 else
  657.                                 {
  658. // wenn das Programm als Import der REPAIRSTATION läuft, ist dieses Verzeichnis mit Daten aus "JUDGE" besetzt, läuft es als Import der Daten der AOI ist dieses Verzeichnis ein leeres Verzeichnis => "Leerverzeichnis" !!!!!
  659.  
  660.                                     act_Directory = m_Config.NW_LW_Quelle + m_Config.FileDirectory_Judge;         // JUDGE   => alle restlichen Files
  661.                                 }
  662.  
  663.                                 foreach (string f in System.IO.Directory.GetFiles(act_Directory, "*.xml"))
  664.                                 {
  665.                                     if (f.IndexOf("PASSMODE") > 0 || (f.IndexOf("@NG@") > 0 && n == 0))
  666.                                     {
  667.                                         // nothing to do :)
  668.                                     }
  669.                                     else
  670.                                     {
  671.                                         file_name = f;
  672.  
  673.                                         datei_error = false;
  674.                                         int[] quali = new int[max];
  675.                                         string[] Parts_Ref = new string[max];
  676.                                         string[] NGReason = new string[max];
  677.                                         string[] PinNo = new string[max];
  678.                                         string[] Status_First = new string[max];
  679.                                         string[] Status_Sec = new string[max];
  680.                                         string[] Res_First = new string[max];
  681.                                         string[] Res_Sec = new string[max];
  682.                                         string[] serialn = new string[max];
  683.                                         string machine_ser = "";
  684.                                         string PCB_Num_Laser = "";
  685.                                         string PCB_ID = "";
  686.                                         string Prog_Name = "";
  687.  
  688.                                         string Insp_Op = "";
  689.                                         string First_Op = "";
  690.                                         string Sec_Op = "";
  691.  
  692.                                         string Insp_Dat = "";
  693.                                         string First_Op_Dat = "";
  694.                                         string Sec_Op_Dat = "";
  695.  
  696.                                         int Insp_user_ID = 0;
  697.                                         int First_user_ID = 0;
  698.                                         int Sec_user_ID = 0;
  699.  
  700.                                         string Insp_Res_ch = "";
  701.                                         string Insp_NG_Count_ch = "";
  702.                                         string Insp_NG_Parts_ch = "";
  703.  
  704.                                         string First_Op_Res_ch = "";
  705.                                         string First_Op_NG_Count_ch = "";
  706.                                         string First_Op_NG_Parts_ch = "";
  707.  
  708.                                         string Sec_Op_Res_ch = "";
  709.                                         string Sec_Op_NG_Count_ch = "";
  710.                                         string Sec_Op_NG_Parts_ch = "";
  711.  
  712.                                         string jj = "";
  713.                                         string mm = "";
  714.                                         string tt = "";
  715.                                         string archiv_pfad = "";
  716.                                         string MES_File = "";
  717.                                         string ng_folder = "";
  718.                                         string Spc_Path = "";
  719.                                         string Spc_File = "";
  720.                                         string help_serial_num = "";
  721.  
  722.                                         s = f.IndexOf("@");         // 1. @
  723.                                         e = f.IndexOf("@", s + 1);  // 2. @
  724.                                         s = e + 1;
  725.                                         e = f.IndexOf("@", s);      // 3. @
  726.                                         string PCB_Num = f.Substring(s, e - s);
  727.                                         s = e + 1;
  728.                                         e = f.IndexOf("@", s);      // 4. @
  729.                                         s = e + 1;
  730.                                         e = f.IndexOf("@", s);      // 5. @
  731.                                         s = e + 1;
  732.                                         e = f.IndexOf("@", s);      // 6. @
  733.                                         string erg = f.Substring(s, e - s);
  734.                                         string dat = f.Substring(e + 1, 14);
  735.                                         string zeit = f.Substring(e + 9, 6);
  736.  
  737.                                         if (PCB_Num.IndexOf("B") == 0 || PCB_Num.IndexOf("L") == 0)
  738.                                         {
  739.                                             help_serial_num = PCB_Num.Substring(1);
  740.                                         }
  741.                                         else
  742.                                         {
  743.                                             help_serial_num = PCB_Num;
  744.                                         }
  745.  
  746.                                         string wanted_stage = "LASER";
  747.                                         //                      Device stage ID
  748.                                         int look_up_dev_stage_laser_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
  749.  
  750.                                         if (look_up_dev_stage_laser_id == 0)
  751.                                         {
  752.                                             // Fehler
  753.                                             glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
  754.                                             datei_error = true;
  755.                                         }
  756.                                         else
  757.                                         {
  758.                                             // nix zu tun ;-)
  759.                                         }
  760.  
  761.                                         int dummy_kennz_b = 0;
  762.                                         wanted_stage = "AOI (Bestückseite)";
  763.                                         //                      Device stage ID
  764.                                         int look_up_dev_stage_aoi_b_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
  765.  
  766.                                         if (look_up_dev_stage_aoi_b_id == 0)
  767.                                         {
  768.                                             // Dummy-Satz benutzen, da kein AOI im Auftrag verankert
  769.                                             look_up_dev_stage_aoi_b_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, "Dummy-Durchlaufzeit");
  770.                                             if (look_up_dev_stage_aoi_b_id == 0)
  771.                                             {
  772.                                                 // Auswertung später, könnte Fehler sein
  773.                                             }
  774.                                             else
  775.                                             {
  776.                                                 dummy_kennz_b = 1;
  777.                                             }
  778.                                         }
  779.                                         else
  780.                                         {
  781.                                             // nix zu tun ;-)
  782.                                         }
  783.  
  784.                                         int dummy_kennz_l = 0;
  785.                                         wanted_stage = "AOI (Lötseite)";
  786.                                         //                      Device stage ID
  787.                                         int look_up_dev_stage_aoi_l_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
  788.  
  789.                                         if (look_up_dev_stage_aoi_l_id == 0)
  790.                                         {
  791.                                             // Dummy-Satz benutzen, da kein AOI im Auftrag verankert
  792.                                             look_up_dev_stage_aoi_l_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, "Dummy-Durchlaufzeit");
  793.                                             if (look_up_dev_stage_aoi_b_id == 0)
  794.                                             {
  795.                                                 // Auswertung später, könnte Fehler sein
  796.                                             }
  797.                                             else
  798.                                             {
  799.                                                 dummy_kennz_l = 1;
  800.                                             }
  801.                                         }
  802.                                         else
  803.                                         {
  804.                                             // nix zu tun ;-)
  805.                                         }
  806.  
  807.                                         if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  808.                                         {
  809.                                             PCB_Num_Laser = "B" + PCB_Num.Substring(1);
  810.                                             Laser_ResultData = DbAccess.Get_DB_Laser_SerialNum_MES(connection, PCB_Num_Laser, "", value_name_PCBNum);
  811.  
  812.                                             if (Laser_ResultData != null && Laser_ResultData.Count > 0)
  813.                                             {
  814.                                                 a = 0;
  815.                                                 s = 0;
  816.                                                 ordern = 0;
  817.                                                 foreach (MES_DB_Laser_SerialNum p in Laser_ResultData)
  818.                                                 {
  819.                                                     quali[s] = status_in_progress;
  820.                                                     serialn[s] = p.SerialNum;
  821.                                                     ordern = p.Order_ID;
  822.                                                     if (s == max - 1)
  823.                                                     {
  824.                                                         eine_mail = true;
  825.                                                         message.Body += "Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num + "\r\n";
  826.                                                         m_TsLogFile.WriteLine("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
  827.                                                         throw new Exception("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
  828.                                                     }
  829.                                                     s += 1;
  830.                                                     a += 1;
  831.                                                 }
  832.                                             }
  833.                                             else
  834.                                             {
  835.                                                 eine_mail = true;
  836.                                                 message.Body += "Für die PCB_Num: " + PCB_Num + " wurden keine Serialnummern-Sätze der Laser-Station gefunden.\r\n";
  837.                                                 m_TsLogFile.WriteLine("Für die PCB_Num: " + PCB_Num + " wurden keine Serialnummern-Sätze der Laser-Station gefunden.");
  838.                                                 Fehler = true;
  839.                                                 datei_error = true;
  840.                                                 glob_rc = Convert.ToInt32(Glob_RC.Keine_SerialNums_gefunden);
  841.                                             }
  842.                                         }
  843.  
  844.                                         if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  845.                                         {
  846.                                             char[] line_delimiters = new char[] { '\r', '\n' };
  847.                                             string text_file = System.IO.File.ReadAllText(f);
  848.                                             string[] txt_zeile = text_file.Split(line_delimiters, StringSplitOptions.RemoveEmptyEntries);
  849.  
  850.                                             z = 0;
  851.                                             string RefDataNo = "";
  852.  
  853.                                             for (int i = 0; i < txt_zeile.Length; i++)
  854.                                             {
  855.                                                 if (txt_zeile[i].IndexOf("<Machine Serial=") == 2)
  856.                                                 {
  857.                                                     s = txt_zeile[i].IndexOf("\"");
  858.                                                     e = txt_zeile[i].IndexOf("\"", s + 1);
  859.                                                     machine_ser = txt_zeile[i].Substring(s + 1, e - s - 1);
  860.                                                 }
  861.  
  862.                                                 if (txt_zeile[i].IndexOf("<Board Count=") == 2)
  863.                                                 {
  864.                                                     s = txt_zeile[i].IndexOf("ID=\"");
  865.                                                     e = txt_zeile[i].IndexOf("\"", s + 4);
  866.                                                     PCB_ID = txt_zeile[i].Substring(s + 4, e - s - 4);
  867.                                                 }
  868.  
  869.                                                 if (txt_zeile[i].IndexOf("<Info No=") == 4)
  870.                                                 {
  871.                                                     s = txt_zeile[i].IndexOf(" Name=\"");
  872.                                                     e = txt_zeile[i].IndexOf("\"", s + 7);
  873.                                                     Prog_Name = txt_zeile[i].Substring(s + 7, e - s - 7);
  874.                                                 }
  875.  
  876.                                                 if (txt_zeile[i].IndexOf("<Insp OperatorID=") == 6)
  877.                                                 {
  878.                                                     s = txt_zeile[i].IndexOf("OperatorName=\"");
  879.                                                     e = txt_zeile[i].IndexOf("\"", s + 14);
  880.                                                     Insp_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
  881.                                                     s = txt_zeile[i].IndexOf(" Result=\"");
  882.                                                     e = txt_zeile[i].IndexOf("\"", s + 9);
  883.                                                     Insp_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
  884.                                                     s = txt_zeile[i].IndexOf(" NGCount=\"");
  885.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  886.                                                     Insp_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  887.                                                     s = txt_zeile[i].IndexOf(" NGParts=\"");
  888.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  889.                                                     Insp_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  890.                                                     s = txt_zeile[i].IndexOf(" Time=\"");
  891.                                                     e = txt_zeile[i].IndexOf("\"", s + 7);
  892.                                                     Insp_Dat = txt_zeile[i].Substring(s + 7, 4) + "-" + txt_zeile[i].Substring(s + 15, 2) + "-" + txt_zeile[i].Substring(s + 12, 2) + " " + txt_zeile[i].Substring(s + 18, 8);
  893.                                                 }
  894.  
  895.                                                 if (txt_zeile[i].IndexOf("<NGImage Folder=") == 4)
  896.                                                 {
  897.                                                     s = txt_zeile[i].IndexOf("Folder=\"");
  898.                                                     e = txt_zeile[i].IndexOf("\"", s + 8);
  899.                                                     ng_folder = txt_zeile[i].Substring(s + 8, e - s - 6 - 1 - 1);
  900.                                                 }
  901.  
  902.                                                 if (txt_zeile[i].IndexOf("<Spc ") == 4)
  903.                                                 {
  904.                                                     s = txt_zeile[i].IndexOf("Database");
  905.                                                     e = txt_zeile[i].IndexOf("\"", s);
  906.                                                     Spc_Path = txt_zeile[i].Substring(s, e - s);                  // ohne Yamaha-Netzwerk-IP
  907.  
  908.                                                     s = txt_zeile[i].IndexOf("File=\"\"");
  909.                                                     if (s <= 0)
  910.                                                     {
  911.                                                         s = txt_zeile[i].IndexOf("File=\"");
  912.                                                         e = txt_zeile[i].IndexOf("\"", s + 6);
  913.                                                         Spc_File = txt_zeile[i].Substring(s + 6, e - s - 6 - 4);    // ohne ".csv"  umständlich, aber transparent
  914.                                                     }
  915.                                                 }
  916.  
  917.                                                 if (txt_zeile[i].IndexOf("<First OperatorID=") == 6)
  918.                                                 {
  919.                                                     s = txt_zeile[i].IndexOf("OperatorName=\"");
  920.                                                     e = txt_zeile[i].IndexOf("\"", s + 14);
  921.                                                     First_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
  922.                                                     s = txt_zeile[i].IndexOf(" Result=\"");
  923.                                                     e = txt_zeile[i].IndexOf("\"", s + 9);
  924.                                                     First_Op_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
  925.                                                     s = txt_zeile[i].IndexOf(" NGCount=\"");
  926.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  927.                                                     First_Op_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  928.                                                     s = txt_zeile[i].IndexOf(" NGParts=\"");
  929.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  930.                                                     First_Op_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  931.                                                     s = txt_zeile[i].IndexOf(" StartTime=\"");
  932.                                                     e = txt_zeile[i].IndexOf("\"", s + 12);
  933.                                                     First_Op_Dat = txt_zeile[i].Substring(s + 12, 4) + "-" + txt_zeile[i].Substring(s + 20, 2) + "-" + txt_zeile[i].Substring(s + 17, 2) + " " + txt_zeile[i].Substring(s + 23, 8);
  934.                                                 }
  935.  
  936.                                                 if (txt_zeile[i].IndexOf("<Second OperatorID=") == 6)
  937.                                                 {
  938.                                                     s = txt_zeile[i].IndexOf("OperatorName=\"");
  939.                                                     e = txt_zeile[i].IndexOf("\"", s + 14);
  940.                                                     Sec_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
  941.                                                     s = txt_zeile[i].IndexOf(" Result=\"");
  942.                                                     e = txt_zeile[i].IndexOf("\"", s + 9);
  943.                                                     Sec_Op_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
  944.                                                     s = txt_zeile[i].IndexOf(" NGCount=\"");
  945.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  946.                                                     Sec_Op_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  947.                                                     s = txt_zeile[i].IndexOf(" NGParts=\"");
  948.                                                     e = txt_zeile[i].IndexOf("\"", s + 10);
  949.                                                     Sec_Op_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
  950.                                                     s = txt_zeile[i].IndexOf(" StartTime=\"");
  951.                                                     e = txt_zeile[i].IndexOf("\"", s + 12);
  952.                                                     Sec_Op_Dat = txt_zeile[i].Substring(s + 12, 4) + "-" + txt_zeile[i].Substring(s + 20, 2) + "-" + txt_zeile[i].Substring(s + 17, 2) + " " + txt_zeile[i].Substring(s + 23, 8);
  953.                                                 }
  954.  
  955.                                                 if (txt_zeile[i].IndexOf("Block No") > 0)
  956.                                                 {
  957.                                                     s = txt_zeile[i].IndexOf("No");
  958.                                                     s += 4;
  959.                                                     e = txt_zeile[i].IndexOf("\"");
  960.                                                     e = txt_zeile[i].IndexOf("\"", e + 1);  // 2. "
  961.                                                     z = Convert.ToInt32(txt_zeile[i].Substring(s, e - s));
  962.  
  963.                                                     if (z == 0)
  964.                                                         z = 1;                  // Block No war definiert ab 1, somit nehmen wir "Sonderfehler", die auf Block 0 geschreiben werden auf Block 1
  965.  
  966.                                                     quali[z - 1] = status_repair;
  967.                                                 }
  968.  
  969.                                                 if (z > max)
  970.                                                 {
  971.                                                     eine_mail = true;
  972.                                                     message.Body += "Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num + "\r\n";
  973.                                                     m_TsLogFile.WriteLine("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
  974.                                                     throw new Exception("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
  975.                                                 }
  976.  
  977.                                                 if (txt_zeile[i].IndexOf("<Parts RefNo=\"") == 4)
  978.                                                 {
  979.                                                     s = txt_zeile[i].IndexOf("\"");
  980.                                                     e = txt_zeile[i].IndexOf("\"", s + 1);
  981.                                                     Parts_Ref[z - 1] += (txt_zeile[i].Substring(s + 1, e - s - 1));
  982.  
  983.                                                     s = txt_zeile[i].IndexOf(" RefDataNo=\"");
  984.                                                     e = txt_zeile[i].IndexOf("\"", s + 12);
  985.                                                     RefDataNo = "(" + (txt_zeile[i].Substring(s + 12, e - s - 12)) + "); ";
  986.                                                     Parts_Ref[z - 1] += RefDataNo;
  987.                                                 }
  988.  
  989.                                                 if (txt_zeile[i].IndexOf("<Step No=\"") == 6)
  990.                                                 {
  991.                                                     if (txt_zeile[i].IndexOf(" NGReason=\"") > 0)
  992.                                                     {
  993.                                                         s = txt_zeile[i].IndexOf(" NGReason=\"");
  994.                                                         e = txt_zeile[i].IndexOf("\"", s + 11);
  995.                                                         NGReason[z - 1] += (txt_zeile[i].Substring(s + 11, e - s - 11) + RefDataNo);
  996.                                                     }
  997.  
  998.                                                     if (txt_zeile[i].IndexOf(" PinNo=\"") > 0)
  999.                                                     {
  1000.                                                         s = txt_zeile[i].IndexOf(" PinNo=\"");
  1001.                                                         e = txt_zeile[i].IndexOf("\"", s + 8);
  1002.                                                         PinNo[z - 1] += (txt_zeile[i].Substring(s + 8, e - s - 8) + RefDataNo);
  1003.                                                     }
  1004.                                                 }
  1005.  
  1006.                                                 if (txt_zeile[i].IndexOf("<Result First=\"") == 8)
  1007.                                                 {
  1008.                                                     s = txt_zeile[i].IndexOf("First=\"");
  1009.                                                     e = txt_zeile[i].IndexOf("\"", s + 7);
  1010.                                                     string Res = "";
  1011.                                                     string Res_verb = "";
  1012.                                                     Res = txt_zeile[i].Substring(s + 7, e - s - 7);
  1013.                                                     if (String.Compare(Res, "2", false) == 0)
  1014.                                                     {
  1015.                                                         // nix zu tun ;-)
  1016.                                                     }
  1017.                                                     else
  1018.                                                     {
  1019.                                                         if (String.Compare(Res, "1", false) == 0)
  1020.                                                         {
  1021.                                                             Res_verb = "(NG)";
  1022.                                                         }
  1023.                                                         else
  1024.                                                         {
  1025.                                                             Res_verb = "(OK)";
  1026.                                                         }
  1027.                                                     }
  1028.                                                     if (Res.Length != 0 && String.Compare(Res, "2", false) != 0)
  1029.                                                     {
  1030.                                                         Status_First[z - 1] = Res;
  1031.                                                         Res_First[z - 1] += (Res + Res_verb + RefDataNo + "; ");
  1032.                                                     }
  1033.                                                     Res = "";
  1034.                                                     Res_verb = "";
  1035.                                                     s = txt_zeile[i].IndexOf("Second=\"");
  1036.                                                     e = txt_zeile[i].IndexOf("\"", s + 8);
  1037.                                                     Res = txt_zeile[i].Substring(s + 8, e - s - 8);
  1038.                                                     if (String.Compare(Res, "2", false) == 0)
  1039.                                                     {
  1040.                                                         // nix zu tun ;-)
  1041.                                                     }
  1042.                                                     else
  1043.                                                     {
  1044.                                                         if (String.Compare(Res, "1", false) == 0)
  1045.                                                         {
  1046.                                                             Res_verb = "(NG)";
  1047.                                                         }
  1048.                                                         else
  1049.                                                         {
  1050.                                                             Res_verb = "(OK)";
  1051.                                                         }
  1052.                                                     }
  1053.                                                     if (Res.Length != 0 && String.Compare(Res, "2", false) != 0)
  1054.                                                     {
  1055.                                                         Status_Sec[z - 1] = Res;
  1056.                                                         Res_Sec[z - 1] += (Res + Res_verb + RefDataNo + "; ");
  1057.                                                     }
  1058.  
  1059.                                                     if (!String.IsNullOrEmpty(Status_First[z - 1]) && String.Compare(Status_First[z - 1], "0", false) == 0)
  1060. //                                                            if (quali[z - 1] == status_repair && !String.IsNullOrEmpty(Status_First[z - 1]) && String.Compare(Status_First[z - 1], "0", false) == 0)
  1061.                                                     {
  1062.                                                         quali[z - 1] = status_in_progress;
  1063.                                                     }
  1064.  
  1065.                                                     if (!String.IsNullOrEmpty(Status_Sec[z - 1]) && String.Compare(Status_Sec[z - 1], "0", false) == 0)
  1066.                                                     {
  1067.                                                         quali[z - 1] = status_in_progress;
  1068.                                                     }
  1069.  
  1070.                                                 }
  1071.                                             }
  1072.  
  1073.                                             if (Insp_Op.Length > 0)
  1074.                                             {
  1075.                                                 Insp_user_ID = find_user_ID(Insp_Op);
  1076.                                             }
  1077.                                             else
  1078.                                             {
  1079.                                                 Insp_user_ID = find_user_ID("prod.vogtl");
  1080.                                             }
  1081.  
  1082.                                             if (Insp_user_ID == 0)
  1083.                                             {
  1084.                                                 eine_mail = true;
  1085.                                                 message.Body += "Für den Inspektion-Hauptnutzer " + Insp_Op + " existiert kein User in der DB.\r\n";
  1086.                                                 m_TsLogFile.WriteLine("Für den Inspektion-Hauptnutzer " + Insp_Op + " existiert kein User in der DB.");
  1087.                                                 Fehler = true;
  1088.                                                 datei_error = true;
  1089.                                                 glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
  1090.                                             }
  1091.  
  1092.                                             if (First_Op.Length > 0)
  1093.                                             {
  1094.                                                 First_user_ID = find_user_ID(First_Op);
  1095.                                                 if (First_user_ID == 0)
  1096.                                                 {
  1097.                                                     eine_mail = true;
  1098.                                                     message.Body += "Für den ersten Operator " + First_Op + " existiert kein User in der DB.\r\n";
  1099.                                                     m_TsLogFile.WriteLine("Für den ersten Operator " + First_Op + " existiert kein User in der DB.");
  1100.                                                     Fehler = true;
  1101.                                                     datei_error = true;
  1102.                                                     glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
  1103.                                                 }
  1104.                                             }
  1105.                                             else
  1106.                                             {
  1107.                                                 First_user_ID = 0;
  1108.                                             }
  1109.  
  1110.                                             if (Sec_Op.Length > 0)
  1111.                                             {
  1112.                                                 Sec_user_ID = find_user_ID(Sec_Op);
  1113.                                                 if (Sec_user_ID == 0)
  1114.                                                 {
  1115.                                                     eine_mail = true;
  1116.                                                     message.Body += "Für den zweiten Operator " + Sec_Op + " existiert kein User in der DB.\r\n";
  1117.                                                     m_TsLogFile.WriteLine("Für den zweiten Operator " + Sec_Op + " existiert kein User in der DB.");
  1118.                                                     Fehler = true;
  1119.                                                     datei_error = true;
  1120.                                                     glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
  1121.                                                 }
  1122.                                             }
  1123.                                             else
  1124.                                             {
  1125.                                                 Sec_user_ID = 0;
  1126.                                             }
  1127.  
  1128.                                             string datum_zeit = dat.Substring(0, 4) + "-" + dat.Substring(6, 2) + "-" + dat.Substring(4, 2) + " " + dat.Substring(8, 2) + ":" + dat.Substring(10, 2) + ":" + dat.Substring(12, 2);
  1129.  
  1130.                                             jj = dat.Substring(0, 4);
  1131.                                             mm = dat.Substring(4, 2);
  1132.                                             tt = dat.Substring(6, 2);
  1133.                                             archiv_pfad = m_Config.NW_LW_Ziel + m_Config.FileDirectory_ARCHIV + "\\" + jj + "\\" + mm + "\\" + tt + "\\" + PCB_Num + "_" + zeit + "\\";
  1134.  
  1135.                                             MES_File = archiv_pfad + PCB_Num_Laser + ".xml";
  1136.  
  1137.                                             int help_stage_id = 0;
  1138.  
  1139.                                             if (PCB_Num.IndexOf("B") == 0)
  1140.                                             {
  1141.                                                 if (look_up_dev_stage_aoi_b_id == 0)
  1142.                                                 {
  1143.                                                     glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
  1144.                                                     datei_error = true;
  1145.                                                 }
  1146.                                                 else
  1147.                                                 {
  1148.                                                     help_stage_id = look_up_dev_stage_aoi_b_id;
  1149.                                                     AOI_ScanResultData_MES.Dummy_used = dummy_kennz_b;
  1150.                                                     AOI_ScanResultData_MES.Dummy_User = "AOI B-Seite";
  1151.                                                 }
  1152.                                             }
  1153.                                             else
  1154.                                             {
  1155.                                                 if (look_up_dev_stage_aoi_l_id == 0)
  1156.                                                 {
  1157.                                                     glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
  1158.                                                     datei_error = true;
  1159.                                                 }
  1160.                                                 else
  1161.                                                 {
  1162.                                                     help_stage_id = look_up_dev_stage_aoi_l_id;
  1163.                                                     AOI_ScanResultData_MES.Dummy_used = dummy_kennz_l;
  1164.                                                     AOI_ScanResultData_MES.Dummy_User = "AOI L-Seite";
  1165.                                                 }
  1166.                                             }
  1167.  
  1168.                                             if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
  1169.                                             {
  1170.                                                 AOI_Data_MES = DbAccess.GetDB_AOI_Data_MES(connection, help_serial_num, Insp_Dat, help_stage_id);
  1171.  
  1172.                                                 if (AOI_Data_MES != null)
  1173.                                                 {
  1174.                                                     //Keine Aktion, Sätze schon da
  1175.                                                     eine_mail = true;
  1176.                                                     message.Body += "In der DB befinden sich Sätze mit gleichem Zeitstempel (" + Insp_Dat + ") zur PCBNum " + PCB_Num + "; keine Aktion auf DB ausgeführt!\r\n";
  1177.                                                     m_TsLogFile.WriteLine("In der DB befinden sich Sätze mit gleichem Zeitstempel (" + Insp_Dat + ") zur PCBNum " + PCB_Num + "; keine Aktion auf DB ausgeführt!");
  1178.                                                 }
  1179.                                                 else
  1180.                                                 {
  1181.                                                     AOI_ScanResultData_MES.VN_Machine_Serial = vn_Machine_Serial;
  1182.                                                     AOI_ScanResultData_MES.VN_Progr_Name = vn_Progr_Name;
  1183.                                                     AOI_ScanResultData_MES.VN_Insp_user = vn_Insp_user;
  1184.                                                     AOI_ScanResultData_MES.VN_First_user = vn_First_user;
  1185.                                                     AOI_ScanResultData_MES.VN_Sec_user = vn_Sec_user;
  1186.                                                     AOI_ScanResultData_MES.VN_Parts_Ref = vn_Parts_Ref;
  1187.                                                     AOI_ScanResultData_MES.VN_NGReason = vn_NGReason;
  1188.                                                     AOI_ScanResultData_MES.VN_PinNo = vn_PinNo;
  1189.                                                     AOI_ScanResultData_MES.VN_Insp_Res = vn_Insp_Res;
  1190.                                                     AOI_ScanResultData_MES.VN_First_Op_Res = vn_First_Op_Res;
  1191.                                                     AOI_ScanResultData_MES.VN_Sec_Op_Res = vn_Sec_Op_Res;
  1192.                                                     AOI_ScanResultData_MES.VN_Insp_NG_Count = vn_Insp_NG_Count;
  1193.                                                     AOI_ScanResultData_MES.VN_First_Op_NG_Count = vn_First_Op_NG_Count;
  1194.                                                     AOI_ScanResultData_MES.VN_Sec_Op_NG_Count = vn_Sec_Op_NG_Count;
  1195.                                                     AOI_ScanResultData_MES.VN_Insp_NG_Parts = vn_Insp_NG_Parts;
  1196.                                                     AOI_ScanResultData_MES.VN_First_Op_NG_Parts = vn_First_Op_NG_Parts;
  1197.                                                     AOI_ScanResultData_MES.VN_Sec_Op_NG_Parts = vn_Sec_Op_NG_Parts;
  1198.                                                     AOI_ScanResultData_MES.VN_Dummy_used = vn_Dummy;
  1199.  
  1200.                                                     for (int i = 0; i < a; i++)
  1201.                                                     {
  1202.                                                         AOI_ScanResultData_MES.Mand = m_Config.Mandator;
  1203.                                                         AOI_ScanResultData_MES.SerialNum = serialn[i];
  1204.                                                         AOI_ScanResultData_MES.Station_IP = m_Config.Station_IP;
  1205.  
  1206.                                                         if (quali[i] == status_repair)
  1207.                                                         {
  1208.                                                             AOI_ScanResultData_MES.Global_Result = status_repair;     // update device auf repair
  1209.                                                             AOI_ScanResultData_MES.Result = status_repair;
  1210.                                                         }
  1211.                                                         else
  1212.                                                         {
  1213.                                                             AOI_ScanResultData_MES.Global_Result = status_in_progress;    // device bleibt in_progress
  1214.                                                             AOI_ScanResultData_MES.Result = status_pass;
  1215.                                                         }
  1216.  
  1217.                                                         AOI_ScanResultData_MES.Device_Stage_ID = help_stage_id;
  1218.                                                         AOI_ScanResultData_MES.Replication_to = 4;
  1219.                                                         AOI_ScanResultData_MES.Machine_Serial = machine_ser;
  1220.                                                         AOI_ScanResultData_MES.Progr_Name = Prog_Name;
  1221.  
  1222.                                                         if (Insp_user_ID > 0)
  1223.                                                         {
  1224.                                                             AOI_ScanResultData_MES.Insp_user_ID = Insp_user_ID;
  1225.                                                             AOI_ScanResultData_MES.Insp_user = Insp_Op;
  1226.                                                             AOI_ScanResultData_MES.Insp_Dat = Insp_Dat;
  1227.  
  1228.                                                             if (quali[i] == status_repair || quali[i] == status_in_progress)
  1229.                                                             {
  1230.                                                                 AOI_ScanResultData_MES.Insp_Res_ch = Insp_Res_ch;
  1231.                                                                 AOI_ScanResultData_MES.Insp_NG_Count_ch = Insp_NG_Count_ch;
  1232.                                                                 AOI_ScanResultData_MES.Insp_NG_Parts_ch = Insp_NG_Parts_ch;
  1233.                                                             }
  1234.                                                             else
  1235.                                                             {
  1236.                                                                 AOI_ScanResultData_MES.Insp_Res_ch = "";
  1237.                                                                 AOI_ScanResultData_MES.Insp_NG_Count_ch = "";
  1238.                                                                 AOI_ScanResultData_MES.Insp_NG_Parts_ch = "";
  1239.                                                             }
  1240.                                                         }
  1241.                                                         else
  1242.                                                         {
  1243.                                                             AOI_ScanResultData_MES.Insp_user_ID = 0;
  1244.                                                             AOI_ScanResultData_MES.Insp_user = "";
  1245.                                                             AOI_ScanResultData_MES.Insp_Dat = "";
  1246.                                                             AOI_ScanResultData_MES.Insp_Res_ch = "";
  1247.                                                             AOI_ScanResultData_MES.Insp_NG_Count_ch = "";
  1248.                                                             AOI_ScanResultData_MES.Insp_NG_Parts_ch = "";
  1249.                                                         }
  1250.  
  1251.                                                         if (First_user_ID > 0)
  1252.                                                         {
  1253.                                                             AOI_ScanResultData_MES.First_user_ID = First_user_ID;
  1254.                                                             AOI_ScanResultData_MES.First_user = First_Op;
  1255.                                                             AOI_ScanResultData_MES.First_Op_Dat = First_Op_Dat;
  1256.  
  1257.                                                             if (!String.IsNullOrEmpty(Res_First[i]))
  1258.                                                             {
  1259.                                                                 AOI_ScanResultData_MES.First_Op_Res_ch = Status_First[i];
  1260.                                                             }
  1261.                                                             else
  1262.                                                             {
  1263.                                                                 AOI_ScanResultData_MES.First_Op_Res_ch = "";
  1264.                                                             }
  1265.  
  1266.                                                             if (quali[i] == status_repair)
  1267.                                                             {
  1268.                                                                 AOI_ScanResultData_MES.First_Op_NG_Count_ch = First_Op_NG_Count_ch;
  1269.                                                                 AOI_ScanResultData_MES.First_Op_NG_Parts_ch = First_Op_NG_Parts_ch;
  1270.                                                             }
  1271.                                                             else
  1272.                                                             {
  1273.                                                                 AOI_ScanResultData_MES.First_Op_NG_Count_ch = "";
  1274.                                                                 AOI_ScanResultData_MES.First_Op_NG_Parts_ch = "";
  1275.                                                             }
  1276.                                                         }
  1277.                                                         else
  1278.                                                         {
  1279.                                                             AOI_ScanResultData_MES.First_user_ID = 0;
  1280.                                                             AOI_ScanResultData_MES.First_user = "";
  1281.                                                             AOI_ScanResultData_MES.First_Op_Dat = "";
  1282.                                                             AOI_ScanResultData_MES.First_Op_Res_ch = "";
  1283.                                                             AOI_ScanResultData_MES.First_Op_NG_Count_ch = "";
  1284.                                                             AOI_ScanResultData_MES.First_Op_NG_Parts_ch = "";
  1285.                                                         }
  1286.  
  1287.                                                         if (Sec_user_ID > 0)
  1288.                                                         {
  1289.                                                             AOI_ScanResultData_MES.Sec_user_ID = Sec_user_ID;
  1290.                                                             AOI_ScanResultData_MES.Sec_user = Sec_Op;
  1291.                                                             AOI_ScanResultData_MES.Sec_Op_Dat = Sec_Op_Dat;
  1292.  
  1293.                                                             if (!String.IsNullOrEmpty(Status_Sec[i]))
  1294.                                                             {
  1295.                                                                 AOI_ScanResultData_MES.Sec_Op_Res_ch = Status_Sec[i];
  1296.                                                             }
  1297.                                                             else
  1298.                                                             {
  1299.                                                                 AOI_ScanResultData_MES.Sec_Op_Res_ch = "";
  1300.                                                             }
  1301.  
  1302.                                                             if (quali[i] == status_repair)
  1303.                                                             {
  1304.                                                                 AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = Sec_Op_NG_Count_ch;
  1305.                                                                 AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = Sec_Op_NG_Parts_ch;
  1306.                                                             }
  1307.                                                             else
  1308.                                                             {
  1309.                                                                 AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = "";
  1310.                                                                 AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = "";
  1311.                                                             }
  1312.                                                         }
  1313.                                                         else
  1314.                                                         {
  1315.                                                             AOI_ScanResultData_MES.Sec_user_ID = 0;
  1316.                                                             AOI_ScanResultData_MES.Sec_user = "";
  1317.                                                             AOI_ScanResultData_MES.Sec_Op_Dat = "";
  1318.                                                             AOI_ScanResultData_MES.Sec_Op_Res_ch = "";
  1319.                                                             AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = "";
  1320.                                                             AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = "";
  1321.                                                         }
  1322.  
  1323.                                                         if (!String.IsNullOrEmpty(Parts_Ref[i]))
  1324.                                                         {
  1325.                                                             if (Parts_Ref[i].Length > 100)
  1326.                                                             {
  1327.                                                                 AOI_ScanResultData_MES.Parts_Ref = Parts_Ref[i].Substring(0, 100);
  1328.                                                             }
  1329.                                                             else
  1330.                                                             {
  1331.                                                                 AOI_ScanResultData_MES.Parts_Ref = Parts_Ref[i];
  1332.                                                             }
  1333.                                                         }
  1334.                                                         else
  1335.                                                         {
  1336.                                                             AOI_ScanResultData_MES.Parts_Ref = "";
  1337.                                                         }
  1338.  
  1339.                                                         if (!String.IsNullOrEmpty(NGReason[i]))
  1340.                                                         {
  1341.                                                             if (NGReason[i].Length > 100)
  1342.                                                             {
  1343.                                                                 AOI_ScanResultData_MES.NGReason = NGReason[i].Substring(0, 100);
  1344.                                                             }
  1345.                                                             else
  1346.                                                             {
  1347.                                                                 AOI_ScanResultData_MES.NGReason = NGReason[i];
  1348.                                                             }
  1349.                                                         }
  1350.                                                         else
  1351.                                                         {
  1352.                                                             AOI_ScanResultData_MES.NGReason = "";
  1353.                                                         }
  1354.  
  1355.                                                         if (!String.IsNullOrEmpty(PinNo[i]))
  1356.                                                         {
  1357.                                                             if (PinNo[i].Length > 100)
  1358.                                                             {
  1359.                                                                 AOI_ScanResultData_MES.PinNo = PinNo[i].Substring(0, 100);
  1360.                                                             }
  1361.                                                             else
  1362.                                                             {
  1363.                                                                 AOI_ScanResultData_MES.PinNo = PinNo[i];
  1364.                                                             }
  1365.                                                         }
  1366.                                                         else
  1367.                                                         {
  1368.                                                             AOI_ScanResultData_MES.PinNo = "";
  1369.                                                         }
  1370.  
  1371.                                                         if (!String.IsNullOrEmpty(Res_First[i]))
  1372.                                                         {
  1373.                                                             AOI_ScanResultData_MES.VN_Res_First_OP = vn_Res_First;
  1374.                                                             if (Res_First[i].Length > 100)
  1375.                                                             {
  1376.                                                                 AOI_ScanResultData_MES.Res_First_OP = Res_First[i].Substring(0, 100);
  1377.                                                             }
  1378.                                                             else
  1379.                                                             {
  1380.                                                                 AOI_ScanResultData_MES.Res_First_OP = Res_First[i];
  1381.                                                             }
  1382.                                                         }
  1383.                                                         else
  1384.                                                         {
  1385.                                                             AOI_ScanResultData_MES.VN_Res_First_OP = "";
  1386.                                                             AOI_ScanResultData_MES.Res_First_OP = "";
  1387.                                                         }
  1388.  
  1389.                                                         if (!String.IsNullOrEmpty(Res_Sec[i]))
  1390.                                                         {
  1391.                                                             AOI_ScanResultData_MES.VN_Res_Sec_OP = vn_Res_Sec;
  1392.                                                             if (Res_Sec[i].Length > 100)
  1393.                                                             {
  1394.                                                                 AOI_ScanResultData_MES.Res_Sec_OP = Res_Sec[i].Substring(0, 100);
  1395.                                                             }
  1396.                                                             else
  1397.                                                             {
  1398.                                                                 AOI_ScanResultData_MES.Res_Sec_OP = Res_Sec[i];
  1399.                                                             }
  1400.                                                         }
  1401.                                                         else
  1402.                                                         {
  1403.                                                             AOI_ScanResultData_MES.VN_Res_Sec_OP = "";
  1404.                                                             AOI_ScanResultData_MES.Res_Sec_OP = "";
  1405.                                                         }
  1406.  
  1407.                                                         int rc_code = DbAccess.Insert_AOI_Data_MES(connection, AOI_ScanResultData_MES);
  1408.                                                         // Test maskiert                                                        int rc_code = 0;
  1409.  
  1410.                                                         switch (rc_code)
  1411.                                                         {
  1412.                                                             case 0:
  1413.                                                                 m_TsLogFile.WriteLine("MES AOI-Results INSERT: " + AOI_ScanResultData_MES.SerialNum + " erfolgreich");
  1414.                                                                 break;
  1415.  
  1416.                                                             case 50:
  1417.                                                                 datei_error = true;
  1418.                                                                 Fehler = true;
  1419.                                                                 eine_mail = true;
  1420.                                                                 m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! Serial-Num " + AOI_ScanResultData_MES.SerialNum + " nicht im DB-Bestand vorhanden");
  1421.                                                                 message.Body += "MES AOI-Results INSERT fehlgeschlagen! Serial-Num  " + AOI_ScanResultData_MES.SerialNum + " nicht im DB-Bestand vorhanden \r\n\r\n";
  1422.                                                                 break;
  1423.  
  1424.                                                             case 51:
  1425.                                                                 datei_error = true;
  1426.                                                                 Fehler = true;
  1427.                                                                 eine_mail = true;
  1428.                                                                 m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! SerialNum fehlt. Datei " + f);
  1429.                                                                 message.Body += "MES AOI-Results INSERT fehlgeschlagen! Serial-Num  fehlt. Datei " + f + " \r\n\r\n";
  1430.                                                                 break;
  1431.  
  1432.                                                             case 52:
  1433.                                                                 datei_error = true;
  1434.                                                                 Fehler = true;
  1435.                                                                 eine_mail = true;
  1436.                                                                 m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! Datumsangaben fehlen. Datei " + f);
  1437.                                                                 message.Body += "MES AOI-Results INSERT fehlgeschlagen! Datumsangaben fehlen. Datei " + f + " \r\n\r\n";
  1438.                                                                 break;
  1439.  
  1440.                                                             case 99:
  1441.                                                                 datei_error = true;
  1442.                                                                 Fehler = true;
  1443.                                                                 eine_mail = true;
  1444.                                                                 message.Body += "DB Zugriffsfehler => Error Number: " + Convert.ToString(DBReturn_Errors.ErrorNumber) + "    Sererity: " + Convert.ToString(DBReturn_Errors.ErrorSeverity) + "    State: " + Convert.ToString(DBReturn_Errors.ErrorState) + "    Procedure: " + DBReturn_Errors.ErrorProcedure + "    Line: " + Convert.ToString(DBReturn_Errors.ErrorLine) + "    Message: " + DBReturn_Errors.ErrorMessage + "\r\n\r\n";
  1445.                                                                 m_TsLogFile.WriteLine("DB Zugriffsfehler => Error Number: " + Convert.ToString(DBReturn_Errors.ErrorNumber) + "    Sererity: " + Convert.ToString(DBReturn_Errors.ErrorSeverity) + "    State: " + Convert.ToString(DBReturn_Errors.ErrorState) + "    Procedure: " + DBReturn_Errors.ErrorProcedure + "    Line: " + Convert.ToString(DBReturn_Errors.ErrorLine) + "    Message: " + DBReturn_Errors.ErrorMessage);
  1446.                                                                 break;
  1447.  
  1448.                                                             default:
  1449.                                                                 datei_error = true;
  1450.                                                                 Fehler = true;
  1451.                                                                 eine_mail = true;
  1452.                                                                 message.Body += "DB unbekannter Fehler aufgetreten !!!!! \r\n\r\n";
  1453.                                                                 m_TsLogFile.WriteLine("DB unbekannter Fehler aufgetreten !!!!!");
  1454.                                                                 break;
  1455.  
  1456.                                                         }
  1457.                                                     }
  1458.                                                 }
  1459.                                             }
  1460.                                         }
  1461.                                         else
  1462.                                         {
  1463.                                             string fehler_text;
  1464.                                             switch (glob_rc)
  1465.                                             {
  1466.                                                 case 4:
  1467.                                                     fehler_text = "User ID fehlt";
  1468.                                                     break;
  1469.                                                 case 5:
  1470.                                                     fehler_text = "Decive Stage ID oder Serialnum fehlt";
  1471.                                                     break;
  1472.                                                 case 6:
  1473.                                                     fehler_text = "Keine Serial Nummern gefunden";
  1474.                                                     break;
  1475.                                                 default:
  1476.                                                     fehler_text = "unbekannte Ausnahme";
  1477.                                                     break;
  1478.                                             }
  1479.  
  1480.                                             datei_error = true;
  1481.                                             Fehler = true;
  1482.                                             eine_mail = true;
  1483.                                             message.Body += "Grundlegender Error:  Basisdaten " + fehler_text + "\r\n\r\n";
  1484.                                             m_TsLogFile.WriteLine("Grundlegender Error: Basisdaten " + fehler_text);
  1485.                                             glob_rc = Convert.ToInt32(Glob_RC.I_O);
  1486.                                         }
  1487.  
  1488. //                                        }
  1489.  
  1490.                                         if (!datei_error)
  1491.                                         {
  1492.                                             datei_verarb = true;
  1493.                                             lbFiles.Items.Add("Die Datei " + System.IO.Path.GetFileName(f) + " wurde ordnungsgemäss verarbeitet.");
  1494.                                         }
  1495.                                         else
  1496.                                         {
  1497.                                             lbFiles.Items.Add("Die Datei " + System.IO.Path.GetFileName(f) + " konnte nicht ordnungsgemäss verarbeitet werden.");
  1498.                                         }
  1499.  
  1500.                                         // Datei verschieben
  1501.                                         if (datei_verarb)
  1502.                                         {
  1503.                                             //                      Exists Archiv-Verzeichnis?
  1504.                                             if (!System.IO.Directory.Exists(archiv_pfad))
  1505.                                             {
  1506.                                                 System.IO.Directory.CreateDirectory(archiv_pfad);
  1507.                                             }
  1508.  
  1509.                                             if (System.IO.File.Exists(MES_File))
  1510.                                                 System.IO.File.Delete(MES_File);
  1511.  
  1512.                                             System.IO.File.Move(f, MES_File);
  1513.  
  1514.                                             if (ng_folder.Length > 0 && Spc_File.Length > 0)
  1515.                                             {
  1516.                                                 string pic_path = m_Config.NW_LW_Quelle + "\\" + Spc_Path + "\\" + Spc_File + "Image";
  1517.  
  1518.                                                 if (System.IO.Directory.Exists(pic_path))
  1519.                                                 {
  1520.                                                     foreach (string pic in System.IO.Directory.GetFiles(pic_path, "*.*"))
  1521.                                                     {
  1522.                                                         if (pic.EndsWith("jxr") == true || pic.EndsWith("jpg") == true)
  1523.                                                         {
  1524.                                                             string pic_name = archiv_pfad + pic.Substring(pic.LastIndexOf("\\") + 1);
  1525.  
  1526.                                                             if (System.IO.File.Exists(pic_name))
  1527.                                                                 System.IO.File.Delete(pic_name);
  1528.  
  1529.                                                             System.IO.File.Move(pic, pic_name);
  1530.                                                         }
  1531.                                                     }
  1532.                                                 }
  1533.                                                 else
  1534.                                                 {
  1535.                                                     eine_mail = true;
  1536.                                                     message.Body += "Der Bild-Pfad: " + pic_path + " wurde nicht gefunden. PCB-Num: " + PCB_Num + "\r\n\r\n";
  1537.                                                     m_TsLogFile.WriteLine("Der Bild-Pfad: " + pic_path + " wurde nicht gefunden. PCB-Num: " + PCB_Num);
  1538.                                                 }
  1539.                                             }
  1540.                                         }
  1541.  
  1542.                                         if (datei_error)
  1543.                                         {
  1544.                                             string ERROR_File = m_Config.FileDirectory_ERROR + "\\" + System.IO.Path.GetFileName(f);
  1545.  
  1546.                                             if (System.IO.File.Exists(ERROR_File))
  1547.                                                 System.IO.File.Delete(ERROR_File);
  1548.  
  1549.                                             System.IO.File.Move(f, ERROR_File);
  1550.  
  1551.                                             eine_mail = true;
  1552.                                             message.Body += "Die Datei " + ERROR_File + " konnte nicht ordnungsgemäss verarbeitet werden.\r\n";
  1553.  
  1554.                                             Fehler = true;
  1555.                                         }
  1556.                                     }
  1557.                                 }
  1558.                             }
  1559.                         }
  1560.                         else
  1561.                         {
  1562.                             string fehler_text;
  1563.                             switch (glob_rc)
  1564.                             {
  1565.                                 case 1:
  1566.                                     fehler_text = "Status PASS fehlt";
  1567.                                     break;
  1568.                                 case 2:
  1569.                                     fehler_text = "Status FAIL fehlt";
  1570.                                     break;
  1571.                                 case 3:
  1572.                                     fehler_text = "Status REPAIR fehlt";
  1573.                                     break;
  1574.                                 case 7:
  1575.                                     fehler_text = "Value_Name PCBNum fehlt";
  1576.                                     break;
  1577.                                 case 8:
  1578.                                     fehler_text = "Value_Name Machine Serial fehlt";
  1579.                                     break;
  1580.                                 case 9:
  1581.                                     fehler_text = "Value_Name Progr. Name fehlt";
  1582.                                     break;
  1583.                                 case 10:
  1584.                                     fehler_text = "Value_Name Insp. user ID fehlt";
  1585.                                     break;
  1586.                                 case 11:
  1587.                                     fehler_text = "Value_Name First User ID fehlt";
  1588.                                     break;
  1589.                                 case 12:
  1590.                                     fehler_text = "Value_Name Sec User ID fehlt";
  1591.                                     break;
  1592.                                 case 13:
  1593.                                     fehler_text = "Value_Name Insp. Datum fehlt";
  1594.                                     break;
  1595.                                 case 14:
  1596.                                     fehler_text = "Value_Name First Operator Datum fehlt";
  1597.                                     break;
  1598.                                 case 15:
  1599.                                     fehler_text = "Value_Name Second Operator Datum fehlt";
  1600.                                     break;
  1601.                                 case 16:
  1602.                                     fehler_text = "Value_Name Insp. Result fehlt";
  1603.                                     break;
  1604.                                 case 17:
  1605.                                     fehler_text = "Value_Name First Operator Result fehlt";
  1606.                                     break;
  1607.                                 case 18:
  1608.                                     fehler_text = "Value_Name Second Operator Result fehlt";
  1609.                                     break;
  1610.                                 case 19:
  1611.                                     fehler_text = "Value_Name Insp. NG Count fehlt";
  1612.                                     break;
  1613.                                 case 20:
  1614.                                     fehler_text = "Value_Name First Operator NG Count fehlt";
  1615.                                     break;
  1616.                                 case 21:
  1617.                                     fehler_text = "Value_Name Second Operator NG Count fehlt";
  1618.                                     break;
  1619.                                 case 22:
  1620.                                     fehler_text = "Value_Name Insp. NG Parts fehlt";
  1621.                                     break;
  1622.                                 case 23:
  1623.                                     fehler_text = "Value_Name First Operator NG Parts fehlt";
  1624.                                     break;
  1625.                                 case 24:
  1626.                                     fehler_text = "Value_Name Second Operator NG Parts fehlt";
  1627.                                     break;
  1628.                                 case 25:
  1629.                                     fehler_text = "Value_Name Parts Reference Number fehlt";
  1630.                                     break;
  1631.                                 case 26:
  1632.                                     fehler_text = "Value_Name NG Reason fehlt";
  1633.                                     break;
  1634.                                 case 27:
  1635.                                     fehler_text = "Value_Name Pin Number fehlt";
  1636.                                     break;
  1637.                                 case 28:
  1638.                                     fehler_text = "Value Name Dummy Record used as fehlt";
  1639.                                     break;
  1640.                                 case 29:
  1641.                                     fehler_text = "Status IN PROGRESS fehlt";
  1642.                                     break;
  1643.                                 case 30:
  1644.                                     fehler_text = "Value Name Result First OP fehlt";
  1645.                                     break;
  1646.                                 case 31:
  1647.                                     fehler_text = "Value Name Secound OP fehlt";
  1648.                                     break;
  1649.                                 case 32:
  1650.                                     fehler_text = "Das Quell-Verzeichnis Good fehlt";
  1651.                                     break;
  1652.                                 case 33:
  1653.                                     fehler_text = "Das Quell-Verzeichnis Judge fehlt";
  1654.                                     break;
  1655.  
  1656.                                 default:
  1657.                                     fehler_text = "unbekannte Ausnahme";
  1658.                                     break;
  1659.                             }
  1660.  
  1661.                             Fehler = true;
  1662.                             eine_mail = true;
  1663.                             message.Body += "Grundlegender Error: Parameter " + fehler_text + "\r\n\r\n";
  1664.                             m_TsLogFile.WriteLine("Grundlegender Error: Parameter " + fehler_text);
  1665.                         }
  1666. //                        connection = DbAccess.Open_MES(false);
  1667.                     }
  1668.                    
  1669.                     catch (Exception ex)
  1670.                     {
  1671.                         string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
  1672.                         throw new Exception(methodName + ": " + ex.Message + " File: " + file_name);
  1673.                     }
  1674.  
  1675.                     if (Fehler)
  1676.                     {
  1677.                         lbFiles.Items.Add("Verarbeitung mit Fehler/n abgeschlossen");
  1678.                         m_TsLogFile.WriteLine("Verarbeitung mit Fehler/n abgeschlossen");
  1679.                     }
  1680.                     else
  1681.                     {
  1682.                         lbFiles.Items.Add("Verarbeitung erfolgreich abgeschlossen");
  1683.                         m_TsLogFile.WriteLine("Verarbeitung erfolgreich abgeschlossen");
  1684.                     }
  1685.  
  1686.                     if (eine_mail)
  1687.                     {
  1688.                         try
  1689.                         {
  1690.                             SmtpClient client = new SmtpClient(m_Config.MAIL_Client, int.Parse(m_Config.MAIL_Port));
  1691.  
  1692.                             client.Credentials = new NetworkCredential(m_Config.MAIL_User, m_Config.MAIL_PW);
  1693.  
  1694.                             client.EnableSsl = false;
  1695.  
  1696.                             ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };         // unsauberer Griff um Daun-Experten am Exchange mit ihren "Änderungen" zu umgehen   !!!!!
  1697.  
  1698.                             client.Send(message);
  1699.                         }
  1700.  
  1701.                         catch (SmtpException exeption)
  1702.                         {
  1703.                             MessageBox.Show(exeption.Message);
  1704.                         }
  1705.  
  1706.                         LBAnzDateien.Text = lbFiles.Items.Count.ToString();
  1707.                     }
  1708.                     else
  1709.                     {
  1710. //                        nix zu tun ;-)
  1711.                     }
  1712.                     DeleteObsoleteLogfiles();
  1713.                 }
  1714.  
  1715. //                MapNetworkDriveDisconnect("TTTTT:"); könnte zur Lösung der Netzwerkverbindung aktiviert werden
  1716. //                MapNetworkDriveDisconnect("VVVVV:"); ebenso
  1717.             }
  1718.             catch (Exception ex)
  1719.             {
  1720.                 string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
  1721.                 throw new Exception(methodName + ": " + ex.HResult + "  " + ex.Message + " File: " + file_name);
  1722.             }
  1723.         }
  1724.  
  1725.  
  1726.         private void auswahlToolStripMenuItem_Click(object sender, EventArgs e)
  1727.         {
  1728.             openFileDialog1.ShowDialog();
  1729.         }
  1730.  
  1731.         private void Form1_Load(object sender, EventArgs e)
  1732.         {
  1733.             this.Show();
  1734.             this.Activate();
  1735.             Application.DoEvents();
  1736.             System.Threading.Thread.Sleep(200);
  1737.             this.Close();
  1738.         }
  1739.  
  1740.         /// <summary>
  1741.         /// Löschen veralteter Protokolldateien übernommen von J. Mayer
  1742.         /// </summary>
  1743.         private void DeleteObsoleteLogfiles()
  1744.         {
  1745.             try
  1746.             {
  1747.                 if (m_Config.IsLogfileDeadlineActive)
  1748.                 {
  1749.                     DateTime deadline = DateTime.Now;
  1750.                     TimeSpan livingTime = new TimeSpan(
  1751.                         m_Config.LogfileDeadline.Days,
  1752.                         m_Config.LogfileDeadline.Hours,
  1753.                         m_Config.LogfileDeadline.Minutes,
  1754.                         m_Config.LogfileDeadline.Seconds);
  1755.                     deadline = deadline.Subtract(livingTime);
  1756.                     int deletedFiles = m_TsLogFile.DeleteObsoleteFiles(deadline);
  1757.                     m_TsLogFile.WriteLine(string.Format("{0} veraltete Log-Dateien sind gelöscht worden.", deletedFiles), TsLogFile.MsgCharacter.Info);
  1758.                 }
  1759.             }
  1760.             catch (Exception ex)
  1761.             {
  1762.                 string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
  1763.                 throw new Exception(methodName + ": " + ex.Message);
  1764.             }
  1765.         }
  1766.  
  1767.  
  1768.         /// <summary>
  1769.         /// bereinigen User-Name und bereitstellen User_ID aus DB
  1770.         /// </summary>
  1771.         private int find_user_ID(string name)
  1772.         {
  1773.             // Einschub Namenskorrektur
  1774.             int pos_st;
  1775.             int pos_pt;
  1776.             int pos_bl;
  1777.             string vn = "";
  1778.             string nn = "";
  1779.  
  1780.             if (name.Contains("SCHMIEDT R."))
  1781.             {
  1782.                 name = "SCHMIDT R";
  1783.             }
  1784.             else
  1785.             {
  1786.                 name = name.TrimStart();
  1787.             }
  1788.  
  1789.             if (name.Contains("_DEFAULT_OPERATOR"))
  1790.             {
  1791.                 name = "prod.vogtl";
  1792.             }
  1793.  
  1794.             if (name.Contains("TSV:"))
  1795.             {
  1796.                 name = name.Substring(4);
  1797.                 pos_st = name.IndexOf("-");
  1798.                 vn = name.Substring(pos_st + 1);
  1799.                 nn = name.Substring(0, pos_st);
  1800.             }
  1801.  
  1802.             if (name.Contains("-"))
  1803.             {
  1804.                 pos_st = name.IndexOf("-");
  1805.                 vn = name.Substring(pos_st + 1);
  1806.                 nn = name.Substring(0, pos_st);
  1807.             }
  1808.  
  1809.             if (name.Contains("."))
  1810.             {
  1811.                 pos_pt = name.IndexOf(".");
  1812.                 if (name.Length == pos_pt + 1)
  1813.                 {
  1814.                     pos_bl = name.IndexOf(" ");
  1815.                     vn = name.Substring(pos_bl + 1, pos_pt - pos_bl - 1);
  1816.                     nn = name.Substring(0, pos_bl);
  1817.                 }
  1818.                 else
  1819.                 {
  1820.                     vn = name.Substring(0, pos_pt);
  1821.                     nn = name.Substring(pos_pt + 1);
  1822.                     nn = nn.TrimStart(' ');
  1823.                 }
  1824.             }
  1825.             else
  1826.             {
  1827.                 if (name.Contains(" "))
  1828.                 {
  1829.                     vn = name.Substring(name.IndexOf(" ") + 1);
  1830.                     vn = vn.Replace(".", "");
  1831.                     nn = name.Substring(0, name.IndexOf(" "));
  1832.                 }
  1833.             }
  1834.             name = vn.ToLower() + "." + nn.ToLower();
  1835.  
  1836.             int look_up_user_id_rc = DbAccess.Look_up_User_ID_MES(connection, name);
  1837.  
  1838.             if (look_up_user_id_rc == 0)
  1839.             {
  1840.                 // Fehler keine User_id, ersatzweise user "prod.vogtl" verwenden
  1841.                 look_up_user_id_rc = DbAccess.Look_up_User_ID_MES(connection, "prod.vogtl");
  1842.                 if (look_up_user_id_rc == 0)
  1843.                 {
  1844.                     // totaler Fehler "prod.vogtl" gelöscht
  1845.                     return 0;
  1846.                 }
  1847.                 else
  1848.                 {
  1849.                     return look_up_user_id_rc;
  1850.                 }
  1851.             }
  1852.             else
  1853.             {
  1854.                 return look_up_user_id_rc;
  1855.             }
  1856.         }
  1857.  
  1858.         /// <summary>
  1859.         /// Disconnects a network drive
  1860.         /// </summary>
  1861.         /// <param name="drive">Drive (z.B. L:)</param>
  1862.         private void MapNetworkDriveDisconnect(string drive)
  1863.         {
  1864.             Process p = new Process();
  1865.             p.StartInfo.FileName = "net";
  1866.             p.StartInfo.Arguments = string.Format("use {0} /DELETE /yes", drive);
  1867.             p.StartInfo.UseShellExecute = false;
  1868.             p.Start();
  1869.         }
  1870.  
  1871.         /// <summary>
  1872.         /// Connects a network drive
  1873.         /// </summary>
  1874.         /// <param name="drive">The drive letter (e.g. L:)</param>
  1875.         /// <param name="server">The UNC path to the remote drive (e.g. \\MyServer\MyPrinter)</param>
  1876.         /// <param name="user">The User</param>
  1877.         /// <param name="password">The Password Used For Login</param>
  1878.         private void MapNetworkDriveConnect(string drive, string server, string user, string password)
  1879.         {
  1880.             Process p = new Process();
  1881.             p.StartInfo.FileName = "net";
  1882.             p.StartInfo.Arguments = string.Format("use {0} {1} /user:{2} {3}", drive, server, user, password);
  1883.             p.StartInfo.UseShellExecute = false;
  1884.             p.Start();
  1885.         }
  1886.  
  1887.     }
  1888.  
  1889. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement