Exemple #1
0
        private string GetForeignKeyReferenceTableName(string owner, string tableName, string columnName)
        {
            var conn = new IngresConnection(_connectionString);

            conn.Open();
            try
            {
                using (conn)
                {
                    using (var tableCommand = conn.CreateCommand())
                    {
                        tableCommand.CommandText = "SELECT p.table_name " + "FROM iiref_constraints rc " +
                                                   "INNER JOIN iikeys p " +
                                                   "ON p.schema_name = rc.unique_schema_name " +
                                                   "AND p.constraint_name = rc.unique_constraint_name " +
                                                   "INNER JOIN iiconstraints c " +
                                                   "ON c.schema_name = rc.ref_schema_name " +
                                                   "AND c.constraint_name = rc.ref_constraint_name " +
                                                   "INNER JOIN iikeys f " + "ON f.schema_name = rc.ref_schema_name " +
                                                   "AND f.constraint_name = rc.ref_constraint_name " +
                                                   "AND p.key_position = f.key_position " +
                                                   $"WHERE f.schema_name = '{owner}' " +
                                                   $"AND f.table_name = '{tableName}' " +
                                                   $"AND f.column_name = '{columnName}'";
                        return(tableCommand.ExecuteScalar().ToString());
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #2
0
        private void metroButton1_Click(object sender, EventArgs e)
        {
            IngresConnection con = new IngresConnection(Login.myConnectionString);

            con.Open();
            IngresCommand cmd = new IngresCommand();

            cmd.Connection  = con;
            cmd.CommandText = "rol_create";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new IngresParameter("t_id_rol", IngresType.Decimal));
            cmd.Parameters.Add(new IngresParameter("t_nombre", IngresType.VarChar));
            cmd.Parameters["t_id_rol"].Value = 0;
            cmd.Parameters["t_nombre"].Value = this.nombre.Text;
            try
            {
                cmd.ExecuteNonQuery();
                MetroMessageBox.Show(this, "Elemento creado correctamente.", "Nota", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            catch (IngresException c)
            {
                MetroMessageBox.Show(this, c.ErrorCode + c.Message, "Error");
            }
            con.Close();
            this.read();
        }
    static public void Main()
    {
        string myConnectionString =
        "Host=myserver.mycompany.com;" +
        "User Id=myname;PWD=mypass;" +
        "Database=mydatabase";

        using (DbConnection conn = new IngresConnection())
        {
            conn.ConnectionString = myConnectionString;
            conn.Open();   // open the Ingres connection

            string cmdtext =
                "select table_owner, table_name, " +
                " create_date from iitables " +
                " where table_type in ('T','V') and " +
                " table_name not like 'ii%' and" +
                " table_name not like 'II%'";

            DbCommand cmd = conn.CreateCommand();
            cmd.CommandText = cmdtext;


            DataSet ds = new DataSet("my_list_of_tables");

            //  read the data using the DataAdapter method
            DbDataAdapter adapter = new IngresDataAdapter();
            adapter.SelectCommand = cmd;
            adapter.Fill(ds);  // execute the query and fill the dataset

            //  write the dataset to an XML file
            ds.WriteXml("c:/temp/temp.xml");

        }   // close the connection
    }  // end Main()
Exemple #4
0
        public static async Task <object> ExecuteScalarAsync(this IngresConnection conn, string sql, IngresTransaction tx = null)
        {
            var cmd = tx == null ? new IngresCommand(sql, conn) : new IngresCommand(sql, conn, tx);

            using (cmd)
                return(await cmd.ExecuteScalarAsync());
        }
Exemple #5
0
        static void Main(string[] args)
        {
            string SQLStatement = "select * from revenue";
            // SQLStatement = "delete from revenue";
            // SQLStatement = "insert into revenue(myid, material, revenue) values(1, 'Flower', 12.34)";
            // SQLStatement = "insert into revenue(myid, material, revenue) values(2, 'car', 1.34)";
            // SQLStatement = "insert into revenue(myid, material, revenue) values(3, '花', 26.989)";
            // SQLStatement = "insert into revenue(myid, material, revenue) values(3, '汽车',26.989)";

            IngresConnection  con       = new IngresConnection(string.Format("Host={0};Database={1};Uid={2};Pwd={3}", "XXX", "demodb", "Administrator", "HX"));
            IngresDataAdapter da        = new IngresDataAdapter(new IngresCommand(SQLStatement, con));
            DataTable         sqlresult = new DataTable();

            da.Fill(sqlresult);
            con.Close();
            da.Dispose();

            foreach (DataColumn sqlcol in sqlresult.Columns)
            {
                Console.WriteLine(sqlcol.DataType);
            }

            Console.WriteLine(sqlresult.Rows.Count);
            Console.Read();
        }
Exemple #6
0
        public override object EditValue(
			ITypeDescriptorContext context,
			IServiceProvider       provider,
			object                 value)
        {
            if (context          != null  &&
                context.Instance != null  &&
                provider         != null)
            {
                IWindowsFormsEditorService edSvc =
                    (IWindowsFormsEditorService)provider.GetService(
                    typeof(IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    // set connection string into an IngresConnection
                    IngresConnection connection =
                        new IngresConnection((string)value);
                    // call the dialog for building/modifying the connection str
                    ConnectionEditor editor =
                        new ConnectionEditor(connection);
                    value = connection.ConnectionString;  // return updated string
                }  // end if (edSvc != null)
            } // end if context is OK
            return value;
        }
Exemple #7
0
        public static object ExecuteScalar(this IngresConnection conn, string sql, IngresTransaction tx = null)
        {
            var cmd = tx == null ? new IngresCommand(sql, conn) : new IngresCommand(sql, conn, tx);

            using (cmd)
                return(cmd.ExecuteScalar());
        }
Exemple #8
0
        private void Delete_Click(object sender, EventArgs e)
        {
            IngresConnection con = new IngresConnection(Login.myConnectionString);

            con.Open();
            IngresCommand cmd = new IngresCommand();

            cmd.Connection  = con;
            cmd.CommandText = "rol_delete";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new IngresParameter("t_id_rol", IngresType.Decimal));
            cmd.Parameters["t_id_rol"].Value = int.Parse(this.metroTextBox1.Text);
            IngresTransaction trans = con.BeginTransaction();

            cmd.Transaction = trans;
            try
            {
                cmd.ExecuteNonQuery();
                trans.Commit();
                MetroMessageBox.Show(this, "Elemento eliminado correctamente.", "Nota", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            catch (IngresException c)
            {
                MetroMessageBox.Show(this, c.ErrorCode + c.Message, "Error");
            }
            con.Close();
            this.read();
        }
        private string GetConstraintName(string owner, string tableName, string columnName)
        {
            var conn = new IngresConnection(_connectionString);

            conn.Open();
            try
            {
                using (conn)
                {
                    using (var tableDetailsCommand = conn.CreateCommand())
                    {
                        tableDetailsCommand.CommandText = string.Format("SELECT k.constraint_name " +
                                                                        "FROM iikeys k " +
                                                                        "INNER JOIN iiconstraints c " +
                                                                        "ON k.constraint_name = c.constraint_name " +
                                                                        "WHERE c.constraint_type = 'R' " +
                                                                        "AND k.schema_name = '{0}' " +
                                                                        "AND k.table_name = '{1}' " +
                                                                        "AND k.column_name = '{2}'",
                                                                        owner, tableName, columnName);
                        var result = tableDetailsCommand.ExecuteScalar();
                        return(result == null ? String.Empty : result.ToString());
                    }
                }
            }
            finally
            {
                conn.Close();
            }
        }
Exemple #10
0
        public Task <List <Table> > GetTables(string owner)
        {
            var tables = new List <Table>();
            var conn   = new IngresConnection(_connectionString);

            conn.Open();
            try
            {
                using (conn)
                {
                    var tableCommand = conn.CreateCommand();
                    tableCommand.CommandText = String.Format("SELECT table_name " +
                                                             "FROM iitables " +
                                                             "WHERE table_owner = '{0}' " +
                                                             "AND table_type in ('T', 'V') " +
                                                             "AND table_name NOT LIKE 'ii%'",
                                                             owner);

                    var sqlDataReader = tableCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    while (sqlDataReader.Read())
                    {
                        var tableName = sqlDataReader.GetString(0).TrimEnd();
                        tables.Add(new Table {
                            Name = tableName
                        });
                    }
                }
                tables.Sort((x, y) => String.CompareOrdinal(x.Name, y.Name));
            }
            finally
            {
                conn.Close();
            }
            return(Task.FromResult(tables));
        }
Exemple #11
0
        private IList <HasMany> DetermineHasManyRelationships(Table table)
        {
            var hasManyRelationships = new List <HasMany>();
            var conn = new IngresConnection(_connectionString);

            conn.Open();
            using (conn)
            {
                using (var command = conn.CreateCommand())
                {
                    command.CommandText = "SELECT f.table_name " + "FROM iiref_constraints rc " +
                                          "INNER JOIN iikeys p " + "ON p.schema_name = rc.unique_schema_name " +
                                          "AND p.constraint_name = rc.unique_constraint_name " +
                                          "INNER JOIN iiconstraints c " + "ON c.schema_name = rc.ref_schema_name " +
                                          "AND c.constraint_name = rc.ref_constraint_name " + "INNER JOIN iikeys f " +
                                          "ON f.constraint_name = rc.ref_constraint_name " +
                                          "AND p.key_position = f.key_position " +
                                          $"WHERE p.schema_name = '{table.Owner}' " +
                                          $"AND p.table_name = '{table.Name}'";
                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            hasManyRelationships.Add(new HasMany
                            {
                                Reference = reader.GetString(0).TrimEnd(),
                            });
                        }
                    }

                    return(hasManyRelationships);
                }
            }
        }
Exemple #12
0
        private bool IsForeignKey(string owner, string tableName, string columnName)
        {
            var conn = new IngresConnection(_connectionString);

            conn.Open();
            try
            {
                using (conn)
                {
                    using (var tableDetailsCommand = conn.CreateCommand())
                    {
                        tableDetailsCommand.CommandText = "SELECT COUNT(0) " + "FROM iikeys k " +
                                                          "INNER JOIN iiconstraints c " +
                                                          "ON k.constraint_name = c.constraint_name " +
                                                          "WHERE c.constraint_type = 'R' " +
                                                          $"AND k.schema_name = '{owner}' " +
                                                          $"AND k.table_name = '{tableName}' " +
                                                          $"AND k.column_name = '{columnName}'";
                        var obj = tableDetailsCommand.ExecuteScalar();

                        int result;
                        if (obj != null &&
                            Int32.TryParse(obj.ToString(), out result))
                        {
                            return(result > 0);
                        }
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(false);
        }
Exemple #13
0
        public Task <IList <string> > GetOwners()
        {
            IList <string> owners = new List <string>();
            var            conn   = new IngresConnection(_connectionString);

            conn.Open();
            try
            {
                using (conn)
                {
                    var tableCommand = conn.CreateCommand();
                    tableCommand.CommandText = "SELECT DISTINCT table_owner FROM iitables WHERE table_owner <> '$ingres'";
                    var sqlDataReader = tableCommand.ExecuteReader(CommandBehavior.CloseConnection);
                    while (sqlDataReader.Read())
                    {
                        var ownerName = sqlDataReader.GetString(0).TrimEnd();
                        owners.Add(ownerName);
                    }
                }
            }
            finally
            {
                conn.Close();
            }

            return(Task.FromResult(owners));
        }
Exemple #14
0
        public static List <Employer> GetDeliveryReport(string hub_code)
        {
            using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
            {
                List <Employer> data = new List <Employer>();
                db.Open();
                try
                {
                    var key = "batchno" + hub_code;

                    // Try to get the object from the cache
                    //data = _cache[key] as List<Employer>;
                    //if (data == null)
                    //{
                    db.Query("set lockmode session where readlock=nolock");
                    data = db.Query <Employer>("select batchno,cutdate " +
                                               "from lo_stl_billing_employer " +
                                               "where  ifnull(batchno,'')<>'' " +
                                               "group by batchno,cutdate").ToList();
                    // _cache.Set(key, data, DateTimeOffset.Now.AddMinutes(1));
                    // }
                }
                catch (Exception ex)
                {
                }
                db.Close();
                db.Dispose();
                return(data);
            }
        }
Exemple #15
0
 public static List <Members> ReportHQPSLF132(string batchno)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         List <Members> data = new List <Members>();
         db.Open();
         try
         {
             db.Query("set lockmode session where readlock=nolock");
             if (batchno.Contains("ER"))
             {
                 data = db.Query <Members>("select a.status_code,a.batchno,a.eyername as fname," +
                                           "b.branch_name, int2(0) as indiv_payor,a.eyeraddr as home_address,a.zipcode from lo_stl_billing_employer a " +
                                           "inner join hdmf_branches b on b.branch_code=a.branch_code " +
                                           "where batchno=@batchno and a.status_code=10", new { batchno = batchno }).ToList();
             }
             else
             {
                 data = db.Query <Members>("select a.lname,a.fname,a.mid,a.name_ext,e.branch_name," +
                                           " home_address,int2(1) as indiv_payor,a.zipcode from lo_stl_billing_members a inner join hdmf_branches e on " +
                                           "e.branch_code=a.branch_code where   a.status_code=10 and a.indiv_payor=1 and batchno=@batchno",
                                           new { batchno = batchno }).ToList();
             }
             db.Close();
             db.Dispose();
         }
         catch (Exception ex)
         {
         }
         return(data);
     }
 }
Exemple #16
0
        /// <summary>
        /// Connect to two databases while automatically enlisting in the ambient Transaction,
        /// and execute two non-query SQL commands under the TransactionScope.
        /// Commit the Transaction by marking the TransactionScope complete,
        /// if issueScopeComplete argument is set true for testing purposes.
        /// </summary>
        /// <param name="connString1">ConnectionString for database 1.</param>
        /// <param name="connString2">ConnectionString for database 2.</param>
        /// <param name="commandText1">Non-query CommandText to execute against database 1.</param>
        /// <param name="commandText2">Non-query CommandText to execute against database 2.</param>
        /// <param name="issueScopeComplete">If true, issue TransactionScope.Complete()</param>
        static void ExecuteNonQueryWithinTransactionScope(
            string connString1, string connString2,
            string commandText1, string commandText2,
            bool issueScopeComplete)
        {
            Console.WriteLine("\n\tUpdateUsingTransactionScope...\n");

            using (TransactionScope scope = new TransactionScope())
            {
                using (IngresConnection conn1 = new IngresConnection(connString1))
                {
                    using (IngresConnection conn2 = new IngresConnection(connString2))
                    {
                        Console.WriteLine("\tIngresConnection1.Open()...");
                        // Open the connection to the database and
                        // enlist in the ambient Transaction using MSDTC
                        conn1.Open();
                        Console.WriteLine("\tIngresConnection1.Open() complete\n");

                        Console.WriteLine("\tIngresConnection2.Open()...");
                        // Open the connection to the database and
                        // enlist in the ambient Transaction using MSDTC
                        conn2.Open();
                        Console.WriteLine("\tIngresConnection2.Open() complete\n");

                        try
                        {
                            IngresCommand cmd1 = conn1.CreateCommand();
                            cmd1.CommandText = commandText1;
                            cmd1.ExecuteNonQuery();

                            IngresCommand cmd2 = conn2.CreateCommand();
                            cmd2.CommandText = commandText2;
                            cmd2.ExecuteNonQuery();

                            // mark the Transaction complete
                            // mark the Transaction complete
                            if (issueScopeComplete)                              // test debug flag for testing scope.Complete
                            {
                                Console.WriteLine("\tTransactionScope completing...");
                                scope.Complete();
                                Console.WriteLine("\tTransactionScope complete\n");
                            }
                            // note: TransactionScope will not be committed until
                            // TransactionScope Dispose() is called.
                        }
                        catch (Exception ex)
                        {
                            string s = ex.ToString();
                            Console.WriteLine("\n\tApplication throws Exception!!  " + s + "\n");
                            throw;
                        }
                    }              // end using (IngresConnection2)  // closes and disposes conn2
                }                  // end using (IngresConnection1)      // closes and disposes conn1

                Console.WriteLine("\tTransactionScope.Dispose()...");
            }      // end using (TransactionScope)  // calls System.Transactions.Dispose() --> System.Transactions.CommittableTransaction.Commit
            Console.WriteLine("\tTransactionScope.Dispose() complete\n");
        }          // end ExecuteNonQueryWithinTransactionScope
 public static List <Hub> GetAllHub()
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Hub>("SELECT * FROM hdmf_hub_master").ToList());
     }
 }
 public static List <Branches> GetAllBranches(string hub_code)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Branches>("SELECT * FROM hdmf_branches where hub_code=@hub_code", new{ hub_code = hub_code }).ToList());
     }
 }
 public static string Remove(int id)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         db.Query("delete from lo_stl_billing_users where id=@id", new { id = id });
     }
     return("Ok");
 }
Exemple #20
0
 static void UsingIngresConnection(IngresConnection connection, Action <DbConnection> action)
 {
     using (IngresConnection conn = (IngresConnection)connection.Clone())
     {
         conn.Open();
         action(conn);
         // using's Dispose will close conn
     } // end using clone of IngresConnection
 }
 public static Users GetUserEdit(int id)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Users>("SELECT * FROM lo_stl_billing_users a " +
                                 "where id=@id", new { id = id }).SingleOrDefault());
     }
 }
 public static List <CutOff> GetCutOffs(string hub_code)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <CutOff>("select cutdate,(date_format(cutdate,'%M %Y')) as desc from lo_stl_billing_employer " +
                                  "where hub_code=@hub_code " +
                                  "group by cutdate order by cutdate desc", new { hub_code = hub_code }).ToList());
     }
 }
 public static List <Users> GetAllUsers()
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Users>("SELECT a.*,b.hub_name,c.branch_name FROM lo_stl_billing_users a " +
                                 "inner join hdmf_hub_master b on b.hub_code=a.hub_code " +
                                 "inner join hdmf_branches c on c.branch_code=a.branch_code ").ToList());
     }
 }
 public static List <Employer> GetEmployer(DateTime cutdate, string hub_code)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Employer>("SELECT distinct a.*,b.address as branch_address,b.contact_no as branch_contactno FROM lo_stl_billing_employer a " +
                                    "inner join  hdmf_branches b on b.branch_code=a.branch_code " +
                                    "where a.cutdate=@cutdate and a.hub_code=@hub_code", new { cutdate = cutdate.ToString("MM/dd/yyyy"), hub_code = hub_code }).ToList());
     }
 }
 public static Users GetUser(string username)
 {
     using (IngresConnection db = new IngresConnection(ConfigurationManager.ConnectionStrings["pfmdb"].ConnectionString))
     {
         db.Query("set lockmode session where readlock=nolock");
         return(db.Query <Users>("SELECT a.*,b.hub_name FROM lo_stl_billing_users a " +
                                 "inner join hdmf_hub_master b on b.hub_code=a.hub_code " +
                                 "where a.username=@username", new { username = username }).SingleOrDefault());
     }
 }
        /// <summary>
        /// Gets the Id for the current application.
        /// </summary>
        /// <param name="conn">The Ingres connection to use.</param>
        /// <param name="tran">The Ingres transaction to use.</param>
        /// <returns>The Id for the current application.</returns>
        private string GetApplicationId(IngresConnection conn, IngresTransaction tran)
        {
            string id = null;

            string sql = @"
                          SELECT  
                              ApplicationId 
                          FROM 
                              aspnet_Applications 
                          WHERE LoweredApplicationName = ?
                         ";

            // Create the new command and enrol in the current transaction
            IngresCommand cmd = new IngresCommand(sql, this.conn);

            cmd.Transaction = this.tran;

            cmd.Parameters.Add("LoweredApplicationName", DbType.String).Value = this.config.ApplicationName.ToLower();

            conn.Open();

            IngresDataReader reader = cmd.ExecuteReader();

            if (reader != null)
            {
                if (reader.HasRows)
                {
                    reader.Read();

                    // Retrieve the Id
                    id = DBUtil.ColValAsString(reader, "ApplicationId");

                    reader.Close();
                }
                else
                {
                    // Close the reader.
                    reader.Close();

                    // We don't have an application so create one.
                    this.CreateApplication(this.config.ApplicationName, out id);
                }
            }

            // Mark the application Id as current so that we don't have to fetch it from the database
            // again unless it changes.
            this.config.IsApplicationIdCurrent = true;

            // Close the connection
            conn.Close();

            return(id);
        }
Exemple #27
0
        /// <summary>
        /// Enumerate the items for the Ingres data objects of the
        /// specified type (e.g. Index), with the specified restrictions
        /// and sort string.
        /// </summary>
        /// <param name="typeName">Type name of the object to enumerate.</param>
        /// <param name="items">The items (strings) to enumerate.</param>
        /// <param name="restrictions">Filtering restrictions.</param>
        /// <param name="sort">ORDER BY sort specification.</param>
        /// <param name="parameters"></param>
        /// <returns></returns>
        public override DataReader EnumerateObjects(
            string typeName,
            object[] items,
            object[] restrictions,
            string sort,
            object[] parameters)
        {
            //System.Windows.Forms.MessageBox.Show(
            //    "EnumerateObjects Called", "IngresDataObjectEnumerator");

            if (typeName == null)               // safety check; should not happen
            {
                throw new ArgumentNullException("typeName");
            }

            // retrieve the Ingres data provider connection that
            // supports the the current connection.
            IngresConnection conn =
                Connection.GetLockedProviderObject() as IngresConnection;

            if (conn == null)
            {
                throw new ArgumentException(
                          "EnumerateObjects does not have the correct " +
                          "IngresConnection type for the underlying connection.");
            }
            try
            {
                if (Connection.State != DataConnectionState.Open)
                {
                    Connection.Open();
                }

                switch (typeName)
                {
                case IngresDataObjectTypes.Root:
                    System.Data.DataTable dt = conn.GetSchema("Root");
                    return(new AdoDotNetDataTableReader(dt));
                }                  // end switch

                return(adoDataObjectEnumerator.EnumerateObjects(
                           typeName,
                           items,
                           restrictions,
                           sort,
                           parameters));
            }
            finally
            {
                // Unlock the DDEX Provider object
                Connection.UnlockProviderObject();
            }
        }  // EnumerateObjects
Exemple #28
0
        }          // end ExecuteNonQueryWithinExplicitTransactionScope

        /// <summary>
        /// Open a database and execute a non-query SQL string.
        /// </summary>
        /// <param name="connString"></param>
        /// <param name="commandText"></param>
        static void ExecuteNonQuery(
            string connString, string commandText)
        {
            using (IngresConnection conn = new IngresConnection(connString))
            {
                conn.Open();

                IngresCommand cmd = conn.CreateCommand();
                cmd.CommandText = commandText;
                cmd.ExecuteNonQuery();
            }      // end using (IngresConnection conn)
        }          // end ExecuteNonQuery
Exemple #29
0
        private void Update_Click(object sender, EventArgs e)
        {
            IngresConnection con = new IngresConnection(Login.myConnectionString);

            con.Open();
            IngresCommand cmd = new IngresCommand();

            cmd.Connection  = con;
            cmd.CommandText = "empleado_update";
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.Parameters.Add(new IngresParameter("t_id_empleado", IngresType.Decimal));
            cmd.Parameters.Add(new IngresParameter("t_primer_nombre", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_segundo_nombre", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_primer_apellido", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_segundo_apellido", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_calle", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_avenida", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_num_casa", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_ciudad", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_departamento", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_referencia", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_correo_primario", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_correo_secundario", IngresType.VarChar));
            cmd.Parameters.Add(new IngresParameter("t_fecha_nacimiento", IngresType.Date));
            cmd.Parameters.Add(new IngresParameter("t_fecha_inicio", IngresType.Date));
            cmd.Parameters["t_id_empleado"].Value       = int.Parse(this.id.Text);
            cmd.Parameters["t_primer_nombre"].Value     = this.prinom.Text;
            cmd.Parameters["t_segundo_nombre"].Value    = this.senom.Text;
            cmd.Parameters["t_primer_apellido"].Value   = this.priape.Text;
            cmd.Parameters["t_segundo_apellido"].Value  = this.seape.Text;
            cmd.Parameters["t_calle"].Value             = this.ca.Text;
            cmd.Parameters["t_avenida"].Value           = this.avenida.Text;
            cmd.Parameters["t_num_casa"].Value          = this.numcasa.Text;
            cmd.Parameters["t_ciudad"].Value            = this.ciudad.Text;
            cmd.Parameters["t_departamento"].Value      = this.departamento.Text;
            cmd.Parameters["t_referencia"].Value        = this.referencia.Text;
            cmd.Parameters["t_correo_primario"].Value   = this.pricorreo.Text;
            cmd.Parameters["t_correo_secundario"].Value = this.secorreo.Text;
            cmd.Parameters["t_fecha_nacimiento"].Value  = this.metroDateTime1.Value.ToString("yyyy-MM-dd");
            cmd.Parameters["t_fecha_inicio"].Value      = this.metroDateTime2.Value.ToString("yyyy-MM-dd");
            try
            {
                cmd.ExecuteNonQuery();
                MetroMessageBox.Show(this, "Elemento actualizado correctamente.", "Nota", MessageBoxButtons.OK, MessageBoxIcon.Question);
            }
            catch (IngresException c)
            {
                MetroMessageBox.Show(this, c.ErrorCode + c.Message, "Error");
            }
            con.Close();
            this.read();
        }
Exemple #30
0
        /// <summary>
        /// Handles the press of the test connection string button.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The event arguments.</param>
        private void TestConnectionString(object sender, EventArgs e)
        {
            this.btnTest.Enabled = false;

            IngresConnection conn = new IngresConnection();

            if (this.tbConnectionString.Text.Trim() == string.Empty)
            {
                MessageBox.Show("A connection string must be entered.");

                this.btnTest.Enabled = true;

                return;
            }

            try
            {
                conn.ConnectionString = this.tbConnectionString.Text;
            }
            catch (Exception)
            {
                this.tbConnectionResult.Text = "Invalid connection string.";

                this.btnTest.Enabled = true;

                return;
            }

            try
            {
                conn.Open();

                this.tbConnectionResult.Text = "Successfully opened a connection!";

                MessageBox.Show("A connection to the database was successfully opened!\n\nCopy the generated connection string for use in the web config file.", "Successful Connection");
            }
            catch (Exception ex)
            {
                this.tbConnectionResult.Text = ex.Message;
            }
            finally
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }

                conn = null;

                this.btnTest.Enabled = true;
            }
        }
Exemple #31
0
        private IngresConnection GetConnection(CustomListData data)
        {
            data.Properties.TryGetValue("Host", StringComparison.OrdinalIgnoreCase, out var Host);
            data.Properties.TryGetValue("Database", StringComparison.OrdinalIgnoreCase, out var Database);
            data.Properties.TryGetValue("Username", StringComparison.OrdinalIgnoreCase, out var Username);
            data.Properties.TryGetValue("Password", StringComparison.OrdinalIgnoreCase, out var Password);

            IngresConnection con = new IngresConnection(string.Format("Host={0};Database={1};Uid={2};Pwd={3}", Host, Database, Username, Password));

            con.Open();

            return(con);
        }
Exemple #32
0
        protected override IComponent[] CreateComponentsCore(System.ComponentModel.Design.IDesignerHost host)
        {
            //MessageBox.Show("ConnectionToolboxItem.CreateComponentsCore called!");

            const string prefix = VSNETConst.shortTitle;  // "Ingres"
            IContainer designerHostContainer = host.Container;
            //ComponentCollection components   = null;
            ArrayList newComponents          = new ArrayList();
            ArrayList newCommandComponents   = new ArrayList();
            string    name;

            if (designerHostContainer == null)  // safety check
                return null;

            IngresConnection connection = new IngresConnection();

            // Once a reference to an assembly has been added to this service,
            // this service can load types from names that
            // do not specify an assembly.
            ITypeResolutionService resService =
                (ITypeResolutionService)host.GetService(typeof(ITypeResolutionService));

            System.Reflection.Assembly assembly = connection.GetType().Module.Assembly;

            if (resService != null)
            {
                resService.ReferenceAssembly(assembly.GetName());
                // set the assembly name to load types from
            }

            name = DesignerNameManager.CreateUniqueName(
                designerHostContainer, prefix, "Connection");
            try
            {
                designerHostContainer.Add(connection, name);
                newComponents.Add(connection);
            }
            catch (ArgumentException ex)
            {
                string exMsg = ex.ToString() +
                    "\nRemove IngresConnection component '" + name + "'" +
                    " that is defined outside of the designer. ";
                MessageBox.Show(exMsg, "Add " + name + " failed");
                return null;
            }

            // invoke the wizard to create the connection and query
            ConnectionEditor wizard = new ConnectionEditor(connection);

            return (IComponent[])(newComponents.ToArray(typeof(IComponent)));
            //return base.CreateComponentsCore(host);
        }
Exemple #33
0
        internal ConnectionEditor(IngresConnection connectionParm)
        {
            connection = connectionParm;

            // format the connection string in key/value pairs
            nv = ConnectStringConfig.ParseConnectionString(
                connection.ConnectionString);
            // the editor will update the key/value pairs

            Form dlgConnection = new ConnectionEditorForm(nv);
            DialogResult result = dlgConnection.ShowDialog();

            if (result == DialogResult.Cancel) // if Cancel button, return
            {
                //MessageBox.Show("Connection DialogResult.Cancel", "ConnectionEditor");
                return;
            }
            // else (result == DialogResult.OK)     // if Next button, go on

            // rebuild the updated key/value pairs back into a connection string
            connection.ConnectionString =
                ConnectStringConfig.ToConnectionString(nv);
        }
Exemple #34
0
        internal ConnectionEditor(
			IngresDataAdapter adapter,
			System.ComponentModel.Design.IDesignerHost host)
        {
            if (adapter != null  &&
                adapter.SelectCommand != null  &&
                adapter.SelectCommand.Connection != null)
                connection = adapter.SelectCommand.Connection;
            else
                connection = new IngresConnection();

            // format the connection string in key/value pairs
            nv = ConnectStringConfig.ParseConnectionString(
                connection.ConnectionString);
            // the editor will update the key/value pairs

            Form dlgConnection = new ConnectionEditorForm(nv);
            DialogResult result = dlgConnection.ShowDialog();

            if (result == DialogResult.Cancel) // if Cancel button, return
            {
                //MessageBox.Show("Connection DialogResult.Cancel", "ConnectionEditor");
                return;
            }
            // else (result == DialogResult.OK)     // if Next button, go on

            // rebuild the updated key/value pairs back into a connection string
            connection.ConnectionString = ConnectStringConfig.ToConnectionString(nv);

            // connect the Connection object to the four Adapter commands
            if (adapter != null)
            {
                if (adapter.SelectCommand != null)
                    adapter.SelectCommand.Connection = connection;
                if (adapter.InsertCommand != null)
                    adapter.InsertCommand.Connection = connection;
                if (adapter.UpdateCommand != null)
                    adapter.UpdateCommand.Connection = connection;
                if (adapter.DeleteCommand != null)
                    adapter.DeleteCommand.Connection = connection;
            }
        }
Exemple #35
0
        private void TestConnection(string connectionString)
        {
            IngresConnection connection =
                new IngresConnection(connectionString);

            Cursor cursor = Cursor.Current;   // save cursor, probably Arrow
            Cursor.Current = Cursors.WaitCursor;  // hourglass cursor
            try // to open the connection
            {
                connection.Open();  // try opening the connection
            }
            finally
            {
                Cursor.Current = cursor;  // restore Arrow cursor
            }
            connection.Close();
        }
Exemple #36
0
        public QueryDesignerForm(
			IngresConnection connection, string commandText)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            // remember the command text and connection to work against
            if (commandText != null)
            {
                string savedConnectionString;  // saved connection string

                if (commandText != null)
                    this.CommandText = commandText.Trim();

                this.Connection = connection;
                if (this.Connection != null)
                {
                    Cursor cursor = Cursor.Current;   // save cursor, probably Arrow
                    Cursor.Current = Cursors.WaitCursor;  // hourglass cursor

                    // save the connection because 'Persist Security Info'
                    // option will destroy the password during open
                    savedConnectionString = this.Connection.ConnectionString;

                    try // to open the connection
                    {
                        this.Connection.Open();  // try opening the connection
                        _catalog= this.Connection.OpenCatalog();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(
                            ex.ToString(),
                            VSNETConst.shortTitle +
                            " Query Designer    Server Is Not Available");
                        this.Connection = null;
                    }
                    finally
                    {
                        Cursor.Current = cursor;  // restore Arrow cursor

                        //restore the ConnectionString if changed by Open()
                        if (this.Connection != null  &&
                            this.Connection.ConnectionString!= savedConnectionString)
                            this.Connection.ConnectionString = savedConnectionString;
                    }
                }
            }
        }