예제 #1
0
        private DataTable BuildDataTableForGarage(JArray jsonList)
        {
            DataTable dt = new DataTable();

            dt.TableName = "Garage_" + DateTime.Now.ToString(formatStringDate);
            //Add table headers going cell by cell.
            dt.Columns.Add("STT", typeof(int));
            dt.Columns.Add("Tên sản phẩm", typeof(string));
            dt.Columns.Add("SL nhập", typeof(int));
            dt.Columns.Add("Tổng giá trị nhâp", typeof(int));
            dt.Columns.Add("SL bán", typeof(int));
            dt.Columns.Add("Tổng giá trị bán", typeof(int));
            dt.Columns.Add("SL hiện tại", typeof(int));
            dt.Columns.Add("Lợi nhuận ước tính", typeof(int));

            //Binding data
            int index = 1;

            foreach (JObject json in jsonList)
            {
                ProductInfo productInfo = ProductInfo.FromJson(json);
                dt.Rows.Add(new object[] { index, productInfo.Name, productInfo.SumOfInput, productInfo.SumOfInputTotalAmount,
                                           productInfo.SumOfSale, productInfo.SumOfSaleTotalAmount, productInfo.NumOfRemain, productInfo.Profit });
                index++;
            }

            return(dt);
        }
예제 #2
0
        public void Serialization()
        {
            var pi = new ProductInfo {
                Uri = new Uri("https://s3.something.com/install-me/me-me-me.msi"), Name = "TestProduct",
            };

            pi.Props.Add("prop1", "value1");
            pi.Props.Add("prop2", "value2");
            var json = pi.ToJson();

            Assert.AreEqual(
                "{" + Environment.NewLine
                + "  \"Name\": \"TestProduct\"," + Environment.NewLine
                + "  \"Uri\": \"https://s3.something.com/install-me/me-me-me.msi\"," + Environment.NewLine
                + "  \"LocalPath\": null," + Environment.NewLine
                + "  \"Props\": {" + Environment.NewLine
                + "    \"prop1\": \"value1\"," + Environment.NewLine
                + "    \"prop2\": \"value2\"" + Environment.NewLine
                + "  }" + Environment.NewLine
                + "}",
                json);
            using var ms = new MemoryStream(Encoding.UTF8.GetBytes(json));
            var p = ProductInfo.FromJson(ms).Result;

            Assert.AreEqual("TestProduct", p.Name);
            Assert.AreEqual("https://s3.something.com/install-me/me-me-me.msi", p.Uri.ToString());
            Assert.AreEqual(2, p.Props.Count);
            Assert.AreEqual("value1", p.Props["prop1"]);
            Assert.AreEqual("value2", p.Props["prop2"]);
        }