public static bool LoadFromFile(string fileName, out OrganisationDetailAddress obj)
 {
     Exception exception = null;
     return LoadFromFile(fileName, out obj, out exception);
 }
 public static bool LoadFromFile(string fileName, out OrganisationDetailAddress obj, out Exception exception)
 {
     return LoadFromFile(fileName, Encoding.UTF8, out obj, out exception);
 }
 /// <summary>
 /// Deserializes xml markup from file into an OrganisationDetailAddress object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output OrganisationDetailAddress object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, System.Text.Encoding encoding, out OrganisationDetailAddress obj, out Exception exception)
 {
     exception = null;
     obj = default(OrganisationDetailAddress);
     try
     {
         obj = LoadFromFile(fileName, encoding);
         return true;
     }
     catch (Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 public static bool Deserialize(string input, out OrganisationDetailAddress obj)
 {
     Exception exception = null;
     return Deserialize(input, out obj, out exception);
 }
 /// <summary>
 /// Deserializes workflow markup into an OrganisationDetailAddress object
 /// </summary>
 /// <param name="input">string workflow markup to deserialize</param>
 /// <param name="obj">Output OrganisationDetailAddress object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this Serializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string input, out OrganisationDetailAddress obj, out Exception exception)
 {
     exception = null;
     obj = default(OrganisationDetailAddress);
     try
     {
         obj = Deserialize(input);
         return true;
     }
     catch (Exception ex)
     {
         exception = ex;
         return false;
     }
 }
 //-----------------------------------------------------------------------------------------------------
 public FileAnalysis Func_X12_810_GLO_CWO_XMS_CIV(
     string filename,
     string errorOut,
     string validOut,
     string processOut)
 {
     this.FileStatus = new FileAnalysis();
     try
     {
         if (File.Exists(filename))
         {
             int j;
             DateTime dteInvDate;
             var strBN = string.Empty;
             var strBM = string.Empty;
             var strPO = string.Empty;
             var edi810 = Interchange.LoadFrom(File.OpenRead(filename));
             var ediInt = new XmlInterchange();
             for (var g = 0; g < edi810.Groups.Count; g++)
             {
                 ediInt.Version = "1";
                 ediInt.InterchangeInfo = new InterchangeInfo
                 {
                     Date = DateTime.Now,
                     XmlType = XmlType.LightWeight,
                     EDIOrganisation =
                     {
                         EDICode = "WALINTJFK",
                         OwnerCode = "WALINTJFK"
                     },
                     Source =
                         new InterchangeInfoSource
                         {
                             EnterpriseCode
                                 = "WLT",
                             CompanyCode =
                                 "JFK",
                             OriginServer =
                                 "JFK",
                             LoginName =
                                 "jerry.mabasa",
                             LoginUserEmailAddress
                                 =
                                 "*****@*****.**"
                         },
                     Target = {BranchCode = "JFK"}
                 };
                 ediInt.Payload = new XmlInterchangePayload {Invoices = new Invoices()};
                 for (var m = 0; m < edi810.Groups[g].Messages.Count; m++)
                 {
                     if (edi810.Groups[g].Messages[m].Context.Tag != "810")
                     {
                         this.FileStatus.ExcpMessage = string.Concat("Invalid 810: ", Path.GetFileName(filename));
                     }
                     else
                     {
                         var ediMsg = edi810.Groups[g].Messages[m].DeserializeItem<M_810>();
                         var ediInvH = new InvoiceHeader {InvoiceNumber = ediMsg.S_BIG.D_76_2};
                         var decInvAmnt = new decimal(0);
                         decimal.TryParse(ediMsg.S_TDS.D_610_1, out decInvAmnt);
                         ediInvH.InvoiceAmount.Value = decInvAmnt/new decimal(100);
                         ediInvH.InvoiceAmount.CurrencyCode = ediMsg.S_CUR.D_100_2;
                         string[] strArrays =
                         {
                             ediMsg.S_BIG.D_373_1.Substring(4, 2), "/",
                             ediMsg.S_BIG.D_373_1.Substring(6, 2), "/",
                             ediMsg.S_BIG.D_373_1.Substring(0, 4)
                         };
                         if (DateTime.TryParse(string.Concat(strArrays), out dteInvDate))
                         {
                             ediInvH.InvoiceDate = dteInvDate;
                         }
                         ediInvH.Consignor = new Organisation();
                         ediInvH.Consignee = new Organisation();
                         var clsOrgBuy = new Organisation();
                         var clsOrgSel = new Organisation();
                         for (j = 0; j < ediMsg.G_N1.Count; j++)
                         {
                             if (ediMsg.G_N1[j].S_N1.D_98_1.ToString() == "SF")
                             {
                                 ediInvH.Consignor.EDICode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 ediInvH.Consignor.OwnerCode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 var clsCnrAdd = new OrganisationDetailAddress();
                                 if (ediMsg.G_N1[j].S_N3.Count != 0)
                                 {
                                     clsCnrAdd.AddressLine1 = ediMsg.G_N1[j].S_N3[0].D_166_1;
                                     clsCnrAdd.AddressLine2 = ediMsg.G_N1[j].S_N3[0].D_166_2;
                                 }
                                 if (ediMsg.G_N1[j].S_N4 != null)
                                 {
                                     clsCnrAdd.CityOrSuburb = ediMsg.G_N1[j].S_N4.D_19_1;
                                 }
                                 ediInvH.Consignee.OrganisationDetails.Addresses.Add(clsCnrAdd);
                                 clsOrgSel = ediInvH.Consignor;
                             }
                             if (ediMsg.G_N1[j].S_N1.D_98_1.ToString() == "ST")
                             {
                                 ediInvH.Consignee.EDICode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 ediInvH.Consignee.OwnerCode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 ediInvH.Consignee.OrganisationDetails.Name = ediMsg.G_N1[j].S_N1.D_93_2;
                                 var clsCneAdd = new OrganisationDetailAddress();
                                 if (ediMsg.G_N1[j].S_N3.Count != 0)
                                 {
                                     if (ediMsg.G_N1[j].S_N3[0].D_166_1 != null)
                                     {
                                         clsCneAdd.AddressLine1 = ediMsg.G_N1[j].S_N3[0].D_166_1;
                                     }
                                     if (ediMsg.G_N1[j].S_N3[0].D_166_2 != null)
                                     {
                                         clsCneAdd.AddressLine2 = ediMsg.G_N1[j].S_N3[0].D_166_2;
                                     }
                                 }
                                 if (ediMsg.G_N1[j].S_N4 != null)
                                 {
                                     clsCneAdd.CityOrSuburb = ediMsg.G_N1[j].S_N4.D_19_1;
                                 }
                                 ediInvH.Consignee.OrganisationDetails.Addresses.Add(clsCneAdd);
                             }
                             if (ediMsg.G_N1[j].S_N1.D_98_1.ToString() == "BT")
                             {
                                 clsOrgBuy.EDICode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 clsOrgBuy.OwnerCode = ediMsg.G_N1[j].S_N1.D_67_4;
                                 var clsBuyAdd = new OrganisationDetailAddress();
                                 if (ediMsg.G_N1[j].S_N3.Count != 0)
                                 {
                                     if (ediMsg.G_N1[j].S_N3[0].D_166_1 != null)
                                     {
                                         clsBuyAdd.AddressLine1 = ediMsg.G_N1[j].S_N3[0].D_166_1;
                                     }
                                     if (ediMsg.G_N1[j].S_N3[0].D_166_2 != null)
                                     {
                                         clsBuyAdd.AddressLine2 = ediMsg.G_N1[j].S_N3[0].D_166_2;
                                     }
                                 }
                                 if (ediMsg.G_N1[j].S_N4 != null)
                                 {
                                     clsBuyAdd.CityOrSuburb = ediMsg.G_N1[j].S_N4.D_19_1;
                                 }
                             }
                             if (ediMsg.G_N1[j].S_REF_2.Count > 0)
                             {
                                 for (var h = 0; h < ediMsg.G_N1[j].S_REF_2.Count; h++)
                                 {
                                     if (ediMsg.G_N1[j].S_REF_2[h].D_128_1.ToString() == "BN")
                                     {
                                         if (ediMsg.G_N1[j].S_REF_2[h].D_127_2 != null)
                                         {
                                             strBN = ediMsg.G_N1[j].S_REF_2[h].D_127_2;
                                         }
                                     }
                                     if (ediMsg.G_N1[j].S_REF_2[h].D_128_1.ToString() == "BM")
                                     {
                                         if (ediMsg.G_N1[j].S_REF_2[h].D_127_2 != null)
                                         {
                                             strBM = ediMsg.G_N1[j].S_REF_2[h].D_127_2;
                                         }
                                     }
                                 }
                             }
                         }
                         ediInvH.IsGroupInvoice = TrueFalse.@false;
                         ediInvH.Incoterm = ediMsg.S_FOB.D_335_5.ToString();
                         var decVol = new decimal(0);
                         ediInvH.Volume.Value = decVol;
                         ediInvH.Volume.DimensionType = "M3";
                         var decWgt = new decimal(0);
                         decimal.TryParse(ediMsg.S_CTT.D_81_3, out decWgt);
                         ediInvH.Weight.Value = decWgt;
                         ediInvH.Weight.DimensionType = ediMsg.S_CTT.D_355_4.ToString();
                         ediInvH.StandAloneInvoiceDirection = "EXP";
                         var clsInvRef = new InvoiceReference {Type = ediMsg.S_CAD_2.D_128_7.ToString()};
                         if (clsInvRef.Type == "BM")
                         {
                             clsInvRef.Type = "MB";
                         }
                         clsInvRef.Value = ediMsg.S_CAD_2.D_127_8;
                         ediInvH.References.Add(clsInvRef);
                         var clsPORef = new InvoiceReference {Type = "PO", Value = ediMsg.S_BIG.D_324_4};
                         ediInvH.References.Add(clsPORef);
                         strPO = clsPORef.Value;
                         for (j = 0; j < ediMsg.G_IT1.Count; j++)
                         {
                             var clsInvLine = new InvoiceLine
                             {
                                 InvoiceLineNumber = ediMsg.G_IT1[j].S_IT1.D_350_1
                             };
                             var decInvQty = new decimal(0);
                             decimal.TryParse(ediMsg.G_IT1[j].S_IT1.D_358_2, out decInvQty);
                             clsInvLine.InvoiceQty.Value = decInvQty;
                             clsInvLine.InvoiceQty.DimensionType = ediMsg.G_IT1[j].S_IT1.D_355_3.ToString();
                             if (clsInvLine.InvoiceQty.DimensionType == "CA")
                             {
                                 clsInvLine.InvoiceQty.DimensionType = "CAS";
                             }
                             if (clsInvLine.InvoiceQty.DimensionType == "EA")
                             {
                                 clsInvLine.InvoiceQty.DimensionType = "PCS";
                             }
                             var decLinPrc = new decimal(0);
                             decimal.TryParse(ediMsg.G_IT1[j].S_IT1.D_212_4, out decLinPrc);
                             clsInvLine.LinePrice.Value = decLinPrc*decInvQty;
                             if (ediMsg.G_IT1[j].S_IT1.D_234_7 != null)
                             {
                                 clsInvLine.ProductNumber = ediMsg.G_IT1[j].S_IT1.D_234_7;
                             }
                             clsInvLine.ProductDescription = ediMsg.G_IT1[j].S_IT1.D_234_11;
                             var decCusQty = new decimal(0);
                             decimal.TryParse(ediMsg.G_IT1[j].S_IT1.D_358_2, out decCusQty);
                             clsInvLine.CustomsInvoiceQty.Value = decCusQty;
                             clsInvLine.CustomsInvoiceQty.DimensionType =
                                 ediMsg.G_IT1[j].S_IT1.D_355_3.ToString();
                             if (ediMsg.G_IT1[j].S_IT1.D_235_12.ToString() == "CH")
                             {
                                 clsInvLine.LineClassification.OriginOfGoods = ediMsg.G_IT1[j].S_IT1.D_234_13;
                             }
                             if (ediMsg.G_IT1[j].S_IT1.D_235_14.ToString() == "HD")
                             {
                                 clsInvLine.LineClassification.TariffCode.Type = "HTS";
                             }
                             clsInvLine.LineClassification.TariffCode.Value = ediMsg.G_IT1[j].S_IT1.D_234_15;
                             var decNetWgt = new decimal(0);
                             decimal.TryParse(ediMsg.G_IT1[j].S_PO4.D_384_6, out decNetWgt);
                             clsInvLine.NetWeight.Value = decNetWgt;
                             clsInvLine.NetWeight.DimensionType = ediMsg.G_IT1[j].S_PO4.D_355_7.ToString();
                             clsInvLine.CustomText1 = strBN;
                             clsInvLine.CustomText2 = strBM;
                             clsInvLine.CustomText3 = strPO;
                             var clsUSInv = new USInvoice
                             {
                                 Organisations =
                                 {
                                     Buyer = clsOrgBuy,
                                     Seller = clsOrgSel
                                 }
                             };
                             ediInvH.CountryPayload.USInvoice = new USInvoice();
                             ediInvH.CountryPayload.USInvoice = clsUSInv;
                             clsInvLine.OrderNumber = clsPORef.Value;
                             ediInvH.InvoiceLines.Add(clsInvLine);
                         }
                         ediInt.Payload.Invoices.InvoiceHeader.Add(ediInvH);
                     }
                 }
             }
             ediInt.Serialize();
             if (
                 File.Exists(
                     string.Concat(validOut, "\\810_JNJ_", Path.GetFileNameWithoutExtension(filename), ".xml")))
             {
                 File.Delete(
                     string.Concat(validOut, "\\810_JNJ_", Path.GetFileNameWithoutExtension(filename), ".xml"));
             }
             ediInt.SaveToFile(
                 string.Concat(validOut, "\\810_JNJ_", Path.GetFileNameWithoutExtension(filename), ".xml"));
             if (File.Exists(string.Concat(processOut, "\\", Path.GetFileName(filename))))
             {
                 File.Delete(string.Concat(processOut, "\\", Path.GetFileName(filename)));
             }
             File.Move(filename, string.Concat(processOut, "\\", Path.GetFileName(filename)));
         }
     }
     catch (Exception exception)
     {
         this.FileStatus.ExcpMessage = exception.Message;
     }
     return this.FileStatus;
 }