Example #1
0
        private static string MakeInputFromJSonAndExcelFile(string fileName, string content64, string sJSonDatabase64, DataTable dt)
        {
            StringBuilder sBuilder = new StringBuilder();
            var jsonSerializer = new JavaScriptSerializer();
            byte[] bJSonData = Convert.FromBase64String(sJSonDatabase64);
            string RawJsonData = ASCIIEncoding.ASCII.GetString(bJSonData);
            PMSA.Framework.Log.CLogManager.WriteSL("JsonRawInput", RawJsonData);
            var objtest = jsonSerializer.Deserialize<CTradeInterfaceList>(RawJsonData);
            //   if(objtest is CTradeInterfaceList)
            //    {
            CTradeInterfaceList oCTradeInterfaceList = (CTradeInterfaceList)objtest;
            //string CSVContent = "ID;Code;Name;Phone;BirthDate\n1;'KH01';'Tuong';'0989876666';'2013-12-01'\n2;'KH02';'Nam';'0102001111';'2013-12-20'" +
            //                              "\n3;'KH03';'Thien';'0102001111';'2013-12-24'" +
            //                              "\n###\nID;Code;Name;Phone;BirthDate\n1;'KH01';'Tuong';'0989876666';'2013-12-01'\n2;'KH02';'Nam';'0102001111';'2013-12-20'";
            int sheetsNumber = 1;
            string fileContent = CreateExcelSampleContent(fileName, content64, ref sheetsNumber);
            List<CTradeInterface>[] lTemp = new List<CTradeInterface>[1];
            lTemp[0] = new List<CTradeInterface>();
            //lTemp[1] = new List<CTradeInterface>();
            //lTemp[2] = new List<CTradeInterface>();
            /*   foreach (var item in oCTradeInterfaceList.ListTrade)
               {
                   if (item.IsFixedIncome == "1")
                       lTemp[2].Add(item);
               }

               foreach (var item in oCTradeInterfaceList.ListTrade)
               {
                   if (item.IsPreferredShare == "1")
                       lTemp[1].Add(item);
               }

               foreach (var item in oCTradeInterfaceList.ListTrade)
               {
                   if (item.IsFixedIncome != "1" && item.IsPreferredShare != "1")
                       lTemp[0].Add(item);
               }
                */
            int i = 1;
            foreach (DataRow r in dt.Rows)
            {
                CTradeInterface item = new CTradeInterface();
                item.ID = i++;
                item.Address = r["Address"] != null ? r["Address"].ToString() : "";
                item.Name = r["Name"] != null ? r["Name"].ToString() : "";
                item.AvailableArea = r["AvailableArea"] != null ? r["AvailableArea"].ToString() : "";
                item.PriceDescription = r["PriceDescription"] != null ? r["PriceDescription"].ToString() : "";
                item.VATTax = r["VATTax"] != null ? r["VATTax"].ToString() : "";
                item.ServiceFee = r["ServiceFee"] != null ? r["ServiceFee"].ToString() : "";
                item.Description = r["Description"] != null ? r["Description"].ToString() : "";

                lTemp[0].Add(item);
            }
            //ltemp[1].add(item);
            // ltemp[2].add(item);
            string JSONContent = FormatCSV(lTemp, sheetsNumber);
            JSONContent = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(JSONContent));
            string inputXML = string.Format("<InputValue FileName=\"{0}\" FileStructContent=\"{1}\" FileCSVContent=\"{2}\"/>", fileName, fileContent, JSONContent);

            sBuilder.Append(MakeExcelOnlineEx(inputXML));
            // }

            return sBuilder.ToString();
        }
Example #2
0
        private static string MakeInputFromJSonAndExcelFile(string fileName, string content64, string sJSonDatabase64, DataTable dt)
        {
            StringBuilder sBuilder       = new StringBuilder();
            var           jsonSerializer = new JavaScriptSerializer();

            byte[] bJSonData   = Convert.FromBase64String(sJSonDatabase64);
            string RawJsonData = ASCIIEncoding.ASCII.GetString(bJSonData);

            PMSA.Framework.Log.CLogManager.WriteSL("JsonRawInput", RawJsonData);
            var objtest = jsonSerializer.Deserialize <CTradeInterfaceList>(RawJsonData);
            //   if(objtest is CTradeInterfaceList)
            //    {
            CTradeInterfaceList oCTradeInterfaceList = (CTradeInterfaceList)objtest;
            //string CSVContent = "ID;Code;Name;Phone;BirthDate\n1;'KH01';'Tuong';'0989876666';'2013-12-01'\n2;'KH02';'Nam';'0102001111';'2013-12-20'" +
            //                              "\n3;'KH03';'Thien';'0102001111';'2013-12-24'" +
            //                              "\n###\nID;Code;Name;Phone;BirthDate\n1;'KH01';'Tuong';'0989876666';'2013-12-01'\n2;'KH02';'Nam';'0102001111';'2013-12-20'";
            int    sheetsNumber = 1;
            string fileContent  = CreateExcelSampleContent(fileName, content64, ref sheetsNumber);

            List <CTradeInterface>[] lTemp = new List <CTradeInterface> [1];
            lTemp[0] = new List <CTradeInterface>();
            //lTemp[1] = new List<CTradeInterface>();
            //lTemp[2] = new List<CTradeInterface>();

            /*   foreach (var item in oCTradeInterfaceList.ListTrade)
             * {
             *     if (item.IsFixedIncome == "1")
             *         lTemp[2].Add(item);
             * }
             *
             * foreach (var item in oCTradeInterfaceList.ListTrade)
             * {
             *     if (item.IsPreferredShare == "1")
             *         lTemp[1].Add(item);
             * }
             *
             * foreach (var item in oCTradeInterfaceList.ListTrade)
             * {
             *     if (item.IsFixedIncome != "1" && item.IsPreferredShare != "1")
             *         lTemp[0].Add(item);
             * }
             */
            int i = 1;

            foreach (DataRow r in dt.Rows)
            {
                CTradeInterface item = new CTradeInterface();
                item.ID               = i++;
                item.Address          = r["Address"] != null ? r["Address"].ToString() : "";
                item.Name             = r["Name"] != null ? r["Name"].ToString() : "";
                item.AvailableArea    = r["AvailableArea"] != null ? r["AvailableArea"].ToString() : "";
                item.PriceDescription = r["PriceDescription"] != null ? r["PriceDescription"].ToString() : "";
                item.VATTax           = r["VATTax"] != null ? r["VATTax"].ToString() : "";
                item.ServiceFee       = r["ServiceFee"] != null ? r["ServiceFee"].ToString() : "";
                item.Description      = r["Description"] != null ? r["Description"].ToString() : "";

                lTemp[0].Add(item);
            }
            //ltemp[1].add(item);
            // ltemp[2].add(item);
            string JSONContent = FormatCSV(lTemp, sheetsNumber);

            JSONContent = Convert.ToBase64String(ASCIIEncoding.UTF8.GetBytes(JSONContent));
            string inputXML = string.Format("<InputValue FileName=\"{0}\" FileStructContent=\"{1}\" FileCSVContent=\"{2}\"/>", fileName, fileContent, JSONContent);

            sBuilder.Append(MakeExcelOnlineEx(inputXML));
            // }

            return(sBuilder.ToString());
        }