Пример #1
0
 public DataTable GetTableData(Table table)
 {
     return _db.DataTableGet(table.Name);
 }
Пример #2
0
 /// <summary>
 /// Gets columns of the table
 /// </summary>
 /// <exception cref="AssortmentException"></exception>
 /// <param name="table">Table object</param>
 public List<Column> GetTableColumns(Table table)
 {
     var columns = new List<Column>();
     AssortmentProcedure.GetTableDefinition.Parameters["i_tablename"].Value = table.DBName.ToUpper();
     var parameters = _db.CallProcedure(AssortmentProcedure.GetTableDefinition);
     var dims = parameters["o_recordset"] as List<Dictionary<string, object>>;
     if (dims == null) throw new AssortmentException("Table has no columns");
     if (dims.Count == 0) throw new AssortmentException("Table has no columns");
     foreach (var dim in dims)
     {
         if (dim["COLUMN_NAME"] == DBNull.Value) throw new AssortmentException("Dimension COLUMN_NAME is null");
         if (dim["COMMENTS"] == DBNull.Value) throw new AssortmentException("Comment field of " + dim["COLUMN_NAME"] + " row is null");
         columns.Add(new Column { Name = (string)dim["COLUMN_NAME"], Desc = (string)dim["COMMENTS"] });
     }
     return columns;
 }
Пример #3
0
        //public void Backup(ExitCodes result)
        //{
        //    Logger.LogHeadUpdate(_db, (char)result);
        //    AssortmentProcedure.GttTablesBackup.Parameters["i_backup_type"].Value = result.Description();
        //    var parameters = _db.CallProcedure(AssortmentProcedure.GttTablesBackup);
        //}

        ///// <summary>
        ///// Check backup state
        ///// </summary>
        ///// <param name="login">user login</param>
        ///// <param name="result">result/type</param>
        ///// <exception cref="AssortmentException"></exception>
        //public void BackupCheck(out string login, out ExitCodes result)
        //{
        //    var parameters = _db.CallProcedure(AssortmentProcedure.GttTablesCheckBackup);
        //    login = parameters["o_user_id"].ToString();
        //    result = parameters["o_backup_type"].ToString() == ExitCodes.Successful.Description()
        //        ? ExitCodes.Successful
        //        : ExitCodes.Exception;
        //}

        ///// <summary>
        ///// Restore backup state
        ///// </summary>
        ///// <exception cref="CancelException"></exception>        
        ///// <exception cref="AssortmentException"></exception>
        //public void Restore()
        //{
        //    var parameters = _db.CallProcedure(AssortmentProcedure.GttTablesRestore);
        //}

        #endregion

        /// <summary>
        /// Call secondary initialize methods
        /// </summary>
        /// <exception cref="ConnectionException"></exception>
        /// <exception cref="AssortmentException"></exception>
        public void Fill(Table table, bool clearBeforeFill = true)
        {
            _db.FillDataTableCustom(table, clearBeforeFill);
        }
Пример #4
0
        public SortedSet<IL> DataTableGetILByFilters(Table table, List<FilterValues> filters)
        {
            var source = DataTableGet(table.Name);
            if (source == null) throw new ArgumentNullException("table");

            var setIL = new SortedSet<IL>();

            foreach (DataRow row in source.Rows)
            {
                if (CheckFilters(row, filters) == false) continue;
                setIL.Add(new IL { Item = row.GetItem(), Loc = row.GetLoc() });
            }

            return setIL;
        }
Пример #5
0
        /// <summary>
        /// Custom Fill DataTable
        /// </summary>
        /// <exception cref="ConnectionException"></exception>
        /// <exception cref="AssortmentException"></exception>
        /// <param name="table">Table object</param>
        /// <param name="clearBeforeFill">true default clear DataTable</param>
        public void FillDataTableCustom(Table table, bool clearBeforeFill = true)
        {
            if (Connection.State != ConnectionState.Open) throw new ConnectionException("Соединение не установлено");
            if (_adapters[table.Name] == null)
            {
                _adapters.Add(table.Name, new OracleDataAdapter());
            }
            if (_dataSet.Tables.Contains(table.Name))
            {
                if (clearBeforeFill)
                {
                    DataTableClear(table.Name);
                }
            }
            try
            {
                var cmd = Connection.CreateCommand();
                cmd.CommandText = table.SelectClause;

                ((OracleDataAdapter)_adapters[table.Name]).SelectCommand = cmd;
                ((OracleDataAdapter)_adapters[table.Name]).Fill(_dataSet, table.Name);
                var builder = new OracleCommandBuilder((OracleDataAdapter)_adapters[table.Name]);
                ((OracleDataAdapter)_adapters[table.Name]).UpdateCommand = builder.GetUpdateCommand();

                // Create single (multiple-column) primary key if not exists
                if (_dataSet.Tables[table.Name].PrimaryKey.Length == 0)
                {
                    //foreach (var keyField in table.KeyFields)
                    //{
                    //    keyFields.Add(new DataColumn(keyField));
                    //}

                    _dataSet.Tables[table.Name].PrimaryKey = table.KeyFields.Select(field => _dataSet.Tables[table.Name].Columns[field]).ToArray();

                    //_dataSet.Tables[table.Name].PrimaryKey = table.KeyFields.Select(keyField => new DataColumn(keyField)).ToArray();
                }
            }
            catch (Exception ex)
            {
                throw new AssortmentException(ex.Message);
            }
        }
Пример #6
0
 /// <summary>
 /// Custom Fill DataTable
 /// </summary>
 /// <exception cref="ConnectionException"></exception>
 /// <exception cref="AssortmentException"></exception>
 /// <param name="tableName">Table name</param>
 /// <param name="query">Select clause</param>
 /// <param name="keyFields">Key fields</param>
 /// <param name="clearBeforeFill">true default clear DataTable</param>
 public void FillDataTableCustom(string tableName, string query, string[] keyFields, bool clearBeforeFill = true)
 {
     var table = new Table { DBName = tableName, KeyFields = keyFields, Name = tableName, SelectClause = query };
     FillDataTableCustom(table, clearBeforeFill);
 }
Пример #7
0
        /// <summary>
        /// Get's list of item type rows
        /// </summary>
        /// <param name="table"></param>
        /// <param name="itemType"></param>
        /// <returns>List of item type rows</returns>
        public IEnumerable<string> DataTableGetItemsByType(Table table, string itemType)
        {
            var source = DataTableGet(table.Name);
            if (source == null) throw new AssortmentException(String.Format("Source {0} is empty", table.Name));

            var items = new List<string>();

            foreach (DataRow row in source.Rows)
            {
                if (row.GetItemType() == itemType) items.Add(row.GetItem());
            }

            if (items.Count == 0) throw new AssortmentException("No item type rows");

            var dist = items.Distinct();

            return dist;
        }