Esempio n. 1
0
        /// <summary>
        /// Returns a Condition(Of T) which represents the criteria stored in the UserControl
        /// </summary>
        public DynamicCondition.DynamicQuery.Condition <T> GetCondition <T>(T dataSrc)
        {
            var pType = ((PropertyInfo)cmbColumn.SelectedItem).PropertyType;

            // CheckType ensures that T and T? are treated the same
            if (CheckType <bool>(pType))
            {
                return(MakeCond(dataSrc, pType, chkValue.Checked));
            }

            else if (CheckType <DateTime>(pType))
            {
                return(MakeCond(dataSrc, pType, dtpValue.Value));
            }
            else if (CheckType <char>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToChar(tbValue.Text)));
            }
            else if (CheckType <long>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt64(tbValue.Text)));
            }
            else if (CheckType <short>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt16(tbValue.Text)));
            }
            else if (CheckType <ulong>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt64(tbValue.Text)));
            }
            else if (CheckType <ushort>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt16(tbValue.Text)));
            }
            else if (CheckType <float>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToSingle(tbValue.Text)));
            }
            else if (CheckType <double>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToDouble(tbValue.Text)));
            }
            else if (CheckType <decimal>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToDecimal(tbValue.Text)));
            }
            else if (CheckType <int>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt32(SimulateVal.Val(tbValue.Text))));
            }
            else if (CheckType <uint>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt32(tbValue.Text)));
            }

            // This can only ever be String, since we filtered the types that we added to the ComboBox
            else
            {
                return(MakeCond(dataSrc, pType, tbValue.Text));
            }
        }
Esempio n. 2
0
    private static string Parse(long a, bool Female, string SingleName, string PluralName)
    {
        Map();
        string buf = a.ToString();

        buf = SimulateStrReverse.StrReverse(buf);
        int  index    = 0;
        bool negative = (buf[buf.Length - 1] == '-');
        long len      = negative ? buf.Length - 1 : buf.Length;

        string[] name      = new string[len];
        long     unitValue = 0;

        while (index < len)
        {
            var  n          = SimulateVal.Val(buf[index]);
            long decimalPos = index % 3;
            if (decimalPos == 0)
            {
                unitValue = (long)Math.Pow(10, index);
            }
            long decimalPlace = (long)Math.Pow(10, decimalPos);
            switch (decimalPlace)
            {
            case 1:
                if (unitValue > 1 && index + 1 == len)
                {
                    switch (n)
                    {
                    case 1:
                        name[index] = namesMap[unitValue] + "، ";
                        break;

                    case 2:
                        name[index] = namesMap[unitValue] + ("ان") + "، ";
                        break;

                    default:
                        name[index] = PluralNames(namesMap[n], unitValue) + "، ";
                        break;
                    }
                }
                else if (n < 3)
                {
                    if (Female && n == 2 && index == 0)
                    {
                        name[index] = TwoFemales;
                    }
                    else
                    {
                        name[index] = namesMap[n];
                    }
                }
                else
                {
                    name[index] = (Female && index < 3) ? namesMap[n].Substring(0, namesMap[n].Length - 1) : namesMap[n];
                }
                break;

            case 10:
                string tmp = name[index - 1];
                if (n == 1)
                {
                    if (tmp == One)
                    {
                        tmp = (Female && index < 3) ? Ehda : Ahad;
                    }
                    else if (tmp == Two || tmp == TwoFemales)
                    {
                        tmp = (Female && index < 3) ? Ethnta : Ethna;
                    }
                }

                if (unitValue > 1 && index + 1 == len)
                {
                    if (n == 1 && tmp == Zero)
                    {
                        name[index] = PluralNames(Ten, unitValue) + "، ";
                    }
                    else if (n == 1)
                    {
                        name[index] = Ten2 + " " + namesMap[unitValue] + "، ";
                    }
                    else
                    {
                        name[index] = namesMap[n * 10] + " " + namesMap[unitValue] + "، ";
                    }
                }
                else
                {
                    name[index] = namesMap[n * 10];
                    if (name[index - 1] == Zero)
                    {
                        if (n == 1 && Female && index < 3)
                        {
                            name[index] = Ten2;
                        }
                    }
                    else
                    {
                        if (n == 1 && !(Female && index < 3))
                        {
                            name[index] = Ten2;
                        }
                    }
                }

                if (n != 0)
                {
                    name[index - 1] = name[index];
                    name[index]     = tmp;
                }

                break;

            case 100:
                string s1 = null;
                if (n > 2)
                {
                    s1 = namesMap[n];
                    s1 = s1.Substring(0, s1.Length - (((n == 8) ? 2 : 1))) + Hundred;
                }
                else
                {
                    s1 = (n == 2) ? TwoHundreds : namesMap[n * 100];
                }
                if (unitValue > 1 && name[index - 2] != Zero)
                {
                    var X = (name[index - 2] == Ten2) ? Ten : name[index - 2];
                    foreach (var Elm in namesMap)
                    {
                        var val = Elm.Key;
                        if (namesMap[val] == X)
                        {
                            if (val > 2 && val < 10 || val == 10 && name[index - 1] == Zero)
                            {
                                name[index - 2] = PluralNames(name[index - 2], unitValue) + "، ";
                            }
                            else if (s1 == Zero && name[index - 1] == Zero)
                            {
                                if (val == 1)
                                {
                                    name[index - 2] = namesMap[unitValue] + "، ";
                                }
                                else if (val == 2)
                                {
                                    name[index - 2] = namesMap[unitValue] + "ان، ";
                                }
                                else
                                {
                                    name[index - 2] = name[index - 2] + " " + namesMap[unitValue] + "، ";
                                }
                            }
                            else
                            {
                                name[index - 2] = name[index - 2] + " " + namesMap[unitValue] + "، ";
                            }
                            break;
                        }
                    }
                }
                else if (unitValue > 1 && n != 0)
                {
                    if (s1 == TwoHundreds)
                    {
                        s1 = s1.TrimEnd('ن');
                    }
                    s1 += " " + namesMap[unitValue] + "،";
                }

                name[index] = s1;

                break;
            }
            index += 1;
        }

        string s = "";

        for (long c = 0; c < len; c++)
        {
            if (name[c] == Zero)
            {
                continue;
            }
            if (Female && c == 0 && name[c] == One)
            {
                name[c] = OneFemale;
            }
            name[c] = name[c].Trim();
            if (s != "" && !((s.StartsWith(Ten2 + " ") || s.StartsWith(Ten)) && (!(name[c - 1] == Zero))))
            {
                if (c > 0)
                {
                    var X = name[c].Split(' ');
                    if (X.Length > 0)
                    {
                        switch (X[0])
                        {
                        case Ten2:
                        case Twenty:
                        case Thirty:
                        case Fourty:
                        case Fifty:
                        case Sixty:
                        case Seventy:
                        case Eighty:
                        case Ninety:
                            name[c] += "ا";
                            break;
                        }
                    }
                }
                s = name[c] + " و" + s;
            }
            else
            {
                s = name[c] + " " + s;
            }
        }

        s = "(" + s.Trim().Trim('،').Replace("،ا ", "ا، ") + ")";
        if (SingleName != "" && PluralName != "")
        {
            long N = 0;
            var  X = a.ToString();
            if (X.Length < 2)
            {
                N = a;
            }
            else
            {
                N = System.Convert.ToInt64(X.Substring(X.Length - 2, 2));
            }

            if (N == 0)
            {
                if (a > 0)
                {
                    if (s.EndsWith("ان" + ")"))
                    {
                        s = s.TrimEnd(')').TrimEnd('ن') + ")";
                    }
                    s += " " + SingleName;
                }
            }
            else if (N < 11)
            {
                switch (name[0])
                {
                case Zero:

                    break;

                case One:
                case OneFemale:
                    if (a == 1)
                    {
                        s = SingleName + " " + name[0];
                    }
                    else
                    {
                        s += " من ال" + PluralName;
                    }
                    break;

                case Two:
                case TwoFemales:
                    if (a == 2)
                    {
                        SingleName = SingleName.Replace("ة", "ت");
                        s          = SingleName + "ان " + name[0];
                    }
                    else
                    {
                        s += " من ال" + PluralName;
                    }
                    break;

                default:
                    s += " " + PluralName;
                    break;
                }
            }
            else
            {
                s += " " + SingleName + (SingleName.EndsWith("ة") ? "" : "ا");
            }
        }

        return((s == "") ? Zero : ((negative ? "سالب " + s : s)).Trim());
    }
Esempio n. 3
0
        /// <summary>
        /// 返回 Condition(Of T),它表示了存储在 UserControl 控件中的条件.
        /// </summary>
        public DynamicCondition.DynamicQuery.Condition <T> GetCondition <T>(T dataSrc)
        {
            var pType = ((PropertyInfo)cmbColumn.SelectedItem).PropertyType;

            //  CheckType 确保 T 和 T? 被同样对待.
            if (CheckType <bool>(pType))
            {
                return(MakeCond(dataSrc, pType, chkValue.Checked));
            }

            else if (CheckType <DateTime>(pType))
            {
                return(MakeCond(dataSrc, pType, dtpValue.Value));
            }
            else if (CheckType <char>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToChar(tbValue.Text)));
            }
            else if (CheckType <long>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt64(tbValue.Text)));
            }
            else if (CheckType <short>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt16(tbValue.Text)));
            }
            else if (CheckType <ulong>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt64(tbValue.Text)));
            }
            else if (CheckType <ushort>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt16(tbValue.Text)));
            }
            else if (CheckType <float>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToSingle(tbValue.Text)));
            }
            else if (CheckType <double>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToDouble(tbValue.Text)));
            }
            else if (CheckType <decimal>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToDecimal(tbValue.Text)));
            }
            else if (CheckType <int>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToInt32(SimulateVal.Val(tbValue.Text))));
            }
            else if (CheckType <uint>(pType))
            {
                return(MakeCond(dataSrc, pType, Convert.ToUInt32(tbValue.Text)));
            }

            // 这只能是字符串,因为我们筛选了添加到复合框中的类型.
            else
            {
                return(MakeCond(dataSrc, pType, tbValue.Text));
            }
        }