Esempio n. 1
0
        public void F_SaveLog()
        {
            //Read FILE LOG_Source
            v_FileInput = new DirectoryInfo(ConfigurationManager.AppSettings["PathInput"].ToString()).GetFiles().OrderByDescending(f => f.LastWriteTime).First();
            if (v_FileInput.Extension != ".csv")
            {
                return;
            }
            DataTable v_DT_Result = new DataTable();

            v_DT_Result.Columns.Add("Times", typeof(string));
            v_DT_Result.Columns.Add("Model", typeof(string));
            v_DT_Result.Columns.Add("Status", typeof(string));
            List <string> columns  = new List <string>();
            CsvFileReader v_Reader = WriteDatatableToFileCSV.ReadFile(v_FileInput.FullName);

            while (v_Reader.ReadRow(columns))
            {
                if (columns[0].Trim().Length > 0 && columns[1].Trim().Length > 0)
                {
                    DataRow v_Dr = v_DT_Result.NewRow();
                    v_Dr[0] = columns[1].Trim();
                    v_Dr[1] = columns[5].Trim();
                    v_Dr[2] = columns[3].Trim();
                    v_DT_Result.Rows.Add(v_Dr);
                }
            }
            v_Reader.Dispose();
            v_DT_Result.Rows.RemoveAt(0);
            v_DT_Result.Rows.RemoveAt(0);
            //Get PASS OR FAIL
            string v_Status  = "F";
            string v_Model   = string.Empty;
            string v_Serial  = string.Empty;
            string v_Station = string.Empty;

            //GET Model
            v_Model = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[1];

            //GET Serial
            v_Serial = v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][1].ToString().Trim().Split('_')[0];

            //Get Status
            try
            {
                if (v_DT_Result.Rows[v_DT_Result.Rows.Count - 1][2].ToString().Trim() == "OK")
                {
                    v_Status = "P";
                }
                else
                {
                    v_Status = "F";
                }
            }
            catch { v_Status = "F"; }

            //Get Station
            try
            {
                //v_Station = Cbx_Station.SelectedValue.ToString();
            }
            catch { }


            Tbx_BarCode.Text      = v_Serial + "_" + v_Model;
            Tbx_BarCode.ForeColor = Color.Green;
            string v_TimeCurrent = DateTime.Now.ToString("yyMMddHHmmss");
            string v_FileContent = v_Model + "|" + v_Serial + "_" + v_Model + "|" + v_TimeCurrent + "|" + v_Status + "|" + v_Station;

            //Delete OLD File log
            try
            {
                bool          v_StatusOld = false;
                List <string> v_ListPaths = Directory.GetFiles(ConfigurationManager.AppSettings["PathOutput"].ToString(), "*.txt", SearchOption.AllDirectories).ToList();
                string        v_PathPASS  = "";
                string        v_PathNG    = "";
                try
                {
                    v_PathPASS = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|P|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                try
                {
                    v_PathNG = v_ListPaths.Where(p => File.ReadAllLines(p).Any(line => line.IndexOf(v_Serial + "_" + v_Model) >= 0 && line.IndexOf("|F|") >= 0 && line.IndexOf(v_Station) >= 0)).First();
                }
                catch { }
                if (v_PathPASS.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathPASS);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_Pass = v_Pass - 1;
                        v_NG   = v_NG;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
                else if (v_PathNG.Trim().Length > 0)
                {
                    ControlFile.F_DeleteFile(v_PathNG);
                    v_Total = v_Total - 1;
                    if (v_Status == "P")
                    {
                        v_Pass = v_Pass;
                        v_NG   = v_NG - 1;
                    }
                    else if (v_Status == "F")
                    {
                        v_NG = v_NG - 1;
                    }
                    if (v_Total < 0)
                    {
                        v_Total = 0;
                    }
                    if (v_Pass < 0)
                    {
                        v_Pass = 0;
                    }
                    if (v_NG < 0)
                    {
                        v_NG = 0;
                    }
                }
            }
            catch { }
            //Create NEW File log
            ControlFile.F_CreateAndWriteFile(ConfigurationManager.AppSettings["PathOutput"].ToString() + "\\" + v_TimeCurrent + "_" + v_Model.Replace(" ", "").Substring(0, 9) + ".txt", v_FileContent);

            if (v_Status == "P")
            {
                Panel_Result.BackColor = System.Drawing.Color.Blue;
                Lbl_Result.BackColor   = System.Drawing.Color.Blue;
                Lbl_Result.Text        = "PASS";
            }
            else if (v_Status == "F")
            {
                Panel_Result.BackColor = System.Drawing.Color.Red;
                Lbl_Result.BackColor   = System.Drawing.Color.Red;
                Lbl_Result.Text        = "FAIL";
            }

            //Count PCS
            F_CountModelsChecked(v_Status);
            F_LoadTotalPCS();
        }