public TravComModels CheckIfPosted(string _ticketNo) { var db = new TravComEntities(); var query = from ARInvoiceDetails in db.ARInvoiceDetails //ARInvoiceDetails join a in db.Airlines on ARInvoiceDetails.ValidatingCarrier equals a.AirlineNumber into qA //Airlines from airline in qA.DefaultIfEmpty() join s in db.Segments on ARInvoiceDetails.InvoiceDetailID equals s.InvoiceDetailID into qS //Segments from segment in qS.DefaultIfEmpty() join inv in db.ARInvoices on ARInvoiceDetails.InvoiceID equals inv.InvoiceID into qInv //ARInvoices from invoice in qInv.DefaultIfEmpty() join p in db.Profiles on invoice.BookingAgentNumber equals p.ProfileNumber into qP //Profiles from profile in qP.DefaultIfEmpty() where ARInvoiceDetails.TicketNumber == _ticketNo select new TravComModels { TicketNumber = ARInvoiceDetails.TicketNumber, Tax1 = ARInvoiceDetails.Tax1, Tax2 = ARInvoiceDetails.Tax2, PublishedFare = ARInvoiceDetails.PublishedFare, CommissionAmount = ARInvoiceDetails.CommissionAmount, NetFare = ARInvoiceDetails.NetFare, NetPayable = (ARInvoiceDetails.Tax1 + ARInvoiceDetails.Tax2 + ARInvoiceDetails.PublishedFare + ARInvoiceDetails.CommissionAmount), PassengerName = ARInvoiceDetails.PassengerName, CurrencyCode = ARInvoiceDetails.CurrencyCode, AirlineCode = airline.AirlineCode, DepartureCityCode = segment.DepartureCityCode, ArrivalCityCode = segment.ArrivalCityCode, BookingDate = invoice.BookingDate, InvoiceDate = invoice.InvoiceDate, ProfileNo = invoice.ProfileNumber, ProfileName = invoice.ProfileName, FullName = profile.FullName }; return(query.FirstOrDefault()); }
public void ReadAirFile(FileInfo file, MainWindow mainWindow) { //Variables from first gen string[] temp; string[] bTTemp; string[] tkt; int ctrLX = 0, found = 0, r, rj, rjf, rTkt; int rTInfo, rHotel, rCar; int spClt; string pStr = "", pCeb = ""; int xy, rNoPax, p = 0; //string EACode = "", Etck = "", NoPax = ""; List <string> lines = new List <string>(); List <string> linesNew = new List <string>(); List <string> Tlines = new List <string>(); List <string> Alines = new List <string>(); int x, y, tk = 0, chkSabre; string textLine = ""; //try //{ using (var fileStream = File.OpenRead(file.FullName)) { using (var streamReader = new StreamReader(fileStream, Encoding.UTF8, true, 128)) { while (streamReader.Peek() > -1) { //Process textLine = streamReader.ReadLine(); lines.Add(textLine); temp = textLine.Split(';'); chkSabre = textLine.IndexOf("M6ADT"); if (chkSabre > 0) { ctrLX = 4; } for (x = 0; x < temp.Count(); x++) { //Voided Air Files if (temp[x] == "MA" || temp[x].Contains("VOID")) { List <string> ticketNumbers = new List <string>(); while (streamReader.Peek() > -1) { textLine = streamReader.ReadLine(); if (textLine.Contains("T-"))//TicketNo { ticketNumbers.Add(textLine.Substring(textLine.Length - 10, 10)); } } //TravCom Database Connection using (var db = new TravComEntities()) { ticketNumbers.ForEach(ticketNo => { var product = db.IfInvoiceDetails.Where(q => q.TicketNumber == ticketNo).ToList(); if (product.Count > 0) { product.ForEach(item => { item.TransactionType = 2; item.GrossAmount = item.GrossAmount * -1; }); } }); db.SaveChanges(); } } //Determine if Air File is Cebu Pac or IASA Ticket if (temp[x].Contains("BT") || temp[x].Contains("IM")) { while (streamReader.Peek() > -1) { textLine = streamReader.ReadLine(); r = textLine.IndexOf(";ET;"); rj = textLine.IndexOf(";N;;"); rjf = textLine.IndexOf(";FLWN;"); if (r > 0 || rj > 0 || rjf > 0) { textLine = textLine.Replace("U-", "H-").Replace("X;", ";"); lines.Add(textLine); } else { lines.Add(textLine); } rNoPax = textLine.IndexOf("I-0"); if (rNoPax > 0) { p++; } //Insert Ticket Number and Airline Code from Air File rTkt = textLine.IndexOf("ETCK"); if (rTkt > 0) { tkt = textLine.Split('-'); Alines.Add(tkt[0].Substring(7, 3)); Tlines.Add(tkt[1]); } rTInfo = textLine.IndexOf("INSR"); rHotel = textLine.IndexOf(";RTT-;"); rCar = textLine.IndexOf("CCR-;"); if (rTInfo > 0) { pCeb = "OTHER"; } else if (rHotel > 0) { pCeb = "HOTEL"; } else if (rCar > 0) { pCeb = "IASA"; } //Condition to check if Cebu Pac Tickets if (textLine.Contains("H-")) { if (textLine.Contains(";5J")) { pCeb = "CebuPac"; } else if (CheckIfIASA(textLine)) { pCeb = "IASA"; } } //end of If clause } //end of while loop } //end of if else "BT or "IM" //IATA Tickets if (temp[x].Contains("7A") && !temp[x].Contains("IM")) { while (streamReader.Peek() > -1) { textLine = streamReader.ReadLine(); rNoPax = textLine.IndexOf("I-0"); if (rNoPax > 0) { p++; } lines.Add(textLine); bTTemp = textLine.Split(';'); for (y = 0; y < bTTemp.Count(); y++) { if (bTTemp[y] != "") { ctrLX = GetCTRLX(textLine); } } //end of for loop } //end of while loop } //end of if else } //end of for loop } //end of while loop (reader - 1) if (pCeb == "CebuPac") { int ctr = 0; using (var streamWriter = File.CreateText(mainWindow.txtBoxCebuPacificLocationPath.Text + "\\" + file.Name)) { for (xy = 0; xy < lines.Count(); xy++) { if (xy == lines.Count - 1) { streamWriter.WriteLine("ENDX"); streamWriter.Close(); break; } if (lines[xy].Contains("TKOK") || lines[xy].Contains("TKTL")) { if (lines[xy].Contains("TKOK")) { var tktDate = lines[xy].Substring(4, 5); DateTime date = DateTime.Parse(tktDate); streamWriter.WriteLine("RM*FF65/" + string.Format("{0:MM-dd-yy}", date)); } streamWriter.WriteLine("T-K" + Alines[ctr] + "-" + Tlines[ctr]); streamWriter.WriteLine("RM*ET/" + Tlines[ctr]); streamWriter.WriteLine("RM*NA" + Alines[ctr] + "/PC1/V10000029"); ctr++; } else if (lines[xy].Contains("RM*FOP/CC/")) { string tempCC = lines[xy].Substring(10, lines[xy].Length - 17); string decrpytedCC = ""; Decrypt(tempCC, out decrpytedCC); var tempExpDate = lines[xy].Substring(lines[xy].Length - 7, 7); streamWriter.WriteLine("RM*FOP/CC/" + decrpytedCC + tempExpDate); } else { streamWriter.WriteLine(lines[xy]); } } streamWriter.Close(); } } else if (pCeb == "HOTEL") { int UH = 0; int chkHHL = 0; for (int yx = 0; yx < lines.Count; yx++) { if (lines[yx].Contains("HHL") || lines[yx].Contains("CCR")) { chkHHL = 1; } } if (chkHHL == 1) { using (var streamWriter = File.CreateText(mainWindow.txtBoxOtherInfoPath.Text + "\\" + file.Name)) { for (xy = 0; xy < lines.Count; xy++) { if (lines[xy].Contains("H-")) { streamWriter.WriteLine(lines[xy].Replace("H-", "U-")); } else if (lines[xy].Contains("RM*FOP/CC/")) { string tempCC = lines[xy].Substring(10, lines[xy].Length - 17); string decrpytedCC = ""; Decrypt(tempCC, out decrpytedCC); var tempExpDate = lines[xy].Substring(lines[xy].Length - 7, 7); streamWriter.WriteLine("RM*FOP/CC/" + decrpytedCC + tempExpDate); } else { streamWriter.WriteLine(lines[xy]); } } streamWriter.Close(); } } } else if (pCeb == "IASA") { int ctr = 0; int jx = 0; int uh = 0; using (var streamWriter = File.CreateText(mainWindow.txtBoxIASALocationPath.Text + "\\" + file.Name)) { for (xy = 0; xy < lines.Count(); xy++) { if (lines[xy].Contains("ETCK")) { jx = xy; if (Alines.Count != 0 && Tlines.Count != 0) { streamWriter.WriteLine("T-K" + Alines[ctr] + "-" + Tlines[ctr]); streamWriter.WriteLine("RM*ET/" + Tlines[ctr]); streamWriter.WriteLine("RM*NA/" + Alines[ctr] + "/PC1/V10000044"); ctr++; } } else if (lines[xy].Contains("RM*FOP/CC/")) { string tempCC = lines[xy].Substring(10, lines[xy].Length - 17); string decrpytedCC = ""; Decrypt(tempCC, out decrpytedCC); var tempExpDate = lines[xy].Substring(lines[xy].Length - 7, 7); streamWriter.WriteLine("RM*FOP/CC/" + decrpytedCC + tempExpDate); } else { streamWriter.WriteLine(lines[xy]); } } streamWriter.Close(); } }//end of else if IASA //IATA if (ctrLX == 3) { int chkIATA = 0; for (int pp = 0; pp < lines.Count; pp++) { for (int i = 0; i < mainWindow.DGW1.Rows.Count; i++) { spClt = lines[pp].IndexOf(mainWindow.DGW1.Rows[i].Cells[0].Value.ToString()); if (spClt > 0) { chkIATA = 1; } } } if (chkIATA == 1) { int ctr = 0; double pubAmount = 0; int comp = 0, chk = 0; string sf = ""; double comAmount = 0, sfAmount = 0; using (var streamWriter = File.CreateText(mainWindow.txtBoxSpecialClientLocationPath.Text + "\\" + file.Name)) { for (xy = 0; xy < lines.Count; xy++) { if (lines[xy].Contains("K-")) { if (lines[xy].Length >= 32 && lines[xy].Substring(21, 10) != "") { chk = 1; } else { chk = 2; } } if (lines[xy].Contains("FM*M*")) { if (lines[xy].Length > 5) { comp = int.Parse(lines[xy].Substring(6, 1)); chk = 1; } else if (lines[xy].Length == 5) { chk = 2; } if (chk == 1) { if (lines[xy].Contains("RM*SF/")) { sf = lines[xy]; comAmount = (pubAmount * (comp / 100)); sfAmount = pubAmount - comAmount; streamWriter.WriteLine(lines[xy].Replace(sf, "RM*SF/" + sfAmount)); streamWriter.WriteLine("RM*CM/" + comAmount); xy++; } } else if (chk == 2) { if (lines[xy].Contains("RM*SF/")) { xy++; } } else { if (lines[xy].Contains("RM*SF/")) { sf = lines[xy]; streamWriter.WriteLine(lines[xy].Replace(sf, "RM*CP/0")); streamWriter.WriteLine("RM*NF/0"); } } if (lines[xy].Contains("TKOK") || lines[xy].Contains("TKTL")) { if (lines[xy].Contains("TKOK")) { var tktDate = lines[xy].Substring(4, 5); DateTime date = DateTime.Parse(tktDate); streamWriter.WriteLine("RM*FF65/" + string.Format("{0:MM-dd-yy}", date)); } streamWriter.WriteLine("RM*PC/0/10000001"); ctr++; } else if (lines[xy].Contains("RM*FOP/CC/")) { string tempCC = lines[xy].Substring(10, lines[xy].Length - 17); string decrpytedCC = ""; Decrypt(tempCC, out decrpytedCC); var tempExpDate = lines[xy].Substring(lines[xy].Length - 7, 7); streamWriter.WriteLine("RM*FOP/CC/" + decrpytedCC + tempExpDate); } else { streamWriter.WriteLine(lines[xy]); } } } streamWriter.WriteLine("ENDX"); streamWriter.Close(); } //end of using } //end of if else { //==============================IATA=========================== int ctr = 0; //using (var streamWriter = File.CreateText(mainWindow.txtBoxIATALocationPath.Text + "\\" + file.Name)) using (var streamWriter = File.CreateText(mainWindow.txtBoxAmadeusTemp.Text + "\\" + file.Name)) { string netFare = ""; string segmentNoToBeRemove = ""; for (xy = 0; xy < lines.Count; xy++) { if (lines[xy].Length > 2 && lines[xy].Substring(0, 2).Contains("K-")) { string[] tempLine = lines[xy].Split(';'); if (tempLine.Length > 1 && tempLine[1] != "") { netFare = tempLine[1].Substring(3, tempLine[1].Length - 3).Replace(" ", ""); } } else if ((lines[xy].Length > 2 && lines[xy].Substring(0, 3).Contains("KN-"))) { string[] tempLine = lines[xy].Split(';'); if (tempLine.Length > 1 && tempLine[1] != "") { netFare = tempLine[1].Substring(3, tempLine[1].Length - 3).Replace(" ", ""); } } if (lines[xy].Contains("TKOK") || lines[xy].Contains("TKTL")) { if (lines[xy].Contains("TKOK")) { var tktDate = lines[xy].Substring(4, 5); DateTime date = DateTime.Parse(tktDate); streamWriter.WriteLine("RM*FF65/" + string.Format("{0:MM-dd-yy}", date)); } streamWriter.WriteLine("RM*PC/0/10000001"); ctr++; } else if (lines[xy].Contains("RM*NF") && lines[xy].Contains("/*") && lines[xy].Contains(netFare)) { string[] tempLine = lines[xy].Split('/'); string line = tempLine[0] + "/" + tempLine[2]; segmentNoToBeRemove = tempLine[1]; streamWriter.WriteLine(line); } else if (segmentNoToBeRemove != "" && lines[xy].Contains(segmentNoToBeRemove)) { lines[xy] = lines[xy].Replace("/" + segmentNoToBeRemove, ""); streamWriter.WriteLine(lines[xy]); } else if (lines[xy].Contains("RM*FOP/CC/")) { string tempCC = lines[xy].Substring(10, lines[xy].Length - 17); string decrpytedCC = ""; Decrypt(tempCC, out decrpytedCC); var tempExpDate = lines[xy].Substring(lines[xy].Length - 7, 7); streamWriter.WriteLine("RM*FOP/CC/" + decrpytedCC + tempExpDate); } else { streamWriter.WriteLine(lines[xy]); } } //streamWriter.WriteLine("ENDX"); streamWriter.Close(); }//using //TransferTempFile(mainWindow); } } } }//end of using clause //}//end of try clause // catch (Exception error) // { // } }//end of ReadAirFile function