Guest User

Untitled

a guest
Aug 3rd, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.Specialized;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Text;
  7.  
  8. using Android.App;
  9. using Android.Content;
  10. using Android.Graphics;
  11. using Android.OS;
  12. using Android.Runtime;
  13. using Android.Support.Design.Widget;
  14. using Android.Support.V7.App;
  15. using Android.Views;
  16. using Android.Widget;
  17.  
  18. namespace CPDEP1
  19. {
  20. [Activity(Label = "Formulaire d'enregistrement", Theme="@style/Theme.AppCompat.Light")]
  21. public class FormActivity : AppCompatActivity
  22. {
  23. CoordinatorLayout FrootLayout;
  24. protected override void OnCreate(Bundle savedInstanceState)
  25. {
  26. base.OnCreate(savedInstanceState);
  27. FrootLayout = FindViewById<CoordinatorLayout>(Resource.Id.FcoordLayout);
  28. SetContentView(Resource.Layout.Form);
  29. var inputNom = FindViewById<EditText>(Resource.Id.nom);
  30. var inputPrenom = FindViewById<EditText>(Resource.Id.pren);
  31. var inputTel = FindViewById<EditText>(Resource.Id.tel);
  32. var inputID = FindViewById<EditText>(Resource.Id.iden);
  33. var inputDep = FindViewById<EditText>(Resource.Id.dep);
  34. var inputCom = FindViewById<EditText>(Resource.Id.com);
  35. var savebtn = FindViewById<Button>(Resource.Id.save);
  36. var inputAdresse = FindViewById<EditText>(Resource.Id.adresse);
  37. var inputCourriel = FindViewById<EditText>(Resource.Id.email);
  38.  
  39. savebtn.Click += delegate
  40. {
  41. string nom = inputNom.Text;
  42. string prenom = inputPrenom.Text;
  43. string tel = inputTel.Text;
  44. string id = inputID.Text;
  45. string dep = inputDep.Text;
  46. string com = inputCom.Text;
  47. string adress = inputAdresse.Text;
  48. string courriel = inputCourriel.Text;
  49.  
  50. //REceiving value from an activity
  51. //string user = Intent.GetStringExtra("User");
  52. //string pass = Intent.GetStringExtra("Password");
  53.  
  54.  
  55. if (nom == null || prenom == null || tel == null || id == null || dep == null || com == null || adress == null || courriel == null)
  56. {
  57. ////////////SSNACKBAR///////////
  58. Snackbar snack = Snackbar.Make(FrootLayout, "Empty Field", Snackbar.LengthShort)
  59. .SetAction("", (view) =>
  60. {
  61. Toast.MakeText(this, "OK", ToastLength.Short).Show();
  62. }).SetActionTextColor(Color.ParseColor("#000000"));
  63.  
  64. View SnackView = snack.View;
  65. SnackView.SetBackgroundColor(Color.ParseColor("#E72222"));
  66. snack.Show();
  67.  
  68. }
  69. else
  70. {
  71. WebClient client = new WebClient();
  72. Uri uri = new Uri("http://localhost/CRUDSERVICE/CreateContact.php");
  73. NameValueCollection parameters = new NameValueCollection();
  74.  
  75. parameters.Add("Nom", nom);
  76. parameters.Add("Prenom", prenom);
  77. parameters.Add("Tel", tel);
  78. parameters.Add("Dep", dep);
  79. parameters.Add("Com", com);
  80. parameters.Add("Adress", adress);
  81. parameters.Add("Courriel", courriel);
  82.  
  83. client.UploadValuesAsync(uri, parameters);
  84.  
  85.  
  86.  
  87.  
  88.  
  89. }
  90. };
  91.  
  92. }
  93.  
  94. // }
  95.  
  96.  
  97. }
  98.  
  99. <?php
  100.  
  101. class ConnectionInfo
  102. {
  103. public $mServerName;
  104. public $mConnectionInfo;
  105. public $conn;
  106.  
  107. public function GetConnection()
  108. {
  109. $this->mServerName = 'localhost';
  110. $this->mConnectionInfo = array("Database"=>"formation", "UID"=>"root", "PWD"=>"cpdep");
  111. $this->conn = sqlsrv_connect($this->mServerName,$this->mConnectionInfo);
  112.  
  113. return $this->conn;
  114. }
  115. }
  116. ?>
  117.  
  118. <?php
  119. require_once(dirname(__FILE__).'/ConnectionInfo.php');
  120.  
  121.  
  122. if (isset($_POST['Nom']) && isset($_POST['Prenom']) && isset($_POST['Tel']) && isset($_POST['Dep']) && isset($_POST['Com']) && isset($_POST['Adress']) && isset($_POST['Courriel']))
  123. {
  124. //Get the POST variables
  125. $mNom = $_POST['Nom'];
  126. $mPrenom = $_POST['Prenom'];
  127. $mTel = $_POST['Tel'];
  128. $mDep = $_POST['Dep'];
  129. $mCom = $_POST['Com'];
  130. $mAdress = $_POST['Adress'];
  131. $mCourriel = $_POST['Courriel'];
  132.  
  133.  
  134. //Set up our connection
  135. $connectionInfo = new ConnectionInfo();
  136. $connectionInfo->GetConnection();
  137.  
  138. if (!$connectionInfo->conn)
  139. {
  140. //Connection failed
  141. echo 'No Connection';
  142. }
  143.  
  144. else
  145. {
  146. //Insert new contact into database
  147. $query = 'INSERT INTO thinktank (nom, prenom, telephone, departement, commune, adresse, courriel) VALUES (?, ?, ?, ?, ?, ?, ?)';
  148. $parameters = array($mNom, $mPrenom, $mTel, $mDep, $mCom, $mAdress, $mCourriel);
  149.  
  150. //Execute query
  151. $stmt = sqlsrv_query($connectionInfo->conn, $query, $parameters);
  152.  
  153. if (!$stmt)
  154. { //The query failed
  155. echo 'Query Failed';
  156. }
  157.  
  158. else
  159. {
  160. //The query succeeded, now echo back the new contact ID
  161. $query = "SELECT IDENT_CURRENT('Contacts') AS NewID";
  162. $stmt = sqlsrv_query($connectionInfo->conn, $query);
  163.  
  164. $row = sqlsrv_fetch_array($stmt,SQLSRV_FETCH_ASSOC);
  165.  
  166. echo $row['NewID'];
  167. }
  168. }
  169. }
  170.  
  171. ?>
  172.  
  173. String prenom="john";
  174. String nom="doe";
  175. String tel="025545";
  176. String dep="security";
  177. String com="somecom";
  178. String adress="street431";
  179. String courriel="youremail@gmail.com";
  180. // let's build our link
  181. String link="http://localhost/CRUDSERVICE/CreateContact.php?Nom="+nom+"&Prenom="+prenom+"&Tel="+tel+"&Dep="+dep+"&Com="+com+"&Adress+"+adress+"&Courriel="+courriel;
  182. WebClient wc=new WebClient(); // don't forget using System.Net;
  183. String res=wc.DownloadString(link); // res is data printed by echo
  184. if(res.equals("No Connection ") || res.equals("Query Failed"))
  185. {
  186. // something went wrong
  187. }
  188. else
  189. {
  190.  
  191. }
Add Comment
Please, Sign In to add comment