Exemple #1
0
        public List <ReferenciaDoc> getReferencia(int tipoDoc, int folioDoc)
        {
            List <ReferenciaDoc> referencias = new List <ReferenciaDoc>();
            ReferenciaDoc        referencia  = new ReferenciaDoc();
            string referenciaJson            = string.Empty;

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select row_to_json(referencia) from referencia where \"FolioDoc\" = " + folioDoc + " and \"TipoDoc\" = " + tipoDoc + " order by \"NroLinRef\" ASC;";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    referenciaJson = reader.GetString(reader.GetOrdinal("row_to_json"));
                    string referenciaJson1        = referenciaJson.Replace("null", "\"\"");
                    string referenciaJson2        = referenciaJson1.Replace("\"TpoDocRef\\r\\n", "\"TpoDocRef");
                    DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(ReferenciaDoc));
                    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(referenciaJson2));
                    referencia = (ReferenciaDoc)js.ReadObject(ms);
                    referencias.Add(referencia);
                }
                return(referencias);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
        public void save(CafModel cafmodel)
        {
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "INSERT INTO caf("
                                     + "cafxml, fecha, \"tipoDte\", \"dirCaf\", \"folioInicial\", \"folioFinal\",\"rutEmpresa\",\"nomXml\")"
                                     + " VALUES ('"
                                     + cafmodel.cafxml + "','"
                                     + cafmodel.fecha + "','"
                                     + cafmodel.tipoDte + "','"
                                     + cafmodel.dirCaf + "',"
                                     + cafmodel.folioInicial + ","
                                     + cafmodel.folioFinal + ",'"
                                     + cafmodel.rutEmpresa + "','"
                                     + cafmodel.nomXml + "'"
                                     + ");";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
Exemple #3
0
        public List <Detalle> getDetalle(int tipoDoc, int folioDoc)
        {
            List <Detalle> detalles    = new List <Detalle>();
            Detalle        detalle     = new Detalle();
            string         detalleJson = string.Empty;

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select row_to_json(detalle) from detalle where \"FolioDoc\" = " + folioDoc + " and \"TipoDoc\" = " + tipoDoc + ";";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    detalleJson = reader.GetString(reader.GetOrdinal("row_to_json"));
                    DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(Detalle));
                    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(detalleJson));
                    detalle = (Detalle)js.ReadObject(ms);
                    detalles.Add(detalle);
                }
                return(detalles);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
Exemple #4
0
 public void save(DocumentoModel documento)
 {
     foreach (ReferenciaDoc det in documento.Referencia)
     {
         MemoryStream stream = new MemoryStream();
         DataContractJsonSerializer referencia = new DataContractJsonSerializer(typeof(ReferenciaDoc));
         referencia.WriteObject(stream, det);
         string jsonString = Encoding.UTF8.GetString(stream.ToArray());
         stream.Close();
         string json  = jsonString.Replace("null", "\"\"");
         string json0 = json.Replace("{", "{\"FolioDoc\":" + documento.Folio + ", \"TipoDoc\":" + documento.TipoDTE + ",");
         if (det.TpoDocRef == "SET")
         {
             json0 = json0.Replace("\"TpoDocRef\":\"SET\"", "\"TpoDocRef\\r\\n\":\"1000\"");
         }
         if (det.TpoDocRef == "1000")
         {
             json0 = json0.Replace("\"TpoDocRef\":\"1000\"", "\"TpoDocRef\\r\\n\":\"1000\"");
         }
         try
         {
             BaseDato       con      = new BaseDato();
             OdbcConnection conexion = con.ConnectPostgres();
             OdbcCommand    select   = new OdbcCommand();
             select.Connection  = conexion;
             select.CommandText = "INSERT INTO referencia SELECT * FROM json_populate_record(NULL::referencia,'" + json0 + "')";
             OdbcDataReader reader = select.ExecuteReader();
         }
         catch (Exception ex)
         {
             throw new Exception("Error" + ex.Message);
         }
     }
 }
Exemple #5
0
        public DataTable getVentasXFecha(string desde, string hasta)

        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = " SELECT * "
                                     + " FROM documento,tipodte "
                                     + " where documento.\"fchcreate\" between '" + desde + " 00:00:00' and '" + hasta + " 23:59:00'"
                                     + " and documento.\"TipoDTE\" in ('33','61','56')"
                                     + " and documento.\"TipoDTE\" = tipodte.tipo order by fchcreate DESC ";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
Exemple #6
0
        public void save(DocumentoModel documento)
        {
            foreach (Detalle det in documento.detalle)
            {
                MemoryStream stream = new MemoryStream();
                DataContractJsonSerializer detalle = new DataContractJsonSerializer(typeof(Detalle));
                detalle.WriteObject(stream, det);
                string jsonString = Encoding.UTF8.GetString(stream.ToArray());
                stream.Close();
                string json = jsonString.Replace("null", "\"\"");
                json = jsonString.Replace("{", "{\"FolioDoc\":" + documento.Folio + ", \"TipoDoc\":" + documento.TipoDTE + ",");

                try
                {
                    BaseDato       con      = new BaseDato();
                    OdbcConnection conexion = con.ConnectPostgres();
                    OdbcCommand    select   = new OdbcCommand();
                    select.Connection  = conexion;
                    select.CommandText = "INSERT INTO detalle SELECT * FROM json_populate_record(NULL::detalle,'" + json + "')";
                    OdbcDataReader reader = select.ExecuteReader();
                }
                catch (Exception ex)
                {
                    throw new Exception("Error" + ex.Message);
                }
            }
        }
Exemple #7
0
        public DocumentoModel getDocumento(int tipo, int folio)
        {
            DocumentoModel documentoModel = new DocumentoModel();
            string         documento      = string.Empty;

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select row_to_json(documento) from documento where \"Folio\" = " + folio + " and \"TipoDTE\" = '" + tipo + "';";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    documento = reader.GetString(reader.GetOrdinal("row_to_json"));
                }

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(DocumentoModel));
                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(documento));
                documentoModel            = (DocumentoModel)js.ReadObject(ms);
                documentoModel.detalle    = new Detalle().getDetalle(tipo, folio);
                documentoModel.Referencia = new ReferenciaDoc().getReferencia(tipo, folio);
                return(documentoModel);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
Exemple #8
0
        public DataTable getAllDocDTxFecha(string desde, string hasta)

        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = " SELECT \"nombre\",\"TipoDTE\",\"Folio\",\"FchEmis\",\"RznSocRecep\",\"MntTotal\""
                                     + " FROM documento,tipodte "
                                     + " where documento.\"fchcreate\" between '" + desde + " 00:00:00' and '" + hasta + " 23:59:00'"
                                     + " and documento.\"TipoDTE\" = tipodte.tipo order by fchcreate DESC LIMIT 50";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
Exemple #9
0
        public void save(DocumentoModel documento)
        {
            MemoryStream stream           = new MemoryStream();
            DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(DocumentoModel));

            ds.WriteObject(stream, documento);
            string jsonString = Encoding.UTF8.GetString(stream.ToArray());

            stream.Close();
            string json = jsonString.Replace("null", "\"\"");

            json = jsonString.Replace("{", "{\"fchcreate\":\"" + DateTime.Now.ToString() + "\",");
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "INSERT INTO documento SELECT * FROM json_populate_record(NULL::documento,'" + json + "')";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
        public String getNombre(String codDte)
        {
            String        nombre = String.Empty;
            SqlConnection sqlcon = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM tipodte where tipo = '" + codDte + "';";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    nombre = reader.GetString(reader.GetOrdinal("nombre"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(nombre);
        }
        public DataTable getTipoDte()
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM tipodte where tipo in('35','33','34','52','61','801','802','1000','46') order by nombre";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
        public int getUltimoFolioCaf(int idCaf, int tipoDte)
        {
            int ultimo = 0;

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM caf where id = " + idCaf + " and  \"tipoDte\" = '" + tipoDte + "';";
                OdbcDataReader reader = select.ExecuteReader();
                if (reader.RecordsAffected != 0)
                {
                    while (reader.Read())
                    {
                        ultimo = reader.GetInt32(reader.GetOrdinal("folioFinal"));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
            return(ultimo + 1);
        }
Exemple #13
0
        public string validaUser(string usuario, string clave)
        {
            string        respuesta = "true";
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select * from usuario "
                                     + "where \"usuario\" = '" + usuario + "' and \"password\" = '" + clave + "'";
                OdbcDataReader reader = select.ExecuteReader();
                if (reader.HasRows == false)
                {
                    respuesta = "false";
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }


            return(respuesta);
        }
        public void updateCiudad(Int32 codPais, String nomCiudad, Int32 codCiudad)
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "UPDATE ciudades "
                                     + "SET \"codPais\"='" + codPais + "',"
                                     + "\"nomCiudad\"='" + nomCiudad + "'"
                                     + "WHERE \"codCiudad\" = " + codCiudad + ";";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }
        }
Exemple #15
0
        public Int32 getUltimoFolioPedido()
        {
            Int32         ultimoFolio = 0;
            SqlConnection sqlcon      = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select MAX(\"Folio\") from documento where \"TipoDTE\" = '802'";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    ultimoFolio = Convert.ToInt32(reader.GetValue(0));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
            finally
            {
                sqlcon.Close();
            }

            ultimoFolio = ultimoFolio + 1;
            return(ultimoFolio);

            //select min(folio) from folio where estado = 'DISPONIBLE'
            //cambiar a estado a ocupado
            // validar con try catch
        }
Exemple #16
0
        public void save(FolioModel foliomodel)


        {
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "INSERT INTO folio("
                                     + "folio, estado, idcaf, \"codSucSii\")"
                                     + " VALUES ("
                                     + foliomodel.folio + ",'"
                                     + "DISPONIBLE" + "',"
                                     + foliomodel.idcaf + ",'"
                                     + foliomodel.codSucSii + "'"
                                     + ");";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
Exemple #17
0
        public Int32 getUltimoFolio(Int32 idCaf)
        {
            Int32         ultimoFolio = 0;
            SqlConnection sqlcon      = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();
                OdbcCommand    select   = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select min(folio) from folio where estado = 'DISPONIBLE' and idcaf = " + idCaf + ";";
                OdbcDataReader reader = select.ExecuteReader();
                //no quedan folios no recorrer
                while (reader.Read())
                {
                    ultimoFolio = Convert.ToInt32(reader.GetValue(0));
                }
                // modificaEstado("OCUPADO", ultimoFolio,idCaf);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
            finally
            {
                sqlcon.Close();
            }

            return(ultimoFolio);
            //select min(folio) from folio where estado = 'DISPONIBLE'
            //cambiar a estado a ocupado
            // validar con try catch
        }
        public DataTable getProdXCod(String codProd)
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM producto where \"codigoInt\" = '" + codProd + "'";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
Exemple #19
0
        public DataTable getFolioXId(Int32 id)
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM folio where idcaf = " + id + " order by folio ASC";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
 public void save(ProductosModel producto)
 {
     try
     {
         BaseDato       con      = new BaseDato();
         OdbcConnection conexion = con.ConnectPostgres();
         OdbcCommand    select   = new OdbcCommand();
         select.Connection  = conexion;
         select.CommandText =
             "INSERT INTO producto("
             // +"id, "
             + "nombre, "
             + "\"codigoInt\", "
             + "unmditem, "
             + "\"precioNeto\", "
             + "\"precioVenta\","
             + "\"exento\""
             //+"codimpuesto "
             + ") VALUES ('"
             //+ producto.id +",'"//"id, "
             + producto.nombre + "','"              //"nombre, "
             + producto.codigoInt + "','"           //"\"codigoInt\", "
             + producto.unmditem + "',"             //"unmditem, "
             + producto.precioNeto + ","            //"\"precioNeto\", "
             + producto.precioventa + ",'"          //"\"precioVenta\", "
             + producto.exento + "'"                //"\"precioVenta\", "
             // + "codimpuesto "
             + ");";
         OdbcDataReader reader = select.ExecuteReader();
     }
     catch (Exception ex)
     {
         throw new Exception("Error" + ex.Message);
     }
 }
        public void update(ProductosModel producto)
        {
            SqlConnection sqlcon = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "UPDATE producto SET "
                                     + "\"nombre\"='" + producto.nombre + "',"
                                     + "\"codigoInt\"='" + producto.codigoInt + "',"
                                     + "\"unmditem\"='" + producto.unmditem + "',"
                                     + "\"precioNeto\"=" + producto.precioNeto + ","
                                     + "\"precioVenta\"=" + producto.precioventa + ","
                                     + "\"exento\"='" + producto.exento + "'"
                                     + "WHERE \"id\" = " + producto.id + ";";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }
        }
        public DataTable getProdClientXNom(string rut, string nomProd)
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select producto.\"id\",producto.nombre,producto.\"codigoInt\", "
                                     + "clienteproducto.\"precioNeto\",clienteproducto.\"precioVenta\", "
                                     + "producto.codimpuesto,producto.exento "
                                     + "from   clienteproducto,producto,cliente "
                                     + "where  clienteproducto.\"idProducto\" = producto.\"id\" "
                                     + "and    clienteproducto.\"rutCliente\" = cliente.\"rutRecep\" "
                                     + "and    clienteproducto.\"rutCliente\" = '" + rut + "'"
                                     + "and    producto.\"nombre\" LIKE '%" + nomProd + "%'";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }
            return(datatable);
        }
        public string searchProdxCliente(Int32 codProd, string rutCliente)
        {
            string        respuesta = "true";
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "select * from clienteproducto "
                                     + "where \"idProducto\" = " + codProd + " and \"rutCliente\" = '" + rutCliente + "'";
                OdbcDataReader reader = select.ExecuteReader();
                if (reader.HasRows == false)
                {
                    respuesta = "false";
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }


            return(respuesta);
        }
        public void save(ClienteProductoModel cliProdModel)
        {
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText =
                    "INSERT INTO clienteproducto("
                    + "\"idProducto\", \"rutCliente\", \"precioNeto\", \"precioVenta\")"
                    + " VALUES ("
                    + cliProdModel.idProducto + ",'"
                    + cliProdModel.rutCliente + "',"
                    + cliProdModel.precioNeto + ","
                    + cliProdModel.precioVenta + ");";

                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
        public DataTable getCiudadXNombre(String nomCiudad)
        {
            DataTable     datatable = new DataTable();
            SqlConnection sqlcon    = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM ciudades where \"nomCiudad\" Like '%" + nomCiudad + "%'";
                OdbcDataReader reader = select.ExecuteReader();
                datatable.Load(reader);
            }
            catch (Exception ex)
            {
                datatable = null;
                throw new Exception("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(datatable);
        }
        public EmpresaModel getEmpresa()
        {
            SqlConnection sqlcon = new SqlConnection();

            try
            {
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "SELECT * FROM empresa ";
                OdbcDataReader reader = select.ExecuteReader();
                while (reader.Read())
                {
                    Rut               = reader.GetString(reader.GetOrdinal("rutempresa"));
                    RazonSocial       = reader.GetString(reader.GetOrdinal("razonsocial"));
                    GiroEmisor        = reader.GetString(reader.GetOrdinal("giroemisor"));
                    CodigoSiiSucursal = reader.GetInt32(reader.GetOrdinal("codigosiisucursal"));
                    Telefono          = reader.GetString(reader.GetOrdinal("telefonoemis"));
                    Correo            = reader.GetString(reader.GetOrdinal("correoemis"));
                    Acteco            = reader.GetInt32(reader.GetOrdinal("acteco"));
                    DireccionOrigen   = reader.GetString(reader.GetOrdinal("direccionorigen"));
                    ComunaOrigen      = reader.GetString(reader.GetOrdinal("comunaorigen"));
                    CiudadOrigen      = reader.GetString(reader.GetOrdinal("ciudadorigen"));
                    DirRegionalSII    = reader.GetString(reader.GetOrdinal("dirregionalsii"));
                    sucurEmisor       = reader.GetString(reader.GetOrdinal("sucuremisor"));
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error en la tabal empresa postgres" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }

            return(this);
        }
        public void delete(Int32 codCiudad)
        {
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "DELETE FROM ciudades "
                                     + " WHERE \"codCiudad\" = " + codCiudad + ";";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
        public int getCafActual(int tipoDte)
        {
            string         idUltimoCaf = string.Empty;
            BaseDato       con         = new BaseDato();
            OdbcConnection conexion    = con.ConnectPostgres();

            OdbcCommand select = new OdbcCommand();

            select.Connection  = conexion;
            select.CommandText = "SELECT max(id) FROM caf where \"tipoDte\" =  '" + tipoDte + "';";
            OdbcDataReader reader = select.ExecuteReader();

            while (reader.Read())
            {
                idUltimoCaf = reader.GetString(reader.GetOrdinal("max"));
            }
            return(Convert.ToInt32(idUltimoCaf));
        }
        public void save(String nomPais)
        {
            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();
                select.Connection  = conexion;
                select.CommandText = "INSERT INTO paises("
                                     + "\"nomPais\")"
                                     + "VALUES ('" + nomPais + "');";
                OdbcDataReader reader = select.ExecuteReader();
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex.Message);
            }
        }
        public void save(ContribuyenteModel cm)
        {
            SqlConnection sqlcon = new SqlConnection();

            try
            {
                BaseDato       con      = new BaseDato();
                OdbcConnection conexion = con.ConnectPostgres();

                OdbcCommand select = new OdbcCommand();

                select.Connection  = conexion;
                select.CommandText = "INSERT INTO cliente("
                                     + "\"rutRecep\","
                                     + "\"rznSocRecep\","
                                     + "\"giroRecep\","
                                     + "\"dirRecep\","
                                     + "\"codCmnaRecep\","
                                     + "\"codCiudadRecep\","
                                     + "\"telefono\""
                                     + ") VALUES ('"
                                     + cm.rut + "','"
                                     + cm.rznSoc + "','"
                                     + cm.giro + "','"
                                     + cm.direccion + "',"
                                     + cm.codComuna + ","
                                     + cm.codCiudad + ",'"
                                     + cm.telefono + "');";

                OdbcDataReader reader = select.ExecuteReader();
            }

            catch (Exception ex)
            {
                Console.WriteLine("Error" + ex.Message);
            }

            finally
            {
                sqlcon.Close();
            }
        }