private ControllerDataSource this[XOFieldContext FieldContext]
 {
     get
     {
         return Items.Keys.Contains(FieldContext) ? Items[FieldContext] : null;
     }
 }
        public LookUpSearchEdit(XOFieldContext XOFieldContext)
            : base(XOFieldContext)
        {
            _searchEditDgtr = new DataAvail.XtraSearcherEditors.BaseSearchEdit<LookUpSearchEdit>(this, new CheckEdit());

            _searchEditDgtr.Initialize();
        }
        internal XtraContainerControlProperties(object Control, XtraContainerBuilderControlType ControlType, XOFieldContext FieldContext)
        {
            control = Control;

            controlType = ControlType;

            fieldContext = FieldContext;
        }
        internal CCExtBindingProperties(XOFieldContext FieldContext)
        {
            _field = FieldContext;

            _controlProperties = new CCProperties();

            _defProps = new CCBindingProperties();
        }
        protected override object CreateFieldControl(DataAvail.XtraContainerBuilder.XtraContainerBuilderControlType ControlType, XOFieldContext FieldContext)
        {
            /*
            if (ControlType != DataAvail.XtraContainerBuilder.XtraContainerBuilderControlType.Custom)
                return new DevExpress.XtraGrid.Columns.GridColumn();
            else
                return null;
             */

            return new DevExpress.XtraGrid.Columns.GridColumn();
        }
        internal ControllerDataSource GetDataSourceProperty(XOFieldContext FieldContext)
        {
            ControllerDataSource ds = this[FieldContext];

            if (ds == null)
            {
                ds = new ControllerDataSource(Controller, FieldContext);

                Items.Add(FieldContext, ds);
            }

            return ds;
        }
        internal void Reset(XOFieldContext Field, DataAvail.XtraBindings.Calculator.ObjectProperties ObjectProperties)
        {
            this._field = Field;

            _objectProperties = ObjectProperties;

            BindingDefaultProperties.Reset(Field);

            this.ControlProperties.ReadOnly = GetReadOnly();
            this.ControlProperties.BackColor = GetBackColor();
            this.ControlProperties.DataSource = GetDataSource();
            this.ControlProperties.DataSourceFilter = GetDataSourceFilter();
            this.ControlProperties.Mask = GetMask();
        }
        public DateRangeSearchEdit(XOFieldContext XOFieldContext)
        {
            InitializeComponent();

            _searchEditDgtr = new DataAvail.XtraSearcherEditors.BaseSearchEdit<DateRangeSearchEdit>(this, new CheckEdit());

            _fieldName = XOFieldContext.Name;

            _fieldType = XOFieldContext.FieldType;

            _appFieldContext = XOFieldContext;

            _searchEditDgtr.Initialize();

            dateEdit2.PreviewKeyDown += new PreviewKeyDownEventHandler(dateEdit2_PreviewKeyDown);
        }
        protected virtual object BuildField(XOFieldContext FieldContext)
        {
            bool isAdmitted = IsAdmittedField(FieldContext.Name);

            if (isAdmitted)
            {
                object ctl = GetSpecifiedControl(FieldContext.XOField);

                if (ctl == null)
                {
                    XtraContainerBuilderControlType controlType = GetControlType(FieldContext);

                    ctl = CreateFieldControl(controlType, FieldContext);

                    if (ctl != null)
                    {

                        XtraContainerControlProperties props = new XtraContainerControlProperties(ctl, controlType, FieldContext);

                        InitializeFieldControl(ctl, props);

                        BindFieldControl(ctl, FieldContext.Name, FieldContext.BindingProperty);

                        AddFieldControl(ctl, props);

                        ContainerControls.Add(FieldContext.XOField, ctl);
                    }

                    return ctl;
                }
                else
                {
                    BindFieldControl(ctl, FieldContext.Name, FieldContext.BindingProperty);

                    return null;
                }

                

            }
            else
            {
                return CreateEmptyControl();
            }
        }
        internal ButtonCommandItem(
            DataAvail.XtraEditors.IXtraEdit XtraEdit,
            XOFieldContext AppFieldContext,
            DevExpress.XtraEditors.ButtonEdit ButtonEdit,
            DevExpress.XtraEditors.Controls.EditorButton Button,
            DataAvail.Controllers.Commands.ControllerCommandTypes CommandType) :
            base(CommandType)
        {
            _xtraEdit = XtraEdit;

            _appFieldContext = AppFieldContext;

            _buttonEdit = ButtonEdit;

            _button = Button;

            _buttonEdit.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(Properties_ButtonClick);
        }
        protected override object CreateFieldControl(XtraContainerBuilderControlType ControlType, XOFieldContext AppFieldContext)
        {
            switch (ControlType)
            {
                case XtraContainerBuilderControlType.Text:
                    return new DataAvail.DX.XtraEditors.TextEdit(AppFieldContext);
                case XtraContainerBuilderControlType.Numeric:
                    return new DataAvail.DX.XtraEditors.TextEdit(AppFieldContext);
                case XtraContainerBuilderControlType.Date:
                    return new DataAvail.DX.XtraEditors.DateEdit(AppFieldContext);
                case XtraContainerBuilderControlType.Combo:
                    return new DataAvail.DX.XtraEditors.LookUpEdit(AppFieldContext);
                case XtraContainerBuilderControlType.Custom:
                    return base.CreateFieldControl(ControlType, AppFieldContext);
            }

            return null;
        }
 internal LikeLookUpEditDataProvider(XOFieldContext FieldContext)
 {
     _fieldContex = FieldContext;
 }
 protected override object OnCreateDateFieldControl(XOFieldContext XOFieldContext)
 {
     return new System.Windows.Forms.DateTimePicker();
 }
 protected override object OnCreateNumericFieldControl(XOFieldContext XOFieldContext)
 {
     return new System.Windows.Forms.TextBox();
 }
        /*
        protected override void OnSubscribeControllerEvents()
        {
        }
         */

        #region Custom field controls

        protected override object OnCreateCustomFieldControl(XOFieldContext AppFieldContext)
        {
            switch (AppFieldContext.SpecifiedControlType)
            {
                case "AutoRefCombo":
                case "LikeLookUpEdit":
                    return new XtraSearcherEditors.AutoRefComboSearchEdit(AppFieldContext);
            }

            return null;
        }
 internal void Reset(XOFieldContext FieldContext)
 {
     _fieldContext = FieldContext;
 }
        internal LikeLookUpEditDataProvider(IBindingListView BindingListView, XOFieldContext FieldContext)
        {
            _bindingListView = BindingListView;

            _fieldContex = FieldContext;
        }
        private static void CalculateFieldCalculator(DataAvail.XtraBindings.Calculator.ObjectProperties Item, XOFieldContext AppFieldContext)
        {
            object val = null;

            foreach (XOFieldCalculatorRouteRelation rel in AppFieldContext.Calculator.RouteRelations)
            {
                if (val == null)
                    val = Item.GetValue(AppFieldContext.Calculator.IssueField);

                if (val != System.DBNull.Value)
                {

                    string fillExr = string.Format("{0} = {1}", rel.KeyFieldForFill.Name, val);

                    if (!string.IsNullOrEmpty(rel.Filter))
                    {
                        fillExr = string.Format("{0} AND {1}", fillExr, rel.Filter);
                    }

                    val = DbContext.GetScalar("SELECT {0} FROM {1} WHERE {2}", rel.FieldForRetrieve.Name, rel.TableForFill.Source, fillExr);


                    if (val != null)
                    {
                        continue;
                    }
                }

                val = null;

                break;
            }

            if (val != null)
            {
                Item.SetValue(AppFieldContext.Name, val);
            }
            else
            {
                Item.SetValue(AppFieldContext.Name, System.DBNull.Value);
                Item.SetError(AppFieldContext.Name, "Can't evalute defiened calculator expresssion!");
            }
        }
 protected override object OnCreateComboboxFieldControl(XOFieldContext XOFieldContext)
 {
     return new System.Windows.Forms.ComboBox();
 }
 public LikeLookUpEdit(XOFieldContext XOFieldContext)
     : base(XOFieldContext)
 {}
        public FKCommandItemContext(XOFieldContext FieldContext, string Filter)
        {
            this.fieldContext = FieldContext;

            this.filter = Filter;
        }
        protected virtual object CreateFieldControl(XtraContainerBuilderControlType ControlType, XOFieldContext FieldContext)
        {
            switch (ControlType)
            {
                case XtraContainerBuilderControlType.Text:
                    return OnCreateTextFieldControl(FieldContext);
                case XtraContainerBuilderControlType.Numeric:
                    return OnCreateNumericFieldControl(FieldContext);
                case XtraContainerBuilderControlType.Date:
                    return OnCreateDateFieldControl(FieldContext);
                case XtraContainerBuilderControlType.Combo:
                    return OnCreateComboboxFieldControl(FieldContext);
                case XtraContainerBuilderControlType.Custom:
                    return OnCreateCustomFieldControl(FieldContext);
            }

            return null;
        }
        protected override object OnCreateCustomFieldControl(XOFieldContext AppFieldContext)
        {
            switch (AppFieldContext.SpecifiedControlType)
            { 
                case "TextBoxMultiLine":
                    return new DataAvail.DX.XtraEditors.MemoEdit(AppFieldContext);
                case "AutoRefCombo":
                case "LikeLookUpEdit":
                    return new DataAvail.DX.XtraEditors.AutoRefCombo(AppFieldContext);
                case "HoohlShmoohlEditor":
                    return new HoohlShmoohlEditor.HoohlShmoohlEditor();
            }

            return base.OnCreateCustomFieldControl(AppFieldContext);
        }
 protected virtual object OnCreateNumericFieldControl(XOFieldContext FieldContext)
 {
     return null;
 }
 protected virtual object OnCreateComboboxFieldControl(XOFieldContext FieldContext)
 {
     return null;
 }
 protected virtual object OnCreateCustomFieldControl(XOFieldContext FieldContext)
 {
     return null;
 }
 internal AutoRefComboDataProvider(XOFieldContext FieldContext)
 {
     _appFieldContext = FieldContext;
 }
        protected virtual XtraContainerBuilderControlType GetControlType(XOFieldContext FieldContext)
        {
            if (!string.IsNullOrEmpty(FieldContext.SpecifiedControlType))
                return XtraContainerBuilderControlType.Custom;

            if (FieldContext.FieldType == typeof(string))
            {
                return XtraContainerBuilderControlType.Text;
            }
            else if (FieldContext.FieldType == typeof(System.DateTime))
            {
                return XtraContainerBuilderControlType.Date;
            }
            else if (FieldContext.FieldType == typeof(int)
                || FieldContext.FieldType == typeof(long)
                || FieldContext.FieldType == typeof(double)
                || FieldContext.FieldType == typeof(decimal)
                || FieldContext.FieldType == typeof(float))
            {
                if (FieldContext.IsFkChildField)
                {
                    return XtraContainerBuilderControlType.Combo;
                }
                else
                {
                    return XtraContainerBuilderControlType.Numeric;
                }
            }
            else
            {
                return XtraContainerBuilderControlType.Custom;
            }
        }
            public object FkItemAction(XOFieldContext ChildFieldContext, object Value, bool ListSelector, string Filter)
            {

                XContext context = ListSelector ?
                    XContext.GetFkItemSelectContext(ChildFieldContext) :
                    XContext.GetFkAddItemContext(ChildFieldContext);


                //Select all Controllers, which parents relation's SeraializationName are the same.

                ItemSelectorController controller = Controller.controllerContext.Controllers.OfType<ItemSelectorController>()
                    .FirstOrDefault(p =>
                    p.TableContext.Context.GetType() == context.GetType() &&
                    ((XFkSelectItemContext)p.TableContext.Context).childFieldContext.ParentRelationTable ==
                    ChildFieldContext.ParentRelationTable &&
                    ((XFkSelectItemContext)p.TableContext.Context).childFieldContext.ParentRelation.SerializationName ==
                    ChildFieldContext.ParentRelation.SerializationName);

                if (controller == null)
                {
                    XOTableContext parTableContext = ChildFieldContext.ParentRelationTable.CreateTableContext(context);

                    ControllerDynamicContext dynamicContext = new ControllerDynamicContext(parTableContext);

                    controller = (ItemSelectorController)Controller.controllerContext.
                        AddController(parTableContext, (p, x) => new ItemSelectorController(p, dynamicContext));
                }
                else
                {
                    //Just switch coontext for the same table
                    ControllerDynamicContext dynamicContext = (ControllerDynamicContext)controller.DynamicContext;

                    XOTableContext appItemContext  = dynamicContext.GetAppItemContext(context);

                    if (appItemContext == null)
                    {
                        appItemContext = controller.TableContext.XOTable.CreateTableContext(context);

                        dynamicContext.AddAppItemContext(appItemContext, true);
                    }
                    else
                    {
                        dynamicContext.SetCurrentAppItemContext(appItemContext);
                    }
                }

                string totFilter = ChildFieldContext.ParentRelation.Filter;

                if (!string.IsNullOrEmpty(totFilter))
                {
                    if (!string.IsNullOrEmpty(Filter) && totFilter != Filter)
                        totFilter = string.Format("{0} AND {1}", totFilter, Filter);
                }
                else
                {
                    totFilter = Filter;
                }

                controller.SetDataSourceFilter(totFilter);

                if (ListSelector)
                    return controller.ShowAsItemSelector(Value);
                else
                    return controller.ShowAsAddItem(Value);
            }
        internal ControllerDataSource(Controller Controller, XOFieldContext XOFieldContext)
        {
            _controller = Controller;

            _xOFieldContext = XOFieldContext;
        }