public override void ApplyValue(Dictionary <string, object> item, object state)
        {
            Money money = new Money((decimal)NumberEx.Parse((string)state, numberFormatInfo));

            item[_args.Column.Field] = money;
            this.RaiseOnChange(item);
        }
Example #2
0
        private static NumberFormatInfo GetNumberFormatInfo(Func <System.Collections.Dictionary> allBindingsAccessor)
        {
            NumberFormatInfo format = NumberEx.GetNumberFormatInfo();

            format.Precision = int.Parse((string)allBindingsAccessor()["precision"]);


            if ((Number)allBindingsAccessor()["minvalue"] == null)
            {
                format.MinValue = -2147483648;
            }
            else
            {
                format.MinValue = (Number)allBindingsAccessor()["minvalue"];
            }

            if ((Number)allBindingsAccessor()["maxvalue"] == null)
            {
                format.MaxValue = 2147483647;
            }
            else
            {
                format.MaxValue = (Number)allBindingsAccessor()["maxvalue"];
            }
            return(format);
        }
        public static Column BindReadOnlyColumn(Column column)
        {
            column.Formatter = Formatter;
            NumberFormatInfo numberFormatInfo = NumberEx.GetCurrencyEditFormatInfo();

            column.Options = numberFormatInfo;
            return(column);
        }
        public static string getCurrencySymbol(EntityReference currencyid)
        {
            if (currencyid != null && currencyid.Id != null && currencyid.Id.Value != null)
            {
                return(NumberEx.GetCurrencySymbol(currencyid.Id));
            }

            return(string.Empty);
        }
        public static Column BindReadOnlyColumn(Column column, int precision)
        {
            column.Formatter = XrmNumberEditor.Formatter;
            NumberFormatInfo numberFormatInfo = NumberEx.GetNumberFormatInfo();

            numberFormatInfo.Precision = precision;
            column.Options             = numberFormatInfo;
            return(column);
        }
        public static Column BindColumn(Column column, int minValue, int maxValue)
        {
            column.Editor    = MoneyEditor;
            column.Formatter = Formatter;
            NumberFormatInfo numberFormatInfo = NumberEx.GetCurrencyEditFormatInfo();

            numberFormatInfo.MinValue = minValue;
            numberFormatInfo.MaxValue = maxValue;
            column.Options            = numberFormatInfo;
            return(column);
        }
        public static string getCurrencySymbol(Func <object> valueAccessor)
        {
            EntityReference value = (EntityReference)KnockoutUtils.UnwrapObservable(valueAccessor());

            if (value != null)
            {
                return(NumberEx.GetCurrencySymbol(value.Id));
            }

            return(string.Empty);
        }
Example #8
0
 private static string FormatNumber(Money value, NumberFormatInfo format)
 {
     if (value != null)
     {
         return(NumberEx.Format(value.Value, format));
     }
     else
     {
         return(String.Empty);
     }
 }
 // Formatter to format number
 public static string Formatter(int row, int cell, object value, Column columnDef, object dataContext)
 {
     if (value != null)
     {
         Number numeric = (Number)value;
         return(NumberEx.Format(numeric, (NumberFormatInfo)columnDef.Options));
     }
     else
     {
         return("");
     }
 }
        public override void LoadValue(Dictionary <string, object> item)
        {
            defaultValue = NumberEx.Format((Number)item[_args.Column.Field], numberFormatInfo);

            if (defaultValue == null)
            {
                defaultValue = "";
            }
            input.Value(defaultValue);
            input[0].SetAttribute("defaultValue", defaultValue);
            input.Select();
        }
        public static Column BindColumn(Column column, int minValue, int maxValue, int precision)
        {
            column.Editor    = NumberEditor;
            column.Formatter = XrmNumberEditor.Formatter;
            NumberFormatInfo numberFormatInfo = NumberEx.GetNumberFormatInfo();

            numberFormatInfo.MinValue  = minValue;
            numberFormatInfo.MaxValue  = maxValue;
            numberFormatInfo.Precision = precision;
            column.Options             = numberFormatInfo;
            return(column);
        }
 // Formatter to format number
 public static string Formatter(int row, int cell, object value, Column columnDef, object dataContext)
 {
     if (value != null)
     {
         string currencySymbol = getCurrencySymbol((EntityReference)((EntityBuiltInAttributes)dataContext).TransactionCurrencyId);
         Money  numeric        = (Money)value;
         return(currencySymbol + " " + NumberEx.Format(numeric.Value, (NumberFormatInfo)columnDef.Options));
     }
     else
     {
         return("");
     }
 }
Example #13
0
        public bool NumberParse()
        {
            NumberFormatInfo format = new NumberFormatInfo();

            format.DecimalSymbol  = ",";
            format.NumberSepartor = ".";
            Script.Literal("debugger");
            Number value1 = NumberEx.Parse("22,10", format);

            Assert.AreEqual(value1, 22.10);

            Number value2 = NumberEx.Parse("1.022,10", format);

            Assert.AreEqual(value2, 1022.10);

            return(true);
        }
        public override void LoadValue(Dictionary <string, object> item)
        {
            // Get currency symbol
            string currencySymbolString = getCurrencySymbol((EntityReference)((EntityBuiltInAttributes)((object)item)).TransactionCurrencyId);

            currencySymbol.Text(currencySymbolString + " ");
            Money value = (Money)item[_args.Column.Field];

            defaultValue = "";
            if (value != null)
            {
                defaultValue = NumberEx.Format(value.Value, numberFormatInfo);
            }

            input.Value(defaultValue);
            input[0].SetAttribute("defaultValue", defaultValue);
            input.Select();
        }
Example #15
0
        private static void TrySetObservable(Func <object> valueAccessor, jQueryObject inputField, string value, NumberFormatInfo format)
        {
            Observable <Money> observable = (Observable <Money>)valueAccessor();
            bool isValid = true;


            Number numericValue = NumberEx.Parse(value, format);

            if (!Number.IsNaN(numericValue) && numericValue >= format.MinValue && numericValue <= format.MaxValue)
            {
                Money newValue = null;
                if (numericValue != null) // Issue #46
                {
                    // Set to precision
                    numericValue = NumberEx.Round(numericValue, format.Precision);
                    newValue     = new Money((decimal)numericValue);
                }

                observable.SetValue(newValue);

                if (((string)Script.Literal("typeof({0}.isValid)", observable)) != "undefined")
                {
                    isValid = ((IValidatedObservable)observable).IsValid() == true;
                }

                if (isValid)
                {
                    string formattedNumber = FormatNumber(newValue, format);
                    inputField.Value(formattedNumber);
                    inputField.Blur();
                }
            }
            else
            {
                Script.Alert(String.Format("You must enter a number between {0} and {1}", format.MinValue, format.MaxValue));
                Money currentValue = observable.GetValue();

                string formattedNumber = FormatNumber(currentValue, format);
                inputField.Value(formattedNumber);
                inputField.Focus();
            }
        }
Example #16
0
        public override void Update(System.Html.Element element, Func <object> valueAccessor, Func <System.Collections.Dictionary> allBindingsAccessor, object viewModel, object context)
        {
            jQueryObject     textBox          = jQuery.FromElement(element).Find(".sparkle-input-textbox-part");
            NumberFormatInfo format           = GetNumberFormatInfo(allBindingsAccessor);
            Func <object>    interceptAccesor = delegate()
            {
                Money value = ((Observable <Money>)valueAccessor()).GetValue();
                if (value != null)
                {
                    return(NumberEx.Format(value.Value, format));
                }
                else
                {
                    return(String.Empty);
                }
            };

            // Use the standard value binding from ko
            Script.Literal("ko.bindingHandlers.value.update({0},{1},{2},{3},{4})", textBox.GetElement(0), interceptAccesor, allBindingsAccessor, viewModel, context);
        }
        public override ValidationResult NativeValidation(object newValue)
        {
            bool isValid = true;


            Number newValueNumber = NumberEx.Parse((string)newValue, numberFormatInfo);

            isValid = !(Number.IsNaN(newValueNumber));

            isValid = isValid && (newValueNumber >= numberFormatInfo.MinValue) && (newValueNumber <= numberFormatInfo.MaxValue);

            if (!isValid)
            {
                ValidationResult result = new ValidationResult();
                result.Valid   = false;
                result.Message = String.Format("Please enter a number between {0} and {1}.", numberFormatInfo.MinValue, numberFormatInfo.MaxValue);
                return(result);
            }
            return(null);
        }
Example #18
0
        private static NumberFormatInfo GetNumberFormatInfo(Func <System.Collections.Dictionary> allBindingsAccessor)
        {
            NumberFormatInfo format = NumberEx.GetCurrencyEditFormatInfo();


            if ((Number)allBindingsAccessor()["minvalue"] == null)
            {
                format.MinValue = -2147483648;
            }
            else
            {
                format.MinValue = (Number)allBindingsAccessor()["minvalue"];
            }

            if ((Number)allBindingsAccessor()["maxvalue"] == null)
            {
                format.MaxValue = 2147483647;
            }
            else
            {
                format.MaxValue = (Number)allBindingsAccessor()["maxvalue"];
            }
            return(format);
        }
 public override void ApplyValue(Dictionary <string, object> item, object state)
 {
     item[_args.Column.Field] = NumberEx.Parse((string)state, numberFormatInfo);
     this.RaiseOnChange(item);
 }
Example #20
0
        public void IOEx_BlobIO()
        {
            string[] map = new string[] { "Int", "Int", "NVarChar", "VarBinary" };
            object[] val = new object[] { 1234, IOEx.SafeIO <int>(null), "初めまして", Encoding.UTF8.GetBytes("This is a binary string") };
            BlobIO   b   = new BlobIO(map, val);

            byte[] m = b.Map;
            Assert.Equal(b.GetN <int>(0), val[0]); // Failed to get value");
            b.Set(0, 9876);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Set(0, 9876.0);
            Assert.Equal(b.GetN <int>(0), 9876);   // Failed to set value");
            b.Clear(0);
            Assert.Equal(b.GetN <int>(0), null);   // Failed to clear value");
            b = BlobIO.Data(NumberEx.Numeric(Math.PI, out decimal? v) ? v : null);
            Assert.Equal((decimal)Math.PI, b.GetDecimal(0));
            b = BlobIO.Data(val);
            Assert.Equal(b.GetN <int>(0), val[0]);         // Failed to get value");
            Assert.Equal(b.GetN <int>(1), val[1] as int?); // Failed to get value");
            Assert.Equal(b.Get <string>(2), val[2]);       // Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(b.Get <byte[]>(3), val[3] as byte[]), "Failed to get value");
            Assert.True(CollectionEx.ArrayEquals(m, b.Map), "Failed to get value");
            byte[] io;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO");
            b = new BlobIO(io);
            Assert.Null(b.PK);
            string str = b.Str;

            b.PK = 0;
            Assert.True(NumberEx.TryFromServerHex("0x000100030808000000000C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(0, b.PK);
            b.PK = null;
            Assert.True(NumberEx.TryFromServerHex("0x0000000308080C001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.Equal(str, b.Str);
            Assert.Null(b.PK);
            b.PK = -1;
            Assert.True(NumberEx.TryFromServerHex("0x0001000308080FFFFFFFFC001111111100111111110000000000", out io), "Failed to parse IO with PK");
            Assert.NotEqual(str, b.Str);
            Assert.Equal(-1, b.PK);

            b  = null;
            b += 1;
            b += (short)1;
            b += "初めまして";
            b += Math.PI;
            b += Math.PI.DoubleToFloat();
            b += IOEx.SafeIO <long>(null);
            b += (bool?)null;
            b += TestGuid;
            b += io;
            b += DateTimeEx.s_Epoch;
            string friendly = "1, 1, '初めまして', 3.142, 3.142, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 'AAEAAwgID/////wAEREREQARERERAAAAAAA=', '01/01/1970 00:00:00'";
            string bstr     = "AAMACggQDAYNAAIOFSEAAAAAAQAAAQAAAAAP5Yid44KB44G+44GX44GmAEAJIftURC0YAEBJD9sBAQD/////////////////////AAAAABoAAQADCAgP/////AARERERABEREREAAAAAAAAIn3/197WAAAD/AAAABQAAAMD/";

            Assert.Null(b.PK);
            Assert.Equal(bstr, b.Str);                                                                                                                                                                            // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                  // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData); // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                   // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            byte[] bio = BlobIO.ExportBlobList(b);

            b = BlobIO.Data(1, (short)1, "初めまして", Math.PI, Math.PI.DoubleToFloat(), IOEx.SafeIO <long>(null), (bool?)null, TestGuid, io, DateTimeEx.s_Epoch);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Concat(b));
            Assert.Equal(string.Join(", ", friendly, friendly), b.Friendly);                                                                       // Failed to get value");
            b = new BlobIO(bio);
            Assert.Equal(friendly, b.Friendly);                                                                                                    // Failed to get value");
            Assert.True(b.Set(4, BlobIO.Data(float.NaN, 0L, false, Guid.Empty, (byte[])null)));
            Assert.Equal("1, 1, '初めまして', 3.142, NULL, 0, False, '00000000-0000-0000-0000-000000000000', NULL, '01/01/1970 00:00:00'", b.Friendly); // Failed to get value");

            b  = new BlobIO(bio);
            io = b.IO;
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList();
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            int ix = 0;

            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            byte[] dataio, prefixio, suffixio, ixsio, sbioio;
            string data = "0000000001000001000000000fe5889de38281e381bee38197e381a600400921fb54442d180040490fdb010100ffffffffffffffffffffffffffffffff000000001a0001000308080ffffffffc00111111110011111111000000000000089f7ff5f7b5800000";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            string prefix = "0x0003000a08100c060d00020e1521";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            string presuffix = "ff000a016101620163016401650166016701680169016a00";
            string suffix    = presuffix + "05000000c0ff";

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            string ixs = "0002" + "00000066" + "000000cc";

            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            string sio  = prefix + data + suffix;
            string sbio = sio + ixs + data + data + data;

            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b = new BlobIO(bstr);
            Assert.Equal(friendly, b.Friendly); // Failed to get value");

            b.PK = 0;
            Assert.Equal(0, b.PK);
            Assert.Equal("AQMAAAAAAAoIEAwGDQACDhUhAAAAAAEAAAEAAAAAD+WIneOCgeOBvuOBl+OBpgBACSH7VEQtGABASQ/bAQEA/////////////////////wAAAAAaAAEAAwgID/////wAEREREQARERERAAAAAAAACJ9/9fe1gAAA/wAAAAUAAADA/w==", b.Str); // Failed to get value");
            Assert.Equal("Int, SmallInt, NVarChar, Float, Real, BigInt, Bit, UniqueIdentifier, VarBinary, DateTime2", b.StrMap);                                                                                     // Failed to get value");
            Assert.Equal("1, 1, '初めまして', 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000'", b.StrData);    // Failed to get value");
            Assert.Equal(friendly, b.Friendly);                                                                                                                                                                      // Failed to get value");
            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            Assert.Equal("a, b, c, d, e, f, g, h, i, j", b.StrCols);                                                                                                                                                                                                                                             // Failed to get value");
            Assert.Equal("\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\"", b.Select);                                                                                                                                                                                                      //, "Failed to get value");
            Assert.Equal("\"a\" = 1, \"b\" = 1, \"c\" = 0x1d5281307e3057306630, \"d\" = 3.1415927, \"e\" = 3.141593, \"f\" = NULL, \"g\" = NULL, \"h\" = 'ffffffff-ffff-ffff-ffff-ffffffffffff', \"i\" = 0x0001000308080ffffffffc001111111100111111110000000000, \"j\" = '1970-01-01T00:00:00.000'", b.Update);  //, "Failed to get value");
            Assert.Equal("\"a\" = V.GetInt32(0), \"b\" = V.GetInt16(1), \"c\" = V.GetString(2), \"d\" = V.GetDouble(3), \"e\" = V.GetSingle(4), \"f\" = V.GetInt64(5), \"g\" = V.GetBool(6), \"h\" = V.GetGuid(7), \"i\" = V.GetBytes(8), \"j\" = V.GetDateTime(9)", b.UpdateVar);                               //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (1, 1, 0x1d5281307e3057306630, 3.1415927, 3.141593, NULL, NULL, 'ffffffff-ffff-ffff-ffff-ffffffffffff', 0x0001000308080ffffffffc001111111100111111110000000000, '1970-01-01T00:00:00.000')", b.Insert); //, "Failed to get value");
            Assert.Equal(" (\"a\", \"b\", \"c\", \"d\", \"e\", \"f\", \"g\", \"h\", \"i\", \"j\") VALUES (V.GetInt32(0), V.GetInt16(1), V.GetString(2), V.GetDouble(3), V.GetSingle(4), V.GetInt64(5), V.GetBool(6), V.GetGuid(7), V.GetBytes(8), V.GetDateTime(9))", b.InsertVar);                              //, "Failed to get value");
            Assert.Equal("V", b.Name);                                                                                                                                                                                                                                                                           // Failed to get value");

            int seed = 0;

            io  = b.Export(false, ref seed);
            bio = BlobIO.ExportBlobList(false, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(false);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(false, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io.Take(pair.Value.Length)));
            }
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + data, out dataio) ? dataio : null, b.DataIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(prefix, out prefixio) ? prefixio : null, b.PrefixIO));
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            Assert.Equal(io.Length + sizeof(int), b.IO.Length);
            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(0, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "00000000" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "00000000" + data + "00000000" + data + "00000000" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b    = new BlobIO(bstr);
            b.PK = -1;
            Assert.Equal(-1, b.PK);

            io  = b.IO;
            bio = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + "ff00000005000000c0ff";
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");


            b.Name = "V";
            b.Cols = "a,b,c,d,e,f,g,h,i,j".Split(',');
            io     = b.IO;
            bio    = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(-1, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFF" + data + "FFFFFFFF" + data + "FFFFFFFF" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            sio    = prefix + data + suffix;
            sbio   = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");



            b.PK = null;
            Assert.Null(b.PK);
            b.Indexes = new int[] { 1, 3, 5 };
            Assert.Equal("1,3,5", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);         // Failed to get null oks");
            Assert.Null(b.StrOuts);          // Failed to get outputs");

            seed = 0;
            io   = b.Export(true, ref seed);
            bio  = BlobIO.ExportBlobList(true, b);
            Assert.True(CollectionEx.ArrayEquals(bio, io));
            bio = BlobIO.ExportBlobList(true);
            Assert.Null(bio);
            bio = BlobIO.ExportBlobList(true, b, b, b, b);
            Assert.True(CollectionEx.ArrayEquals(bio.Take(io.Length), io));
            Assert.True(bio?.Length > io.Length);
            Assert.True(bio?.Length < (io.Length * 4));
            io = b.PrefixIO.Concat(b.DataIO).ToArray();
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
                Assert.True(CollectionEx.ArrayEquals(pair.Value, io));
            }
            ixs = "0002" + "0000006a" + "000000d4";
            Assert.Equal(sizeof(short) + (sizeof(int) * 2), NumberEx.TryFromServerHex("0x" + ixs, out ixsio) ? ixsio?.Length : null);
            prefix = "0x0103" + "FFFFFFFF" + "000a08100c060d00020e1521";
            suffix = presuffix + "052a0000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));
            sio  = prefix + data + suffix;
            sbio = sio + ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data;
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex(sbio, out sbioio) ? sbioio : null, bio), "BlobList serialized");

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);                       // Failed to get null oks");
            Assert.Null(b.StrOuts);                        // Failed to get outputs");
            suffix = presuffix + "05ff0300c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 24 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            suffix = presuffix + "05010000c0ff";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0 };
            Assert.Equal("0", b.StrIxs); // Failed to get indexes");
            Assert.Null(b.StrNulls);     // Failed to get null oks");
            Assert.Null(b.StrOuts);      // Failed to get outputs");
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Ins     = new int[] { 6 };
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrIxs);   // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "05ffffff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Indexes = null;
            b.Nulls   = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs    = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts);  // Failed to get outputs");
            suffix = presuffix + "0500fcff3f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = null;
            b.Outs  = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            Assert.Null(b.StrIxs);                          // Failed to get indexes");
            Assert.Null(b.StrNulls);                        // Failed to get null oks");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrOuts); // Failed to get outputs");
            suffix = presuffix + "050000f03f10";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            b.Nulls = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
            b.Outs  = null;
            Assert.Null(b.StrIxs);                           // Failed to get indexes");
            Assert.Equal("0,1,2,3,4,5,6,7,8,9", b.StrNulls); // Failed to get null oks");
            Assert.Null(b.StrOuts);                          // Failed to get outputs");
            suffix = presuffix + "0500fc0f0010";
            Assert.True(CollectionEx.ArrayEquals(NumberEx.TryFromServerHex("0x" + suffix, out suffixio) ? suffixio : null, b.SuffixIO));

            Assert.True(NumberEx.TryFromServerHex("0x0100" + "FFFFFFFF" + "000a08100c060d00020e1521" + data +
                                                  presuffix +
                                                  ixs + "FFFFFFFE" + data + "FFFFFFFD" + data + "FFFFFFFC" + data, out bio));
            ix = 0;
            foreach (var pair in BlobIO.ToBlobList(bio))
            {
                Assert.Equal(--ix, pair.Key);
            }
        }
Example #21
0
        public static void init()
        {
            DataGroupingViewModel vm = new DataGroupingViewModel();
            NumberFormatInfo      numberFormatInfo = NumberEx.GetNumberFormatInfo();

            numberFormatInfo.MinValue  = 0;
            numberFormatInfo.MaxValue  = 1000;
            numberFormatInfo.Precision = 2;
            BooleanBindingOptions boolFormatInfo = new BooleanBindingOptions();

            boolFormatInfo.FalseOptionDisplayName = "No";
            boolFormatInfo.TrueOptionDisplayName  = "Yes";

            // Add Columns
            SubTotalsFormatterDelegate sumTotalsFormatterDelegate = SumTotalsFormatter;
            SubTotalsFormatterDelegate avgTotalsFormatterDelegate = AvgTotalsFormatter;
            FormatterDelegate          percentageFormatter        = XrmNumberEditor.Formatter;
            FormatterDelegate          checkboxFormatter          = XrmBooleanEditor.Formatter;

            List <Column> columns = new List <Column>(
                new Column(
                    ColumnProperties.Id, "sel",
                    ColumnProperties.Name, "#",
                    ColumnProperties.Field, "num",
                    ColumnProperties.CssClass, "cell-selection",
                    ColumnProperties.Width, 40,
                    ColumnProperties.Resizable, false,
                    ColumnProperties.Selectable, false,
                    ColumnProperties.Focusable, false),
                new Column(
                    ColumnProperties.Id, "title",
                    ColumnProperties.Name, "Title",
                    ColumnProperties.Field, "title",
                    ColumnProperties.Width, 70,
                    ColumnProperties.MinWidth, 50,
                    ColumnProperties.CssClass, "cell-title",
                    ColumnProperties.Sortable, true,
                    ColumnProperties.Editor, XrmTextEditor.TextEditor),
                new Column(
                    ColumnProperties.Id, "duration",
                    ColumnProperties.Name, "Duration",
                    ColumnProperties.Field, "duration",
                    ColumnProperties.Width, 70,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "%",
                    ColumnProperties.Name, "% Complete",
                    ColumnProperties.Field, "percentComplete",
                    ColumnProperties.Width, 80,
                    ColumnProperties.Formatter, percentageFormatter,
                    ColumnProperties.Options, numberFormatInfo,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, avgTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "start",
                    ColumnProperties.Name, "Start",
                    ColumnProperties.Field, "start",
                    ColumnProperties.MinWidth, 60,
                    ColumnProperties.Sortable, true),
                new Column(
                    ColumnProperties.Id, "finish",
                    ColumnProperties.Name, "Finish",
                    ColumnProperties.Field, "finish",
                    ColumnProperties.MinWidth, 60,
                    ColumnProperties.Sortable, true),
                new Column(
                    ColumnProperties.Id, "cost",
                    ColumnProperties.Name, "Cost",
                    ColumnProperties.Field, "cost",
                    ColumnProperties.Width, 90,
                    ColumnProperties.Sortable, true,
                    ColumnProperties.GroupTotalsFormatter, sumTotalsFormatterDelegate),
                new Column(
                    ColumnProperties.Id, "effort-driven",
                    ColumnProperties.Name, "Effort Driven",
                    ColumnProperties.Width, 80,
                    ColumnProperties.MinWidth, 20,
                    ColumnProperties.CssClass, "cell-effort-driven",
                    ColumnProperties.Field, "effortDriven",
                    ColumnProperties.Formatter, checkboxFormatter,
                    ColumnProperties.Options, boolFormatInfo,
                    ColumnProperties.Sortable, true)
                );

            GridOptions options = new GridOptions();

            options.EnableCellNavigation = true;
            options.Editable             = true;
            DataViewBase view = (DataViewBase)(object)vm.Projects;

            GridDataViewBinder binder = new GridDataViewBinder();
            Grid grid = binder.DataBindDataViewGrid(vm.Projects, columns, "myGrid", null, true, false);

            // register the group item metadata provider to add expand/collapse group handlers
            grid.RegisterPlugin(new GroupItemMetadataProvider());

            // Data Bind
            ViewBase.RegisterViewModel(vm);
        }