Commit dd535048627667739e1dfd862ca6d7db6418a70b

Authored by Nikita Kulshreshtha
1 parent 5683a731

converted the desired resukt into json.

now just need to remove sapce before name and slug in modules array.
we can do that by using indexof..
350-UTILITIES/Parser/XMLtoJSON_utility/XMLtoJSON_utility.v12.suo
No preview for this file type
350-UTILITIES/SQL_To_Json/Newtonsof_Json_Net45.rar 0 → 100644
No preview for this file type
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs
... ... @@ -9,6 +9,8 @@ using System.Configuration;
9 9 using System.Data.SqlClient;
10 10 using System.Configuration;
11 11 using Newtonsoft.Json.Linq;
  12 +using System.Text.RegularExpressions;
  13 +using System.Web;
12 14  
13 15 namespace SQLToJSON
14 16 {
... ... @@ -16,7 +18,7 @@ namespace SQLToJSON
16 18 {
17 19 string connString = string.Empty;
18 20 public Custom()
19   - {
  21 + {
20 22 connString = Convert.ToString(ConfigurationManager.AppSettings["connectionString"]);
21 23 }
22 24  
... ... @@ -34,77 +36,138 @@ namespace SQLToJSON
34 36 {
35 37 string JSONString = string.Empty;
36 38 JSONString = JsonConvert.SerializeObject(table);
37   - return JSONString;
  39 + string XYX = JSONString.Replace(@"\r", "");
  40 + string YYY = XYX.Replace(@"\n", "");
  41 + string uuu = YYY.Replace(@"\", "");
  42 +
  43 + //System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer();
  44 +
  45 + //string vvv = js.Serialize(table);
  46 + //JSONString= JToken.Parse(JSONString).ToString();
  47 + //var obj = new JObject();
  48 + //obj["data"] = JToken.FromObject(table);
  49 +
  50 + // string jsonString = obj.ToString();
  51 + // dynamic DATA = new JObject();
  52 + // var jsonObj = new JObject();
  53 + // dynamic mo = jsonObj;
  54 + // mo.data1 = new JObject() as dynamic;
  55 + // foreach (var d in table)
  56 + // {
  57 + // dynamic data = new JObject();
  58 + // data.loginId = d.loginId;
  59 +
  60 + // data.password = d.password;
  61 + // data.firstName = d.firstName;
  62 + // data.lastName = d.lastName;
  63 + // data.userType = d.userType;
  64 + // data.emailId = d.emailId;
  65 + // data.isActive = d.isActive;
  66 + // data.securityQuestion = d.securityQuestion;
  67 + // data.securityAnswer = d.securityAnswer;
  68 + // data.creatorId = d.creatorId;
  69 + // data.creationDate = d.creationDate;
  70 + // data.modifierId = d.modifierId;
  71 + // data.modifiedDate = d.modifiedDate;
  72 + // data.deactivationDate = d.deactivationDate;
  73 + // data.module = d.module;
  74 + // // data.ToString();
  75 + // DATA.Add(data.ToString());
  76 + // }
  77 + //// }
  78 + //// string abc = Convert.ToString(JsonConvert.DeserializeObject(JSONString));
  79 + // //JSONString.Replace(@"\","");
  80 + // //var json = JsonConvert.SerializeObject(new { root = table }, Formatting.Indented);
  81 + // //json.Replace(@"\\\", "");
  82 + //string x = DATA.ToString();
  83 + return uuu;
38 84 }
39 85  
40 86 public dynamic GetModifiedTableWithUserModules(DataTable userTable, DataTable moduleTable)
41 87 {
42 88 List<User> data2 = null;
  89 + List<dynamic> RESULT = new List<dynamic>();
43 90 try
44 91 {
45   -
  92 +
46 93 List<User> data = (from d in userTable.AsEnumerable()
47   - join e in moduleTable.AsEnumerable()
48   - on d.Field<int>("Id") equals
49   - e.Field<int>("UserId")
50   - select new User
51   - {
52   - loginId = d.Field<string>("loginId"),
53   - password = d.Field<string>("password"),
54   - firstName = d.Field<string>("firstName"),
55   - lastName = d.Field<string>("lastName"),
56   - userType = d.Field<string>("userType"),
57   - emailId = d.Field<string>("emailId"),
58   - isActive = d.Field<Boolean>("isActive"),
59   - securityQuestion = d.Field<string>("securityQuestion"),
60   - securityAnswer = d.Field<string>("securityAnswer"),
61   - creatorId = d.Field<int>("creatorId"),
62   - creationDate = d.Field<DateTime?>("creationDate"),
63   - modifierId = d.Field<int>("modifierId"),
64   - modifiedDate = d.Field<DateTime?>("modifiedDate"),
65   - deactivationDate = d.Field<DateTime?>("deactivationDate"),
66   - module = e.Field<string>("Title"),
67   - }).ToList();
  94 + join e in moduleTable.AsEnumerable()
  95 + on d.Field<int>("Id") equals
  96 + e.Field<int>("UserId")
  97 + select new User
  98 + {
  99 + loginId = d.Field<string>("loginId"),
  100 + password = d.Field<string>("password"),
  101 + firstName = d.Field<string>("firstName"),
  102 + lastName = d.Field<string>("lastName"),
  103 + userType = d.Field<string>("userType"),
  104 + emailId = d.Field<string>("emailId"),
  105 + isActive = d.Field<Boolean>("isActive"),
  106 + securityQuestion = d.Field<string>("securityQuestion"),
  107 + securityAnswer = d.Field<string>("securityAnswer"),
  108 + creatorId = d.Field<int>("creatorId"),
  109 + creationDate = d.Field<DateTime?>("creationDate"),
  110 + modifierId = d.Field<int>("modifierId"),
  111 + modifiedDate = d.Field<DateTime?>("modifiedDate"),
  112 + deactivationDate = d.Field<DateTime?>("deactivationDate"),
  113 + module = e.Field<string>("Title"),//JsonConvert.SerializeObject(e.Field<string>("Title")),
  114 + }).ToList();
68 115  
69   -
70   - data2=data.ToList();
  116 +
  117 + data2 = data.ToList();
  118 + string previousUserId ="";
71 119 foreach (var row in data)
72 120 {
73 121  
74 122 string userloginId = row.loginId;
75   - var Modules = (from m in data
76   - where m.loginId == userloginId
77   - select m.module).ToList();
78   -
79   - string modu= JsonConvert.SerializeObject(Modules);
  123 + if (userloginId != previousUserId)
  124 + {
  125 + previousUserId = userloginId;
80 126  
81   - var jsonObj = new JObject();
82   - dynamic mo = jsonObj;
83   - mo.modules = new JArray() as dynamic;
  127 + var Modules = (from m in data
  128 + where m.loginId == userloginId
  129 + select m.module).ToList();
84 130  
85   - foreach (var mods in Modules)
86   - {
87   - dynamic modul= new JObject();
88   - modul.name = mods;
89   - modul.slug = ConfigurationManager.AppSettings[mods];
90   - mo.modules.Add(modul);
91   -
  131 + string modu = JsonConvert.SerializeObject(Modules);
  132 +
  133 + var jsonObj = new JObject();
  134 + dynamic mo = jsonObj;
  135 + mo.modules = new JArray();
  136 +
  137 + foreach (var mods in Modules)
  138 + {
  139 + dynamic modul = new JObject();
  140 + string MO = mods.ToString().Replace(@"\", "");
  141 + modul.name = mods;
  142 + modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")];
  143 + mo.modules.Add(modul);
  144 +
  145 + }
  146 +
  147 + var lst = data2.Where(w => w.loginId == userloginId).Select(r => { r.module =(mo).ToString(); return r; }).ToList();
  148 + string moddd = ((from mod in lst
  149 + select mod.module).FirstOrDefault().ToString()).Replace(@"\", "");
  150 + string abc = Regex.Unescape(moddd);
  151 + var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = ((moddd)).ToString(); return r; }).ToList();
  152 +
  153 + var reultantRow = lst2.FirstOrDefault();
  154 + //lst.GroupBy(x => x.loginId).Select(g => g.First());
  155 + RESULT.Add(reultantRow);
  156 + // data2 = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = mo.ToString(); return r; }).ToList();
92 157 }
93   -
94   - data2 = data2.Where(w=>w.loginId == userloginId).Select (r => { r.module = mo.ToString(); return r; }).ToList();
  158 + }
95 159  
96   - }
97 160  
98   -
99   - var result = data2.GroupBy(x => x.loginId).Select(g => g.First());
  161 + //var result = data2.GroupBy(x => x.loginId).Select(g => g.First());
100 162 string bb = "";
101   -
102   - return result;
  163 +
  164 + return RESULT;
103 165 }
104   - catch (Exception e) {
105   - return e.Message;
  166 + catch (Exception e)
  167 + {
  168 + return e.Message;
106 169 }
107   -
  170 +
108 171 }
109 172  
110 173 }
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs
1   -using System;
  1 +using Newtonsoft.Json.Linq;
  2 +using System;
2 3 using System.Collections.Generic;
3 4 using System.ComponentModel;
4 5 using System.Data;
... ... @@ -67,6 +68,7 @@ namespace SQLToJSON
67 68 File.Delete(@"D:/AIAUser.json");
68 69 }
69 70 System.IO.File.WriteAllText("D:/AIAUser.json", aiaUserJson);
  71 +
70 72 label1.Text = "Conversion Successfull.";
71 73 }
72 74 catch (Exception ex)
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/SQLToJSON.csproj
... ... @@ -39,6 +39,7 @@
39 39 <Reference Include="System" />
40 40 <Reference Include="System.Configuration" />
41 41 <Reference Include="System.Core" />
  42 + <Reference Include="System.Web.Extensions" />
42 43 <Reference Include="System.Xml.Linq" />
43 44 <Reference Include="System.Data.DataSetExtensions" />
44 45 <Reference Include="Microsoft.CSharp" />
... ... @@ -58,6 +59,8 @@
58 59 </Compile>
59 60 <Compile Include="Program.cs" />
60 61 <Compile Include="Properties\AssemblyInfo.cs" />
  62 + <Compile Include="StringContent.cs" />
  63 + <Compile Include="StringContent_2.cs" />
61 64 <Compile Include="User.cs" />
62 65 <EmbeddedResource Include="Form1.resx">
63 66 <DependentUpon>Form1.cs</DependentUpon>
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/StringContent.cs 0 → 100644
  1 +
0 2 \ No newline at end of file
... ...
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/StringContent_2.cs 0 → 100644
  1 +using System;
  2 +using System.Collections.Generic;
  3 +using System.Linq;
  4 +using System.Text;
  5 +
  6 +namespace SQLToJSON
  7 +{
  8 + class StringContent
  9 + {
  10 + }
  11 +}
... ...