//te devuelve los datos de la tabla webcommands, imprescindible para trabajar!!
        public List <Dictionary <string, object> > GetWebCommands()
        {
            string sql = "SELECT commandname, commandparameters, tablename, uidtablename, sqlcommand FROM webcommands WHERE active = ? ORDER BY ordercommand ASC";

            Dictionary <string, object> parameters = new Dictionary <string, object>
            {
                { "active", 1 }
            };

            Dictionary <string, OdbcType> types = new Dictionary <string, OdbcType>
            {
                { "active", OdbcType.Int }
            };

            OdbcCommand commandOdbc = new OdbcCommand(sql, Infx.Database.Connection);

            DatabaseTools.InsertParameters(parameters, types, commandOdbc);
            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            try
            {
                Infx.Database.Connection.Open();
                result = Infx.ExecuteSelectCommand(commandOdbc);
                Infx.Database.Connection.Close();
            }
            catch (MyOdbcException e)
            {
                if (Infx.Database.Connection.State == System.Data.ConnectionState.Open)
                {
                    Infx.Database.Connection.Close();
                }
                ErrorDBLog.Write(e.Message);
            }
            return(result);
        }
Example #2
0
 public InformixOdbcDao(string rutaIniFile, string section)
 {
     try
     {
         if (Database == null)
         {
             Database = new InformixOdbcDatabase(DatabaseTools.GetConnectionString(rutaIniFile, section));
         }
     }
     catch (Exception e)
     {
         ErrorDBLog.Write(e.Message);
         Database = null;
     }
 }
 public InformixOdbcDao()
 {
     try
     {
         if (Database == null)
         {
             Database = new InformixOdbcDatabase(DatabaseTools.GetConnectionString("[OdbcInformixServer]"));
         }
     }
     catch (Exception e)
     {
         ErrorDBLog.Write(e.Message);
         Database = null;
     }
 }
        /// <summary>
        /// Actualiza el GUID de una fila en una tabla, comprovado con webusers y webaccessgroup
        /// </summary>
        /// <param name="controller"></param>
        /// <param name="row"></param>
        /// <param name="uid"></param>
        /// <param name="campoCodeId"></param>
        /// <returns>Devuelve le numero de filas actualizadas en la base de  datos</returns>
        public int UpdateTableForGUID(WebCommandsController controller, Dictionary <string, object> row, string uid, string campoCodeId)
        {
            string sql = "UPDATE " + controller.TableName + " SET " + controller.UidTableName + " = ? WHERE " + campoCodeId + " = ?;";

            Dictionary <string, object> parameters = new Dictionary <string, object>
            {
                { controller.UidTableName, uid },
                { campoCodeId, row.GetValueOrDefault(campoCodeId).ToString() }
            };

            Dictionary <string, OdbcType> types = new Dictionary <string, OdbcType>
            {
                { controller.UidTableName, OdbcType.VarChar },
                { campoCodeId, OdbcType.VarChar }
            };

            OdbcCommand commandOdbc = new OdbcCommand(sql, Infx.Database.Connection);

            DatabaseTools.InsertParameters(parameters, types, commandOdbc);

            int updateadas = 0;

            try
            {
                Infx.Database.Connection.Open();

                updateadas = commandOdbc.ExecuteNonQuery();

                Infx.Database.Connection.Close();
            }
            catch (MyOdbcException e)
            {
                if (Infx.Database.Connection.State == System.Data.ConnectionState.Open)
                {
                    Infx.Database.Connection.Close();
                }
                ErrorDBLog.Write(e.Message);
            }

            return(updateadas);
        }
        //devuelve los datos de la consulta sql de la tabla webcommands
        public List <Dictionary <string, object> > GetRowData(string sql)
        {
            OdbcCommand commandOdbc = new OdbcCommand(sql, Infx.Database.Connection);

            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            try
            {
                Infx.Database.Connection.Open();
                result = Infx.ExecuteSelectCommand(commandOdbc);
                Infx.Database.Connection.Close();
            }
            catch (Exception e)
            {
                if (Infx.Database.Connection.State == System.Data.ConnectionState.Open)
                {
                    Infx.Database.Connection.Close();
                }
                ErrorDBLog.Write(e.Message);
            }
            return(result);
        }
        public async Task ExecuteCommitCommit(Event eventReceived)
        {
            WebEventsController controller = WebEventsController.Singelton(eventReceived.GetType().Name);

            int updateadas = 0;

            if (controller != null)
            {
                //datos de la select inicial
                string sqlS = "SELECT eventcommit, changevalue FROM " + controller.TableName + " WHERE " + controller.UidName + " = ?";

                Dictionary <string, object> whereDataS = new Dictionary <string, object>()
                {
                    { controller.UidName, eventReceived.AggregateId }
                };

                Dictionary <string, OdbcType> whereTypeS = new Dictionary <string, OdbcType>()
                {
                    { controller.UidName, OdbcType.VarChar }
                };

                OdbcCommand selectCommand = new OdbcCommand(sqlS);
                DatabaseTools.InsertParameters(whereDataS, whereTypeS, selectCommand);

                //datos de la update
                string sqlU = "UPDATE " + controller.TableName + " SET eventcommit = ?, changevalue = ? WHERE " + controller.UidName + " = ?";

                Dictionary <string, OdbcType> typeU = new Dictionary <string, OdbcType>()
                {
                    { "eventcommit", OdbcType.Int },
                    { "changevalue", OdbcType.Int },
                    { controller.UidName, OdbcType.VarChar }
                };

                OdbcCommand updateCommand = new OdbcCommand(sqlU);

                OdbcTransaction transaction = null;

                try
                {
                    Infx.Database.Connection.Open();
                    transaction = Infx.Database.Connection.BeginTransaction();

                    selectCommand.Transaction = transaction;

                    List <Dictionary <string, object> > result = Infx.ExecuteSelectCommandWithTransaction(selectCommand, transaction);

                    if (result.Count == 1)
                    {
                        Dictionary <string, object> dataU = new Dictionary <string, object>()
                        {
                            { "eventcommit", ((int)(result.ToArray()[0].GetValueOrDefault("eventcommit")) + 1) },
                            { "changevalue", ((int)(result.ToArray()[0].GetValueOrDefault("changevalue")) - 1) },
                            { controller.UidName, eventReceived.AggregateId }
                        };

                        DatabaseTools.InsertParameters(dataU, typeU, updateCommand);

                        updateCommand.Transaction = transaction;

                        updateadas = Infx.ExecuteUpdateCommandWithTransaction(updateCommand, transaction);

                        transaction.Commit();
                    }
                    else
                    {
                        transaction.Rollback();
                    }
                }
                catch (MyOdbcException e)
                {
                    if (transaction != null)
                    {
                        transaction.Rollback();
                    }
                    ErrorDBLog.Write(e.Message);
                }
                finally
                {
                    if (Infx.Database.Connection.State == System.Data.ConnectionState.Open)
                    {
                        Infx.Database.Connection.Close();
                    }
                }
            }
            else
            {
                throw new MyNoImplementedException("No se ha encontrado ningun controlador para el evento " + eventReceived.GetType().Name);
            }

            await Task.CompletedTask;
        }