예제 #1
0
        /// <summary>
        /// Gets the icon index to show for each field
        /// </summary>
        /// <param name="field"></param>
        /// <returns></returns>
        private static StatusIcons GetIconIndexForField(FieldInformation field)
        {
            if (field.State == FieldState.Ansi)
                return StatusIcons.Text;
            if (field.State == FieldState.Unicode)
                return StatusIcons.Unicode;

            return StatusIcons.Error;
        }
        /// <summary>
        /// Searches and inits a field into the tables/fields collection
        /// </summary>
        /// <param name="tableName">The name of the db table</param>
        /// <param name="fieldName">The name of the db field</param>
        /// <returns></returns>
        public FieldInformation InitField(string tableName, string fieldName)
        {
            FieldInformation field = null;
            Dictionary<string, FieldInformation> fields;

            if (String.IsNullOrEmpty(tableName))
                throw new System.Exception("Table Name cannot be empty!");

            if (String.IsNullOrEmpty(fieldName))
                throw new System.Exception("Table Name cannot be empty!");

            tableName = tableName.ToUpper();
            fieldName = fieldName.ToUpper();

            // Check for table existence
            if (!tables.ContainsKey(tableName))
                tables[tableName] = new Dictionary<string, FieldInformation>();

            fields = tables[tableName];

            // Check for field existence
            if (!fields.ContainsKey(fieldName))
                fields[fieldName] = new FieldInformation(tableName, fieldName);

            field = fields[fieldName];

            return field;
        }
예제 #3
0
 private Column GetColumnFromSQLMgmtObjects(FieldInformation field)
 {
     Server serv = new Server(_serverConnection);
     Database dbase = serv.Databases[_databaseName];
     Table table = dbase.Tables[field.tableName, "sysdba"];
     Column col = table.Columns[field.fieldName];
     return col;
 }
예제 #4
0
        public void SetUnicodeOnDbField(FieldInformation field, bool UnicodeEnabled, int? newLength)
        {
            if (newLength <= 0) newLength = null;

            string createScript = GetCreateScriptForIndexes(field.tableName, field.fieldName),
                dropScript = GetDropScriptForIndexes(field.tableName, field.fieldName);

            Column col = GetColumnFromSQLMgmtObjects(field);
            SqlDataType newType = GetNewTypeForColumn(UnicodeEnabled, col);

            OpenDbConnection();

            // Drop the indexes on the field
            ExecuteCommandOnDBConnection(dropScript);

            // Actually alter the column type (using SMO)
            col.DataType = new DataType(newType, (newLength ?? col.DataType.MaximumLength));
            col.Alter();

            // restores the indexes on the field
            ExecuteCommandOnDBConnection(createScript);

            CloseConnection();
        }
예제 #5
0
 public void SetUnicodeOnDbField(FieldInformation field, bool UnicodeEnabled)
 {
     SetUnicodeOnDbField(field, UnicodeEnabled, null);
 }
예제 #6
0
        /// <summary>
        /// Main update method: sets the field type (and size) based on the provided options
        /// </summary>
        /// <param name="field">Provides entity and property names</param>
        /// <param name="UnicodeEnabled">True if must enable Unicode, false otherwise</param>
        /// <param name="newSize">New size</param>
        public void SetUnicodeOnSlxField(FieldInformation field, bool UnicodeEnabled, int newSize)
        {
            try
            {
                XmlDocument doc = ModelPersister.OpenEntityFile(field.tableName);

                var property = doc.SelectSingleNode(String.Format(@"//property[@columnName='{0}']", field.fieldName));

                property.Attributes["lastModifiedUtc"].Value = DateTime.UtcNow.ToString("o");

                var currentSlxLength = property.Attributes["maxLength"].Value;

                if (newSize > 0)
                {
                    property.Attributes["maxLength"].Value = newSize.ToString();
                }

                // new xml snippet: use provided models and replace ***** with length
                var newTypeXML = (UnicodeEnabled ? unicodeTextPropertyXMLModel : textPropertyXMLModel)
                    .Replace("******", (newSize > 0 ? newSize.ToString() : currentSlxLength));

                string xpathSelector = String.Format(@"//property[@columnName='{0}']/SystemDataType", field.fieldName);

                doc.CreateNavigator().SelectSingleNode(xpathSelector).OuterXml = newTypeXML;

                ModelPersister.SaveEntityFile(field.tableName, doc);
            }
            catch (Exception)
            {
                throw;// new Exception("Error reading entity model files!");
            }
        }
예제 #7
0
        private void SetNewSizeForSelectedField(FieldInformation selectedField)
        {
            int newSize;

            if (Int32.TryParse(cmbNewSize.Text, out newSize))
            {
                selectedField.NewLength = newSize;
            }
        }