Esempio n. 1
0
        public static Movimiento Traer(Int32 movimiento)
        {
            OdbcConnection  conexion    = new OdbcConnection(NegocioBase.getConnectionString());
            OdbcDataAdapter dataAdapter = new OdbcDataAdapter("", conexion);

            dataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

            OdbcParameter parametro = new OdbcParameter();

            parametro.Direction = ParameterDirection.Input;

            dataAdapter.SelectCommand.CommandText = "call SP_TraerMovimiento(?)";
            parametro.ParameterName = "pMovimiento";
            parametro.Value         = movimiento;
            parametro.OdbcType      = OdbcType.VarChar;
            parametro.Size          = 50;
            dataAdapter.SelectCommand.Parameters.Add(parametro);

            Movimiento Movimiento = new Movimiento();

            try
            {
                conexion.Open();
                OdbcDataReader drMovimientos = dataAdapter.SelectCommand.ExecuteReader();

                Movimiento tmp = new Movimiento();
                while (drMovimientos.Read())
                {
                    tmp.idExpediente     = drMovimientos.GetInt32(0);
                    tmp.idMovimiento     = drMovimientos.GetByte(1);
                    tmp.idTipoMovimiento = drMovimientos.GetByte(2);
                    tmp.fechaMovimiento  = drMovimientos.GetDateTime(3);
                    tmp.idPersona        = drMovimientos.GetByte(4);
                    tmp.comentario       = drMovimientos.GetString(5);
                    tmp.realizado        = drMovimientos.GetByte(6);
                }
                return(tmp);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
                //listaExpediente.Clear();
            }
        }
Esempio n. 2
0
        public List <Category> Read_all()
        {
            List <Category> categories = new List <Category>();

            try
            {
                Database.Connect();
                command = new OdbcCommand()
                {
                    Connection  = Database.GetConn(),
                    CommandType = System.Data.CommandType.StoredProcedure,
                    CommandText = "{call csg.Category_Read_all}"
                };
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Category category = new Category()
                    {
                        Category_id   = dataReader.GetByte(0),
                        Category_name = dataReader.GetString(1)
                    };
                    categories.Add(category);
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Database.Disconnect();
            }
            return(categories);
        }
Esempio n. 3
0
        public void GetByteTest()
        {
            OdbcDataReader reader = null;

            try {
                // For this Test, you must create sample table
                // called test, with a column of name 'col_int'.
                // and the table with atleast a row with a minimum value for col_int as 0xff
                // This tries to read a int column using GetByte method
                OdbcCommand cmd   = conn.CreateCommand();
                string      query = "select col_int from test order by col_int;";
                cmd.CommandText = query;
                reader          = cmd.ExecuteReader();
                if (reader.Read())
                {
                    byte b = reader.GetByte(0);
                    Assert.AreEqual(0xff, b, "GetByte returns wrong result!");
                }
                else           // This should not happen while testing
                {
                    Assert.AreEqual(true, true, "test table doens not have a test data!");
                }
            } finally {         // try/catch is necessary to gracefully close connections
                if (reader != null && reader.IsClosed)
                {
                    reader.Close();
                }
                CleanTestSetup();
                CloseConnection();
            }
        }
Esempio n. 4
0
        public static List <ExpedienteMVL> Listar(Int32 expediente)
        {
            OdbcConnection conexion = new OdbcConnection(NegocioBase.getConnectionString());

            OdbcParameter parametro = new OdbcParameter();

            parametro.ParameterName = "_idExpediente";
            parametro.Value         = expediente;
            parametro.OdbcType      = OdbcType.Int;
            OdbcDataAdapter dataAdapter = new OdbcDataAdapter("Call SP_TraerExpedientesMVL(?)", conexion);

            dataAdapter.SelectCommand.Parameters.Add(parametro);
            conexion.Open();

            List <ExpedienteMVL> listaExpedienteMVL = new List <ExpedienteMVL>();

            try
            {
                OdbcDataReader drExpedienteMVL = dataAdapter.SelectCommand.ExecuteReader();
                while (drExpedienteMVL.Read())
                {
                    ExpedienteMVL tmp = new ExpedienteMVL();
                    tmp.idExpediente           = drExpedienteMVL.GetInt32(0);
                    tmp.idMovimiento           = drExpedienteMVL.GetByte(1);
                    tmp.idMovimientoRecepcion  = drExpedienteMVL.GetByte(2);
                    tmp.idMovimientoDevolucion = drExpedienteMVL.GetByte(3);
                    tmp.codigoExpedienteMVL    = drExpedienteMVL.GetString(4);
                    tmp.numeroExpedienteMVL    = drExpedienteMVL.GetString(5);
                    tmp.anioExpediente         = drExpedienteMVL.GetInt16(6);
                    listaExpedienteMVL.Add(tmp);
                }
                return(listaExpedienteMVL);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
            }
        }
Esempio n. 5
0
        public static List <Movimiento> Listar(Int32 expediente)
        {
            OdbcConnection conexion = new OdbcConnection(NegocioBase.getConnectionString());

            OdbcParameter parametro = new OdbcParameter();

            parametro.ParameterName = "idexp";
            parametro.Value         = expediente;
            parametro.OdbcType      = OdbcType.Int;
            OdbcDataAdapter dataAdapter = new OdbcDataAdapter("Call SP_TraerMovimientosPorExpediente(?)", conexion);

            dataAdapter.SelectCommand.Parameters.Add(parametro);
            conexion.Open();

            List <Movimiento> listaMovimientos = new List <Movimiento>();

            try
            {
                OdbcDataReader drMovimientos = dataAdapter.SelectCommand.ExecuteReader();
                while (drMovimientos.Read())
                {
                    Movimiento tmp = new Movimiento();
                    tmp.idExpediente     = drMovimientos.GetInt32(0);
                    tmp.idMovimiento     = drMovimientos.GetByte(1);
                    tmp.idTipoMovimiento = drMovimientos.GetByte(2);
                    tmp.fechaMovimiento  = drMovimientos.GetDateTime(3);
                    tmp.idPersona        = drMovimientos.GetByte(4);
                    tmp.comentario       = drMovimientos.GetString(5);
                    tmp.realizado        = drMovimientos.GetByte(6);
                    listaMovimientos.Add(tmp);
                }
                return(listaMovimientos);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
            }
        }
Esempio n. 6
0
        public static List <DetalleMovimiento> Listar(Int32 expediente)
        {
            OdbcConnection conexion = new OdbcConnection(NegocioBase.getConnectionString());

            OdbcParameter parametro = new OdbcParameter();

            parametro.ParameterName = "idexp";
            parametro.Value         = expediente;
            parametro.OdbcType      = OdbcType.Int;
            OdbcDataAdapter dataAdapter = new OdbcDataAdapter("Call SP_TraerDetalleMovimientosPorExpediente(?)", conexion);

            dataAdapter.SelectCommand.Parameters.Add(parametro);
            conexion.Open();

            List <DetalleMovimiento> listaDetalleMovimientos = new List <DetalleMovimiento>();

            try
            {
                OdbcDataReader drDetalleMovimientos = dataAdapter.SelectCommand.ExecuteReader();
                while (drDetalleMovimientos.Read())
                {
                    DetalleMovimiento tmp = new DetalleMovimiento();
                    tmp.idExpediente     = drDetalleMovimientos.GetInt32(0);
                    tmp.idMovimiento     = drDetalleMovimientos.GetByte(1);
                    tmp.nombreArchivo    = drDetalleMovimientos.GetString(2);
                    tmp.numeroResolucion = drDetalleMovimientos.GetInt16(3);
                    tmp.idDependencia    = drDetalleMovimientos.GetByte(4);
                    listaDetalleMovimientos.Add(tmp);
                }
                return(listaDetalleMovimientos);
            }
            catch
            {
                throw;
            }
            finally
            {
                if (conexion.State == ConnectionState.Open)
                {
                    conexion.Close();
                }
            }
        }
Esempio n. 7
0
        public Cotization Read_once(string id)
        {
            Cotization cotization = new Cotization();

            try
            {
                //Console.WriteLine("Conexion Cotizacion: " + Database.GetConn().State);
                if (!Database.GetConn().State.ToString().Equals("Open"))
                {
                    Database.Connect();
                }
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Cotization_ReadOnce(?)}"
                };
                command.Parameters.Add("Id", OdbcType.VarChar, 50).Value = id;
                dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    cotization = new Cotization
                    {
                        Cotization_id = dataReader.GetString(0),
                        Cotization_generation_date = dataReader.GetDateTime(1),
                        Cotization_expiration_date = dataReader.GetDateTime(2),
                        Cotization_quantity        = dataReader.GetByte(3),
                        Cotization_comentarys      = dataReader.GetString(4),
                        Cotization_subtotal        = dataReader.GetString(5),
                        Cotization_discount        = dataReader.GetString(6),
                        Cotization_iva             = dataReader.GetString(7),
                        Cotization_total           = dataReader.GetString(8)
                    };
                }
                else
                {
                    cotization = null;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en CotizationDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(cotization);
        }
Esempio n. 8
0
        public List <Cotization_refactionFK> Read_RefactionsOfCotization(string cotization_id)
        {
            List <Cotization_refactionFK> cotization_Refactions = new List <Cotization_refactionFK>();

            try
            {
                if (!Database.GetConn().State.ToString().Equals("Open"))
                {
                    Database.Connect();
                }
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Cotization_refactionFK_ReadRefactionsOfCotization(?)}"
                };
                command.Parameters.Add("CotizationId", OdbcType.VarChar, 50).Value = cotization_id;
                //ejecutamos la lectura del DataReader
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Cotization_refactionFK cotization_RefactionFK = new Cotization_refactionFK
                    {
                        Cotization_id      = cotization_id,
                        Refaction_code     = dataReader.GetString(0),
                        Refaction_quantity = dataReader.GetByte(1),
                        Refaction_amount   = dataReader.GetString(2)
                    };
                    //Refaction refaction = refactionDAO.Read_once(dataReader.GetString(0));
                    //cotization_RefactionFK.Refaction = refaction;
                    //cotization_RefactionFK.Refaction_quantity = ushort.Parse(dataReader.GetInt32(1).ToString());
                    //cotization_RefactionFK.Refaction_amount = dataReader.GetDecimal(2);
                    cotization_Refactions.Add(cotization_RefactionFK);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en Cotization_refactionFKDAO->Read_RefactionsOfCotization: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(cotization_Refactions);
        }
Esempio n. 9
0
        public Article Read_once(string code)
        {
            Article article = new Article();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Article_ReadOnce(?)}"
                };
                command.Parameters.Add("Code", OdbcType.VarChar, 50).Value = code;
                dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    article = new Article
                    {
                        Article_code        = dataReader.GetString(0),
                        Article_description = dataReader.GetString(1),
                        Article_warranty    = dataReader.GetInt32(2),
                        Category            = dataReader.GetByte(3)
                    };
                    //agregamos los datos de creación
                    article.Create_by   = dataReader.GetString(4);
                    article.Create_date = dataReader.GetDateTime(5);
                    //Agregamos los campos de actualización
                    article.Update_by   = dataReader.GetString(6);
                    article.Update_date = dataReader.GetDateTime(7);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en ArticleDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(article);
        }
Esempio n. 10
0
        public List <Cotization> Read_all()
        {
            List <Cotization> cotizations = new List <Cotization>();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Cotization_ReadAll}"
                };
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Cotization cotization = new Cotization
                    {
                        Cotization_id = dataReader.GetString(0),
                        Cotization_generation_date = dataReader.GetDateTime(1),
                        Cotization_expiration_date = dataReader.GetDateTime(2),
                        Cotization_quantity        = dataReader.GetByte(3),
                        Cotization_comentarys      = dataReader.GetString(4),
                        Cotization_subtotal        = dataReader.GetString(5),
                        Cotization_discount        = dataReader.GetString(6),
                        Cotization_iva             = dataReader.GetString(7),
                        Cotization_total           = dataReader.GetString(8)
                    };
                    cotizations.Add(cotization);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en CotizationDAO->Read_all: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(cotizations);
        }
Esempio n. 11
0
        public List <Article> Read_all()
        {
            List <Article> articles = new List <Article>();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Article_ReadAll}"
                };
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Article article = new Article
                    {
                        Article_code        = dataReader.GetString(0),
                        Article_description = dataReader.GetString(1),
                        Article_warranty    = dataReader.GetInt32(2),
                        Category            = dataReader.GetByte(3)
                    };
                    //CategoryDAO categoryDAO = new CategoryDAO();
                    //Category category = new Category();
                    //category = categoryDAO.Read_once(dataReader.GetByte(6));
                    //article.Category = category;
                    articles.Add(article);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en ArticleDAO->Read_all: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(articles);
        }
Esempio n. 12
0
        public List <Article> Read_all_like(string search)
        {
            List <Article> articles = new List <Article>();

            try
            {
                Database.Connect();
                command = new OdbcCommand
                {
                    Connection  = Database.GetConn(),
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "{call csg.Article_ReadAllLike(?)}"
                };
                command.Parameters.Add("Search", OdbcType.VarChar, 50).Value = search;
                dataReader = command.ExecuteReader();
                while (dataReader.Read())
                {
                    Article article = new Article
                    {
                        Article_code        = dataReader.GetString(0),
                        Article_description = dataReader.GetString(1),
                        Article_warranty    = dataReader.GetInt32(2),
                        Category            = dataReader.GetByte(3)
                    };
                    articles.Add(article);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en ArticleDAO->Read_all_like: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(articles);
        }
Esempio n. 13
0
        public Category Read_once(byte id)
        {
            Category category = new Category();

            try
            {
                if (!Database.GetConn().State.ToString().Equals("Open"))
                {
                    Database.Connect();
                }
                command = new OdbcCommand()
                {
                    Connection  = Database.GetConn(),
                    CommandType = System.Data.CommandType.StoredProcedure,
                    CommandText = "{call csg.Category_Read_once(?)}"
                };
                command.Parameters.Add("Id", OdbcType.TinyInt).Value = id;
                dataReader = command.ExecuteReader();
                if (dataReader.Read())
                {
                    category = new Category()
                    {
                        Category_id   = dataReader.GetByte(0),
                        Category_name = dataReader.GetString(1)
                    };
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Excepción controlada en CategoryDAO->Read_once: " + ex.Message, "Excepción", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Database.Disconnect();
            }
            return(category);
        }
Esempio n. 14
0
        public int MySQLquery(string inprefix, string end, short pflen)
        {
            if (this.MySQLconnection == null)
            {
                return(-1);
            }

            if (this.MySQLconnection.State == ConnectionState.Closed)
            {
                MessageBox.Show(StringsDictionary.KeyValue("FormDB_MySQLquery_closed", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_closed_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }

            this.liste.Clear();

            int    r         = 0;
            string MySQLcmd  = "";
            string is128bits = "";

            if (this.chks == CheckState.Unchecked)
            {
                is128bits = " AND pflen > " + pflen + " AND pflen <= 64";
            }
            else if (this.chks == CheckState.Checked)
            {
                is128bits = " AND pflen > " + pflen;
            }

            MySQLcmd = "SELECT inet6_ntoa(prefix), pflen, netname, status "
                       + " from " + this.ServerInfo.Tablename
                       + " WHERE ( prefix BETWEEN inet6_aton('" + inprefix + "') "
                       + " AND inet6_aton('" + end + "') "
                       + is128bits + " AND parentpflen= " + pflen + ") "
                       + " LIMIT 32768; ";

            OdbcCommand MyCommand = new OdbcCommand(MySQLcmd, this.MySQLconnection);

            try
            {
                MyDataReader = MyCommand.ExecuteReader();

                r = MyDataReader.RecordsAffected;
                this.liste.Clear();

                while (MyDataReader.Read())
                {
                    this.liste.Add(new string[] {
                        MyDataReader.GetString(0), MyDataReader.GetByte(1).ToString(),
                        MyDataReader.GetString(2),
                        MyDataReader.GetString(3)
                    }
                                   );
                }

                MyDataReader.Close();
                if (MyDataReader is IDisposable)
                {
                    MyDataReader.Dispose();
                }
                return(r);
            }
            //catch (System.InvalidOperationException ex)
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message +
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }
Esempio n. 15
0
        //The static method reads the serial port configuration from SQL database
        public static byte QueryPortsConfig(ref Attributes.PortConfig[] config)
        {
            try
            {
                using (OdbcConnection connection = new OdbcConnection(connectionString))
                {
                    // Create and ODBC connection
                    connection.Open();

                    // Get number of rows with the serial port settings
                    string queryString = @"SELECT COUNT(*) OVER () AS TotalRecords 
                                           FROM [dbo].[port_config] AS pc
                                           JOIN port_data AS pd ON pc.port_name = pd.port_name
                                           GROUP BY pc.port_name;";

                    byte portCounter = 0;

                    using (OdbcCommand command = new OdbcCommand(queryString, connection))
                    {
                        // Execute the data reader and access the port_config table
                        using (OdbcDataReader reader = command.ExecuteReader(System.Data.CommandBehavior.SingleRow))
                        {
                            if (!reader.HasRows)
                            {
                                // Always call Close and Dispose when done reading
                                reader.Close();
                                command.Dispose();
                                return(0);
                            }

                            reader.Read();

                            portCounter = reader.GetByte(0);
                        }
                    }

                    // Read the COM-port configuration data
                    queryString = @"SELECT DISTINCT pc.[port_name]
	                                        ,pc.[baud_rate]
	                                        ,pc.[data_bits]
	                                        ,pc.[stop_bits]
	                                        ,pc.[parity]
	                                        ,pc.[handshake]
	                                        ,pc.[timeout]
                                    FROM [dbo].[port_config] AS pc 
                                    JOIN port_data AS pd ON pc.port_name = pd.port_name;";

                    string ports = null;

                    using (OdbcCommand command = new OdbcCommand(queryString, connection))
                    {
                        // Execute the data reader and access the port_config table data
                        using (OdbcDataReader reader = command.ExecuteReader())
                        {
                            if (!reader.HasRows || portCounter == 0)
                            {
                                // Always call Close and Dispose when done reading
                                reader.Close();
                                command.Dispose();
                                return(0);
                            }

                            // Reassign a new value to the variable
                            portCounter = 0;

                            while (reader.Read())
                            {
                                config[portCounter].portName    = Convert.ToString(reader["port_name"]);
                                config[portCounter].baudRate    = Convert.ToString(reader["baud_rate"]);
                                config[portCounter].dataBits    = Convert.ToString(reader["data_bits"]);
                                config[portCounter].stopBits    = Convert.ToString(reader["stop_bits"]);
                                config[portCounter].parity      = Convert.ToString(reader["parity"]);
                                config[portCounter].handShaking = Convert.ToString(reader["handshake"]);
                                config[portCounter].timeOut     = Convert.ToString(reader["timeout"]);
                                if (config[portCounter].portData == null)
                                {
                                    config[portCounter].portData = new List <Attributes.PortData> {
                                    }
                                }
                                ;
                                else
                                {
                                    config[portCounter].portData.Clear();
                                }
                                ports += "'" + config[portCounter].portName + "',";
                                portCounter++;
                            }
                        }
                    }

                    //  Read the data to send through the serial port
                    queryString = @"SELECT[id]
                                          ,[port_name]
                                          ,[send_data]
                                        FROM [dbo].[port_data] 
                                        WHERE port_name IN(" + ports.Remove(ports.Length - 1) + ")" +
                                  "GROUP BY port_name, send_data, id ORDER BY id;";


                    using (OdbcCommand command = new OdbcCommand(queryString, connection))
                    {
                        // Execute the data reader and access the data to send
                        using (OdbcDataReader reader = command.ExecuteReader())
                        {
                            if (!reader.HasRows || String.IsNullOrEmpty(ports))
                            {
                                // Always call Close and Dispose when done reading
                                reader.Close();
                                command.Dispose();
                                return(0);
                            }

                            // Add the data to send to the structure
                            while (reader.Read())
                            {
                                for (int i = 0; i < config.Length; i++)
                                {
                                    if (config[i].portName == Convert.ToString(reader["port_name"]))
                                    {
                                        portData.id   = Convert.ToString(reader["id"]);
                                        portData.send = Convert.ToString(reader["send_data"]);
                                        config[i].portData.Add(portData);
                                    }
                                }
                            }
                        }
                    }

                    /* The connection is automatically closed at
                     * the end of the Using block. */
                    return(portCounter);
                }
            }
            catch (OdbcException e)
            {
                Service.log.Error(e);
                return(0);
            }
            catch (Exception e)
            {
                Service.log.Error("The exception occurred while reading the COM-port database configuration : " + e);
                return(0);
            }
        }
        public int MySQLquery(int button)
        {
            if (this.MySQLconnection == null)
            {
                return(-1);
            }

            if (this.MySQLconnection.State == ConnectionState.Closed)
            {
                MessageBox.Show(StringsDictionary.KeyValue("FormDB_MySQLquery_closed", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_closed_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }

            if (this.tmp_last == "")
            {
                this.tmp_last = this.prefix;
            }

            int    r        = 0;
            string MySQLcmd = "";

            this.listBox1.Items.Clear();

            if (button == 1) // // First page
            {
                MySQLcmd = "SELECT "
                           + " INET6_NTOA(prefix), pflen, netname, person, organization, "
                           + "`as-num`, phone, email, status, created, `last-updated` FROM "
                           + this.ServerInfo.Tablename
                           + " WHERE ( prefix >= inet6_aton('" + this.tmp_last + "')"
                           + " AND prefix <= inet6_aton('" + this.end + "')"
                           + " AND parentpflen= " + parentpflen + " AND pflen= " + pflen + " ) "
                           //+ " LIMIT 4 ";
                           + " LIMIT " + this.records_perpage;
            }
            else if (button == 2) // Backwd page
            {
                MySQLcmd = "SELECT "
                           + " INET6_NTOA(prefix), pflen, netname, person, organization, "
                           + "`as-num`, phone, email, status, created, `last-updated` FROM "
                           + this.ServerInfo.Tablename
                           + " WHERE ( prefix < inet6_aton('" + this.tmp_first + "')"
                           + " AND prefix >= inet6_aton('" + this.prefix + "')"
                           + " AND parentpflen= " + parentpflen + " AND pflen= " + pflen + " ) "
                           //+ " ORDER BY prefix LIMIT 4 ";
                           + " ORDER BY prefix DESC LIMIT " + this.records_perpage;
            }
            else if (button == 3) // Fwd page
            {
                MySQLcmd = "SELECT "
                           + " INET6_NTOA(prefix), pflen, netname, person, organization, "
                           + "`as-num`, phone, email, status, created, `last-updated` FROM "
                           + this.ServerInfo.Tablename
                           + " WHERE ( prefix > inet6_aton('" + this.tmp_last + "')"
                           + " AND prefix <= inet6_aton('" + this.end + "')"
                           + " AND parentpflen= " + parentpflen + " AND pflen= " + pflen + " ) "
                           //+ " LIMIT 4 ";
                           + " LIMIT " + this.records_perpage;
            }
            else if (button == 4) // Last page
            {
                MySQLcmd = "SELECT "
                           + " INET6_NTOA(prefix), pflen, netname, person, organization, "
                           + "`as-num`, phone, email, status, created, `last-updated` FROM "
                           + this.ServerInfo.Tablename
                           + " WHERE ( prefix <= inet6_aton('" + this.tmp_first + "')"
                           + " AND parentpflen= " + parentpflen + " AND pflen= " + pflen + " ) "
                           //+ " ORDER BY prefix DESC LIMIT 4 ";
                           + " ORDER BY prefix DESC LIMIT " + this.records_perpage;
            }

            OdbcCommand MyCommand = new OdbcCommand(MySQLcmd, this.MySQLconnection);

            try
            {
                MyDataReader      = MyCommand.ExecuteReader();
                this.page_records = r = MyDataReader.RecordsAffected;

                if (r > 0)
                {
                    liste.Clear();

                    if (button == 1 || button == 3)
                    {
                        while (MyDataReader.Read())
                        {
                            liste.Add("prefix:\t\t " + MyDataReader.GetString(0) + "/" + MyDataReader.GetByte(1).ToString());
                            liste.Add("netname:\t " + MyDataReader.GetString(2));
                            liste.Add("person:\t\t " + MyDataReader.GetString(3));
                            liste.Add("organization:\t " + MyDataReader.GetString(4));
                            liste.Add("as-num:\t\t " + MyDataReader.GetString(5));
                            liste.Add("phone:\t\t " + MyDataReader.GetString(6));
                            liste.Add("email:\t\t " + MyDataReader.GetString(7));
                            liste.Add("status:\t\t " + MyDataReader.GetString(8));
                            liste.Add("created:\t\t " + MyDataReader.GetString(9));
                            liste.Add("last-updated:\t " + MyDataReader.GetString(10));
                            liste.Add("");
                        }
                    }
                    else if (button == 2 || button == 4)
                    {
                        String[] fs = new String[10];
                        while (MyDataReader.Read())
                        {
                            liste.Add("");
                            fs[0] = "prefix:\t\t " + MyDataReader.GetString(0) + "/" + MyDataReader.GetByte(1).ToString();
                            fs[1] = "netname:\t " + MyDataReader.GetString(2);
                            fs[2] = "person:\t\t " + MyDataReader.GetString(3);
                            fs[3] = "organization:\t " + MyDataReader.GetString(4);
                            fs[4] = "as-num:\t\t " + MyDataReader.GetString(5);
                            fs[5] = "phone:\t\t " + MyDataReader.GetString(6);
                            fs[6] = "email:\t\t " + MyDataReader.GetString(7);
                            fs[7] = "status:\t\t " + MyDataReader.GetString(8);
                            fs[8] = "created:\t\t " + MyDataReader.GetString(9);
                            fs[9] = "last-updated:\t " + MyDataReader.GetString(10);

                            for (int i = 9; i > -1; i--)
                            {
                                liste.Add(fs[i]);
                            }
                        }

                        liste.Reverse();
                    }

                    this.listBox1.Items.AddRange(liste.ToArray());
                    this.tmp_first = liste[0].Split(' ')[1].Split('/')[0];
                    this.tmp_last  = liste[liste.Count - 11].Split(' ')[1].Split('/')[0];
                }

                MyDataReader.Close();
                if (MyDataReader is IDisposable)
                {
                    MyDataReader.Dispose();
                }
                return(r);
            }
            //catch (System.InvalidOperationException ex)
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message +
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }
        public int MySQLquery()
        {
            if (this.MySQLconnection == null)
            {
                MessageBox.Show("MySQLconnection = null", "MySQLconnection=null",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }

            if (this.MySQLconnection.State == ConnectionState.Closed)
            {
                MessageBox.Show(StringsDictionary.KeyValue("FormDB_MySQLquery_closed", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_closed_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }

            try
            {
                int    r        = 0;
                string MySQLcmd = "";
                this.listBox1.Items.Clear();

                string spfx1 = "", spfx2 = "", sDBName = "", sTableName = "";

                if (this.MySQLconnection.State != ConnectionState.Open)
                {
                    this.MySQLconnection.Open();
                }

                if (this.currentMode == "v6")
                {
                    this.MySQLconnection.ChangeDatabase(this.ServerInfo.DBname);

                    spfx1 = " inet6_ntoa(prefix)";
                    spfx2 = " inet6_aton('" + this.prefix + "') ";

                    sDBName    = this.ServerInfo.DBname;
                    sTableName = this.ServerInfo.Tablename;

                    if (sDBName == "" || sTableName == "")
                    {
                        return(-1);
                    }
                }
                else // v4
                {
                    this.MySQLconnection.ChangeDatabase(this.ServerInfo.DBname_v4);

                    spfx1 = " inet_ntoa(prefix)";
                    spfx2 = " inet_aton('" + this.prefix + "') ";

                    sDBName    = this.ServerInfo.DBname_v4;
                    sTableName = this.ServerInfo.Tablename_v4;

                    if (sDBName == "" || sTableName == "")
                    {
                        return(-1);
                    }
                }

                MySQLcmd = "SELECT "
                           + spfx1
                           + ", pflen, netname, person, organization, "
                           + "`as-num`, phone, email, status, created, `last-updated` FROM "
                           + "`" + sDBName + "`" + ".`" + sTableName + "`"
                           + " WHERE ( prefix = "
                           + spfx2
                           + " AND pflen = " + this.pflen + " )";

                OdbcCommand MyCommand = new OdbcCommand(MySQLcmd, this.MySQLconnection);
                MyDataReader = MyCommand.ExecuteReader();
                r            = MyDataReader.RecordsAffected;

                if (r > 0)
                {
                    liste.Clear();

                    while (MyDataReader.Read())
                    {
                        liste.Add("prefix:\t\t " + MyDataReader.GetString(0) + "/" + MyDataReader.GetByte(1).ToString());
                        liste.Add("netname:\t " + MyDataReader.GetString(2));
                        liste.Add("person:\t\t " + MyDataReader.GetString(3));
                        liste.Add("organization:\t " + MyDataReader.GetString(4));
                        liste.Add("as-num:\t\t " + MyDataReader.GetString(5));
                        liste.Add("phone:\t\t " + MyDataReader.GetString(6));
                        liste.Add("email:\t\t " + MyDataReader.GetString(7));
                        liste.Add("status:\t\t " + MyDataReader.GetString(8));
                        liste.Add("created:\t\t " + MyDataReader.GetString(9));
                        liste.Add("last-updated:\t " + MyDataReader.GetString(10));
                        liste.Add("");
                    }

                    this.listBox1.Items.AddRange(liste.ToArray());
                }
                else
                {
                    liste.Add(" ");
                    liste.Add(StringsDictionary.KeyValue("Form1_prefixNotFoundinDB.Text", this.culture));
                    this.listBox1.Items.AddRange(liste.ToArray());
                }

                MyDataReader.Close();

                if (MyDataReader is IDisposable)
                {
                    MyDataReader.Dispose();
                }

                return(r);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message +
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }
Esempio n. 18
0
 /// <summary>
 /// Gets the value of the column at the specified index as a byte.
 /// </summary>
 /// <param name="columnIndex">Index of column to examine.</param>
 /// <returns>Value of the column as a byte.</returns>
 public int GetByte(int columnIndex)
 {
     return(_reader.GetByte(columnIndex));
 }
        public int MySQLquery(string[] sa, string MySQLcmd, int btn)
        {
            int         r         = 0;
            OdbcCommand MyCommand = new OdbcCommand(MySQLcmd, this.MySQLconnection);

            try
            {
                if (this.MySQLconnection.State == ConnectionState.Closed)
                {
                    MessageBox.Show(StringsDictionary.KeyValue("FormDB_MySQLquery_closed", this.culture),
                                    StringsDictionary.KeyValue("FormDB_MySQLquery_closed_header", this.culture),
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(-1);
                }

                #region if btn=1
                if (btn == 1)
                {
                    try
                    {
                        r = MyCommand.ExecuteNonQuery();
                        this.toolStripStatusLabel1.Text =
                            StringsDictionary.KeyValue("FormDB_insertrecord", this.culture);
                        return(r);
                    }
                    catch (System.InvalidOperationException ex)
                    {
                        MessageBox.Show(ex.Message +
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                    catch (OdbcException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                }
                #endregion if btn=1
                #region if btn=2
                else if (btn == 2)
                {
                    try
                    {
                        MyDataReader = MyCommand.ExecuteReader();

                        r = MyDataReader.RecordsAffected;
                        liste.Clear();

                        while (MyDataReader.Read())
                        {
                            liste.Add("prefix:\t\t " + MyDataReader.GetString(0) + "/" + MyDataReader.GetByte(1).ToString());
                            liste.Add("netname:\t " + MyDataReader.GetString(2));
                            liste.Add("person:\t\t " + MyDataReader.GetString(3));
                            liste.Add("organization:\t " + MyDataReader.GetString(4));
                            liste.Add("as-num:\t\t " + MyDataReader.GetString(5));
                            liste.Add("phone:\t\t " + MyDataReader.GetString(6));
                            liste.Add("email:\t\t " + MyDataReader.GetString(7));
                            liste.Add("status:\t\t " + MyDataReader.GetString(8));
                            liste.Add("created:\t\t " + MyDataReader.GetString(9));
                            liste.Add("last-updated:\t " + MyDataReader.GetString(10));
                            liste.Add("");

                            if (sa[0] != "")
                            {
                                this.textBox7.Text          = MyDataReader.GetString(0) + "/" + MyDataReader.GetByte(1).ToString();
                                this.textBox1.Text          = MyDataReader.GetString(2);
                                this.textBox2.Text          = MyDataReader.GetString(3);
                                this.textBox3.Text          = MyDataReader.GetString(4);
                                this.textBox6.Text          = MyDataReader.GetString(5);
                                this.textBox4.Text          = MyDataReader.GetString(6);
                                this.textBox5.Text          = MyDataReader.GetString(7);
                                this.comboBox1.SelectedItem = MyDataReader.GetString(8);
                            }
                        }
                        this.listBox1.Items.AddRange(liste.ToArray());

                        MyDataReader.Close();
                        if (MyDataReader is IDisposable)
                        {
                            MyDataReader.Dispose();
                        }
                        return(r);
                    }
                    catch (System.InvalidOperationException ex)
                    {
                        MessageBox.Show(ex.Message +
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                    catch (OdbcException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                }
                #endregion btn2
                #region if btn=3
                else if (btn == 3)
                {
                    try
                    {
                        r = MyCommand.ExecuteNonQuery();
                    }
                    catch (System.InvalidOperationException ex)
                    {
                        MessageBox.Show(ex.Message +
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception", this.culture),
                                        StringsDictionary.KeyValue("FormDB_MySQLquery_exception_header", this.culture),
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                    catch (OdbcException ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(-1);
                    }
                }
                #endregion btn=3
            }
            catch (OdbcException ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(r);
        }
Esempio n. 20
0
        private short QuerySelectedPrefix(string inprefix, short pflen)
        {
            if (MySQLconnection.State == ConnectionState.Closed)
            {
                MessageBox.Show(StringsDictionary.KeyValue("FormDB_MySQLquery_closed", this.culture),
                                StringsDictionary.KeyValue("FormDB_MySQLquery_closed_header", this.culture),
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }

            string MySQLcmd = "";

            if (this.currentMode == "v6")
            {
                this.toolStripStatusLabel1.Text = "Database: " + this.ServerInfo.DBname;

                MySQLcmd = "SELECT inet6_ntoa(prefix), pflen, parentpflen "
                           + " from " + "`" + this.ServerInfo.DBname + "`" + ".`" + this.ServerInfo.Tablename + "` "
                           + " WHERE ( prefix=inet6_aton('" + inprefix + "') "
                           + " AND pflen=" + pflen + " );";
            }
            else // v4
            {
                this.toolStripStatusLabel2.Text = this.ServerInfo.DBname_v4;

                MySQLcmd = "SELECT inet_ntoa(prefix), pflen, parentpflen "
                           + " from " + "`" + this.ServerInfo.DBname_v4 + "`" + ".`" + this.ServerInfo.Tablename_v4 + "` "
                           + " WHERE ( prefix=inet_aton('" + inprefix + "') "
                           + " AND pflen=" + pflen + " );";
            }

            OdbcCommand MyCommand = new OdbcCommand(MySQLcmd, MySQLconnection);

            try
            {
                if (this.MySQLconnection.State != ConnectionState.Open)
                {
                    this.MySQLconnection.Open();
                }

                if (this.currentMode == "v6")
                {
                    this.MySQLconnection.ChangeDatabase(this.ServerInfo.DBname);
                }
                else // v4
                {
                    this.MySQLconnection.ChangeDatabase(this.ServerInfo.DBname_v4);
                }

                OdbcDataReader MyDataReader = MyCommand.ExecuteReader();
                int            r            = MyDataReader.RecordsAffected;

                if (r > 0)
                {
                    MyDataReader.Read();
                    short parentpflen = MyDataReader.GetByte(2);
                    MyDataReader.Close();
                    if (MyDataReader is IDisposable)
                    {
                        MyDataReader.Dispose();
                    }
                    return(parentpflen);
                }
                else  // not found
                {
                    MyDataReader.Close();
                    if (MyDataReader is IDisposable)
                    {
                        MyDataReader.Dispose();
                    }

                    MessageBox.Show(StringsDictionary.KeyValue("Form1_prefixnotfound", this.culture),
                                    "No Prefix", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(-1);  // not found
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: \r\n" + ex.Message, "Error: QuerySelectedPrefix()", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(-1);
            }
        }