public clsEntityDatabaseWeb cs_fxObtenerUnoPorDeclaranteId(string cs_pr_Declarant_Id)
        {
            SQLiteDataReader     datos = null;
            clsEntityDatabaseWeb WEB   = null;

            try
            {
                string           sql = "SELECT * FROM " + cs_cmTabla + " WHERE cp9 ='" + cs_pr_Declarant_Id.Trim() + "';";
                SQLiteConnection cs_pxConexion_basedatos = new SQLiteConnection(clsBaseConexionSistema.conexionstring);
                cs_pxConexion_basedatos.Open();
                datos = new SQLiteCommand(sql, cs_pxConexion_basedatos).ExecuteReader();
                while (datos.Read())
                {
                    WEB = new clsEntityDatabaseWeb();
                    WEB.Cs_pr_DatabaseWeb_Id = datos[0].ToString();
                    WEB.Cs_pr_DBMS           = datos[1].ToString();
                    WEB.Cs_pr_DBMSDriver     = datos[2].ToString();
                    WEB.Cs_pr_DBMSServername = datos[3].ToString();
                    WEB.Cs_pr_DBMSServerport = datos[4].ToString();;
                    WEB.Cs_pr_DBName         = datos[5].ToString();;
                    WEB.Cs_pr_DBUser         = datos[6].ToString();
                    WEB.Cs_pr_DBPassword     = datos[7].ToString();
                    WEB.Cs_pr_DBUse          = datos[8].ToString();
                    WEB.Cs_pr_Declarant_Id   = datos[9].ToString();
                }
                cs_pxConexion_basedatos.Close();
            }
            catch (Exception ex)
            {
                clsBaseLog.cs_pxRegistarAdd(" cs_fxObtenerUnoPorDeclaranteId " + ex.ToString());
            }

            return(WEB);
        }
        private bool cs_pxInsertarEnWeb(string tabla, List <string> campos, List <string> valores, bool obtener_mensaje_respuesta, string Id_InformacionBD)
        {
            bool retorno = false;

            try
            {
                clsEntityDatabaseWeb bd  = new clsEntityDatabaseWeb().cs_fxObtenerUnoPorId(Id_InformacionBD);
                string cadena_base_datos = "";
                switch (bd.Cs_pr_DBMS)
                {
                case "MySQL":

                    cadena_base_datos = "DRIVER={" + bd.Cs_pr_DBMSDriver + "};SERVER=" + bd.Cs_pr_DBMSServername + ";PORT=" + bd.Cs_pr_DBMSServerport + ";Database=" + bd.Cs_pr_DBName + ";USER="******";PASSWORD="******";OPTION=3;";
                    break;

                case "Microsoft SQL Server":

                    cadena_base_datos = "Driver={" + bd.Cs_pr_DBMSDriver + "};Server=" + bd.Cs_pr_DBMSServername + "," + bd.Cs_pr_DBMSServerport + ";Database=" + bd.Cs_pr_DBName + ";Uid=" + bd.Cs_pr_DBUser + ";Pwd=" + bd.Cs_pr_DBPassword + ";";
                    break;
                }

                // OdbcConnection cn_web = new OdbcConnection(cadena_base_datos);

                OdbcConnection cs_cmConexion = new OdbcConnection(cadena_base_datos);
                string         sql = "", sql_campos = "", sql_valores = "";
                for (int i = 1; i < campos.Count; i++)
                {
                    sql_campos  += " " + campos[i] + ",";
                    sql_valores += " '" + valores[i] + "',";
                }
                sql = "INSERT INTO " + tabla + " (" + sql_campos.Substring(1, sql_campos.Length - 2) + ") VALUES (" + sql_valores.Substring(1, sql_valores.Length - 2) + ");";

                cs_cmConexion.Open();
                new OdbcCommand(sql, cs_cmConexion).ExecuteReader();
                cs_cmConexion.Close();
                if (obtener_mensaje_respuesta)
                {
                    clsBaseMensaje.cs_pxMsgOk("OKE5");
                }
                retorno = true;
            }
            catch (Exception ex)
            {
                retorno = false;
                //clsBaseLog.cs_pxRegistar(ex.ToString());
                clsBaseLog.cs_pxRegistarAdd(" cs_pxInsertarEnWeb " + tabla + " " + ex.ToString());
                //clsBaseMensaje.cs_pxMsgEr("ERR5", ex.ToString());
            }
            return(retorno);
        }
        private void cs_pxInsertarRegistrosEnWeb(string Id, string Id_InformacionBD, clsEntityDatabaseLocal localBD)
        {
            int  errores       = 0;
            bool inserto_exito = false;

            try
            {
                clsEntityDatabaseWeb bd = new clsEntityDatabaseWeb().cs_fxObtenerUnoPorId(Id_InformacionBD);

                clsEntityDocument anterior_clsEntityDocument = new clsEntityDocument(localBD).cs_fxObtenerUnoPorId(Id);

                //Insertar: clsEntityDocument
                List <string> valores1 = new List <string>();
                foreach (var prop in anterior_clsEntityDocument.GetType().GetProperties())
                {
                    valores1.Add(prop.GetValue(anterior_clsEntityDocument, null).ToString().Replace("'", " "));
                }
                if (bd.Cs_pr_DBMS == "MySQL")
                {
                    inserto_exito = cs_pxInsertarEnWeb(anterior_clsEntityDocument.cs_cmTabla_min, anterior_clsEntityDocument.cs_cmCampos_min, valores1, false, Id_InformacionBD);
                    if (inserto_exito == false)
                    {
                        errores++;
                    }
                }
                else
                {
                    inserto_exito = cs_pxInsertarEnWeb(anterior_clsEntityDocument.cs_cmTabla, anterior_clsEntityDocument.cs_cmCampos, valores1, false, Id_InformacionBD);
                    if (inserto_exito == false)
                    {
                        errores++;
                    }
                }

                if (errores > 0)
                {
                    //clsBaseMensaje.cs_pxMsg("Error envio de documentos a web","Se ha producido un error al intentar enviar documentos a la web.");
                }
            }
            catch (Exception ex)
            {
                //System.Windows.Forms.MessageBox.Show(ex.ToString());
                clsBaseLog.cs_pxRegistarAdd(" cs_pxInsertarRegistrosEnWeb " + ex.ToString());
            }
        }
        public void cs_pxEnviarAWeb(clsEntityDeclarant Empresa)
        {
            try
            {
                clsEntityDatabaseLocal localDB = new clsEntityDatabaseLocal().cs_fxObtenerUnoPorDeclaranteId(Empresa.Cs_pr_Declarant_Id);
                //Seleccionar la configuración web de la empresa.
                clsEntityDatabaseWeb bd = new clsEntityDatabaseWeb().cs_fxObtenerUnoPorDeclaranteId(Empresa.Cs_pr_Declarant_Id);

                List <string> documentos_web;
                //1. Seleccionar todas las cabeceras en la web.
                string cadena_base_datos = "";
                switch (bd.Cs_pr_DBMS)
                {
                case "MySQL":

                    cadena_base_datos = "DRIVER={" + bd.Cs_pr_DBMSDriver + "};SERVER=" + bd.Cs_pr_DBMSServername + ";PORT=" + bd.Cs_pr_DBMSServerport + ";Database=" + bd.Cs_pr_DBName + ";USER="******";PASSWORD="******";OPTION=3;";
                    break;

                case "Microsoft SQL Server":

                    cadena_base_datos = "Driver={" + bd.Cs_pr_DBMSDriver + "};Server=" + bd.Cs_pr_DBMSServername + "," + bd.Cs_pr_DBMSServerport + ";Database=" + bd.Cs_pr_DBName + ";Uid=" + bd.Cs_pr_DBUser + ";Pwd=" + bd.Cs_pr_DBPassword + ";";
                    break;
                }

                OdbcConnection cn_web = new OdbcConnection(cadena_base_datos);
                cn_web.Open();
                documentos_web = new List <string>();
                OdbcDataReader datos       = null;
                DateTime       FechaLimite = DateTime.Today.AddDays(-7);
                string         sql         = "SELECT cp1 FROM cs_Document WHERE (cp3='01' OR cp3='03' OR cp3='07' OR cp3='08') AND cp2>='" + FechaLimite.ToString("yyyy-MM-dd") + "' AND cp27='0';";

                datos = new OdbcCommand(sql, cn_web).ExecuteReader();
                while (datos.Read())
                {
                    documentos_web.Add(datos[0].ToString().Trim());
                }
                cn_web.Close();

                //2. Seleccionar todas las cabeceras en local.
                List <List <string> > documentos_local = new clsEntityDocument(localDB).cs_pxObtenerActualizacionAWeb();
                if (documentos_local != null && documentos_local.Count > 0)
                {
                    //3. Buscar si local existe en la web. Si no existe, insertar.
                    foreach (var item_local in documentos_local)
                    {
                        bool   insertar = true;
                        string Id       = item_local[0].ToString();
                        foreach (var item_web in documentos_web)
                        {
                            if (item_local[1].ToString().Equals(item_web.ToString()))
                            {
                                insertar = false;
                            }
                        }
                        if (insertar == true)
                        {
                            cs_pxInsertarRegistrosEnWeb(Id, bd.Cs_pr_DatabaseWeb_Id, localDB);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                clsBaseLog.cs_pxRegistarAdd(" cs_pxEnviarAWeb " + ex.Message);
            }
        }
示例#5
0
        public void cs_pxInsertarACuenta(bool obtener_mensaje_respuesta)
        {
            cs_pxActualizarEntidad();
            new clsBaseConexionSistema().cs_pxInsertar(cs_cmTabla, cs_cmCampos, cs_cmValores, obtener_mensaje_respuesta);

            clsEntityAccount account = new clsEntityAccount
            {
                Cs_pr_Account_Id   = Guid.NewGuid().ToString(),
                Cs_pr_Declarant_Id = Cs_pr_Declarant_Id,
                Cs_pr_Users_Id     = "01"
            };

            account.cs_pxInsertar(false);

            clsEntityDatabaseLocal bdlocal = new clsEntityDatabaseLocal
            {
                Cs_pr_DatabaseLocal_Id = Guid.NewGuid().ToString(),
                Cs_pr_DBMS             = "Microsoft SQL Server",
                Cs_pr_DBMSDriver       = "SQL Server",
                Cs_pr_DBMSServername   = "SERVERNAME_REGISTERS",
                Cs_pr_DBMSServerport   = "1433",
                Cs_pr_DBName           = "cs_bdfei",
                Cs_pr_DBPassword       = "******",
                Cs_pr_DBUse            = "T",
                Cs_pr_DBUser           = "******",
                Cs_pr_Declarant_Id     = Cs_pr_Declarant_Id
            };

            bdlocal.cs_pxInsertar(false);

            clsEntityDatabaseWeb bdweb = new clsEntityDatabaseWeb
            {
                Cs_pr_DatabaseWeb_Id = Guid.NewGuid().ToString(),
                Cs_pr_DBMS           = "Microsoft SQL Server",
                Cs_pr_DBMSDriver     = "SQL Server",
                Cs_pr_DBMSServername = "SERVERNAME_WEBPUBLICATION",
                Cs_pr_DBMSServerport = "1433",
                Cs_pr_DBName         = "cs_bdfei_web",
                Cs_pr_DBPassword     = "******",
                Cs_pr_DBUse          = "T",
                Cs_pr_DBUser         = "******",
                Cs_pr_Declarant_Id   = Cs_pr_Declarant_Id
            };

            bdweb.cs_pxInsertar(false);

            clsEntityAlarms alarms = new clsEntityAlarms
            {
                Cs_pr_Alarms_Id                             = Guid.NewGuid().ToString(),
                Cs_pr_Declarant_Id                          = Cs_pr_Declarant_Id,
                Cs_pr_Envioautomatico                       = "T",
                Cs_pr_Envioautomatico_hora                  = "T",
                Cs_pr_Envioautomatico_horavalor             = DateTime.Now.ToString(),
                Cs_pr_Envioautomatico_minutos               = "F",
                Cs_pr_Envioautomatico_minutosvalor          = "6",
                Cs_pr_Enviomanual                           = "F",
                Cs_pr_Enviomanual_mostrarglobo              = "F",
                Cs_pr_Enviomanual_mostrarglobo_minutosvalor = "10",
                Cs_pr_Enviomanual_nomostrarglobo            = "T",
                Cs_pr_Iniciarconwindows                     = "F"
            };

            alarms.cs_pxInsertar(false);
        }