Пример #1
0
 public SearchPanelDataBinder(IObject currentObject, LinkedContent linkedContent, BaseSearchPanel searchPanel)
 {
     obj = currentObject;
     this.linkedContent        = linkedContent;
     m_searchPanel             = searchPanel;
     this.obj.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(PropertyChanged);
 }
Пример #2
0
        /// <summary>
        /// Get FilterParams by linked content
        /// </summary>
        /// <param name="linkedContent"></param>
        /// <returns></returns>
        public static FilterParams GetFilterParams(IObject obj, LinkedContent linkedContent)
        {
            var filterParams = new FilterParams();

            var notComboboxLinkedContext = linkedContent.m_LinkedItems.Where(s => s.MetaItem.Location != SearchPanelLocation.Combobox && s.MetaItem.Location != SearchPanelLocation.Toolbox);
            var comboboxLinkedContext    = linkedContent.m_LinkedItems.Where(s => s.MetaItem.Location == SearchPanelLocation.Combobox || s.MetaItem.Location == SearchPanelLocation.Toolbox);

            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Text))
            {
                string valText = control.Controls.First().Text == null ? null : control.Controls.First().Text.Trim();
                if (!String.IsNullOrEmpty(valText))
                {
                    filterParams.Add(control.MetaItem.Name, Utils.IsEmpty(control.MetaItem.DefaultOper) ? "Like" : control.MetaItem.DefaultOper, valText);
                }
                else if (control.MetaItem.Mandatory(obj))
                {
                    throw new ValidationModelException("strSearchPanelMandatoryFields_msgId", control.MetaItem.Name, control.MetaItem.Name, null, typeof(RequiredValidator), ValidationEventType.Error, obj);
                }
            }
            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Numeric).Where(
                    f => f.MetaItem.IsRange == false) /*.Where(d => !string.IsNullOrWhiteSpace(d.Controls.First().Text))*/)
            {
                if (!control.Controls.First().Visible)
                {
                    object val = obj.GetValue(control.MetaItem.Name);
                    if (val != null)
                    {
                        filterParams.Add(control.MetaItem.Name, Utils.IsEmpty(control.MetaItem.DefaultOper) ? "=" : control.MetaItem.DefaultOper, val, EditorType.Numeric);
                    }
                }
                if (!Utils.IsEmpty(control.Controls.First().EditValue))
                {
                    filterParams.Add(control.MetaItem.Name, Utils.IsEmpty(control.MetaItem.DefaultOper) ? "=" : control.MetaItem.DefaultOper, control.Controls.First().Text, EditorType.Numeric);
                }
            }

            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Numeric).Where(f => f.MetaItem.IsRange))
            {
                List <BaseEdit> contr = control.Controls.ToList();
                if (!Utils.IsEmpty(contr[0].EditValue))
                {
                    filterParams.Add(control.MetaItem.Name, ">=", contr[0].Text, EditorType.Numeric);
                }
                if (!Utils.IsEmpty(contr[1].EditValue))
                {
                    filterParams.Add(control.MetaItem.Name, "<=", contr[1].Text, EditorType.Numeric);
                }
            }

            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Date).Where(
                    f => f.MetaItem.IsRange == false).Where(d => !string.IsNullOrWhiteSpace(d.Controls.First().Text)))
            {
                if (!Utils.IsEmpty(control.Controls.First().EditValue))
                {
                    var start = control.Controls.First().EditValue as DateTime?;
                    if (start.HasValue)
                    {
                        filterParams.Add(control.MetaItem.Name,
                                         string.IsNullOrEmpty(control.MetaItem.DefaultOper) ? "=" : control.MetaItem.DefaultOper,
                                         start.Value, EditorType.Date);
                    }
                }
            }
            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Date).Where(f => f.MetaItem.IsRange))
            {
                List <BaseEdit> contr = control.Controls.ToList();

                bool bStart = false;
                var  start  = contr[0].EditValue as DateTime?;
                if (start.HasValue)
                {
                    filterParams.Add(control.MetaItem.Name, ">=", start.Value, EditorType.Date);
                    bStart = true;
                }
                bool bEnd = false;
                var  end  = contr[1].EditValue as DateTime?;
                if (end.HasValue)
                {
                    filterParams.Add(control.MetaItem.Name, "<", end.Value.AddDays(1), EditorType.Date);
                    bEnd = true;
                }

                if (control.MetaItem.Mandatory(obj) && (!bStart || !bEnd))
                {
                    throw new ValidationModelException("strSearchPanelMandatoryFields_msgId", control.MetaItem.Name, control.MetaItem.Name, null, typeof(RequiredValidator), ValidationEventType.Error, obj);
                }
            }
            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Lookup && !f.MetaItem.IsMultiple))
            {
                var cntrl           = (control.Controls.First() as LookUpEdit);
                var lookUpEditValue = cntrl.EditValue as IObject;
                //if (!Utils.IsEmpty(lookUpEditValue))
                if (lookUpEditValue != null)
                {
                    if ((long)lookUpEditValue.Key != 0)
                    {
                        filterParams.Add(control.MetaItem.Name, "=", lookUpEditValue.Key);
                    }
                }
                else if (!Utils.IsEmpty(cntrl.EditValue))   //This is the case of Case_Status lookup, we use custom values for it
                {
                    filterParams.Add(control.MetaItem.Name, "=", cntrl.EditValue);
                }
            }
            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Lookup && f.MetaItem.IsMultiple))
            {
                var cntrl     = (control.Controls.First() as PopupContainerEdit);
                var container = cntrl.Properties.PopupControl;
                var list      = container.Controls[0] as CheckedListBoxControl;
                foreach (var i in list.CheckedItems)
                {
                    var o = i as IObject;
                    if (o == null)
                    {
                        continue;
                    }
                    if (0L.Equals(o.Key))
                    {
                        continue;
                    }
                    if (control.MetaItem.IsBitMask)
                    {
                        filterParams.Add(control.MetaItem.Name, "&", o.Key, true);
                    }
                    else
                    {
                        filterParams.Add(control.MetaItem.Name, "=", o.Key, true);
                    }
                }
            }


            foreach (
                var control in
                comboboxLinkedContext.Where(f => f.MetaItem.IsMultiple))
            {
                var cntrl     = (control.Controls.ToArray()[2] as PopupContainerEdit);
                var container = cntrl.Properties.PopupControl;
                var list      = container.Controls[0] as CheckedListBoxControl;
                foreach (var i in list.CheckedItems)
                {
                    var o = i as IObject;
                    if (o == null)
                    {
                        continue;
                    }
                    if (0L.Equals(o.Key))
                    {
                        continue;
                    }
                    if (control.MetaItem.IsBitMask)
                    {
                        filterParams.Add(control.MetaItem.Name, "&", o.Key, true);
                    }
                    else
                    {
                        filterParams.Add(control.MetaItem.Name, "=", o.Key, true);
                    }
                }
            }

            foreach (
                var control in
                comboboxLinkedContext.Where(f => !f.MetaItem.IsMultiple))
            {
                var    controlWithValue = control.Controls.ToArray()[2] as BaseEdit;
                var    condition        = control.MetaItem.IsRange ? ">=" : control.Controls.ToArray()[1].EditValue.ToString();
                object value            = null;

                if (controlWithValue.Controls.Count == 4) // panel with range controls
                {
                    var cnt1 = controlWithValue.Controls[1];
                    var cnt2 = controlWithValue.Controls[3];
                    if (cnt1 is DateEdit)
                    {
                        value = (cnt1 as DateEdit).EditValue;
                        if (!Utils.IsEmpty(value))
                        {
                            filterParams.Add(control.MetaItem.Name, ">=", value);
                        }
                    }
                    if (cnt2 is DateEdit)
                    {
                        value = (cnt2 as DateEdit).EditValue;
                        if (!Utils.IsEmpty(value))
                        {
                            filterParams.Add(control.MetaItem.Name, "<=", value);
                        }
                    }
                }

                if (!Utils.IsEmpty(controlWithValue.EditValue) && !String.IsNullOrWhiteSpace(condition))
                {
                    if (controlWithValue is LookUpEdit)
                    {
                        //value = (controlWithValue as LookUpEdit).EditValue;
                        var lookUpEditValue = (controlWithValue as LookUpEdit).EditValue as IObject;
                        if (lookUpEditValue != null)
                        {
                            value = lookUpEditValue.Key;
                        }
                    }
                    else if (controlWithValue is DateEdit)
                    {
                        value = (controlWithValue as DateEdit).EditValue;
                    }
                    else
                    {
                        if (control.Controls.ToArray()[1].Text != "Like")
                        {
                            value = controlWithValue.Text;
                        }
                        else
                        {
                            value = controlWithValue.Text;
                        }
                    }

                    filterParams.Add(control.MetaItem.Name, condition, value); //  as ListControl));
                }
            }
            foreach (
                var control in
                notComboboxLinkedContext.Where(f => f.MetaItem.EditorType == EditorType.Flag))
            {
                //for null values if needed
                var flag = (control.Controls.First() as CheckEdit);
                filterParams.Add(control.MetaItem.Name, "=", flag.Checked?1:0);
            }
            return(filterParams);
        }