} // End of ReadFile private void ProcessData(string filestring)// bc of threading, parameter has to be object. { try { // string message = Message.ToString(); bProcessData = true; PEK = false; // Discover the delimiters used. They're always in the same positions char SegDelimiter = filestring[105]; char ElemDelimiter = filestring[103]; var segments = from seg in filestring.Split(SegDelimiter).Select(x => x.Trim()) where !String.IsNullOrEmpty(seg) select new { SegID = seg.Substring(0, seg.IndexOf(ElemDelimiter)), Elements = seg.Split(ElemDelimiter).Skip(1).ToArray() }; var aList = segments.ToList(); PekinDate = aList[3].Elements[2].ToString(); PekinMinutes = aList[3].Elements[3].ToString(); PekinSeconds = aList[3].Elements[4].ToString(); CompanyName = aList[5].Elements[1].ToString().Substring(0, 2).ToString().ToUpper(); if (CompanyName == "D8") { CompanyName = aList[1].Elements[1].ToString().Substring(0, 9); } else { CompanyName = aList[5].Elements[1].ToString().Substring(0, 10); } // string CompanyName1 = aList[0].Elements[5].ToString().Substring(0, 5); if (CompanyName.ToUpper() == "HEALTHSPRI") { HPS = false; this.Invoke((MethodInvoker) delegate { chbHealthSprings.Checked = true; lblStatus.ForeColor = System.Drawing.Color.Black; lblStatus.Text = "Processing HealthSpring file."; // runs on UI thread }); } else if (CompanyName.ToUpper() == "HEALTHPLAN") { HPS = true; this.Invoke((MethodInvoker) delegate { chbHPS.Checked = true; lblStatus.ForeColor = System.Drawing.Color.Black; lblStatus.Text = "Processing HPS file."; // runs on UI thread }); } else if (CompanyName.ToUpper() == "PEKIN") { PEK = true; this.Invoke((MethodInvoker) delegate { chbPekin.Checked = true; lblStatus.ForeColor = System.Drawing.Color.Black; lblStatus.Text = "Processing Pekin file."; // runs on UI thread }); CompanyName = "PEKIN"; } else if (CompanyName.ToUpper() == "BOONGROUP") { BOON = true; this.Invoke((MethodInvoker) delegate { chbBoon.Checked = true; lblStatus.ForeColor = System.Drawing.Color.Black; lblStatus.Text = "Processing BoonGroup file."; // runs on UI thread }); CompanyName = "BOON"; } if (CompanyName.ToUpper() == "HEALTHPLAN") { OutputStream = ConfigurationManager.AppSettings["HPSFilePath"] + DateTime.Now.ToString("MMddyyyy") + ".TXT"; } else if (CompanyName.ToUpper() == "HEALTHSPRI") { OutputStream = ConfigurationManager.AppSettings["HealthSpringsFilePath"] + DateTime.Now.ToString("MMddyyyy") + ".TXT"; } else if (CompanyName.ToUpper() == "PEKIN") { OutputStream = ConfigurationManager.AppSettings["PekinFilePath"] + DateTime.Now.ToString("MMddyyyy") + ".TXT"; } else if (CompanyName.ToUpper() == "BOON") { OutputStream = ConfigurationManager.AppSettings["BoonFilePath"] + DateTime.Now.ToString("MMddyyyy") + ".TXT"; } if (File.Exists(OutputStream)) { File.Delete(OutputStream); } if (CompanyName == "PEKIN")// Create Pekin Header { try { if (File.Exists(OutputStream)) { using (StreamWriter sw = File.AppendText(OutputStream)) { //string test = ConfigurationManager.recipients["wagner']; sw.WriteLine("PEK" + PekinDate + PekinMinutes + PekinSeconds + "00M26 RPRXPEK/*ALL/*ALL 1 " + ConfigurationManager.AppSettings["bwagner"] + " 0000000000 "); sw.Flush(); } } else { using (StreamWriter sw = File.CreateText(OutputStream)) { sw.WriteLine("PEK" + PekinDate + PekinMinutes + PekinSeconds + "00M26 RPRXPEK/*ALL/*ALL 1 " + ConfigurationManager.AppSettings["bwagner"] + " 0000000000"); sw.Flush(); } } }// end try catch (IOException ex) { MessageBox.Show(ex.Message); } } if (CompanyName.ToUpper() == "HEALTHPLAN") { StartingCount = 6; } else if (CompanyName.ToUpper() == "HEALTHSPRI") { StartingCount = 7; } else if (CompanyName.ToUpper() == "PEKIN") { StartingCount = 7; } else if (CompanyName.ToUpper() == "BOON") { StartingCount = 8; } int ULength = 0; string sTest = ""; if (bProcessData) { for (int iRCnt = 0; iRCnt < aList.Count; iRCnt++) { TESTCOUNTER += 1; //if (TESTCOUNTER == 2608) // TESTCOUNTER = 2608; if (iRCnt > StartingCount) { FldValue = ""; sTest = aList[iRCnt].SegID.ToString(); if (aList[iRCnt].SegID == "REF" && aList[iRCnt].Elements[0] == "0F" && !HPS && !PEK) { ULength = aList[iRCnt].Elements[1].Length; //MessageBox.Show("This is the length " + ULength.ToString()); UniqID = aList[iRCnt].Elements[1].Substring(0, ULength); //MessageBox.Show("This is the length " + aList[iRCnt].Elements[1].ToString()); } if (aList[iRCnt].SegID == "REF" && aList[iRCnt].Elements[0] == "1L" && PEK) { if (string.IsNullOrEmpty(GroupCode)) { GroupCode = aList[iRCnt].Elements[1].Substring(0, 6); } //Temporarily hardcode groupcode for testing // GroupCode = "H15000"; } if (aList[iRCnt].SegID == "REF" && aList[iRCnt].Elements[0] == "0F" && PEK) { UniqID = aList[iRCnt].Elements[1].Substring(0, 11); } if (aList[iRCnt].SegID == "REF" && aList[iRCnt].Elements[0] == "1L" && (HPS || BOON)) { if (HPS) { UniqID = aList[iRCnt].Elements[1].Substring(15, 8); GroupCode = aList[iRCnt].Elements[1].Substring(0, 3); PrintData(); } else// Boon only { GroupCode = aList[iRCnt].Elements[1].Substring(0, 9); } } if (aList[iRCnt].SegID == "REF" && aList[iRCnt].Elements[0] == "F6") { if (!HPS) { if (aList[iRCnt].Elements.Length >= 1) { SSN = aList[iRCnt].Elements[1];// Doesn't always have element[1] } else { SSN = ""; } SSNSub = SSN.Substring(0, 2); SSNSub1 = SSN.Substring(0, 1); SSNSub2 = SSN.Substring(0, 3); if (SSNSub == "MA" || SSNSub == "WD" || SSNSub == "CA") { SSN = SSN.Substring(2, 9); } if (SSNSub1 == "A") { SSN = SSN.Substring(1, 9); } if (SSNSub == "WA" || SSNSub2 == "WCA") { SSN = ""; } if (SSNSub2 == "WCD") { SSN = SSN.Substring(3, 9); } } } if (aList[iRCnt].SegID == "NM1" && aList[iRCnt].Elements[0] == "IL") { LName = aList[iRCnt].Elements[2]; if (aList[iRCnt].Elements.Length >= 4) { FName = aList[iRCnt].Elements[3]; } else { FName = ""; } if (aList[iRCnt].Elements.Length >= 5) { MidIni = aList[iRCnt].Elements[4];// Doesn't always have element[4] } else { MidIni = ""; } if (aList[iRCnt].Elements.Length >= 9) { SSN = aList[iRCnt].Elements[8];// Doesn't always have element[1] } else { SSN = ""; } } if (aList[iRCnt].SegID == "PER" && aList[iRCnt].Elements[0] == "IP") { if (aList[iRCnt].Elements.Length >= 4) { HomePhone = aList[iRCnt].Elements[3];// Doesn't always have element[3] } else { HomePhone = ""; } } if (aList[iRCnt].SegID == "N3") { Addr1 = aList[iRCnt].Elements[0]; if (aList[iRCnt].Elements.Length >= 2) { Addr2 = aList[iRCnt].Elements[1];// Doesn't always have element[1] } else { Addr2 = ""; } } if (!HPS) { if (aList[iRCnt].SegID == "N4" && aList[iRCnt].Elements.Length == 6) { City = aList[iRCnt].Elements[0]; // Seg n4 State = aList[iRCnt].Elements[1]; // Seg n4 Zip = aList[iRCnt].Elements[2]; // Seg n4 Zip4 = aList[iRCnt].Elements[3]; // Seg n4' } } if (PEK || BOON) { if (aList[iRCnt].SegID == "N4" && aList[iRCnt].Elements.Length == 3) { City = aList[iRCnt].Elements[0]; // Seg n4 State = aList[iRCnt].Elements[1]; // Seg n4 Zip = aList[iRCnt].Elements[2]; // Seg n4 // Zip4 = aList[iRCnt].Elements[3];// Seg n4' } } if (HPS) { if (aList[iRCnt].SegID == "N4") { City = aList[iRCnt].Elements[0];// Seg n4 if (aList[iRCnt].Elements.Length >= 2) { State = aList[iRCnt].Elements[1];// Seg n4// Doesn't always have element[2] } else { State = ""; } if (aList[iRCnt].Elements.Length >= 3) { Zip = aList[iRCnt].Elements[2];// Seg n4// Doesn't always have element[2] } else { Zip = " "; } } } if (aList[iRCnt].SegID == "DMG" && aList[iRCnt].Elements[0] == "D8") { DOB = aList[iRCnt].Elements[1];// Seg DMG if (!PEK) { DOB = FormatDate(DOB); } if (aList[iRCnt].Elements.Length >= 3) { Gender = aList[iRCnt].Elements[2];// Doesn't always have element[2] } else { Gender = ""; } // Gender = aList[iRCnt].Elements[2];// Seg DMG } if (aList[iRCnt].SegID == "DTP" && aList[iRCnt].Elements[0] == "348") { EffDate = aList[iRCnt].Elements[2];// Seg DTP if (!PEK) { EffDate = FormatDate(EffDate); } else { EffDate = PekinFormatDate(EffDate); } } if (aList[iRCnt].SegID == "DTP" && aList[iRCnt].Elements[0] == "543") { PaidThruDT = aList[iRCnt].Elements[2];// Seg DTP PaidThruDT = FormatDate(PaidThruDT); } if (aList[iRCnt].SegID == "DTP" && aList[iRCnt].Elements[0] == "349") { TermDate = aList[iRCnt].Elements[2];// Seg DTP if (!PEK) { TermDate = FormatDate(TermDate); } else { TermDate = PekinFormatDate(TermDate); } if (BOON) { StandardPrintData(); } } if (aList[iRCnt].SegID == "INS") { if (BOON && !String.IsNullOrEmpty(EffDate)) { StandardPrintData(); } Relation = aList[iRCnt].Elements[1];// Relation if (HPS || BOON || CompanyName.ToUpper() == "HEALTHSPRI" || CompanyName.ToUpper() == "HEALTHSPRING") { if (Relation == "18") { SequenceNo = "00"; Sequence = 00; Relation = "M"; } else if (Relation == "19") { Sequence += 1; SequenceNo = "0" + Sequence.ToString(); Relation = "C"; } else if (Relation == "01") { Sequence += 1; SequenceNo = "0" + Sequence.ToString(); Relation = "S"; } else { SequenceNo = "00"; Relation = "O"; } } if (PEK) { if (Relation == "18") { SequenceNo = "00"; } else { SequenceNo = "01"; } } if (!HPS && !PEK && !BOON) { PrintData(); } } if (aList[iRCnt].SegID == "N1" && aList[iRCnt].Elements[0] == "TV" && CompanyName == "PEKIN") { PekinPrintData(); } } } if (PEK) { PekinPrintData(); } else if (BOON) { StandardPrintData(); } else { PrintData(); } this.Invoke((MethodInvoker) delegate { lblStatus.ForeColor = System.Drawing.Color.DarkGreen; lblStatus.Text = "Process Completed."; // runs on UI thread lstbxFileToProcess.Items.RemoveAt(0); chbHPS.Checked = false; chbHealthSprings.Checked = false; lstbxFileToProcess.AllowDrop = true; }); } // End of if (bProcessData) statement } // end try catch (Exception ex) { MessageBox.Show(ex.Message + TESTCOUNTER.ToString()); } } // End of ProcessData