Ejemplo n.º 1
0
 internal bool IsEquivalentTo(string columnName)
 {
     return
         ((ColumnName.Equals(columnName))
          ||
          (AliasOf != null && AliasOf.IsEquivalentTo(columnName)));
 }
Ejemplo n.º 2
0
        public override bool Equals(object?other)
        {
            var otherColumn = other as ColumnModel;

            return(otherColumn != null &&
                   ColumnName.Equals(otherColumn.ColumnName) &&
                   PrimitiveType.Equals(otherColumn.PrimitiveType) &&
                   object.Equals(DocString, otherColumn.DocString));
        }
        /// <summary>
        /// Returns true if SapInventoryVariant instances are equal
        /// </summary>
        /// <param name="other">Instance of SapInventoryVariant to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(SapInventoryVariant other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     InventoryVariantName == other.InventoryVariantName ||
                     InventoryVariantName != null &&
                     InventoryVariantName.Equals(other.InventoryVariantName)
                     ) &&
                 (
                     ColumnName == other.ColumnName ||
                     ColumnName != null &&
                     ColumnName.Equals(other.ColumnName)
                 ) &&
                 (
                     Value == other.Value ||
                     Value != null &&
                     Value.Equals(other.Value)
                 ) &&
                 (
                     ValueRange == other.ValueRange ||
                     ValueRange != null &&
                     ValueRange.Equals(other.ValueRange)
                 ) &&
                 (
                     Operator == other.Operator ||
                     Operator != null &&
                     Operator.Equals(other.Operator)
                 ) &&
                 (
                     IncludeExclude == other.IncludeExclude ||
                     IncludeExclude != null &&
                     IncludeExclude.Equals(other.IncludeExclude)
                 ) &&
                 (
                     SourceSystem == other.SourceSystem ||
                     SourceSystem != null &&
                     SourceSystem.Equals(other.SourceSystem)
                 ));
        }
Ejemplo n.º 4
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            ColumnInfo dest = (ColumnInfo)obj;

            if (this.ColumnName == null || dest.ColumnName == null)
            {
                return(this.ColumnName == null && dest.ColumnName == null);
            }

            return(ColumnName.Equals(dest.ColumnName, StringComparison.CurrentCultureIgnoreCase));
        }
 public bool Equals([AllowNull] ColumnDocString other)
 {
     return other != null
         && ColumnName.Equals(other.ColumnName)
         && DocString.Equals(other.DocString);
 }
Ejemplo n.º 6
0
 public bool Equals(SqlWhereClause other) => other != null && Conjunction.Equals(other.Conjunction) && ColumnName.Equals(other.ColumnName) && ColumnValue.Equals(other.ColumnValue) && Operator.Equals(other.Operator);
Ejemplo n.º 7
0
 public bool Equals([AllowNull] TableColumn other)
 {
     return(other != null &&
            ColumnName.Equals(other.ColumnName) &&
            PrimitiveType == other.PrimitiveType);
 }
Ejemplo n.º 8
0
        private static void Import2DatabaseFromXMLFile(string fileName, string connectionString)
        {
            if (!File.Exists(fileName))
            {
                return;
            }
            fetchRecordsFromDB(fileName, connectionString);
            var reader      = XmlReader.Create(fileName);
            var dataHeaders = new List <string>();
            var dataValues  = new List <string>();
            var dbHeaders   = new List <string>();
            var dbValues    = new List <string>();
            var sqlBatch    = new StringBuilder();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    var tableName = parseXmlEncodedString(reader.Name);
                    if (tableName == "root")
                    {
                        continue;
                    }

                    if (!ConstrainCheckDisabledTables.Any(x => x.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        sqlBatch.AppendLine($"ALTER TABLE {tableName} NOCHECK CONSTRAINT ALL");
                        ConstrainCheckDisabledTables.Add(tableName);
                    }

                    if (XNode.ReadFrom(reader) is XElement el)
                    {
                        try
                        {
                            foreach (var xAttribute in el.Attributes())
                            {
                                dataHeaders.Add(parseXmlEncodedString(xAttribute.Name.LocalName));
                                dataValues.Add(xAttribute.Value);
                            }

                            DataSet ds;
                            if (!MetaDataCache.Any(x => x.Key.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                var sql = $"SELECT * FROM {tableName} WHERE 1 = 0";//used for getting meta data only

                                SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connectionString);
                                ds = new DataSet(tableName);
                                dataAdapter.FillSchema(ds, SchemaType.Source, tableName);
                                dataAdapter.Fill(ds, tableName);
                                MetaDataCache.Add(tableName, ds);
                            }
                            else
                            {
                                ds = MetaDataCache.SingleOrDefault(x => x.Key.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)).Value;
                            }

                            var hasPrimaryKey = ds.Tables[0].PrimaryKey.Any() && ds.Tables[0].PrimaryKey[0].AutoIncrement;

                            DataColumn primaryKeyColumn;

                            if (ds.Tables[0].PrimaryKey.Any())
                            {
                                primaryKeyColumn = ds.Tables[0].PrimaryKey[0];
                            }
                            else
                            {
                                string primaryKeyName = dataHeaders.First();
                                primaryKeyColumn = (DataColumn)
                                                   from DataColumn c in ds.Tables[0].Columns
                                                   where c.ColumnName.Equals(primaryKeyName, StringComparison.InvariantCultureIgnoreCase)
                                                   select c;
                            }

                            var isPrimaryKeysHasValue = hasPrimaryKey && dataHeaders.Any(x => x.Equals(primaryKeyColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase));
                            var primaryKeyIndex       = dataHeaders.FindIndex(x => x.Equals(primaryKeyColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase));
                            var primaryKeyValue       = CreateFieldValueSql(primaryKeyColumn, dataValues[primaryKeyIndex]);

                            foreach (DataColumn column in ds.Tables[0].Columns)
                            {
                                dbHeaders.Add(column.ColumnName);
                                if (dataHeaders.Any(x => x.Equals(column.ColumnName, StringComparison.InvariantCultureIgnoreCase)))
                                {
                                    var dataColumnIndex = dataHeaders.FindIndex(x => x.Equals(column.ColumnName, StringComparison.InvariantCultureIgnoreCase));
                                    dbValues.Add(dataValues[dataColumnIndex]);
                                }
                                else
                                {
                                    dbValues.Add("NULL");
                                }
                            }


                            //searching from firstColumn to check if record already present in DB
                            //var checkSql = $"IF EXISTS(SELECT 1 FROM {tableName} WHERE [{primaryKeyColumn.ColumnName}] = {primaryKeyValue} ) SELECT 1 ELSE SELECT 0";
                            //var isExists = ReadSingleValue<int>(checkSql, connectionString) == 1;
                            var isExists = recordsExistsOnDatabase.FindIndex(x => x.Equals($"[{tableName}]_[{primaryKeyValue}]", StringComparison.InvariantCultureIgnoreCase)) >= 0;
                            if (!isExists)
                            {
                                sqlBatch.AppendLine(CreateInsertSql(tableName, ds.Tables[0].Columns, dbHeaders, dbValues.ToArray(), isPrimaryKeysHasValue, hasPrimaryKey));
                            }
                            else
                            {
                                sqlBatch.AppendLine(CreateUpdateSql(tableName, ds.Tables[0].Columns, dbHeaders, dbValues.ToArray(), primaryKeyColumn.ColumnName, primaryKeyValue));
                            }

                            if (IdentityInsertCheckClosedTables.Any(x => x.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                sqlBatch.AppendLine($"SET IDENTITY_INSERT {tableName} OFF ");
                                IdentityInsertCheckClosedTables.RemoveAll(x => x.Equals(tableName, StringComparison.InvariantCultureIgnoreCase));
                            }
                        }
                        finally
                        {
                            dataHeaders.Clear();
                            dataValues.Clear();
                            dbHeaders.Clear();
                            dbValues.Clear();
                        }
                    }
                }
            }

            if (sqlBatch.Length > 0)
            {
                sqlBatch.Insert(0, "SET XACT_ABORT ON \r\n begin transaction\r\n ");
                sqlBatch.AppendLine("commit transaction");
                SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sqlBatch.ToString());
            }
            recordsExistsOnDatabase.Clear();
        }
Ejemplo n.º 9
0
        private static void Import2DatabaseFromTextFile(string fileName, string connectionString)
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            var reader = ReadAsLines(fileName);

            if (reader.Count() > 2)//first line table name, second line headers
            {
                var sqlBatch = new StringBuilder();

                var tableName = reader.First();
                if (ConstrainCheckDisabledTables.IndexOf(tableName) < 0)
                {
                    sqlBatch.AppendLine($"ALTER TABLE {tableName} NOCHECK CONSTRAINT ALL");
                    ConstrainCheckDisabledTables.Add(tableName);
                }

                var headers = reader
                              .Skip(1)
                              .Take(1)
                              .SingleOrDefault()
                              .Split('\t')
                              .ToList();

                var records = reader.Skip(2).Where(line => !line.StartsWith("#"));
                if (!records.Any())
                {
                    return;
                }

                DataSet ds;
                if (!MetaDataCache.Any(x => x.Key.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    var sql = $"SELECT * FROM {tableName} WHERE 1 = 0";//used for getting meta data only

                    SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, connectionString);
                    ds = new DataSet(tableName);
                    dataAdapter.FillSchema(ds, SchemaType.Source, tableName);
                    dataAdapter.Fill(ds, tableName);
                    MetaDataCache.Add(tableName, ds);
                }
                else
                {
                    ds = MetaDataCache.SingleOrDefault(x => x.Key.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)).Value;
                }

                var hasPrimaryKey = ds.Tables[0].PrimaryKey.Any();

                DataColumn primaryKeyColumn;

                if (ds.Tables[0].PrimaryKey.Any())
                {
                    primaryKeyColumn = ds.Tables[0].PrimaryKey[0];
                }
                else
                {
                    string primaryKeyName = headers.First();
                    primaryKeyColumn = (DataColumn)
                                       from DataColumn c in ds.Tables[0].Columns
                                       where c.ColumnName.Equals(primaryKeyName, StringComparison.InvariantCultureIgnoreCase)
                                       select c;
                }

                var isPrimaryKeysHasValue = hasPrimaryKey && headers.Any(x => x.Equals(primaryKeyColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase));

                foreach (var record in records)
                {
                    var values          = record.Split('\t').ToArray();
                    int primaryKeyIndex = headers.FindIndex(x => x.Equals(primaryKeyColumn.ColumnName, StringComparison.InvariantCultureIgnoreCase));
                    var primaryKeyValue = CreateFieldValueSql(primaryKeyColumn, values[primaryKeyIndex]);

                    //searching from firstColumn to check if record already present in DB
                    var checkSql = $"IF EXISTS(SELECT 1 FROM {tableName} WHERE {primaryKeyColumn.ColumnName} = {primaryKeyValue}) SELECT 1 ELSE SELECT 0";
                    var isExists = ReadSingleValue <int>(checkSql, connectionString) == 1;
                    if (!isExists)
                    {
                        sqlBatch.AppendLine(CreateInsertSql(tableName, ds.Tables[0].Columns, headers, values, isPrimaryKeysHasValue, hasPrimaryKey));
                    }
                    else
                    {
                        sqlBatch.AppendLine(CreateUpdateSql(tableName, ds.Tables[0].Columns, headers, values, primaryKeyColumn.ColumnName, primaryKeyValue));
                    }
                }

                if (IdentityInsertCheckClosedTables.Any(x => x.Equals(tableName, StringComparison.InvariantCultureIgnoreCase)))
                {
                    sqlBatch.AppendLine($"SET IDENTITY_INSERT {tableName} OFF ");
                    IdentityInsertCheckClosedTables.RemoveAll(x => x.Equals(tableName, StringComparison.InvariantCultureIgnoreCase));
                }

                SqlHelper.ExecuteNonQuery(connectionString, CommandType.Text, sqlBatch.ToString());
            }
        }
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            switch (operation)
            {
            case RemoveExtendedPropertyOperation otherAsRemovePropertyOp:
            {
                var thisPropertyName  = GetPropertyName(this);
                var otherPropertyName = GetPropertyName(otherAsRemovePropertyOp);
                if (thisPropertyName.Equals(otherPropertyName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Disabled = operation.Disabled = true;
                    return(MergeResult.Stop);
                }

                break;
            }

            case RemoveSchemaOperation otherAsRemoveSchemaOp when ForSchema &&
                SchemaName.Equals(otherAsRemoveSchemaOp.Name, StringComparison.InvariantCultureIgnoreCase):
                Disabled = true;
                break;

            case RemoveTableOperation otherAsRemoveTableOp when ForTable &&
                TableViewObjectName.Equals(otherAsRemoveTableOp.ObjectName, StringComparison.InvariantCultureIgnoreCase):
                Disabled = true;
                break;

            case RemoveViewOperation otherAsRemoveViewOp when ForView &&
                TableViewObjectName.Equals(otherAsRemoveViewOp.ObjectName, StringComparison.InvariantCultureIgnoreCase):
                Disabled = true;
                break;

            case RenameColumnOperation otherAsRenameColumnOp when TableViewObjectName.Equals(otherAsRenameColumnOp.TableObjectName, StringComparison.InvariantCultureIgnoreCase) && ForColumn && ColumnName.Equals(otherAsRenameColumnOp.Name, StringComparison.InvariantCultureIgnoreCase):
                ColumnName = otherAsRenameColumnOp.NewName;

                break;

            case RenameObjectOperation otherAsRenameOp when TableViewObjectName.Equals(otherAsRenameOp.ObjectName, StringComparison.InvariantCultureIgnoreCase):
                TableViewName = otherAsRenameOp.NewName;

                break;

            case UpdateExtendedPropertyOperation updateExtendedPropOp when !(this is RemoveExtendedPropertyOperation):
            {
                var thisPropertyName  = GetPropertyName(this);
                var otherPropertyName = GetPropertyName(updateExtendedPropOp);
                if (thisPropertyName.Equals(otherPropertyName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Value = updateExtendedPropOp.Value;
                    updateExtendedPropOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case UpdateTableOperation otherAsUpdateTableOp when ForTable &&
                ForColumn &&
                TableViewObjectName.Equals(otherAsUpdateTableOp.ObjectName, StringComparison.InvariantCultureIgnoreCase):
            {
                foreach (var deletedColumnName in otherAsUpdateTableOp.RemoveColumns)
                {
                    if (ColumnName.Equals(deletedColumnName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Disabled = true;
                        return(MergeResult.Stop);
                    }
                }

                break;
            }
            }

            return(MergeResult.Continue);
        }
Ejemplo n.º 11
0
 public bool Matches(Prop otherProp)
 {
     return(ColumnName.Equals(otherProp.ColumnName, StringComparison.InvariantCultureIgnoreCase) &&
            SqlDbType == otherProp.SqlDbType);
 }
Ejemplo n.º 12
0
 public bool IsSorted(DataTablesGridModel <T> model)
 {
     return(ColumnName.Equals(model.SortColumnName, StringComparison.OrdinalIgnoreCase));
 }