Пример #1
0
            public bool AddTable(Guid organizationId, int departmentId, string tableName, ref ImportLog importLog, ref ImportCustomProperty importCustomProperty, IDataReaderAdapter tableReader)
            {
                bool result = false;

                if (_tables != null)
                {
                    if (!_tables.Contains(tableName))
                    {
                        ImportTable _table = new ImportTable(tableName, organizationId, departmentId, ref importLog, ref importCustomProperty, tableReader);
                        if (_table != null)
                        {
                            _tables.Add(tableName, _table);
                            result = true;
                        }
                    }
                }

                return result;
            }
Пример #2
0
            public ImportTable(string sheet_name, Guid organizationId,  int departmentId, ref ImportLog import_log, ref ImportCustomProperty import_custom_property, IDataReaderAdapter dataReaderAdapter)
            {
                _organizationId = organizationId;
                _departmentId = departmentId;

                _require_column_list = new ImportColumns();
                _require_column_list_all = new ImportColumns();
                _available_column_list = new ImportColumns();
                _custom_column_list = new ImportColumns();

                _reader = dataReaderAdapter;
                _log = import_log;

                _import_custom_property = import_custom_property;

                _sheet_name = sheet_name;

                _table = new DataTable();
            }
Пример #3
0
            public string Validate(ref ImportCustomProperty _import_custom_property, DataTable dtImportAssets)
            {
                string result = "";

                try
                {
                    _importTables.AddTable(_organizationId, _departmentId, dtImportAssets.TableName, ref import_log, ref _import_custom_property, new ApiDataReaderAdapter(ref dtImportAssets));

                    ImportTable importTable = _importTables.GetTable(dtImportAssets.TableName);
                    if (importTable != null)
                        importTable.Validate();
                }
                catch (Exception ex)
                {
                    result = "Error Description: " + ex.Message.ToString();
                }
                return result;
            }
Пример #4
0
            public string Validate(ref ImportCustomProperty _import_custom_property, Config cfg)
            {
                string result = "";

                try
                {
                    if (_oledb != null)
                    {
                        _oledb.Open();
                        DataTable schemaTable = _oledb.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

                        foreach (DataRow drTable in schemaTable.Rows)
                        {
                            string tableName = drTable["Table_Name"].ToString();

                            if (!tableName.EndsWith("$")) //Skip filtering and sorting worksheets
                                continue;

                            OleDbCommand oleDbCommand = new OleDbCommand("SELECT * FROM [" + tableName + "]", _oledb);
                            OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();

                            if (!string.IsNullOrEmpty(tableName))
                                tableName = tableName.Substring(0, tableName.Length - 1);

                            _importTables.AddTable(_organizationId, _departmentId, tableName, ref import_log, ref _import_custom_property, new ExcelDataReaderAdapter(ref oleDbDataReader));

                            ImportTable importTable = _importTables.GetTable(tableName);
                            if (importTable != null)
                                importTable.Validate(cfg);
                        }
                    }
                }
                catch (Exception ex)
                {
                    result = "Can't process file: " + _file_name + " Error Description: " + ex.Message.ToString();
                    if (_oledb != null)
                    {
                        if (_oledb.State == ConnectionState.Open) _oledb.Close();
                        _oledb = null;
                    }
                }

                if (_oledb != null)
                {
                    if (_oledb.State == ConnectionState.Open) _oledb.Close();
                }

                return result;
            }
Пример #5
0
        public static DataTable ImportAssetsApi(Guid organizationId, int departmentId, int? userId, string userName, bool isInsertOnly, bool insertMissedValues, DataTable dtAssets, ref int insertedObjectsCount, ref int updatedObjectsCount)
        {
            ImportAssets importAssets = new ImportAssets(organizationId, departmentId);
            ImportCustomProperty importCustomProperty = new ImportCustomProperty();

            importAssets.Validate(ref importCustomProperty, dtAssets);

            if (insertMissedValues)
            {
                DataTable dtNewAssetTypes = importAssets.GetCommonNewAssetTypes(isInsertOnly);
                DataTable dtNewAssetVendors = importAssets.GetCommonNewAssetVendors(isInsertOnly);

                if ((dtNewAssetTypes != null && dtNewAssetTypes.Rows.Count > 0) || (dtNewAssetVendors != null && dtNewAssetVendors.Rows.Count > 0))
                {
                    if (dtNewAssetTypes != null)
                        foreach (DataRow drAssetType in dtNewAssetTypes.Rows)
                            ImportAssets.AddType(organizationId, departmentId, drAssetType["AssetCategoryName"].ToString(), drAssetType["AssetTypeName"].ToString(), drAssetType["AssetMakeName"].ToString(), drAssetType["AssetModelName"].ToString());

                    if (dtNewAssetVendors != null)
                        foreach (DataRow drAssetVendor in dtNewAssetVendors.Rows)
                            ImportAssets.AddVendor(organizationId, departmentId, drAssetVendor["VendorName"].ToString());

                    importAssets.GetImportLog().Clear();
                    importAssets.Validate(ref importCustomProperty, dtAssets);
                }
            }

            importAssets.GetCommonNewAssets(userId, userName, isInsertOnly, ref insertedObjectsCount, ref updatedObjectsCount);

            return importAssets.GetImportLog();
        }