예제 #1
0
        private void SaveBalanceXML(string filename)
        {
            Balanza balanza = new Balanza();

            balanza.Version   = "1.1";
            balanza.RFC       = company.rfc;
            balanza.Mes       = startDate.ToString("MM");
            balanza.Anio      = startDate.Year;
            balanza.TipoEnvio = "N";
            foreach (KeyValuePair <string, Account> accountPair in Accounts)
            {
                BalanzaCtas balanzaCuenta = new BalanzaCtas();
                Account     account       = accountPair.Value;
                balanzaCuenta.NumCta   = account.satAccount.NumCta;
                balanzaCuenta.Debe     = Decimal.Round(Convert.ToDecimal(account.debit), 2, MidpointRounding.AwayFromZero);
                balanzaCuenta.Haber    = Decimal.Round(Convert.ToDecimal(account.credit), 2, MidpointRounding.AwayFromZero);
                balanzaCuenta.SaldoIni = Decimal.Round(Convert.ToDecimal(account.initialAmount), 2, MidpointRounding.AwayFromZero);
                balanzaCuenta.SaldoFin = Decimal.Round(Convert.ToDecimal(account.finalAmount), 2, MidpointRounding.AwayFromZero);
                balanza.Ctas.Add(balanzaCuenta);
            }
            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.LoadXml(balanza.Serialize());
            XmlAttribute xsi_schema_location = xmlDocument.CreateAttribute("xsi", "schemaLocation", "http://www.w3.org/2001/XMLSchema-instance");

            xsi_schema_location.Value = @"www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/BalanzaComprobacion/BalanzaComprobacion_1_1.xsd";
            xmlDocument.LastChild.Attributes.SetNamedItem(xsi_schema_location);
            xmlDocument.Save(filename);
        }
 /// <summary>
 /// Deserializes xml markup from file into an Balanza object
 /// </summary>
 /// <param name="fileName">string xml file to load and deserialize</param>
 /// <param name="obj">Output Balanza object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool LoadFromFile(string fileName, out Balanza obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(Balanza);
     try
     {
         obj = LoadFromFile(fileName);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
 /// <summary>
 /// Deserializes workflow markup into an Balanza object
 /// </summary>
 /// <param name="xml">string workflow markup to deserialize</param>
 /// <param name="obj">Output Balanza object</param>
 /// <param name="exception">output Exception value if deserialize failed</param>
 /// <returns>true if this XmlSerializer can deserialize the object; otherwise, false</returns>
 public static bool Deserialize(string xml, out Balanza obj, out System.Exception exception)
 {
     exception = null;
     obj       = default(Balanza);
     try
     {
         obj = Deserialize(xml);
         return(true);
     }
     catch (System.Exception ex)
     {
         exception = ex;
         return(false);
     }
 }
 public static bool LoadFromFile(string fileName, out Balanza obj)
 {
     System.Exception exception = null;
     return(LoadFromFile(fileName, out obj, out exception));
 }
 public static bool Deserialize(string xml, out Balanza obj)
 {
     System.Exception exception = null;
     return(Deserialize(xml, out obj, out exception));
 }