public void createCatalagoCuentas() { string strAccessConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=database\\" + this.databaseFileName; string strAccessSelect = "SELECT * FROM [CatalogoCuentasSatVendor]"; DataSet myDataSet = new DataSet(); OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); } catch (Exception ex) { Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message); return; } try { myAccessConn.Open(); OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn); OleDbDataReader reader = myAccessCommand.ExecuteReader(); List<SatContabilidad.CatalogoCtas.CatalogoCtas> ctas = new List<SatContabilidad.CatalogoCtas.CatalogoCtas>(); while (reader.Read()) { SatContabilidad.CatalogoCtas.CatalogoCtas cta = new SatContabilidad.CatalogoCtas.CatalogoCtas(); Type code = typeof(CatalogoCtas.c_CodAgrup); foreach (CatalogoCtas.c_CodAgrup o in Enum.GetValues(typeof(CatalogoCtas.c_CodAgrup))) { if (GetXmlAttrNameFromEnumValue(o).Equals(reader["CodAgrupador"].ToString(), StringComparison.OrdinalIgnoreCase)) { cta.CodAgrup = o; } } cta.NumCta = reader["NumCta"].ToString(); cta.Desc = reader["Desc"].ToString(); cta.Natur = reader["Natur"].ToString(); cta.Nivel = int.Parse(reader["Nivel"].ToString()); ctas.Add(cta); } reader.Close(); myAccessConn.Close(); SatContabilidad.CatalogoCtas.Catalogo catalogo = new SatContabilidad.CatalogoCtas.Catalogo(); catalogo.schemaLocation = "www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas/CatalogoCuentas_1_1.xsd"; catalogo.Ctas = ctas.ToArray<SatContabilidad.CatalogoCtas.CatalogoCtas>(); Type mes = typeof(CatalogoCtas.CatalogoMes); catalogo.Mes = (CatalogoCtas.CatalogoMes)Enum.Parse(mes, (int.Parse(this.month) - 1).ToString()); catalogo.Anio = int.Parse(this.year); catalogo.RFC = this.rfc; XmlSerializer serializer = new XmlSerializer(typeof(SatContabilidad.CatalogoCtas.Catalogo)); System.IO.TextWriter writer = new System.IO.StreamWriter(this.outputPath + this.rfc + this.year + this.month + "CT.xml"); serializer.Serialize(writer, catalogo); } catch (Exception ex) { Console.WriteLine("Error: Failed to retrive the required data from the Database.\n{0}", ex.Message); return; } finally { myAccessConn.Close(); } }
public void createCatalagoCuentas() { string strAccessConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=database\\" + this.databaseFileName; string strAccessSelect = "SELECT * FROM [CatalogoCuentasSatVendor]"; DataSet myDataSet = new DataSet(); OleDbConnection myAccessConn = null; try { myAccessConn = new OleDbConnection(strAccessConn); } catch (Exception ex) { Console.WriteLine("Error: Failed to create a database connection. \n{0}", ex.Message); return; } try { myAccessConn.Open(); OleDbCommand myAccessCommand = new OleDbCommand(strAccessSelect, myAccessConn); OleDbDataReader reader = myAccessCommand.ExecuteReader(); List <SatContabilidad.CatalogoCtas.CatalogoCtas> ctas = new List <SatContabilidad.CatalogoCtas.CatalogoCtas>(); while (reader.Read()) { SatContabilidad.CatalogoCtas.CatalogoCtas cta = new SatContabilidad.CatalogoCtas.CatalogoCtas(); Type code = typeof(CatalogoCtas.c_CodAgrup); foreach (CatalogoCtas.c_CodAgrup o in Enum.GetValues(typeof(CatalogoCtas.c_CodAgrup))) { if (GetXmlAttrNameFromEnumValue(o).Equals(reader["CodAgrupador"].ToString(), StringComparison.OrdinalIgnoreCase)) { cta.CodAgrup = o; } } cta.NumCta = reader["NumCta"].ToString(); cta.Desc = reader["Desc"].ToString(); cta.Natur = reader["Natur"].ToString(); cta.Nivel = int.Parse(reader["Nivel"].ToString()); ctas.Add(cta); } reader.Close(); myAccessConn.Close(); SatContabilidad.CatalogoCtas.Catalogo catalogo = new SatContabilidad.CatalogoCtas.Catalogo(); catalogo.schemaLocation = "www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas http://www.sat.gob.mx/esquemas/ContabilidadE/1_1/CatalogoCuentas/CatalogoCuentas_1_1.xsd"; catalogo.Ctas = ctas.ToArray <SatContabilidad.CatalogoCtas.CatalogoCtas>(); Type mes = typeof(CatalogoCtas.CatalogoMes); catalogo.Mes = (CatalogoCtas.CatalogoMes)Enum.Parse(mes, (int.Parse(this.month) - 1).ToString()); catalogo.Anio = int.Parse(this.year); catalogo.RFC = this.rfc; XmlSerializer serializer = new XmlSerializer(typeof(SatContabilidad.CatalogoCtas.Catalogo)); System.IO.TextWriter writer = new System.IO.StreamWriter(this.outputPath + this.rfc + this.year + this.month + "CT.xml"); serializer.Serialize(writer, catalogo); } catch (Exception ex) { Console.WriteLine("Error: Failed to retrive the required data from the Database.\n{0}", ex.Message); return; } finally { myAccessConn.Close(); } }