Advertisement
Guest User

Untitled

a guest
Aug 31st, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. namespace primemobilebase.PrimeClasses
  2. {
  3. public class PrimeCommand
  4. {
  5.  
  6.  
  7. //string resultString;
  8. public async Task<string> PrimeMethod(string commandtext, string content)
  9. {
  10. using (var client = new HttpClient())
  11. {
  12. var contents = new StringContent(content);
  13. var response = await client.PostAsync(Api.base_url + commandtext, contents);
  14. var responseString = await response.Content.ReadAsStringAsync();
  15. return responseString;
  16. }
  17. }
  18.  
  19. public async Task<string> PrimeLogin(string username, string password)
  20. {
  21. using (var client = new HttpClient())
  22. {
  23. var newLogin = new LoginObject();
  24.  
  25. // var jsonResultString = JsonConvert.SerializeObject(newLogin);
  26. newLogin.UserName = username;
  27. newLogin.Password = password;
  28. var contentObject = JsonConvert.SerializeObject(newLogin);
  29. var content = new StringContent(contentObject);
  30.  
  31. var response = await client.PostAsync(Api.base_url+Api.url_login, content);
  32. var responseString = await response.Content.ReadAsStringAsync();
  33.  
  34. //reading SessionID in JSON response
  35. dynamic responseObject = JsonConvert.DeserializeObject(responseString);
  36. var sessionID = responseObject.result.SessionID;
  37.  
  38. var searchObj = new SimpleSearchObject
  39. {
  40. SessionID = sessionID
  41. };
  42. var UserPage = new UserPage();
  43.  
  44. return sessionID;
  45. }
  46. }
  47. public async Task<string> PrimeLogout(string sessionId)
  48. {
  49. using (var client = new HttpClient())
  50. {
  51. var content = new StringContent(sessionId);
  52. var response = await client.PostAsync(Api.base_url+Api.url_logout, content);
  53. var responseString = await response.Content.ReadAsStringAsync();
  54.  
  55. return responseString;
  56. }
  57. }
  58.  
  59. public static SQLiteConnection _sqLiteConnection;
  60.  
  61. public void SqliteCon()
  62. {
  63.  
  64. try
  65. {
  66. _sqLiteConnection = DependencyService.Get<ISQLite>().GetConnection();
  67. _sqLiteConnection.CreateTable<LoginObject>();
  68. _sqLiteConnection.CreateTable<SalesInvoiceLine>();
  69. _sqLiteConnection.CreateTable<SalesInvoiceHeader>();
  70. _sqLiteConnection.CreateTable<SaleTransactions>();
  71. }
  72. catch (Exception ex)
  73. {
  74. //("Alert", ex.InnerException.Message, "OK");
  75. }
  76. }
  77.  
  78. public void insertDb(dynamic e)
  79. {
  80.  
  81.  
  82. _sqLiteConnection.Insert(new SalesInvoiceHeader
  83. {
  84. customerName = "" + ((Debtor)e.SelectedItem).debtor_name,
  85. price_level_id = ((Debtor)e.SelectedItem).price_level_id,
  86.  
  87. });
  88. }
  89.  
  90. public void insertItm(dynamic e)
  91. {
  92.  
  93.  
  94. _sqLiteConnection.Insert(new SalesInvoiceLine
  95. {
  96. itemDescription = "" + ((ItemModel)e.SelectedItem).item_desc,
  97.  
  98. });
  99. }
  100. public dynamic connectSOL()
  101. {
  102. return _sqLiteConnection.Table<SalesInvoiceLine>();
  103. }
  104. public dynamic connectCR()
  105. {
  106. return _sqLiteConnection.Table<Currency>();
  107. }
  108.  
  109. public dynamic connectSOH()
  110. {
  111. return _sqLiteConnection.Table<SalesInvoiceHeader>();
  112. }
  113. public dynamic connectWH()
  114. {
  115. return _sqLiteConnection.Table<Warehouse>();
  116. }
  117. public dynamic connectSR()
  118. {
  119. return _sqLiteConnection.Table<SalesRepresentative>();
  120. }
  121. public dynamic connectUser()
  122. {
  123. return _sqLiteConnection.Table<LoginObject>();
  124. }
  125. public dynamic connectST()
  126. {
  127. return _sqLiteConnection.Table<SaleTransactions>();
  128. }
  129. public void insertST(DateTime date, string jsonString, bool sent)
  130. {
  131. _sqLiteConnection.Insert(new SaleTransactions
  132. {
  133. date = date,
  134. jsonString = jsonString,
  135. sent = sent,
  136. });
  137.  
  138. }
  139.  
  140. public void deleteSql(string obj)
  141. {
  142.  
  143. if (obj == "LoginObject")
  144. {
  145. _sqLiteConnection.DeleteAll<LoginObject>();
  146. }
  147. else if (obj == "SalesInvoiceHeader")
  148. {
  149. _sqLiteConnection.DeleteAll<SalesInvoiceHeader>();
  150. }
  151. else if (obj == "SalesInvoiceLine")
  152. {
  153. _sqLiteConnection.DeleteAll<SalesInvoiceLine>();
  154. }
  155. else if (obj == "Warehouse")
  156. {
  157. _sqLiteConnection.DeleteAll<Warehouse>();
  158. }
  159. else if (obj == "SalesRepresentative")
  160. {
  161. _sqLiteConnection.DeleteAll<SalesRepresentative>();
  162. }
  163.  
  164.  
  165. }
  166. public void deleteSql(string obj, string itemDesc)
  167. {
  168.  
  169. if (obj == "SalesOrderLine")
  170. {
  171. _sqLiteConnection.ExecuteScalar<SalesInvoiceLine>("DELETE FROM SalesInvoiceLine WHERE itemDescription = ?", itemDesc);
  172.  
  173. }
  174. }
  175.  
  176. public void insertLogin(string username, string password, string responseString)
  177. {
  178. _sqLiteConnection.Insert(new LoginObject
  179. {
  180. UserName = username,
  181. Password = password,
  182. SessionID = responseString,
  183. });
  184. }
  185. public bool checkInternet()
  186. {
  187. try
  188. {
  189. if (CrossConnectivity.Current.IsConnected)
  190. {
  191. //MainPage = new NavigationPage(new LoginPage());
  192. return true;
  193. }
  194. }
  195. catch (Exception e)
  196. {
  197. }
  198. return false;
  199. }
  200. public SalesInvoiceHeader GetSoh()
  201. {
  202. return _sqLiteConnection.Table<SalesInvoiceHeader>().FirstOrDefault();
  203. }
  204. public SalesRepresentative GetSR()
  205. {
  206. return _sqLiteConnection.Table<SalesRepresentative>().FirstOrDefault();
  207. }
  208. public Warehouse GetWH()
  209. {
  210. return _sqLiteConnection.Table<Warehouse>().FirstOrDefault();
  211. }
  212. public List<SalesInvoiceLine> GetSol()
  213. {
  214. return _sqLiteConnection.Table<SalesInvoiceLine>().ToList();
  215. }
  216.  
  217.  
  218.  
  219.  
  220. public async Task<string> PrimePassingValue(string jsonstring)
  221. {
  222. try
  223. {
  224. Debug.WriteLine("Prime Passing");
  225.  
  226. using (var client = new HttpClient())
  227. {
  228. var httpContent = new StringContent(jsonstring, Encoding.UTF8, "application/json");
  229.  
  230. var response = await client.PostAsync(Api.base_url+"/SalesOrder/Add", httpContent);
  231. var responseString = await response.Content.ReadAsStringAsync();
  232.  
  233. Debug.WriteLine("resp (pc):" + responseString);
  234. return responseString;
  235. }
  236. }
  237. catch (Exception err)
  238. {
  239. //Debug.WriteLine("Error Prime Passing: " + err.InnerException.Message);
  240. return null;
  241. }
  242. }
  243.  
  244. }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement