Exemplo n.º 1
0
        /// <summary>
        /// Parametrized Constructor for Edit functionality.
        /// </summary>
        /// <param name="editMode"></param>
        /// <param name="item"></param>
        public ConditionalAssign(bool editMode, ListBoxItemSource item)
        {
            InitializeComponent();
            this.editMode = editMode;
            SelectedItem  = item;
            FillConditionalComboboxes();
            EwavRule_ConditionalAssign ca = (EwavRule_ConditionalAssign)SelectedItem.Rule;

            txtDestinationField.IsEnabled = false;
            cbxFieldType.SelectedIndex    = SearchColumnIndex(cbxFieldType.Items, ca.CbxFieldType.ToString());
            cbxFieldType.IsEnabled        = false;

            switch (cbxFieldType.SelectedValue.ToString().ToUpper().Replace("/", ""))
            {
            case "YESNO":
                cmbAssignValue.SelectedIndex = SearchColumnIndex(cmbAssignValue.Items, (ca.AssignValue == "True") ? "Yes" : "No");
                if (ca.ElseValue.Length > 0)
                {
                    cmbElseValue.SelectedIndex = SearchColumnIndex(cmbElseValue.Items, (ca.ElseValue == "True") ? "Yes" : "No");
                }

                if (cmbElseValue.SelectedIndex > 0)
                {
                    checkboxUseElse.IsChecked = true;
                }
                break;

            default:
                txtAssignValue.Text = ca.AssignValue;
                txtElseValue.Text   = ca.ElseValue;
                if (ca.ElseValue.Length > 0)
                {
                    checkboxUseElse.IsChecked = true;
                }
                break;
            }

            if (checkboxUseElse.IsChecked == true)
            {
                txtElseValue.IsEnabled = true;
            }
            else
            {
                txtElseValue.IsEnabled = false;
            }

            txtDestinationField.Text = ca.TxtDestination;

            //FillSelectionComboboxes();

            pnlGuidedMode.Visibility = System.Windows.Visibility.Visible;
            //pnlBtns.Visibility = System.Windows.Visibility.Visible;
            pnlAdvancedMode.Visibility = System.Windows.Visibility.Collapsed;
            pnlContainer.Visibility    = System.Windows.Visibility.Visible;

            //ctrl = new EwavFilterControl();
            FilterCtrl.FilterType = FilterControlType.Conditional;
            FilterCtrl.ConstructStackPanelFromDataFilters(((EwavRule_ConditionalAssign)SelectedItem.Rule).ConditionsList);
        }
Exemplo n.º 2
0
        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            FilterCtrl.Clear();
            FilterCtrl.CreateFilterConditionRow();

            GadgetFilters = null;

            this.DialogResult = true;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Validates the controls.
        /// </summary>
        /// <param name="stackPanel"></param>
        /// <returns></returns>
        public Boolean ValidateControl()
        {
            if (txtDestinationField.Text == "")
            {
                MessageBox.Show("Source Column is empty.");
                return(false);
            }

            return(FilterCtrl.ValidateControl());
        }
Exemplo n.º 4
0
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            List <EwavDataFilterCondition> DFilters = FilterCtrl.CreateDataFilters();

            if (DFilters == null)
            {
                return;
            }
            GadgetFilters = DFilters;

            this.DialogResult = true;
        }
Exemplo n.º 5
0
 //EwavFilterControl ctrl;
 //EwavFilter UserControl;
 /// <summary>
 /// Default Constructor
 /// </summary>
 public ConditionalAssign()
 {
     InitializeComponent();
     if (this.applicationViewModel.EwavSelectedDatasource.AllColumns != null)
     {
         FilterCtrl.FilterType = FilterControlType.Conditional;
         FilterCtrl.InitializeDataFilter();
     }
     FillConditionalComboboxes();
     txtElseValue.IsEnabled = false;
     cmbElseValue.IsEnabled = false;
 }
Exemplo n.º 6
0
 public GadgetFilterControl(List <EwavDataFilterCondition> Conditions)
 {
     InitializeComponent();
     FilterCtrl.FilterType = FilterControlType.DataFilter;
     FilterCtrl.ConstructStackPanelFromDataFilters(Conditions);
 }
Exemplo n.º 7
0
 public GadgetFilterControl()
 {
     InitializeComponent();
     FilterCtrl.FilterType = FilterControlType.DataFilter;
     FilterCtrl.InitializeDataFilter();
 }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            List <ListBoxItemSource> TempList = applicationViewModel.ListOfRules.Where(t => t.DestinationColumn.ToLower() == txtDestinationField.Text.ToLower()).ToList();

            Boolean columnNameExists = false;

            columnNameExists = applicationViewModel.EwavSelectedDatasource.AllColumns.Any(c => c.Name.ToLower() == txtDestinationField.Text.ToLower());

            //if ((TempList.Count > 0 && !editMode) || columnNameExists)
            //{
            //    MessageBox.Show("Variable name already exists.");
            //    return;
            //}


            if (ValidateControl())
            {
                List <EwavDataFilterCondition> listOfFilters = FilterCtrl.CreateDataFilters();

                string destinationColumnType = "System.String";

                ColumnDataType colType = ColumnDataType.Text;

                object           elseValue   = this.txtElseValue.Text;
                object           assignValue = this.txtAssignValue.Text;
                cbxFieldTypeEnum fieldEnum   = cbxFieldTypeEnum.None;
                switch (cbxFieldType.SelectedItem.ToString())
                {
                case "Yes/No":
                    destinationColumnType = "System.Boolean";
                    if (cmbAssignValue.SelectedIndex == 0)
                    {
                        assignValue = true;
                    }
                    else if (cmbAssignValue.SelectedIndex == 1)
                    {
                        assignValue = false;
                    }

                    if (checkboxUseElse.IsChecked == false)
                    {
                        elseValue = "";
                    }
                    else if (cmbElseValue.SelectedIndex == 0)
                    {
                        elseValue = true;
                    }
                    else if (cmbElseValue.SelectedIndex == 1)
                    {
                        elseValue = false;
                    }
                    fieldEnum = cbxFieldTypeEnum.YesNo;
                    colType   = ColumnDataType.Boolean;
                    break;

                case "Text":
                    destinationColumnType = "System.String";
                    if (checkboxUseElse.IsChecked == false)
                    {
                        elseValue = "";
                    }
                    else
                    {
                        elseValue = this.txtElseValue.Text;
                    }

                    assignValue = this.txtAssignValue.Text;
                    fieldEnum   = cbxFieldTypeEnum.Text;
                    colType     = ColumnDataType.Text;
                    break;

                case "Numeric":
                    destinationColumnType = "System.Decimal";
                    decimal decElse;
                    decimal decAssign;
                    if (checkboxUseElse.IsChecked == false)
                    {
                        elseValue = "";
                    }
                    else
                    {
                        bool success1 = Decimal.TryParse(this.txtElseValue.Text, out decElse);
                        if (success1)
                        {
                            elseValue = decElse;
                        }
                    }

                    bool success2 = Decimal.TryParse(this.txtAssignValue.Text, out decAssign);
                    if (success2)
                    {
                        assignValue = decAssign;
                    }

                    //if ((!success1 && checkboxUseElse.IsChecked) || !success2)
                    //{
                    //    Epi.Windows.MsgBox.ShowError("Invalid input detected.");
                    //    this.DialogResult = DialogResult.None;
                    //    return;
                    //}
                    fieldEnum = cbxFieldTypeEnum.Numeric;
                    colType   = ColumnDataType.Numeric;
                    break;
                }

                string assignText = FilterCtrl.ConditionText.ToString().Substring(0, FilterCtrl.ConditionText.Length - 3);

                if (checkboxUseElse.IsChecked == true)
                {
                    assignText += ". Otherwise, assign " + txtDestinationField.Text + " the value " + elseValue + ".";
                }
                //conditionText = (

                ListBoxItemSource listBoxItem = new ListBoxItemSource();
                listBoxItem.RuleString        = "Assign " + txtDestinationField.Text + " the value " + assignValue + " when " + assignText;
                listBoxItem.SourceColumn      = null;
                listBoxItem.DestinationColumn = txtDestinationField.Text;
                listBoxItem.RuleType          = EwavRuleType.conditional;

                EwavRule_ConditionalAssign rule = new EwavRule_ConditionalAssign();
                rule.TxtDestination        = txtDestinationField.Text;
                rule.DestinationColumnType = destinationColumnType;
                rule.AssignValue           = assignValue.ToString();
                rule.ElseValue             = elseValue.ToString();
                rule.ConditionsList        = listOfFilters;
                rule.CbxFieldType          = fieldEnum;
                rule.VaraiableName         = txtDestinationField.Text;
                rule.VaraiableDataType     = colType.ToString();

                MyString tempStr = new MyString();
                tempStr.VarName   = "Assign " + txtDestinationField.Text + " the value " + assignValue + " when " + assignText;
                rule.FriendlyRule = tempStr;

                EwavColumn newColumn = new EwavColumn();
                newColumn.Name = txtDestinationField.Text;
                newColumn.SqlDataTypeAsString = colType;// ColumnDataType.Text;
                newColumn.NoCamelName         = txtDestinationField.Text;
                newColumn.IsUserDefined       = true;

                applicationViewModel.InvokePreColumnChangedEvent();



                List <EwavRule_Base> rules = new List <EwavRule_Base>();
                rules            = applicationViewModel.EwavDefinedVariables;
                listBoxItem.Rule = rule;
                //listBoxItem.FilterConditionsPanel = pnlContainer;

                //Shows the error message if name already exists.
                if (!editMode)
                {
                    for (int i = 0; i < applicationViewModel.EwavDefinedVariables.Count; i++)
                    {
                        if (applicationViewModel.EwavDefinedVariables[i].VaraiableName == rule.VaraiableName)
                        {
                            MessageBox.Show("Rule Name already exists. Select another name.");
                            return;
                        }
                    }
                }

                for (int i = 0; i < rules.Count; i++)
                {
                    if (rule.TxtDestination == rules[i].VaraiableName)
                    {
                        rules[i] = rule;
                        //applicationViewModel.ListOfRules.RemoveAt(i);
                        applicationViewModel.ListOfRules[i] = listBoxItem;
                        break;
                    }
                }

                if (!editMode)
                {
                    applicationViewModel.EwavSelectedDatasource.AllColumns.Add(newColumn);
                    applicationViewModel.ListOfRules.Add(listBoxItem);
                    rules.Add(rule);
                }

                applicationViewModel.EwavDefinedVariables = rules;

                this.DialogResult = true;
            }
        }