private void BtnEdiTest_Click(object sender, EventArgs e) { bool _OK = readEdiTest(); string edi = @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*> GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010 ST*940*0001 W05*N*538686**001001*538686 LX*1 W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205 G69*11.500 STRUD BLUBRY W76*56*500*LB*24*CF SE*7*0001 GE*1*3317 IEA*1*000003438"; EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(edi); //Serialize the whole batch to JSON JsonDataWriter w1 = new JsonDataWriter(); string json = w1.WriteToString(b); //OR Serialize selected EDI message to Json string jsonTrans = JsonConvert.SerializeObject(b.Interchanges[0].Groups[0].Transactions[0]); //Serialize the whole batch to XML XmlDataWriter w2 = new XmlDataWriter(); string xml = w2.WriteToString(b); }
public string GetJSONFromEDIDoc(string ediDoc) { string edi = @"ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*> GS*OW*7705551212*3111350000*20000128*0557*3317*T*004010 ST*940*0001 W05*N*538686**001001*538686 LX*1 W01*12*CA*000100000010*VN*000100*UC*DEC0199******19991205 G69*11.500 STRUD BLUBRY W76*56*500*LB*24*CF SE*7*0001 GE*1*3317 IEA*1*000003438"; EdiDataReader ediReader = new EdiDataReader(); EdiBatch ediBatch = ediReader.FromString(ediDoc); //Serialize the whole batch to JSON JsonDataWriter w1 = new JsonDataWriter(); string json = w1.WriteToString(ediBatch); ////OR Serialize selected EDI message to Json //string jsonTrans = JsonConvert.SerializeObject(ediBatch.Interchanges[0].Groups[0].Transactions[0]); ////Serialize the whole batch to XML //XmlDataWriter w2 = new XmlDataWriter(); //string xml = w2.WriteToString(ediBatch); return(JsonConvert.SerializeObject(json)); }
private void readEdi() { string edi = txtEDIinput.Text; EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(edi); MessageBox.Show(b.Interchanges.Count.ToString()); }
public void EdiWriter_WriteComposite() { //nonexisting map with just SLN segment to test composites M_001 map = new M_001(); EdiTrans t = new EdiTrans(map); var sDef = (MapSegment)map.Content.First(s => s.Name == "SLN"); var seg = new EdiSegment(sDef); //create composite var c001 = new EdiCompositeDataElement(sDef.Content[4], null); c001.Content.AddRange(new[] { new EdiSimpleDataElement(c001.Definition.Content[0], "PC"), new EdiSimpleDataElement(c001.Definition.Content[1], "21.1"), new EdiSimpleDataElement(c001.Definition.Content[2], "22.2"), new EdiSimpleDataElement(c001.Definition.Content[3], "EA"), new EdiSimpleDataElement(c001.Definition.Content[4], "23.3"), new EdiSimpleDataElement(c001.Definition.Content[5], "24.4") }); //create segment seg.Content.AddRange(new DataElementBase[] { new EdiSimpleDataElement(sDef.Content[0], "1.1"), new EdiSimpleDataElement(sDef.Content[1], null), new EdiSimpleDataElement(sDef.Content[2], "I"), new EdiSimpleDataElement(sDef.Content[3], "10000"), c001, new EdiSimpleDataElement(sDef.Content[5], "1.56"), new EdiSimpleDataElement(sDef.Content[6], "TP"), new EdiSimpleDataElement(sDef.Content[7], null), new EdiSimpleDataElement(sDef.Content[8], "VC"), new EdiSimpleDataElement(sDef.Content[9], "P-875OS") }); t.Content.Add(seg); string data = TestUtils.WriteEdiEnvelope(t, "ZZ"); EdiDataReader r = new EdiDataReader("EdiEngine.Tests"); EdiBatch b = r.FromString(data); EdiTrans t2 = b.Interchanges[0].Groups[0].Transactions[0]; //1 error - unknown map Assert.AreEqual(1, t2.ValidationErrors.Count); var sln = (EdiSegment)t.Content.First(); Assert.IsTrue(sln.Content[4] is EdiCompositeDataElement); Assert.AreEqual(6, ((EdiCompositeDataElement)sln.Content[4]).Content.Count); }
/// <summary> _ediAdapterFactory /// read edi message to map order list /// </summary> /// <param name="parserFile"></param> /// <returns></returns> private void readEdi(string parserFile, Edi_Customer c, string s) { string _EdiBasePath = ConfigurationManager.AppSettings["EdiBase"]; string edi = System.IO.File.ReadAllText(parserFile); EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(edi); EdiTrans _Trans = b.Interchanges[0].Groups[0].Transactions[0]; EdiBase _EdiBase = _ediAdapterFactory.CreateEdiAdapter(_Trans.Definition.ToString()); string _Log = _EdiBase.Parse(b, c, parserFile); txtLog.Text += _Log; _Log = _EdiBase.Process(c, s, _EdiBasePath); txtLog.Text += _Log; }
private bool readEdiTest( ) { bool _OK = false; try { EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(txtANSIX12.Text); _OK = true; } catch (Exception ex) { MessageBox.Show(ex.Message); } return(_OK); }
private void readEdibyEdifact() { //var grammar = EdiGrammar.NewTradacoms(); //var interchange = default(Interchange); //using (var stream = new StreamReader(@"D:\Users\L180067\Desktop\EDI_C4782x_ORDERS_ATWE_20200423_sample.dat")) //{ // interchange = new EdiSerializer().Deserialize<Interchange>(stream, grammar); //} // return setSalesOrderByEdi(b, c, parserFile); string edi = txtEDIinput.Text; EdiDataReader r = new EdiDataReader(); EdiBatch b = r.FromString(edi); }
static void Main(string[] args) { TextReader tIn = Console.In; String ediData = tIn.ReadLine(); EdiDataReader r = new EdiDataReader(); EdiBatch ediBatch = r.FromString(ediData); //control whether you need to accept all transaction or report error if such. AckBuilderSettings ackSettings = new AckBuilderSettings(AckValidationErrorBehavour.AcceptAll, false, 100, 200); var ack = new AckBuilder(ackSettings); //create FA object structure EdiBatch ackBatch = ack.GetnerateAcknowledgment(ediBatch); string data = ack.WriteToString(ediBatch); Console.WriteLine(data); }
public void EdiWriter_CreateEdi940() { M_940 map = new M_940(); EdiTrans t = new EdiTrans(map); // W05 var sDef = (MapSegment)map.Content.First(s => s.Name == "W05"); var seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "N"), new EdiDataElement(sDef.Content[1], "538686"), new EdiDataElement(sDef.Content[2], null), new EdiDataElement(sDef.Content[3], "001001"), new EdiDataElement(sDef.Content[4], "538686") }); t.Content.Add(seg); //LX*1 var lDef = (MapLoop)map.Content.First(s => s.Name == "L_LX"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "LX"); EdiLoop lx = new EdiLoop(lDef, null); t.Content.Add(lx); seg = new EdiSegment(sDef); seg.Content.Add(new EdiDataElement(sDef.Content[0], "1")); lx.Content.Add(seg); //LX > W01 loop lDef = (MapLoop)lDef.Content.First(s => s.Name == "L_W01"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "W01"); EdiLoop w01 = new EdiLoop(lDef, null); lx.Content.Add(w01); seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "12"), new EdiDataElement(sDef.Content[1], "CA"), new EdiDataElement(sDef.Content[1], "000100033330") }); w01.Content.Add(seg); //LX*2 lDef = (MapLoop)map.Content.First(s => s.Name == "L_LX"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "LX"); lx = new EdiLoop(lDef, null); t.Content.Add(lx); seg = new EdiSegment(sDef); seg.Content.Add(new EdiDataElement(sDef.Content[0], "2")); lx.Content.Add(seg); //LX > W01 loop lDef = (MapLoop)lDef.Content.First(s => s.Name == "L_W01"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "W01"); w01 = new EdiLoop(lDef, null); lx.Content.Add(w01); seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiDataElement(sDef.Content[0], "10"), new EdiDataElement(sDef.Content[1], "CA"), new EdiDataElement(sDef.Content[1], "000100033332") }); w01.Content.Add(seg); //write test envelope string data = TestUtils.WriteEdiEnvelope(t, "OW"); //read produced results and check for errors. EdiDataReader r = new EdiDataReader(); EdiBatch batch = r.FromString(data); Assert.AreEqual(1, batch.Interchanges.Count); Assert.AreEqual(0, batch.Interchanges[0].ValidationErrors.Count); Assert.AreEqual(1, batch.Interchanges[0].Groups.Count); Assert.AreEqual(0, batch.Interchanges[0].Groups[0].ValidationErrors.Count); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; Assert.AreEqual(0, trans.ValidationErrors.Count); }
public void EdiWriter_FromJson() { //get sample json string jsonTrans; using ( Stream s = GetType().Assembly.GetManifestResourceStream("EdiEngine.Tests.TestData.940.OK.json")) { if (s == null) { throw new InvalidDataException("stream is null"); } using (StreamReader sr = new StreamReader(s)) { jsonTrans = sr.ReadToEnd(); } } //Read json and convert it to trans M_940 map = new M_940(); JsonMapReader r = new JsonMapReader(map); EdiTrans t = r.ReadToEnd(jsonTrans); //write EDI string data = TestUtils.WriteEdiEnvelope(t, "OW"); //Read produced results and check for errors and correct parsing EdiDataReader reader = new EdiDataReader(); EdiBatch batch = reader.FromString(data); Assert.AreEqual(1, batch.Interchanges.Count); Assert.AreEqual(0, batch.Interchanges[0].ValidationErrors.Count); Assert.AreEqual(1, batch.Interchanges[0].Groups.Count); Assert.AreEqual(0, batch.Interchanges[0].Groups[0].ValidationErrors.Count); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; Assert.AreEqual(0, trans.ValidationErrors.Count); int w05Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W05)); int n1Count = trans.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_N1)); int n1FirstIterationCount = ((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_N1))).Content.Count; int n1SecondIterationCount = ((EdiLoop)trans.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(1).First()) .Content.Count; int n1ThirdIterationCount = ((EdiLoop)trans.Content.Where(l => l.Definition.GetType() == typeof(M_940.L_N1)).Skip(2).First()) .Content.Count; int n9Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.N9)); int g62Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.G62)); int nteCount = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.NTE)); int w66Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W66)); int lxCount = trans.Content.Count(l => l.Definition.GetType() == typeof(M_940.L_LX)); int lxFirstIterationCount = ((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX))).Content.Count; int lxFirstIterationW01Count = ((EdiLoop)((EdiLoop)trans.Content.First(l => l.Definition.GetType() == typeof(M_940.L_LX))) .Content.Skip(1).First()).Content.Count; int w76Count = trans.Content.Count(l => l.Definition.GetType() == typeof(SegmentDefinitions.W76)); Assert.AreEqual(1, w05Count); Assert.AreEqual(3, n1Count); Assert.AreEqual(3, n1FirstIterationCount); Assert.AreEqual(3, n1SecondIterationCount); Assert.AreEqual(2, n1ThirdIterationCount); Assert.AreEqual(1, n9Count); Assert.AreEqual(2, g62Count); Assert.AreEqual(1, nteCount); Assert.AreEqual(1, w66Count); Assert.AreEqual(3, lxCount); Assert.AreEqual(2, lxFirstIterationCount); Assert.AreEqual(3, lxFirstIterationW01Count); Assert.AreEqual(1, w76Count); }
public string X12_855(Edi_SalesOrder_855 sapSalesOrder, string mode, string receiver) { M_855 map = new M_855(); EdiTrans t = new EdiTrans(map); var sDef = (MapSegment)map.Content.First(s => s.Name == "BAK"); var seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], "00"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], sapSalesOrder.Header.Status), //AD:No change AC:with change RD:rejected new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], sapSalesOrder.Header.PURCH_NO_C), //set 850 order number new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[3], sapSalesOrder.Header.PURCH_DATE), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[7], sapSalesOrder.Header.OrderNumber), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[8], sapSalesOrder.Header.DateTime) }); t.Content.Add(seg); //create segment var lDef = (MapLoop)map.Content.First(s => s.Name == "L_PO1"); sDef = (MapSegment)lDef.Content.First(s => s.Name == "PO1"); EdiLoop p01 = new EdiLoop(lDef, null); t.Content.Add(p01); //get sap order price? foreach (Edi_SalesItem_855 i in sapSalesOrder.ItemList) { seg = new EdiSegment(sDef); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], i.CustomerItemNumber), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], i.TARGET_QTY), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], i.CustomerUnit), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[3], i.Price), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[4], i.CustomerUnitOfPrice), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[5], "BP"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[6], i.CUST_MAT35), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[7], "VP"), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[8], i.MATERIAL) }); p01.Content.Add(seg); var lDef_L_ACK = (MapLoop)lDef.Content.First(s => s.Name == "L_ACK"); var sDef_ACK = (MapSegment)lDef_L_ACK.Content.First(s => s.Name == "ACK"); EdiLoop w = new EdiLoop(lDef_L_ACK, p01); p01.Content.Add(w); foreach (Edi_SalesSchedule_855 j in sapSalesOrder.ScheduleList) { if (i.ITM_NUMBER == j.ITM_NUMBER) { seg = new EdiSegment(sDef_ACK); seg.Content.AddRange(new[] { new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[0], j.Status), //IA:accept IR:reject new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[1], j.REQ_QTY), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], i.CustomerUnit), //ok new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], j.DateTimeCode), new EdiSimpleDataElement((MapSimpleDataElement)sDef.Content[2], j.DateTime) }); w.Content.Add(seg); } } } string data = writeEdiEnvelope(t, "PR", mode, receiver); //read produced results and check for errors. EdiDataReader r = new EdiDataReader(); EdiBatch batch = r.FromString(data); EdiTrans trans = batch.Interchanges[0].Groups[0].Transactions[0]; return(data); }