Beispiel #1
0
        public int UpdateHashtable(String tableName, Hashtable hashData, Hashtable hashPk)
        {
            DB2Connection ncc          = OpenConnection();
            DB2Command    com          = null;
            String        sql          = "UPDATE {0} SET {1} WHERE {2};";
            int           affectedRows = 0;

            try
            {
                string set = "";
                string where = "";

                foreach (string key in hashData.Keys)
                {
                    string col   = key;
                    string value = hashData[key].ToString();

                    if (!set.Equals(""))
                    {
                        set += ",";
                    }

                    set += String.Format("{0} = {1}", col, value);
                }

                foreach (string key in hashPk.Keys)
                {
                    string col   = key;
                    string value = hashPk[key].ToString();

                    if (!where.Equals(""))
                    {
                        where += " AND ";
                    }

                    where += String.Format("{0} = {1}", col, value);
                }

                sql = string.Format(sql, tableName, set, where);

                com          = new DB2Command(sql, ncc);
                affectedRows = com.ExecuteNonQuery();

                QueryCache.removeData(tableName);             //limpiando caché de la tabla...

                HistorialSeguimientoTabla(TABLA_SEGUIR, sql); //Almacenamiento historial de seguimiento a tabla.
            }
            catch (Exception e)
            {
                AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Error, sql, e, e.Message);
                return(-1);
            }
            finally
            {
                CloseConnection(ncc);
            }

            return(affectedRows);
        }
Beispiel #2
0
        public bool SaveHashtable(String tableName, Hashtable hash)
        {
            DB2Connection ncc          = OpenConnection();
            DB2Command    com          = null;
            String        sql          = "INSERT INTO {0} ({1}) VALUES ({2});";
            int           affectedRows = 0;

            try
            {
                string cols   = "";
                string values = "";

                foreach (string key in hash.Keys)
                {
                    string col   = key;
                    string value = hash[key].ToString();

                    if (!cols.Equals(""))
                    {
                        cols += ",";
                    }
                    if (!values.Equals(""))
                    {
                        values += ",";
                    }

                    cols   += col;
                    values += value;
                }

                sql = string.Format(sql, tableName, cols, values);

                com          = new DB2Command(sql, ncc);
                affectedRows = com.ExecuteNonQuery();

                QueryCache.removeData(tableName);             //limpiando caché de la tabla...

                HistorialSeguimientoTabla(TABLA_SEGUIR, sql); //Almacenamiento historial de seguimiento a tabla.
            }
            catch (Exception e)
            {
                AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Error, sql, e, e.Message);
                //exceptions += e.ToString() + cambioLinea;
            }
            finally
            {
                CloseConnection(ncc);
            }

            return(affectedRows == 1);
        }
Beispiel #3
0
        public int DeleteHashtable(string tableName, Hashtable hashPk)
        {
            SqlConnection ncc          = OpenConnection();
            SqlCommand    com          = null;
            String        sql          = "DELETE FROM {0} WHERE {1};";
            int           affectedRows = 0;

            try
            {
                string where = "";
                foreach (string key in hashPk.Keys)
                {
                    string col   = key;
                    string value = hashPk[key].ToString();

                    if (!where.Equals(""))
                    {
                        where += " AND ";
                    }

                    int n = 0;
                    if (int.TryParse(value, out n))
                    {
                        where += String.Format("{0} = {1}", col, value);
                    }
                    else
                    {
                        where += String.Format("{0} = '{1}'", col, value);
                    }
                }

                sql          = string.Format(sql, tableName, where);
                com          = new SqlCommand(sql, ncc);
                affectedRows = com.ExecuteNonQuery();

                QueryCache.removeData(tableName);             //limpiando caché de la tabla...

                HistorialSeguimientoTabla(TABLA_SEGUIR, sql); //Almacenamiento historial de seguimiento a tabla.
            }
            catch (Exception e)
            {
                AdministradorCarpetasRegistro.GrabarLogs(TipoRegistro.Error, sql, e, e.Message);
                return(-1);
            }
            finally
            {
                CloseConnection(ncc);
            }

            return(affectedRows);
        }