Esempio n. 1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        protected SqlStatementCreator(EntityType entityType, EntityField[] fields)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            // set...
            _entityType = entityType;

            // mjr - 12-10-2005 - setup the dialect...
            if (entityType.HasDatabaseName)
            {
                // mjr - 12-10-2005 - this needs to be refactored (not ideal)...
                using (IConnection connection = Database.CreateConnection(entityType.DatabaseName))
                    this.Dialect = connection.Dialect;
            }
            else
            {
                Dialect = Database.DefaultDialect;
            }

            // set...
            if (Dialect == null)
            {
                throw new InvalidOperationException("Dialect is null.");
            }

            // do the fields...
            _fields = new EntityFieldCollection(entityType);

            // mbr - 16-10-2005 - now done on demand...
            //			if(fields.Length == 0)
            //			{
            //				// get default fields...
            //				fields = entityType.GetCommonFields();
            //				if(fields.Length == 0)
            //				{
            //					fields = entityType.GetKeyFields();
            //					if(fields.Length == 0)
            //						throw new InvalidOperationException(string.Format("Entity type '{0}' has no common fields and no key fields.", entityType));
            //				}
            //			}

            // add the ones passed into the constructor...
            _fields.AddRange(fields);

            // order...
            _sortOrder = entityType.DefaultSortOrder.Clone();
            this.FirstApplySortCall = true;

            this.ArrayParameterType = Database.ArrayParameterType;
        }
Esempio n. 2
0
        /// <summary>
        /// Resolves the fields for select.
        /// </summary>
        /// <returns>The fields that will be used in the select.</returns>
        /// <remarks>By default, if the <see cref="Fields"></see> collection is empty, this will return the common fields, failing that, the key fields.  Otherwise,
        /// it will return the fields contained in the <see cref="Fields"></see> collection.</remarks>
        protected EntityField[] ResolveFieldsForSelect()
        {
            // if we have no fields, guess that all of the text fields on the table are free-text searchable...
            EntityFieldCollection toUse = null;

            if (this.Fields.Count == 0)
            {
                toUse = new EntityFieldCollection(this.EntityType);
                this.GetDefaultFields(toUse);

                // check...
                if (toUse.Count == 0)
                {
                    throw new InvalidOperationException("No fields were returned from GetDefaultFields.");
                }
            }
            else
            {
                toUse = this.Fields;
            }

            // mbr - 10-10-2007 - case 875 - make sure we have the key fields from any joined tables...
            if (this.HasJoins)
            {
                foreach (SqlJoin join in this.Joins)
                {
                    if (join.IncludeInTreeFetch)
                    {
                        if (join.TargetEntityType == null)
                        {
                            throw new InvalidOperationException("join.TargetEntityType is null.");
                        }

                        this.MergeFields(toUse, join.TargetEntityType.GetKeyFields());
                    }
                }
            }

            // mbr - 2016-09-25 -- what about sort?
            foreach (SortSpecification sort in this.SortOrder)
            {
                if (sort.Field != null && sort.Field.EntityType == this.EntityType)
                {
                    this.MergeFields(toUse, new EntityField[] { sort.Field });
                }
            }

            // return...
            return(toUse.ToArray());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the default fields.
        /// </summary>
        /// <returns></returns>
        protected virtual void GetDefaultFields(EntityFieldCollection fields)
        {
            if (fields == null)
            {
                throw new ArgumentNullException("fields");
            }

            // common...
            fields.AddRange(this.EntityType.GetCommonFields());
            if (fields.Count == 0)
            {
                fields.AddRange(this.EntityType.GetKeyFields());
                if (fields.Count == 0)
                {
                    throw new InvalidOperationException(string.Format("Entity type '{0}' has no common fields and no key fields.", this.EntityType));
                }
            }

            // mbr - 10-10-2007 - case 875 - add joined names...
            if (this.HasJoins)
            {
                foreach (SqlJoin join in this.Joins)
                {
                    // mbr - 2011-08-30 - include?
                    if (join.IncludeInTreeFetch)
                    {
                        if (join.TargetEntityType == null)
                        {
                            throw new InvalidOperationException("join.TargetEntityType is null.");
                        }

                        this.MergeFields(fields, join.TargetEntityType.GetCommonFields());
                    }
                }
            }
        }
Esempio n. 4
0
 private void Initialize()
 {
     _freeTextFields = new EntityFieldCollection(this.EntityType);
 }
Esempio n. 5
0
        protected void DropDownListEntityFields_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.EntityTypeId == Guid.Empty)
            {
                return;
            }
            EntityFieldCollection fields = EntityNodeProvider.GetEntityFields(this.EntityTypeId);

            if (fields == null)
            {
                return;
            }
            if (!string.IsNullOrEmpty(m_FieldName))
            {
                DropDownListEntityFields.SelectedValue = m_FieldName;
            }
            EntityField field = fields[DropDownListEntityFields.SelectedValue];

            if (field == null)
            {
                return;
            }
            LabelFieldType.Text          = field.DataType.Name;
            LabelFieldsTypeFullName.Text = field.DataType.FullName;
            DropDownListTerm.Items.Clear();
            DropDownListTerm.Items.Add(new ListItem("=="));
            DropDownListTerm.Items.Add(new ListItem("!="));

            ControlValue    FieldTypeConrol = ControlValue.TextBox;
            List <ListItem> lists           = new List <ListItem>();

            lists.Add(new ListItem(">"));
            lists.Add(new ListItem(">="));
            lists.Add(new ListItem("<"));
            lists.Add(new ListItem("<="));

            if (field.ListValues.Count > 0)
            {
                LabelFieldType.Text            = Resources.RuleParametersControl_LookupText;
                FieldTypeConrol                = ControlValue.ComboBox;
                ComboBoxEntityValue.DataSource = field.ListValuesOld;
                ComboBoxEntityValue.DataBind();
                if (m_EntityValue != null)
                {
                    ComboBoxEntityValue.SelectedValue = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
            }
            else if (field.DataType == typeof(short))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Integer;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((short)field.MaxValue).ToString(CultureInfo.CurrentCulture) : short.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((short)field.MinValue).ToString(CultureInfo.CurrentCulture) : short.MinValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.Text           = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : "0";
            }
            else if (field.DataType == typeof(int))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Integer;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((int)field.MaxValue).ToString(CultureInfo.CurrentCulture) : int.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((int)field.MinValue).ToString(CultureInfo.CurrentCulture) : int.MinValue.ToString(CultureInfo.CurrentCulture);
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    TextBoxEntityValue.Text = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : "0";
                }
            }
            else if (field.DataType == typeof(long))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Integer;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((long)field.MaxValue).ToString(CultureInfo.CurrentCulture) : long.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((long)field.MinValue).ToString(CultureInfo.CurrentCulture) : long.MinValue.ToString(CultureInfo.CurrentCulture);
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    TextBoxEntityValue.Text = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : "0";
                }
            }
            else if (field.DataType == typeof(decimal))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Double;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((decimal)field.MaxValue).ToString(CultureInfo.CurrentCulture) : decimal.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((decimal)field.MinValue).ToString(CultureInfo.CurrentCulture) : decimal.MinValue.ToString(CultureInfo.CurrentCulture);
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    TextBoxEntityValue.Text = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : decimal.Zero.ToString(CultureInfo.CurrentCulture);
                }
            }
            else if (field.DataType == typeof(double))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Double;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((double)field.MaxValue).ToString(CultureInfo.CurrentCulture) : double.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((double)field.MinValue).ToString(CultureInfo.CurrentCulture) : double.MinValue.ToString(CultureInfo.CurrentCulture);
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    TextBoxEntityValue.Text = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : decimal.Zero.ToString(CultureInfo.CurrentCulture);
                }
            }
            else if (field.DataType == typeof(float))
            {
                FieldTypeConrol = ControlValue.TextBox;
                DropDownListTerm.Items.AddRange(lists.ToArray());
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                TextBoxEntityValue.ValidationType = CustomValidationDataType.Double;
                TextBoxEntityValue.MaximumValue   = (field.MaxValue != null) ? ((float)field.MaxValue).ToString(CultureInfo.CurrentCulture) : float.MaxValue.ToString(CultureInfo.CurrentCulture);
                TextBoxEntityValue.MinimumValue   = (field.MinValue != null) ? ((float)field.MinValue).ToString(CultureInfo.CurrentCulture) : float.MinValue.ToString(CultureInfo.CurrentCulture);
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    TextBoxEntityValue.Text = (field.DefaultValue != null) ? Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture) : decimal.Zero.ToString(CultureInfo.CurrentCulture);
                }
            }
            else if (field.DataType == typeof(DateTime))
            {
                DropDownListTerm.Items.AddRange(lists.ToArray());
                FieldTypeConrol            = ControlValue.DatePicker;
                DatePickerEntityValue.Type = DatePickerType.DateTimePicker;

                if (field.MaxValue != null)
                {
                    DatePickerEntityValue.MaxDate = (DateTime)field.MaxValue;
                }
                if (field.MinValue != null)
                {
                    DatePickerEntityValue.MinDate = (DateTime)field.MinValue;
                }
                if (m_EntityValue != null)
                {
                    DatePickerEntityValue.SelectedDate = Convert.ToDateTime(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else if (field.DefaultValue != null)
                {
                    DatePickerEntityValue.SelectedDate = (DateTime)field.DefaultValue;
                }
            }
            else if (field.DataType == typeof(bool))
            {
                FieldTypeConrol = ControlValue.CheckBox;
                if (m_EntityValue != null)
                {
                    CheckBoxEntityValue.Checked = Convert.ToBoolean(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else
                {
                    CheckBoxEntityValue.Checked = (field.DefaultValue != null) ? Convert.ToBoolean(field.DefaultValue, CultureInfo.CurrentCulture) : false;
                }
            }
            else if (field.DataType == typeof(Guid))
            {
                FieldTypeConrol = ControlValue.TextBox;
                TextBoxEntityValue.MaxLength            = 25;
                TextBoxEntityValue.ValidationType       = CustomValidationDataType.RegularExpression;
                TextBoxEntityValue.ValidationExpression = @"[({]?(0x)?[0-9a-fA-F]{8}([-,]?(0x)?[0-9a-fA-F]{4}){2}((-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12})|(,\{0x[0-9a-fA-F]{2}(,0x[0-9a-fA-F]{2}){7}\}))[)}]?";
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else if (field.DefaultValue != null)
                {
                    TextBoxEntityValue.Text = ((Guid)field.DefaultValue).ToString();
                }
            }
            else if (field.DataType == typeof(Entity))
            {
                FieldTypeConrol = ControlValue.TreeView;
                EntityTreeViewValue.EntityId = field.Id;
                if (m_EntityValue != null)
                {
                    EntityTreeViewValue.EntityNodeId = (Guid)m_EntityValue;
                }
                EntityTreeViewValue.DataBind();
            }
            else
            {
                TextBoxEntityValue.ValidationType = CustomValidationDataType.String;
                if (field.MaxLength > 0)
                {
                    TextBoxEntityValue.MaxLength = 0;
                }
                if (m_EntityValue != null)
                {
                    TextBoxEntityValue.Text = Convert.ToString(m_EntityValue, CultureInfo.CurrentCulture);
                }
                else if (field.DefaultValue != null)
                {
                    TextBoxEntityValue.Text = HttpUtility.HtmlEncode(Convert.ToString(field.DefaultValue, CultureInfo.CurrentCulture));
                }
            }
            if (!string.IsNullOrEmpty(m_Term))
            {
                DropDownListTerm.SelectedValue = m_Term;
            }
            switch (FieldTypeConrol)
            {
            case ControlValue.TextBox:
                TextBoxEntityValue.Visible    = true;
                ComboBoxEntityValue.Visible   = false;
                DatePickerEntityValue.Visible = false;
                CheckBoxEntityValue.Visible   = false;
                EntityTreeViewValue.Visible   = false;
                break;

            case ControlValue.CheckBox:
                TextBoxEntityValue.Visible    = false;
                ComboBoxEntityValue.Visible   = false;
                DatePickerEntityValue.Visible = false;
                CheckBoxEntityValue.Visible   = true;
                EntityTreeViewValue.Visible   = false;
                break;

            case ControlValue.ComboBox:
                TextBoxEntityValue.Visible    = false;
                ComboBoxEntityValue.Visible   = true;
                DatePickerEntityValue.Visible = false;
                CheckBoxEntityValue.Visible   = false;
                EntityTreeViewValue.Visible   = false;
                break;

            case ControlValue.DatePicker:
                TextBoxEntityValue.Visible    = false;
                ComboBoxEntityValue.Visible   = false;
                DatePickerEntityValue.Visible = true;
                CheckBoxEntityValue.Visible   = false;
                EntityTreeViewValue.Visible   = false;
                break;

            case ControlValue.TreeView:
                TextBoxEntityValue.Visible    = false;
                ComboBoxEntityValue.Visible   = false;
                DatePickerEntityValue.Visible = false;
                CheckBoxEntityValue.Visible   = false;
                EntityTreeViewValue.Visible   = true;
                break;
            }
        }