Commit bb73a96ea98ac46f3fd5d00c27bba32f9557ff97
1 parent
dd535048
converted sql data of users with its type and modules in json.
this will be imported in mongo DB
Showing
3 changed files
with
38 additions
and
83 deletions
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/App.config
... | ... | @@ -12,16 +12,16 @@ |
12 | 12 | <add key ="Clinical Animations" value ="ca-list"/> |
13 | 13 | <add key ="Encyclopedia" value ="Link/encyclopedia"/> |
14 | 14 | <add key ="Curriculum Builder" value ="cb-list"/> |
15 | - <add key ="Anatomy Tests" value ="at-list"/> | |
15 | + <add key ="Anatomy Test" value ="at-list"/> | |
16 | 16 | <add key ="IP 10" value ="Link/IP-10"/> |
17 | 17 | <add key ="Lab Exercises" value ="le-list"/> |
18 | 18 | <add key ="In-Depth Reports" value ="Link/indepth-reports"/> |
19 | - <add key ="Complementary and Alternative Medicine" value ="Link/complementary-and-alternate-medicine"/> | |
20 | - <add key ="A.D.A.M Images" value ="ai-list"/> | |
19 | + <add key ="CAM" value ="Link/complementary-and-alternate-medicine"/> | |
20 | + <add key ="A.D.A.M. Images" value ="ai-list"/> | |
21 | 21 | <add key ="Body Guide" value ="Link/bodyguide"/> |
22 | 22 | <add key ="Symptom Navigator" value ="Link/symptom-navigator"/> |
23 | 23 | <add key ="The Wellness Tools" value ="Link/wellness-tools"/> |
24 | - <add key ="A.D.A.M OnDemand" value ="aod-list"/> | |
24 | + <add key ="A.D.A.M. OnDemand" value ="aod-list"/> | |
25 | 25 | |
26 | 26 | |
27 | 27 | </appSettings> | ... | ... |
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Custom.cs
... | ... | @@ -36,51 +36,13 @@ namespace SQLToJSON |
36 | 36 | { |
37 | 37 | string JSONString = string.Empty; |
38 | 38 | JSONString = JsonConvert.SerializeObject(table); |
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; | |
39 | + string replacedString = JSONString.Replace(@"\r", ""); | |
40 | + string replacedString1 = replacedString.Replace(@"\n", ""); | |
41 | + string replacedString2 = replacedString1.Replace(@"\", ""); | |
42 | + | |
43 | + string finalString = Regex.Replace(replacedString2, "\\s+\"", ""); | |
44 | + | |
45 | + return finalString; | |
84 | 46 | } |
85 | 47 | |
86 | 48 | public dynamic GetModifiedTableWithUserModules(DataTable userTable, DataTable moduleTable) |
... | ... | @@ -138,29 +100,45 @@ namespace SQLToJSON |
138 | 100 | { |
139 | 101 | dynamic modul = new JObject(); |
140 | 102 | string MO = mods.ToString().Replace(@"\", ""); |
141 | - modul.name = mods; | |
103 | + if (MO == "CAM") | |
104 | + { | |
105 | + modul.name = "Complementary and Alternative Medicine"; | |
106 | + } | |
107 | + else if (MO == "Anatomy Test") | |
108 | + { | |
109 | + modul.name = "Anatomy Tests"; | |
110 | + | |
111 | + } | |
112 | + else | |
113 | + { | |
114 | + modul.name = mods; | |
115 | + } | |
142 | 116 | modul.slug = ConfigurationManager.AppSettings[(mods.ToString()).Replace(@"\", "")]; |
143 | 117 | mo.modules.Add(modul); |
144 | 118 | |
145 | 119 | } |
146 | - | |
147 | - var lst = data2.Where(w => w.loginId == userloginId).Select(r => { r.module =(mo).ToString(); return r; }).ToList(); | |
120 | + | |
121 | + previousUserId = userloginId; | |
122 | + | |
123 | + | |
124 | + | |
125 | + var lst = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = (mo).ToString(); return r; }).ToList(); | |
148 | 126 | string moddd = ((from mod in lst |
149 | 127 | select mod.module).FirstOrDefault().ToString()).Replace(@"\", ""); |
150 | 128 | string abc = Regex.Unescape(moddd); |
151 | 129 | var lst2 = data2.Where(w => w.loginId == userloginId).Select(r => { r.module = ((moddd)).ToString(); return r; }).ToList(); |
152 | 130 | |
153 | 131 | 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(); | |
132 | + //to create array of userType | |
133 | + List<string> userTypes = new List<string>(); | |
134 | + var userType1 = (reultantRow.userType); | |
135 | + userTypes.Add(userType1); | |
136 | + //userTypes.Add("Admin"); | |
137 | + reultantRow.userType = JsonConvert.SerializeObject(userTypes); | |
138 | + RESULT.Add(reultantRow); | |
157 | 139 | } |
158 | 140 | } |
159 | 141 | |
160 | - | |
161 | - //var result = data2.GroupBy(x => x.loginId).Select(g => g.First()); | |
162 | - string bb = ""; | |
163 | - | |
164 | 142 | return RESULT; |
165 | 143 | } |
166 | 144 | catch (Exception e) | ... | ... |
350-UTILITIES/SQL_To_Json/SQLToJSON/SQLToJSON/Form1.cs
... | ... | @@ -23,29 +23,6 @@ namespace SQLToJSON |
23 | 23 | |
24 | 24 | private void button1_Click(object sender, EventArgs e) |
25 | 25 | { |
26 | - //string aiaUserCommand = "SELECT U.Id, U.LoginId, U.Password, U.FirstName, U.LastName, U.UserTypeId, R.Title AS UserRoleName, U.EmailId, U.IsActive, U.SecurityQuestionId, U.SecurityAnswer, U.CreatorId, U.CreationDate, U.ModifierId, U.ModifiedDate, U.DeactivationDate FROM AIAUser U INNER JOIN AIAUserActivity UA ON U.Id = UA.UserId INNER JOIN ROle R ON UA.RoleId = R.Id"; | |
27 | - //string roleCommand = "SELECT Role.Id, Role.Title, AIAUserActivity.UserId FROM ROle INNER JOIN AIAUserActivity ON Role.Id = AIAUserActivity.RoleId"; | |
28 | - | |
29 | - //DataTable userTable = objClass.FetchDataFromTable(aiaUserCommand); | |
30 | - //DataTable roleTable = objClass.FetchDataFromTable(roleCommand); | |
31 | - | |
32 | - //DataTable resultTable = objClass.ReturnModifiedTable(userTable, roleTable); | |
33 | - //string aiaUserJson = objClass.DataTableToJSONWithJSONNet(resultTable); | |
34 | - | |
35 | - //System.IO.File.WriteAllText("D:/AIAUser.json", aiaUserJson); | |
36 | - //label1.Text = "Conversion Successfull."; | |
37 | - | |
38 | - | |
39 | - | |
40 | - // raw quries having all Columns | |
41 | - // SELECT U.Id, U.LoginId, U.Password, U.FirstName, U.LastName, U.UserTypeId, UT.Title AS UserRoleName, | |
42 | - //U.EmailId, U.IsActive, U.SecurityQuestionId, sq.Title as SecurityQuestion, U.SecurityAnswer, U.CreatorId, U.CreationDate, U.ModifierId, | |
43 | - // U.ModifiedDate, U.DeactivationDate FROM AIAUser U,UserType UT, SecurityQuestion sq | |
44 | - // WHERE U.UserTypeId = UT.Id and U.SecurityQuestionId = sq.Id | |
45 | - | |
46 | - // select distinct ule.UserId,mt.ModuleId,rm.Title from LicenseToEdition le,AIAUserToLicenseEdition ule, | |
47 | - //ModuleToLicense mt, ResourceModule rm where le.LicenseId = ule.LicenseEditionId and le.LicenseId=mt.LicenseId | |
48 | - //and rm.Id = mt.ModuleId order by ule.UserId,mt.ModuleId | |
49 | 26 | try |
50 | 27 | { |
51 | 28 | string userProfileQuery = "SELECT U.Id, U.LoginId as loginId, U.Password as password, U.FirstName as firstName, U.LastName as lastName, UT.Title AS userType," |
... | ... | @@ -73,7 +50,7 @@ namespace SQLToJSON |
73 | 50 | } |
74 | 51 | catch (Exception ex) |
75 | 52 | { |
76 | - | |
53 | + System.IO.File.WriteAllText("D:/AIAUser.json", "EXCEPTION:"+ex.Message); | |
77 | 54 | } |
78 | 55 | |
79 | 56 | ... | ... |