Пример #1
0
 static string GetDebugInfo(ColumnDataType datatype,
                            object o1,
                            object o2)
 {
     return("datatype=" + datatype.ToString()
            + ",o1=" + (o1 == null ? "<null>" : o1.GetType().ToString())
            + ",o2=" + (o2 == null ? "<null>" : o2.GetType().ToString()));
 }
Пример #2
0
        object AddValue(ColumnDataType datatype,
object o1,
object o2)
        {
            if (o1 == null && o2 == null)
                return null;
            if (o1 == null)
                return o2;
            if (o2 == null)
                return o1;
            if (datatype == ColumnDataType.Auto)
            {
                if (o1 is Int64)
                    return (Int64)o1 + (Int64)o2;
                if (o1 is Int32)
                    return (Int32)o1 + (Int32)o2;
                if (o1 is double)
                {
#if NO
                    if (o2 is long)
                    {
                        return (double)o1 + Convert.ToDouble(o2);
                    }
                    return (double)o1 + (double)o2;
#endif
                    return (double)o1 + Convert.ToDouble(o2);
                }
                if (o1 is decimal)
                    return (decimal)o1 + (decimal)o2;
                if (o1 is string)
                    return (string)o1 + (string)o2;

                throw new Exception("无法支持的 Auto 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.Number)
            {
                if (o1 is Int64)
                    return (Int64)o1 + (Int64)o2;
                if (o1 is Int32)
                    return (Int32)o1 + (Int32)o2;
                if (o1 is double)
                    return (double)o1 + (double)o2;
                if (o1 is decimal)
                    return (decimal)o1 + (decimal)o2;
                if (o1 is string)   // 2015/7/16
                {
                    Int64 v1 = 0;
                    Int64 v2 = 0;
                    Int64.TryParse(o1 as string, out v1);
                    Int64.TryParse(o2 as string, out v2);
                    return (v1 + v2).ToString();
                }

                throw new Exception("无法支持的 Number 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.String)
            {
                if (o1 is string)
                    return (string)o1 + (string)o2;

                throw new Exception("无法支持的 String 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.Price) // 100倍金额整数
            {
                return (Int64)o1 + (Int64)o2;
            }
            if (datatype == ColumnDataType.PriceDouble)  // double,用来表示金额。也就是最多只有两位小数部分 -- 注意,有累计误差问题,以后建议废止
            {
                return (double)o1 + (double)o2;
            }
            if (datatype == ColumnDataType.PriceDecimal) // decimal,用来表示金额。
            {
                return (decimal)o1 + (decimal)o2;
            }
            if (datatype == ColumnDataType.Currency)
            {
#if NO
                // 这一句容易发现列 数据类型 的错误
                return PriceUtil.JoinPriceString((string)o1,
                    (string)o2);
#endif
                return PriceUtil.Add((string)o1,
                    (string)o2);
#if NO
                // 这一句更健壮一些
                return PriceUtil.JoinPriceString(Convert.ToString(o1),
                    Convert.ToString(o2));
#endif
            }
            throw new Exception("无法支持的 " + datatype.ToString() + " 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
        }
Пример #3
0
        object AddValue(ColumnDataType datatype,
                        object o1,
                        object o2)
        {
            if (o1 == null && o2 == null)
            {
                return(null);
            }
            if (o1 == null)
            {
                return(o2);
            }
            if (o2 == null)
            {
                return(o1);
            }
            if (datatype == ColumnDataType.Auto)
            {
                if (o1 is Int64)
                {
                    return((Int64)o1 + Convert.ToInt64(o2)); // 2016/11/24
                }
                if (o1 is Int32)
                {
                    return((Int32)o1 + (Int32)o2);
                }
                if (o1 is double)
                {
#if NO
                    if (o2 is long)
                    {
                        return((double)o1 + Convert.ToDouble(o2));
                    }
                    return((double)o1 + (double)o2);
#endif
                    return((double)o1 + Convert.ToDouble(o2));
                }
                if (o1 is decimal)
                {
                    return((decimal)o1 + (decimal)o2);
                }
                if (o1 is string)
                {
                    return((string)o1 + (string)o2);
                }

                throw new Exception("无法支持的 Auto 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.Number)
            {
                if (o1 is Int64)
                {
                    return((Int64)o1 + (Int64)o2);
                }
                if (o1 is Int32)
                {
                    return((Int32)o1 + (Int32)o2);
                }
                if (o1 is double)
                {
                    return((double)o1 + (double)o2);
                }
                if (o1 is decimal)
                {
                    return((decimal)o1 + (decimal)o2);
                }
                if (o1 is string)   // 2015/7/16
                {
                    Int64 v1 = 0;
                    Int64 v2 = 0;
                    Int64.TryParse(o1 as string, out v1);
                    Int64.TryParse(o2 as string, out v2);
                    return((v1 + v2).ToString());
                }

                throw new Exception("无法支持的 Number 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.String)
            {
                if (o1 is string)
                {
                    return((string)o1 + (string)o2);
                }

                throw new Exception("无法支持的 String 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
            }
            if (datatype == ColumnDataType.Price) // 100倍金额整数
            {
                return((Int64)o1 + (Int64)o2);
            }
            if (datatype == ColumnDataType.PriceDouble)  // double,用来表示金额。也就是最多只有两位小数部分 -- 注意,有累计误差问题,以后建议废止
            {
                return((double)o1 + (double)o2);
            }
            if (datatype == ColumnDataType.PriceDecimal) // decimal,用来表示金额。
            {
                return((decimal)o1 + (decimal)o2);
            }
            if (datatype == ColumnDataType.Currency)
            {
#if NO
                // 这一句容易发现列 数据类型 的错误
                return(PriceUtil.JoinPriceString((string)o1,
                                                 (string)o2));
#endif
                return(PriceUtil.Add((string)o1,
                                     (string)o2));

#if NO
                // 这一句更健壮一些
                return(PriceUtil.JoinPriceString(Convert.ToString(o1),
                                                 Convert.ToString(o2)));
#endif
            }
            throw new Exception("无法支持的 " + datatype.ToString() + " 类型累加 o1 type=" + o1.GetType().ToString() + ", o2 type=" + o2.GetType().ToString());
        }
Пример #4
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;
            }
        }