Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Net;
- using System.Net.Mail;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Configuration;
- using System.Text.RegularExpressions;
- using MES_Import_AOI_Results.Properties;
- using System.Security.Principal;
- using System.Security.Permissions;
- using System.Runtime.InteropServices;
- using System.Diagnostics;
- using TsLib;
- using TSV_Crypt_PW;
- namespace MES_Import_AOI_Results
- {
- public enum Glob_RC
- {
- I_O = 0,
- ST_PASS_fehlt = 1,
- ST_FAIL_fehlt = 2,
- ST_REPAIR_fehlt = 3,
- User_ID_fehlt = 4,
- Dev_stage_ID_fehlt = 5,
- Keine_SerialNums_gefunden = 6,
- Val_PCBNum_fehlt = 7,
- Val_Machine_Serial_fehlt = 8,
- Val_Progr_Name_fehlt = 9,
- Val_Insp_user_fehlt = 10,
- Val_First_user_fehlt = 11,
- Val_Sec_user_fehlt = 12,
- Val_Insp_Dat_fehlt = 13,
- Val_First_Op_Dat_fehlt = 14,
- Val_Sec_Op_Dat_fehlt = 15,
- Val_Insp_Res_fehlt = 16,
- Val_First_Op_Res_fehlt = 17,
- Val_Sec_Op_Res_fehlt = 18,
- Val_Insp_NG_Count_fehlt = 19,
- Val_First_Op_NG_Count_fehlt = 20,
- Val_Sec_Op_NG_Count_fehlt = 21,
- Val_Insp_NG_Parts_fehlt = 22,
- Val_First_Op_NG_Parts_fehlt = 23,
- Val_Sec_Op_NG_Parts_fehlt = 24,
- Val_Parts_Ref_fehlt = 25,
- Val_NGReason_fehlt = 26,
- Val_PinNo_fehlt = 27,
- Val_Dummy_fehlt = 28,
- ST_IN_PROGRESS_fehlt = 29,
- Val_Res_First_OP_fehlt = 30,
- Val_Res_Sec_OP_fehlt = 31,
- Quell_Verzeichnis_Good_fehlt = 32,
- Quell_Verzeichnis_Judge_fehlt = 33,
- None
- }
- public partial class Form1 : Form
- {
- private Config m_Config;
- private TsLogFile m_TsLogFile;
- private DbAccess m_DbAccess;
- private List<DB_AOI_Data_MES> AOI_Data_MES;
- private DB_AOI_ScanResultData_MES AOI_ScanResultData_MES;
- private List<MES_DB_Laser_SerialNum> Laser_ResultData;
- private DBReturn_Errors Proc_Errors;
- public System.Data.SqlClient.SqlConnection connection;
- public static string pw_uv;
- public static string NW_pw_quelle;
- public static string NW_pw_ziel;
- public static string file_name;
- /// <summary>
- /// Konstruktor
- /// </summary>
- public Form1()
- {
- InitializeComponent();
- try
- {
- Init();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Software-Fehler");
- }
- }
- /// <summary>
- /// Prüfung auf numerisch über regulären Ausdruck
- /// </summary>
- static bool IsNumericString(string strAlphanum)
- {
- System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(@"^[0-9]+$");
- return pattern.IsMatch(strAlphanum.Trim());
- }
- /// <summary>
- /// Initialisierung
- /// </summary>
- private void Init()
- {
- try
- {
- m_Config = new Config();
- m_TsLogFile = new TsLogFile();
- m_DbAccess = new DbAccess(m_Config);
- AOI_Data_MES = new List<DB_AOI_Data_MES>();
- AOI_ScanResultData_MES = new DB_AOI_ScanResultData_MES();
- Laser_ResultData = new List<MES_DB_Laser_SerialNum>();
- byte[] key = { 66, 122, 26, 24, 156, 86, 182, 98, 48, 176, 46, 126, 101, 66, 32, 146 };
- byte[] iv = { 44, 58, 41, 33, 77, 142, 165, 42, 73, 84, 32, 69, 24, 76, 37, 56 };
- string Pw = m_Config.Pwd;
- List<string> ret_val = TSV_Crypt.Crypt_PW(Pw, key, iv);
- if (ret_val[0] != null && ret_val[0].Length > 0)
- {
- m_TsLogFile.WriteLine("For use to setup config: \"" + ret_val[0] + "\".");
- }
- pw_uv = ret_val[1];
- string NW_Pw_Quelle = m_Config.NW_PW_Quelle;
- List<string> NW_Quelle_ret_val = TSV_Crypt.Crypt_PW(NW_Pw_Quelle, key, iv);
- if (NW_Quelle_ret_val[0] != null && NW_Quelle_ret_val[0].Length > 0)
- {
- m_TsLogFile.WriteLine("For use to setup config for NW_Quelle: \"" + NW_Quelle_ret_val[0] + "\".");
- }
- NW_pw_quelle = NW_Quelle_ret_val[1];
- string NW_Pw_Ziel = m_Config.NW_PW_Ziel;
- List<string> NW_Ziel_ret_val = TSV_Crypt.Crypt_PW(NW_Pw_Ziel, key, iv);
- if (NW_Ziel_ret_val[0] != null && NW_Ziel_ret_val[0].Length > 0)
- {
- m_TsLogFile.WriteLine("For use to setup config for NW_Ziel: \"" + NW_Ziel_ret_val[0] + "\".");
- }
- NW_pw_ziel = NW_Ziel_ret_val[1];
- bool eine_mail = false; // nur eine Mail senden
- MailMessage message = new MailMessage();
- message.From = new MailAddress(m_Config.MAIL_From);
- message.To.Add(m_Config.MAIL_To);
- if (m_Config.MAIL_CC.Length > 0)
- {
- message.CC.Add(m_Config.MAIL_CC);
- }
- message.Subject = m_Config.MAIL_Betreff;
- int glob_rc = 0; // globaler RC I.O.
- if (m_Config.NW_LW_Quelle.Length > 0)
- {
- // Exists Quelle?
- if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good))
- {
- MapNetworkDriveDisconnect(m_Config.NW_LW_Quelle);
- MapNetworkDriveConnect(m_Config.NW_LW_Quelle, "\\\\smd-vogtland1\\d$", m_Config.NW_User_Quelle, NW_pw_quelle);
- System.Threading.Thread.Sleep(100);
- eine_mail = true;
- message.Body += "Das Quell-Laufwerk existierte nicht und wurde wiederhergestellt. \r\n\r\n";
- }
- }
- if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good))
- {
- eine_mail = true;
- message.Body += "Das Quell-Verzeichnis \"Good\" existiert nicht! \r\n\r\n";
- glob_rc = Convert.ToInt32(Glob_RC.Quell_Verzeichnis_Good_fehlt);
- }
- if (!System.IO.Directory.Exists(m_Config.NW_LW_Quelle + m_Config.FileDirectory_Judge))
- {
- eine_mail = true;
- message.Body += "Das Quell-Verzeichnis \"Judge\" existiert nicht! \r\n\r\n";
- glob_rc = Convert.ToInt32(Glob_RC.Quell_Verzeichnis_Judge_fehlt);
- }
- // Exists Archiv-Ziel?
- if (!System.IO.Directory.Exists(m_Config.NW_LW_Ziel + m_Config.FileDirectory_ARCHIV))
- {
- MapNetworkDriveDisconnect(m_Config.NW_LW_Ziel);
- MapNetworkDriveConnect(m_Config.NW_LW_Ziel, "\\\\sic-vogtland1\\d", m_Config.NW_User_Ziel, NW_pw_ziel);
- System.Threading.Thread.Sleep(100);
- eine_mail = true;
- message.Body += "Das Ziel-Laufwerk existierte nicht und wurde wierehergestellt. \r\n\r\n";
- }
- // MapNetworkDriveDisconnect(m_Config.NW_LW_Quelle);
- // MapNetworkDriveDisconnect(m_Config.NW_LW_Ziel);
- // MapNetworkDriveConnect(m_Config.NW_LW_Quelle, "\\\\smd-vogtland1\\d$", m_Config.NW_User_Quelle, NW_pw_quelle);
- // MapNetworkDriveConnect(m_Config.NW_LW_Ziel, "\\\\sic-vogtland1\\d", m_Config.NW_User_Ziel, NW_pw_ziel);
- if (m_DbAccess.TestDbAccess())
- {
- bool Fehler = false;
- try
- {
- this.Width = int.Parse(m_Config.DisplayWidth);
- this.Height = int.Parse(m_Config.DisplayHeight);
- lbFiles.Width = this.Width - 30;
- SLBDatabaseConection.Text = m_Config.Server + "/" + m_Config.User + " (connected)";
- bool datei_verarb = false;
- bool datei_error = false;
- int max = 100; // maximale Anzahl Serialnummern pro Nutzen
- int s = 0, e = 0, z = 0, a = 0, n = 0; // s => start e => ende z => zahl a => anzahl
- int ordern = 0;
- Settings setting = new Settings();
- connection = DbAccess.Open_MES(true);
- string act_Directory;
- // Exists Fehler-Verzeichnis?
- if (!System.IO.Directory.Exists(m_Config.FileDirectory_ERROR))
- {
- System.IO.Directory.CreateDirectory(m_Config.FileDirectory_ERROR);
- }
- int status_pass = 0;
- // int status_fail = 0;
- int status_repair = 0;
- int status_in_progress = 0;
- // Status PASS
- int look_up_status_pass = DbAccess.Look_up_Status_PASS_MES(connection, "PASS");
- if (look_up_status_pass == 0)
- {
- // Fehler
- status_pass = 0;
- glob_rc = Convert.ToInt32(Glob_RC.ST_PASS_fehlt);
- }
- else
- {
- status_pass = look_up_status_pass;
- }
- // Status FAIL wird zur Zeit hier nicht verwendet
- // if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- // {
- // int look_up_status_fail = DbAccess.Look_up_Status_PASS_MES(connection, "FAIL");
- // if (look_up_status_fail == 0)
- // {
- // Fehler
- // status_fail = 0;
- // glob_rc = Convert.ToInt32(Glob_RC.ST_FAIL_fehlt);
- // }
- // else
- // {
- // status_fail = look_up_status_fail;
- // }
- // }
- // Status REPAIR
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- int look_up_status_repair = DbAccess.Look_up_Status_PASS_MES(connection, "REPAIR");
- if (look_up_status_repair == 0)
- {
- // Fehler
- status_repair = 0;
- glob_rc = Convert.ToInt32(Glob_RC.ST_REPAIR_fehlt);
- }
- else
- {
- status_repair = look_up_status_repair;
- }
- }
- // Status IN_PROGRESS
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- int look_up_status_in_progress = DbAccess.Look_up_Status_PASS_MES(connection, "IN PROGRESS");
- if (look_up_status_in_progress == 0)
- {
- // Fehler
- status_in_progress = 0;
- glob_rc = Convert.ToInt32(Glob_RC.ST_IN_PROGRESS_fehlt);
- }
- else
- {
- status_in_progress = look_up_status_in_progress;
- }
- }
- int look_up_value_name;
- string value_name_PCBNum;
- // value name PCBNum
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Laser PCB number");
- if (look_up_value_name != 0)
- {
- // Fehler
- value_name_PCBNum = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_PCBNum_fehlt);
- }
- else
- {
- value_name_PCBNum = DBReturn_Names.Quality_ID;
- }
- string vn_Machine_Serial;
- // value name Machine_Serial
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Machine Serial");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Machine_Serial = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Machine_Serial_fehlt);
- }
- else
- {
- vn_Machine_Serial = DBReturn_Names.Quality_ID;
- }
- string vn_Progr_Name;
- // value name Progr_Name
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Programm Name");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Progr_Name = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Progr_Name_fehlt);
- }
- else
- {
- vn_Progr_Name = DBReturn_Names.Quality_ID;
- }
- string vn_Insp_user;
- // value name _Insp_user
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection User");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Insp_user = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_user_fehlt);
- }
- else
- {
- vn_Insp_user = DBReturn_Names.Quality_ID;
- }
- string vn_First_user;
- // value name First_user
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First User");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_First_user = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_First_user_fehlt);
- }
- else
- {
- vn_First_user = DBReturn_Names.Quality_ID;
- }
- string vn_Sec_user;
- // value name Sec_user
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second User");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Sec_user = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_user_fehlt);
- }
- else
- {
- vn_Sec_user = DBReturn_Names.Quality_ID;
- }
- string vn_Insp_Res;
- // value name Insp_Res
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection Result");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Insp_Res = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_Res_fehlt);
- }
- else
- {
- vn_Insp_Res = DBReturn_Names.Quality_ID;
- }
- string vn_First_Op_Res;
- // value name First_Op_Res
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator Result");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_First_Op_Res = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_Res_fehlt);
- }
- else
- {
- vn_First_Op_Res = DBReturn_Names.Quality_ID;
- }
- string vn_Sec_Op_Res;
- // value name Sec_Op_Res
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator Result");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Sec_Op_Res = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_Res_fehlt);
- }
- else
- {
- vn_Sec_Op_Res = DBReturn_Names.Quality_ID;
- }
- string vn_Insp_NG_Count;
- // value name Insp_NG_Count
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection NG Count");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Insp_NG_Count = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_NG_Count_fehlt);
- }
- else
- {
- vn_Insp_NG_Count = DBReturn_Names.Quality_ID;
- }
- string vn_First_Op_NG_Count;
- // value name First_Op_NG_Count
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator NG Count");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_First_Op_NG_Count = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_NG_Count_fehlt);
- }
- else
- {
- vn_First_Op_NG_Count = DBReturn_Names.Quality_ID;
- }
- string vn_Sec_Op_NG_Count;
- // value name Sec_Op_NG_Count
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator NG Count");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Sec_Op_NG_Count = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_NG_Count_fehlt);
- }
- else
- {
- vn_Sec_Op_NG_Count = DBReturn_Names.Quality_ID;
- }
- string vn_Insp_NG_Parts;
- // value name Insp_NG_Parts
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Inspection NG Parts");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Insp_NG_Parts = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Insp_NG_Parts_fehlt);
- }
- else
- {
- vn_Insp_NG_Parts = DBReturn_Names.Quality_ID;
- }
- string vn_First_Op_NG_Parts;
- // value name First_Op_NG_Parts
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "First Operator NG Parts");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_First_Op_NG_Parts = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_First_Op_NG_Parts_fehlt);
- }
- else
- {
- vn_First_Op_NG_Parts = DBReturn_Names.Quality_ID;
- }
- string vn_Sec_Op_NG_Parts;
- // value name Sec_Op_NG_Parts
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Second Operator NG Parts");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Sec_Op_NG_Parts = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Sec_Op_NG_Parts_fehlt);
- }
- else
- {
- vn_Sec_Op_NG_Parts = DBReturn_Names.Quality_ID;
- }
- string vn_Parts_Ref;
- // value name Parts_Ref
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Parts Reference Number");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Parts_Ref = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Parts_Ref_fehlt);
- }
- else
- {
- vn_Parts_Ref = DBReturn_Names.Quality_ID;
- }
- string vn_NGReason;
- // value name NGReason
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "NG Reason");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_NGReason = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_NGReason_fehlt);
- }
- else
- {
- vn_NGReason = DBReturn_Names.Quality_ID;
- }
- string vn_PinNo;
- // value name PinNo
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Pin Number");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_PinNo = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_PinNo_fehlt);
- }
- else
- {
- vn_PinNo = DBReturn_Names.Quality_ID;
- }
- string vn_Dummy;
- // value name Dummy Record
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Dummy Record used as");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Dummy = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Dummy_fehlt);
- }
- else
- {
- vn_Dummy = DBReturn_Names.Quality_ID;
- }
- string vn_Res_First;
- // value name Result First OP
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Result First OP");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Res_First = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Res_First_OP_fehlt);
- }
- else
- {
- vn_Res_First = DBReturn_Names.Quality_ID;
- }
- string vn_Res_Sec;
- // value name Result Sec OP
- look_up_value_name = DbAccess.Look_up_Value_Name_MES(connection, "Result Sec OP");
- if (look_up_value_name != 0)
- {
- // Fehler
- vn_Res_Sec = "";
- glob_rc = Convert.ToInt32(Glob_RC.Val_Res_Sec_OP_fehlt);
- }
- else
- {
- vn_Res_Sec = DBReturn_Names.Quality_ID;
- }
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- for (n = 0; n < 2; n++) // Durchlauf durch 2 Quellverzeichnisse
- {
- if (n == 0)
- {
- // 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" !!!!!
- act_Directory = m_Config.NW_LW_Quelle + m_Config.FileDirectory_Good; // PREJUDGE => nur "OK"
- }
- else
- {
- // 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" !!!!!
- act_Directory = m_Config.NW_LW_Quelle + m_Config.FileDirectory_Judge; // JUDGE => alle restlichen Files
- }
- foreach (string f in System.IO.Directory.GetFiles(act_Directory, "*.xml"))
- {
- if (f.IndexOf("PASSMODE") > 0 || (f.IndexOf("@NG@") > 0 && n == 0))
- {
- // nothing to do :)
- }
- else
- {
- file_name = f;
- datei_error = false;
- int[] quali = new int[max];
- string[] Parts_Ref = new string[max];
- string[] NGReason = new string[max];
- string[] PinNo = new string[max];
- string[] Status_First = new string[max];
- string[] Status_Sec = new string[max];
- string[] Res_First = new string[max];
- string[] Res_Sec = new string[max];
- string[] serialn = new string[max];
- string machine_ser = "";
- string PCB_Num_Laser = "";
- string PCB_ID = "";
- string Prog_Name = "";
- string Insp_Op = "";
- string First_Op = "";
- string Sec_Op = "";
- string Insp_Dat = "";
- string First_Op_Dat = "";
- string Sec_Op_Dat = "";
- int Insp_user_ID = 0;
- int First_user_ID = 0;
- int Sec_user_ID = 0;
- string Insp_Res_ch = "";
- string Insp_NG_Count_ch = "";
- string Insp_NG_Parts_ch = "";
- string First_Op_Res_ch = "";
- string First_Op_NG_Count_ch = "";
- string First_Op_NG_Parts_ch = "";
- string Sec_Op_Res_ch = "";
- string Sec_Op_NG_Count_ch = "";
- string Sec_Op_NG_Parts_ch = "";
- string jj = "";
- string mm = "";
- string tt = "";
- string archiv_pfad = "";
- string MES_File = "";
- string ng_folder = "";
- string Spc_Path = "";
- string Spc_File = "";
- string help_serial_num = "";
- s = f.IndexOf("@"); // 1. @
- e = f.IndexOf("@", s + 1); // 2. @
- s = e + 1;
- e = f.IndexOf("@", s); // 3. @
- string PCB_Num = f.Substring(s, e - s);
- s = e + 1;
- e = f.IndexOf("@", s); // 4. @
- s = e + 1;
- e = f.IndexOf("@", s); // 5. @
- s = e + 1;
- e = f.IndexOf("@", s); // 6. @
- string erg = f.Substring(s, e - s);
- string dat = f.Substring(e + 1, 14);
- string zeit = f.Substring(e + 9, 6);
- if (PCB_Num.IndexOf("B") == 0 || PCB_Num.IndexOf("L") == 0)
- {
- help_serial_num = PCB_Num.Substring(1);
- }
- else
- {
- help_serial_num = PCB_Num;
- }
- string wanted_stage = "LASER";
- // Device stage ID
- int look_up_dev_stage_laser_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
- if (look_up_dev_stage_laser_id == 0)
- {
- // Fehler
- glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
- datei_error = true;
- }
- else
- {
- // nix zu tun ;-)
- }
- int dummy_kennz_b = 0;
- wanted_stage = "AOI (Bestückseite)";
- // Device stage ID
- int look_up_dev_stage_aoi_b_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
- if (look_up_dev_stage_aoi_b_id == 0)
- {
- // Dummy-Satz benutzen, da kein AOI im Auftrag verankert
- look_up_dev_stage_aoi_b_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, "Dummy-Durchlaufzeit");
- if (look_up_dev_stage_aoi_b_id == 0)
- {
- // Auswertung später, könnte Fehler sein
- }
- else
- {
- dummy_kennz_b = 1;
- }
- }
- else
- {
- // nix zu tun ;-)
- }
- int dummy_kennz_l = 0;
- wanted_stage = "AOI (Lötseite)";
- // Device stage ID
- int look_up_dev_stage_aoi_l_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, wanted_stage);
- if (look_up_dev_stage_aoi_l_id == 0)
- {
- // Dummy-Satz benutzen, da kein AOI im Auftrag verankert
- look_up_dev_stage_aoi_l_id = DbAccess.Look_up_Device_Stage_ID_MES(connection, help_serial_num, "Dummy-Durchlaufzeit");
- if (look_up_dev_stage_aoi_b_id == 0)
- {
- // Auswertung später, könnte Fehler sein
- }
- else
- {
- dummy_kennz_l = 1;
- }
- }
- else
- {
- // nix zu tun ;-)
- }
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- PCB_Num_Laser = "B" + PCB_Num.Substring(1);
- Laser_ResultData = DbAccess.Get_DB_Laser_SerialNum_MES(connection, PCB_Num_Laser, "", value_name_PCBNum);
- if (Laser_ResultData != null && Laser_ResultData.Count > 0)
- {
- a = 0;
- s = 0;
- ordern = 0;
- foreach (MES_DB_Laser_SerialNum p in Laser_ResultData)
- {
- quali[s] = status_in_progress;
- serialn[s] = p.SerialNum;
- ordern = p.Order_ID;
- if (s == max - 1)
- {
- eine_mail = true;
- message.Body += "Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num + "\r\n";
- m_TsLogFile.WriteLine("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
- throw new Exception("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
- }
- s += 1;
- a += 1;
- }
- }
- else
- {
- eine_mail = true;
- message.Body += "Für die PCB_Num: " + PCB_Num + " wurden keine Serialnummern-Sätze der Laser-Station gefunden.\r\n";
- m_TsLogFile.WriteLine("Für die PCB_Num: " + PCB_Num + " wurden keine Serialnummern-Sätze der Laser-Station gefunden.");
- Fehler = true;
- datei_error = true;
- glob_rc = Convert.ToInt32(Glob_RC.Keine_SerialNums_gefunden);
- }
- }
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- char[] line_delimiters = new char[] { '\r', '\n' };
- string text_file = System.IO.File.ReadAllText(f);
- string[] txt_zeile = text_file.Split(line_delimiters, StringSplitOptions.RemoveEmptyEntries);
- z = 0;
- string RefDataNo = "";
- for (int i = 0; i < txt_zeile.Length; i++)
- {
- if (txt_zeile[i].IndexOf("<Machine Serial=") == 2)
- {
- s = txt_zeile[i].IndexOf("\"");
- e = txt_zeile[i].IndexOf("\"", s + 1);
- machine_ser = txt_zeile[i].Substring(s + 1, e - s - 1);
- }
- if (txt_zeile[i].IndexOf("<Board Count=") == 2)
- {
- s = txt_zeile[i].IndexOf("ID=\"");
- e = txt_zeile[i].IndexOf("\"", s + 4);
- PCB_ID = txt_zeile[i].Substring(s + 4, e - s - 4);
- }
- if (txt_zeile[i].IndexOf("<Info No=") == 4)
- {
- s = txt_zeile[i].IndexOf(" Name=\"");
- e = txt_zeile[i].IndexOf("\"", s + 7);
- Prog_Name = txt_zeile[i].Substring(s + 7, e - s - 7);
- }
- if (txt_zeile[i].IndexOf("<Insp OperatorID=") == 6)
- {
- s = txt_zeile[i].IndexOf("OperatorName=\"");
- e = txt_zeile[i].IndexOf("\"", s + 14);
- Insp_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
- s = txt_zeile[i].IndexOf(" Result=\"");
- e = txt_zeile[i].IndexOf("\"", s + 9);
- Insp_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
- s = txt_zeile[i].IndexOf(" NGCount=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- Insp_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" NGParts=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- Insp_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" Time=\"");
- e = txt_zeile[i].IndexOf("\"", s + 7);
- 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);
- }
- if (txt_zeile[i].IndexOf("<NGImage Folder=") == 4)
- {
- s = txt_zeile[i].IndexOf("Folder=\"");
- e = txt_zeile[i].IndexOf("\"", s + 8);
- ng_folder = txt_zeile[i].Substring(s + 8, e - s - 6 - 1 - 1);
- }
- if (txt_zeile[i].IndexOf("<Spc ") == 4)
- {
- s = txt_zeile[i].IndexOf("Database");
- e = txt_zeile[i].IndexOf("\"", s);
- Spc_Path = txt_zeile[i].Substring(s, e - s); // ohne Yamaha-Netzwerk-IP
- s = txt_zeile[i].IndexOf("File=\"\"");
- if (s <= 0)
- {
- s = txt_zeile[i].IndexOf("File=\"");
- e = txt_zeile[i].IndexOf("\"", s + 6);
- Spc_File = txt_zeile[i].Substring(s + 6, e - s - 6 - 4); // ohne ".csv" umständlich, aber transparent
- }
- }
- if (txt_zeile[i].IndexOf("<First OperatorID=") == 6)
- {
- s = txt_zeile[i].IndexOf("OperatorName=\"");
- e = txt_zeile[i].IndexOf("\"", s + 14);
- First_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
- s = txt_zeile[i].IndexOf(" Result=\"");
- e = txt_zeile[i].IndexOf("\"", s + 9);
- First_Op_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
- s = txt_zeile[i].IndexOf(" NGCount=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- First_Op_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" NGParts=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- First_Op_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" StartTime=\"");
- e = txt_zeile[i].IndexOf("\"", s + 12);
- 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);
- }
- if (txt_zeile[i].IndexOf("<Second OperatorID=") == 6)
- {
- s = txt_zeile[i].IndexOf("OperatorName=\"");
- e = txt_zeile[i].IndexOf("\"", s + 14);
- Sec_Op = txt_zeile[i].Substring(s + 14, e - s - 14);
- s = txt_zeile[i].IndexOf(" Result=\"");
- e = txt_zeile[i].IndexOf("\"", s + 9);
- Sec_Op_Res_ch = txt_zeile[i].Substring(s + 9, e - s - 9);
- s = txt_zeile[i].IndexOf(" NGCount=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- Sec_Op_NG_Count_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" NGParts=\"");
- e = txt_zeile[i].IndexOf("\"", s + 10);
- Sec_Op_NG_Parts_ch = txt_zeile[i].Substring(s + 10, e - s - 10);
- s = txt_zeile[i].IndexOf(" StartTime=\"");
- e = txt_zeile[i].IndexOf("\"", s + 12);
- 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);
- }
- if (txt_zeile[i].IndexOf("Block No") > 0)
- {
- s = txt_zeile[i].IndexOf("No");
- s += 4;
- e = txt_zeile[i].IndexOf("\"");
- e = txt_zeile[i].IndexOf("\"", e + 1); // 2. "
- z = Convert.ToInt32(txt_zeile[i].Substring(s, e - s));
- if (z == 0)
- z = 1; // Block No war definiert ab 1, somit nehmen wir "Sonderfehler", die auf Block 0 geschreiben werden auf Block 1
- quali[z - 1] = status_repair;
- }
- if (z > max)
- {
- eine_mail = true;
- message.Body += "Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num + "\r\n";
- m_TsLogFile.WriteLine("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
- throw new Exception("Array-Überlauf für Anzahl Serialnummern bei PCB-Num: " + PCB_Num);
- }
- if (txt_zeile[i].IndexOf("<Parts RefNo=\"") == 4)
- {
- s = txt_zeile[i].IndexOf("\"");
- e = txt_zeile[i].IndexOf("\"", s + 1);
- Parts_Ref[z - 1] += (txt_zeile[i].Substring(s + 1, e - s - 1));
- s = txt_zeile[i].IndexOf(" RefDataNo=\"");
- e = txt_zeile[i].IndexOf("\"", s + 12);
- RefDataNo = "(" + (txt_zeile[i].Substring(s + 12, e - s - 12)) + "); ";
- Parts_Ref[z - 1] += RefDataNo;
- }
- if (txt_zeile[i].IndexOf("<Step No=\"") == 6)
- {
- if (txt_zeile[i].IndexOf(" NGReason=\"") > 0)
- {
- s = txt_zeile[i].IndexOf(" NGReason=\"");
- e = txt_zeile[i].IndexOf("\"", s + 11);
- NGReason[z - 1] += (txt_zeile[i].Substring(s + 11, e - s - 11) + RefDataNo);
- }
- if (txt_zeile[i].IndexOf(" PinNo=\"") > 0)
- {
- s = txt_zeile[i].IndexOf(" PinNo=\"");
- e = txt_zeile[i].IndexOf("\"", s + 8);
- PinNo[z - 1] += (txt_zeile[i].Substring(s + 8, e - s - 8) + RefDataNo);
- }
- }
- if (txt_zeile[i].IndexOf("<Result First=\"") == 8)
- {
- s = txt_zeile[i].IndexOf("First=\"");
- e = txt_zeile[i].IndexOf("\"", s + 7);
- string Res = "";
- string Res_verb = "";
- Res = txt_zeile[i].Substring(s + 7, e - s - 7);
- if (String.Compare(Res, "2", false) == 0)
- {
- // nix zu tun ;-)
- }
- else
- {
- if (String.Compare(Res, "1", false) == 0)
- {
- Res_verb = "(NG)";
- }
- else
- {
- Res_verb = "(OK)";
- }
- }
- if (Res.Length != 0 && String.Compare(Res, "2", false) != 0)
- {
- Status_First[z - 1] = Res;
- Res_First[z - 1] += (Res + Res_verb + RefDataNo + "; ");
- }
- Res = "";
- Res_verb = "";
- s = txt_zeile[i].IndexOf("Second=\"");
- e = txt_zeile[i].IndexOf("\"", s + 8);
- Res = txt_zeile[i].Substring(s + 8, e - s - 8);
- if (String.Compare(Res, "2", false) == 0)
- {
- // nix zu tun ;-)
- }
- else
- {
- if (String.Compare(Res, "1", false) == 0)
- {
- Res_verb = "(NG)";
- }
- else
- {
- Res_verb = "(OK)";
- }
- }
- if (Res.Length != 0 && String.Compare(Res, "2", false) != 0)
- {
- Status_Sec[z - 1] = Res;
- Res_Sec[z - 1] += (Res + Res_verb + RefDataNo + "; ");
- }
- if (!String.IsNullOrEmpty(Status_First[z - 1]) && String.Compare(Status_First[z - 1], "0", false) == 0)
- // if (quali[z - 1] == status_repair && !String.IsNullOrEmpty(Status_First[z - 1]) && String.Compare(Status_First[z - 1], "0", false) == 0)
- {
- quali[z - 1] = status_in_progress;
- }
- if (!String.IsNullOrEmpty(Status_Sec[z - 1]) && String.Compare(Status_Sec[z - 1], "0", false) == 0)
- {
- quali[z - 1] = status_in_progress;
- }
- }
- }
- if (Insp_Op.Length > 0)
- {
- Insp_user_ID = find_user_ID(Insp_Op);
- }
- else
- {
- Insp_user_ID = find_user_ID("prod.vogtl");
- }
- if (Insp_user_ID == 0)
- {
- eine_mail = true;
- message.Body += "Für den Inspektion-Hauptnutzer " + Insp_Op + " existiert kein User in der DB.\r\n";
- m_TsLogFile.WriteLine("Für den Inspektion-Hauptnutzer " + Insp_Op + " existiert kein User in der DB.");
- Fehler = true;
- datei_error = true;
- glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
- }
- if (First_Op.Length > 0)
- {
- First_user_ID = find_user_ID(First_Op);
- if (First_user_ID == 0)
- {
- eine_mail = true;
- message.Body += "Für den ersten Operator " + First_Op + " existiert kein User in der DB.\r\n";
- m_TsLogFile.WriteLine("Für den ersten Operator " + First_Op + " existiert kein User in der DB.");
- Fehler = true;
- datei_error = true;
- glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
- }
- }
- else
- {
- First_user_ID = 0;
- }
- if (Sec_Op.Length > 0)
- {
- Sec_user_ID = find_user_ID(Sec_Op);
- if (Sec_user_ID == 0)
- {
- eine_mail = true;
- message.Body += "Für den zweiten Operator " + Sec_Op + " existiert kein User in der DB.\r\n";
- m_TsLogFile.WriteLine("Für den zweiten Operator " + Sec_Op + " existiert kein User in der DB.");
- Fehler = true;
- datei_error = true;
- glob_rc = Convert.ToInt32(Glob_RC.User_ID_fehlt);
- }
- }
- else
- {
- Sec_user_ID = 0;
- }
- 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);
- jj = dat.Substring(0, 4);
- mm = dat.Substring(4, 2);
- tt = dat.Substring(6, 2);
- archiv_pfad = m_Config.NW_LW_Ziel + m_Config.FileDirectory_ARCHIV + "\\" + jj + "\\" + mm + "\\" + tt + "\\" + PCB_Num + "_" + zeit + "\\";
- MES_File = archiv_pfad + PCB_Num_Laser + ".xml";
- int help_stage_id = 0;
- if (PCB_Num.IndexOf("B") == 0)
- {
- if (look_up_dev_stage_aoi_b_id == 0)
- {
- glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
- datei_error = true;
- }
- else
- {
- help_stage_id = look_up_dev_stage_aoi_b_id;
- AOI_ScanResultData_MES.Dummy_used = dummy_kennz_b;
- AOI_ScanResultData_MES.Dummy_User = "AOI B-Seite";
- }
- }
- else
- {
- if (look_up_dev_stage_aoi_l_id == 0)
- {
- glob_rc = Convert.ToInt32(Glob_RC.Dev_stage_ID_fehlt);
- datei_error = true;
- }
- else
- {
- help_stage_id = look_up_dev_stage_aoi_l_id;
- AOI_ScanResultData_MES.Dummy_used = dummy_kennz_l;
- AOI_ScanResultData_MES.Dummy_User = "AOI L-Seite";
- }
- }
- if (glob_rc == Convert.ToInt32(Glob_RC.I_O))
- {
- AOI_Data_MES = DbAccess.GetDB_AOI_Data_MES(connection, help_serial_num, Insp_Dat, help_stage_id);
- if (AOI_Data_MES != null)
- {
- //Keine Aktion, Sätze schon da
- eine_mail = true;
- 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";
- 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!");
- }
- else
- {
- AOI_ScanResultData_MES.VN_Machine_Serial = vn_Machine_Serial;
- AOI_ScanResultData_MES.VN_Progr_Name = vn_Progr_Name;
- AOI_ScanResultData_MES.VN_Insp_user = vn_Insp_user;
- AOI_ScanResultData_MES.VN_First_user = vn_First_user;
- AOI_ScanResultData_MES.VN_Sec_user = vn_Sec_user;
- AOI_ScanResultData_MES.VN_Parts_Ref = vn_Parts_Ref;
- AOI_ScanResultData_MES.VN_NGReason = vn_NGReason;
- AOI_ScanResultData_MES.VN_PinNo = vn_PinNo;
- AOI_ScanResultData_MES.VN_Insp_Res = vn_Insp_Res;
- AOI_ScanResultData_MES.VN_First_Op_Res = vn_First_Op_Res;
- AOI_ScanResultData_MES.VN_Sec_Op_Res = vn_Sec_Op_Res;
- AOI_ScanResultData_MES.VN_Insp_NG_Count = vn_Insp_NG_Count;
- AOI_ScanResultData_MES.VN_First_Op_NG_Count = vn_First_Op_NG_Count;
- AOI_ScanResultData_MES.VN_Sec_Op_NG_Count = vn_Sec_Op_NG_Count;
- AOI_ScanResultData_MES.VN_Insp_NG_Parts = vn_Insp_NG_Parts;
- AOI_ScanResultData_MES.VN_First_Op_NG_Parts = vn_First_Op_NG_Parts;
- AOI_ScanResultData_MES.VN_Sec_Op_NG_Parts = vn_Sec_Op_NG_Parts;
- AOI_ScanResultData_MES.VN_Dummy_used = vn_Dummy;
- for (int i = 0; i < a; i++)
- {
- AOI_ScanResultData_MES.Mand = m_Config.Mandator;
- AOI_ScanResultData_MES.SerialNum = serialn[i];
- AOI_ScanResultData_MES.Station_IP = m_Config.Station_IP;
- if (quali[i] == status_repair)
- {
- AOI_ScanResultData_MES.Global_Result = status_repair; // update device auf repair
- AOI_ScanResultData_MES.Result = status_repair;
- }
- else
- {
- AOI_ScanResultData_MES.Global_Result = status_in_progress; // device bleibt in_progress
- AOI_ScanResultData_MES.Result = status_pass;
- }
- AOI_ScanResultData_MES.Device_Stage_ID = help_stage_id;
- AOI_ScanResultData_MES.Replication_to = 4;
- AOI_ScanResultData_MES.Machine_Serial = machine_ser;
- AOI_ScanResultData_MES.Progr_Name = Prog_Name;
- if (Insp_user_ID > 0)
- {
- AOI_ScanResultData_MES.Insp_user_ID = Insp_user_ID;
- AOI_ScanResultData_MES.Insp_user = Insp_Op;
- AOI_ScanResultData_MES.Insp_Dat = Insp_Dat;
- if (quali[i] == status_repair || quali[i] == status_in_progress)
- {
- AOI_ScanResultData_MES.Insp_Res_ch = Insp_Res_ch;
- AOI_ScanResultData_MES.Insp_NG_Count_ch = Insp_NG_Count_ch;
- AOI_ScanResultData_MES.Insp_NG_Parts_ch = Insp_NG_Parts_ch;
- }
- else
- {
- AOI_ScanResultData_MES.Insp_Res_ch = "";
- AOI_ScanResultData_MES.Insp_NG_Count_ch = "";
- AOI_ScanResultData_MES.Insp_NG_Parts_ch = "";
- }
- }
- else
- {
- AOI_ScanResultData_MES.Insp_user_ID = 0;
- AOI_ScanResultData_MES.Insp_user = "";
- AOI_ScanResultData_MES.Insp_Dat = "";
- AOI_ScanResultData_MES.Insp_Res_ch = "";
- AOI_ScanResultData_MES.Insp_NG_Count_ch = "";
- AOI_ScanResultData_MES.Insp_NG_Parts_ch = "";
- }
- if (First_user_ID > 0)
- {
- AOI_ScanResultData_MES.First_user_ID = First_user_ID;
- AOI_ScanResultData_MES.First_user = First_Op;
- AOI_ScanResultData_MES.First_Op_Dat = First_Op_Dat;
- if (!String.IsNullOrEmpty(Res_First[i]))
- {
- AOI_ScanResultData_MES.First_Op_Res_ch = Status_First[i];
- }
- else
- {
- AOI_ScanResultData_MES.First_Op_Res_ch = "";
- }
- if (quali[i] == status_repair)
- {
- AOI_ScanResultData_MES.First_Op_NG_Count_ch = First_Op_NG_Count_ch;
- AOI_ScanResultData_MES.First_Op_NG_Parts_ch = First_Op_NG_Parts_ch;
- }
- else
- {
- AOI_ScanResultData_MES.First_Op_NG_Count_ch = "";
- AOI_ScanResultData_MES.First_Op_NG_Parts_ch = "";
- }
- }
- else
- {
- AOI_ScanResultData_MES.First_user_ID = 0;
- AOI_ScanResultData_MES.First_user = "";
- AOI_ScanResultData_MES.First_Op_Dat = "";
- AOI_ScanResultData_MES.First_Op_Res_ch = "";
- AOI_ScanResultData_MES.First_Op_NG_Count_ch = "";
- AOI_ScanResultData_MES.First_Op_NG_Parts_ch = "";
- }
- if (Sec_user_ID > 0)
- {
- AOI_ScanResultData_MES.Sec_user_ID = Sec_user_ID;
- AOI_ScanResultData_MES.Sec_user = Sec_Op;
- AOI_ScanResultData_MES.Sec_Op_Dat = Sec_Op_Dat;
- if (!String.IsNullOrEmpty(Status_Sec[i]))
- {
- AOI_ScanResultData_MES.Sec_Op_Res_ch = Status_Sec[i];
- }
- else
- {
- AOI_ScanResultData_MES.Sec_Op_Res_ch = "";
- }
- if (quali[i] == status_repair)
- {
- AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = Sec_Op_NG_Count_ch;
- AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = Sec_Op_NG_Parts_ch;
- }
- else
- {
- AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = "";
- AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = "";
- }
- }
- else
- {
- AOI_ScanResultData_MES.Sec_user_ID = 0;
- AOI_ScanResultData_MES.Sec_user = "";
- AOI_ScanResultData_MES.Sec_Op_Dat = "";
- AOI_ScanResultData_MES.Sec_Op_Res_ch = "";
- AOI_ScanResultData_MES.Sec_Op_NG_Count_ch = "";
- AOI_ScanResultData_MES.Sec_Op_NG_Parts_ch = "";
- }
- if (!String.IsNullOrEmpty(Parts_Ref[i]))
- {
- if (Parts_Ref[i].Length > 100)
- {
- AOI_ScanResultData_MES.Parts_Ref = Parts_Ref[i].Substring(0, 100);
- }
- else
- {
- AOI_ScanResultData_MES.Parts_Ref = Parts_Ref[i];
- }
- }
- else
- {
- AOI_ScanResultData_MES.Parts_Ref = "";
- }
- if (!String.IsNullOrEmpty(NGReason[i]))
- {
- if (NGReason[i].Length > 100)
- {
- AOI_ScanResultData_MES.NGReason = NGReason[i].Substring(0, 100);
- }
- else
- {
- AOI_ScanResultData_MES.NGReason = NGReason[i];
- }
- }
- else
- {
- AOI_ScanResultData_MES.NGReason = "";
- }
- if (!String.IsNullOrEmpty(PinNo[i]))
- {
- if (PinNo[i].Length > 100)
- {
- AOI_ScanResultData_MES.PinNo = PinNo[i].Substring(0, 100);
- }
- else
- {
- AOI_ScanResultData_MES.PinNo = PinNo[i];
- }
- }
- else
- {
- AOI_ScanResultData_MES.PinNo = "";
- }
- if (!String.IsNullOrEmpty(Res_First[i]))
- {
- AOI_ScanResultData_MES.VN_Res_First_OP = vn_Res_First;
- if (Res_First[i].Length > 100)
- {
- AOI_ScanResultData_MES.Res_First_OP = Res_First[i].Substring(0, 100);
- }
- else
- {
- AOI_ScanResultData_MES.Res_First_OP = Res_First[i];
- }
- }
- else
- {
- AOI_ScanResultData_MES.VN_Res_First_OP = "";
- AOI_ScanResultData_MES.Res_First_OP = "";
- }
- if (!String.IsNullOrEmpty(Res_Sec[i]))
- {
- AOI_ScanResultData_MES.VN_Res_Sec_OP = vn_Res_Sec;
- if (Res_Sec[i].Length > 100)
- {
- AOI_ScanResultData_MES.Res_Sec_OP = Res_Sec[i].Substring(0, 100);
- }
- else
- {
- AOI_ScanResultData_MES.Res_Sec_OP = Res_Sec[i];
- }
- }
- else
- {
- AOI_ScanResultData_MES.VN_Res_Sec_OP = "";
- AOI_ScanResultData_MES.Res_Sec_OP = "";
- }
- int rc_code = DbAccess.Insert_AOI_Data_MES(connection, AOI_ScanResultData_MES);
- // Test maskiert int rc_code = 0;
- switch (rc_code)
- {
- case 0:
- m_TsLogFile.WriteLine("MES AOI-Results INSERT: " + AOI_ScanResultData_MES.SerialNum + " erfolgreich");
- break;
- case 50:
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! Serial-Num " + AOI_ScanResultData_MES.SerialNum + " nicht im DB-Bestand vorhanden");
- message.Body += "MES AOI-Results INSERT fehlgeschlagen! Serial-Num " + AOI_ScanResultData_MES.SerialNum + " nicht im DB-Bestand vorhanden \r\n\r\n";
- break;
- case 51:
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! SerialNum fehlt. Datei " + f);
- message.Body += "MES AOI-Results INSERT fehlgeschlagen! Serial-Num fehlt. Datei " + f + " \r\n\r\n";
- break;
- case 52:
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- m_TsLogFile.WriteLine("MES AOI-Results INSERT fehlgeschlagen! Datumsangaben fehlen. Datei " + f);
- message.Body += "MES AOI-Results INSERT fehlgeschlagen! Datumsangaben fehlen. Datei " + f + " \r\n\r\n";
- break;
- case 99:
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- 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";
- 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);
- break;
- default:
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- message.Body += "DB unbekannter Fehler aufgetreten !!!!! \r\n\r\n";
- m_TsLogFile.WriteLine("DB unbekannter Fehler aufgetreten !!!!!");
- break;
- }
- }
- }
- }
- }
- else
- {
- string fehler_text;
- switch (glob_rc)
- {
- case 4:
- fehler_text = "User ID fehlt";
- break;
- case 5:
- fehler_text = "Decive Stage ID oder Serialnum fehlt";
- break;
- case 6:
- fehler_text = "Keine Serial Nummern gefunden";
- break;
- default:
- fehler_text = "unbekannte Ausnahme";
- break;
- }
- datei_error = true;
- Fehler = true;
- eine_mail = true;
- message.Body += "Grundlegender Error: Basisdaten " + fehler_text + "\r\n\r\n";
- m_TsLogFile.WriteLine("Grundlegender Error: Basisdaten " + fehler_text);
- glob_rc = Convert.ToInt32(Glob_RC.I_O);
- }
- // }
- if (!datei_error)
- {
- datei_verarb = true;
- lbFiles.Items.Add("Die Datei " + System.IO.Path.GetFileName(f) + " wurde ordnungsgemäss verarbeitet.");
- }
- else
- {
- lbFiles.Items.Add("Die Datei " + System.IO.Path.GetFileName(f) + " konnte nicht ordnungsgemäss verarbeitet werden.");
- }
- // Datei verschieben
- if (datei_verarb)
- {
- // Exists Archiv-Verzeichnis?
- if (!System.IO.Directory.Exists(archiv_pfad))
- {
- System.IO.Directory.CreateDirectory(archiv_pfad);
- }
- if (System.IO.File.Exists(MES_File))
- System.IO.File.Delete(MES_File);
- System.IO.File.Move(f, MES_File);
- if (ng_folder.Length > 0 && Spc_File.Length > 0)
- {
- string pic_path = m_Config.NW_LW_Quelle + "\\" + Spc_Path + "\\" + Spc_File + "Image";
- if (System.IO.Directory.Exists(pic_path))
- {
- foreach (string pic in System.IO.Directory.GetFiles(pic_path, "*.*"))
- {
- if (pic.EndsWith("jxr") == true || pic.EndsWith("jpg") == true)
- {
- string pic_name = archiv_pfad + pic.Substring(pic.LastIndexOf("\\") + 1);
- if (System.IO.File.Exists(pic_name))
- System.IO.File.Delete(pic_name);
- System.IO.File.Move(pic, pic_name);
- }
- }
- }
- else
- {
- eine_mail = true;
- message.Body += "Der Bild-Pfad: " + pic_path + " wurde nicht gefunden. PCB-Num: " + PCB_Num + "\r\n\r\n";
- m_TsLogFile.WriteLine("Der Bild-Pfad: " + pic_path + " wurde nicht gefunden. PCB-Num: " + PCB_Num);
- }
- }
- }
- if (datei_error)
- {
- string ERROR_File = m_Config.FileDirectory_ERROR + "\\" + System.IO.Path.GetFileName(f);
- if (System.IO.File.Exists(ERROR_File))
- System.IO.File.Delete(ERROR_File);
- System.IO.File.Move(f, ERROR_File);
- eine_mail = true;
- message.Body += "Die Datei " + ERROR_File + " konnte nicht ordnungsgemäss verarbeitet werden.\r\n";
- Fehler = true;
- }
- }
- }
- }
- }
- else
- {
- string fehler_text;
- switch (glob_rc)
- {
- case 1:
- fehler_text = "Status PASS fehlt";
- break;
- case 2:
- fehler_text = "Status FAIL fehlt";
- break;
- case 3:
- fehler_text = "Status REPAIR fehlt";
- break;
- case 7:
- fehler_text = "Value_Name PCBNum fehlt";
- break;
- case 8:
- fehler_text = "Value_Name Machine Serial fehlt";
- break;
- case 9:
- fehler_text = "Value_Name Progr. Name fehlt";
- break;
- case 10:
- fehler_text = "Value_Name Insp. user ID fehlt";
- break;
- case 11:
- fehler_text = "Value_Name First User ID fehlt";
- break;
- case 12:
- fehler_text = "Value_Name Sec User ID fehlt";
- break;
- case 13:
- fehler_text = "Value_Name Insp. Datum fehlt";
- break;
- case 14:
- fehler_text = "Value_Name First Operator Datum fehlt";
- break;
- case 15:
- fehler_text = "Value_Name Second Operator Datum fehlt";
- break;
- case 16:
- fehler_text = "Value_Name Insp. Result fehlt";
- break;
- case 17:
- fehler_text = "Value_Name First Operator Result fehlt";
- break;
- case 18:
- fehler_text = "Value_Name Second Operator Result fehlt";
- break;
- case 19:
- fehler_text = "Value_Name Insp. NG Count fehlt";
- break;
- case 20:
- fehler_text = "Value_Name First Operator NG Count fehlt";
- break;
- case 21:
- fehler_text = "Value_Name Second Operator NG Count fehlt";
- break;
- case 22:
- fehler_text = "Value_Name Insp. NG Parts fehlt";
- break;
- case 23:
- fehler_text = "Value_Name First Operator NG Parts fehlt";
- break;
- case 24:
- fehler_text = "Value_Name Second Operator NG Parts fehlt";
- break;
- case 25:
- fehler_text = "Value_Name Parts Reference Number fehlt";
- break;
- case 26:
- fehler_text = "Value_Name NG Reason fehlt";
- break;
- case 27:
- fehler_text = "Value_Name Pin Number fehlt";
- break;
- case 28:
- fehler_text = "Value Name Dummy Record used as fehlt";
- break;
- case 29:
- fehler_text = "Status IN PROGRESS fehlt";
- break;
- case 30:
- fehler_text = "Value Name Result First OP fehlt";
- break;
- case 31:
- fehler_text = "Value Name Secound OP fehlt";
- break;
- case 32:
- fehler_text = "Das Quell-Verzeichnis Good fehlt";
- break;
- case 33:
- fehler_text = "Das Quell-Verzeichnis Judge fehlt";
- break;
- default:
- fehler_text = "unbekannte Ausnahme";
- break;
- }
- Fehler = true;
- eine_mail = true;
- message.Body += "Grundlegender Error: Parameter " + fehler_text + "\r\n\r\n";
- m_TsLogFile.WriteLine("Grundlegender Error: Parameter " + fehler_text);
- }
- // connection = DbAccess.Open_MES(false);
- }
- catch (Exception ex)
- {
- string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
- throw new Exception(methodName + ": " + ex.Message + " File: " + file_name);
- }
- if (Fehler)
- {
- lbFiles.Items.Add("Verarbeitung mit Fehler/n abgeschlossen");
- m_TsLogFile.WriteLine("Verarbeitung mit Fehler/n abgeschlossen");
- }
- else
- {
- lbFiles.Items.Add("Verarbeitung erfolgreich abgeschlossen");
- m_TsLogFile.WriteLine("Verarbeitung erfolgreich abgeschlossen");
- }
- if (eine_mail)
- {
- try
- {
- SmtpClient client = new SmtpClient(m_Config.MAIL_Client, int.Parse(m_Config.MAIL_Port));
- client.Credentials = new NetworkCredential(m_Config.MAIL_User, m_Config.MAIL_PW);
- client.EnableSsl = false;
- ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; // unsauberer Griff um Daun-Experten am Exchange mit ihren "Änderungen" zu umgehen !!!!!
- client.Send(message);
- }
- catch (SmtpException exeption)
- {
- MessageBox.Show(exeption.Message);
- }
- LBAnzDateien.Text = lbFiles.Items.Count.ToString();
- }
- else
- {
- // nix zu tun ;-)
- }
- DeleteObsoleteLogfiles();
- }
- // MapNetworkDriveDisconnect("TTTTT:"); könnte zur Lösung der Netzwerkverbindung aktiviert werden
- // MapNetworkDriveDisconnect("VVVVV:"); ebenso
- }
- catch (Exception ex)
- {
- string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
- throw new Exception(methodName + ": " + ex.HResult + " " + ex.Message + " File: " + file_name);
- }
- }
- private void auswahlToolStripMenuItem_Click(object sender, EventArgs e)
- {
- openFileDialog1.ShowDialog();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.Show();
- this.Activate();
- Application.DoEvents();
- System.Threading.Thread.Sleep(200);
- this.Close();
- }
- /// <summary>
- /// Löschen veralteter Protokolldateien übernommen von J. Mayer
- /// </summary>
- private void DeleteObsoleteLogfiles()
- {
- try
- {
- if (m_Config.IsLogfileDeadlineActive)
- {
- DateTime deadline = DateTime.Now;
- TimeSpan livingTime = new TimeSpan(
- m_Config.LogfileDeadline.Days,
- m_Config.LogfileDeadline.Hours,
- m_Config.LogfileDeadline.Minutes,
- m_Config.LogfileDeadline.Seconds);
- deadline = deadline.Subtract(livingTime);
- int deletedFiles = m_TsLogFile.DeleteObsoleteFiles(deadline);
- m_TsLogFile.WriteLine(string.Format("{0} veraltete Log-Dateien sind gelöscht worden.", deletedFiles), TsLogFile.MsgCharacter.Info);
- }
- }
- catch (Exception ex)
- {
- string methodName = m_TsLogFile.GetMethodName(this.GetType().Name.ToString(), System.Reflection.MethodBase.GetCurrentMethod());
- throw new Exception(methodName + ": " + ex.Message);
- }
- }
- /// <summary>
- /// bereinigen User-Name und bereitstellen User_ID aus DB
- /// </summary>
- private int find_user_ID(string name)
- {
- // Einschub Namenskorrektur
- int pos_st;
- int pos_pt;
- int pos_bl;
- string vn = "";
- string nn = "";
- if (name.Contains("SCHMIEDT R."))
- {
- name = "SCHMIDT R";
- }
- else
- {
- name = name.TrimStart();
- }
- if (name.Contains("_DEFAULT_OPERATOR"))
- {
- name = "prod.vogtl";
- }
- if (name.Contains("TSV:"))
- {
- name = name.Substring(4);
- pos_st = name.IndexOf("-");
- vn = name.Substring(pos_st + 1);
- nn = name.Substring(0, pos_st);
- }
- if (name.Contains("-"))
- {
- pos_st = name.IndexOf("-");
- vn = name.Substring(pos_st + 1);
- nn = name.Substring(0, pos_st);
- }
- if (name.Contains("."))
- {
- pos_pt = name.IndexOf(".");
- if (name.Length == pos_pt + 1)
- {
- pos_bl = name.IndexOf(" ");
- vn = name.Substring(pos_bl + 1, pos_pt - pos_bl - 1);
- nn = name.Substring(0, pos_bl);
- }
- else
- {
- vn = name.Substring(0, pos_pt);
- nn = name.Substring(pos_pt + 1);
- nn = nn.TrimStart(' ');
- }
- }
- else
- {
- if (name.Contains(" "))
- {
- vn = name.Substring(name.IndexOf(" ") + 1);
- vn = vn.Replace(".", "");
- nn = name.Substring(0, name.IndexOf(" "));
- }
- }
- name = vn.ToLower() + "." + nn.ToLower();
- int look_up_user_id_rc = DbAccess.Look_up_User_ID_MES(connection, name);
- if (look_up_user_id_rc == 0)
- {
- // Fehler keine User_id, ersatzweise user "prod.vogtl" verwenden
- look_up_user_id_rc = DbAccess.Look_up_User_ID_MES(connection, "prod.vogtl");
- if (look_up_user_id_rc == 0)
- {
- // totaler Fehler "prod.vogtl" gelöscht
- return 0;
- }
- else
- {
- return look_up_user_id_rc;
- }
- }
- else
- {
- return look_up_user_id_rc;
- }
- }
- /// <summary>
- /// Disconnects a network drive
- /// </summary>
- /// <param name="drive">Drive (z.B. L:)</param>
- private void MapNetworkDriveDisconnect(string drive)
- {
- Process p = new Process();
- p.StartInfo.FileName = "net";
- p.StartInfo.Arguments = string.Format("use {0} /DELETE /yes", drive);
- p.StartInfo.UseShellExecute = false;
- p.Start();
- }
- /// <summary>
- /// Connects a network drive
- /// </summary>
- /// <param name="drive">The drive letter (e.g. L:)</param>
- /// <param name="server">The UNC path to the remote drive (e.g. \\MyServer\MyPrinter)</param>
- /// <param name="user">The User</param>
- /// <param name="password">The Password Used For Login</param>
- private void MapNetworkDriveConnect(string drive, string server, string user, string password)
- {
- Process p = new Process();
- p.StartInfo.FileName = "net";
- p.StartInfo.Arguments = string.Format("use {0} {1} /user:{2} {3}", drive, server, user, password);
- p.StartInfo.UseShellExecute = false;
- p.Start();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement