Advertisement
Guest User

Untitled

a guest
Mar 9th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.38 KB | None | 0 0
  1. using Android.App;
  2. using Android.Widget;
  3. using Android.OS;
  4. using Android.Gms.Ads;
  5. using SQLite;
  6. using System.IO;
  7. using System;
  8.  
  9. namespace LogInApplication
  10. {
  11. [Activity(Label = "Log In Application", MainLauncher = true, Icon = "@mipmap/icon")]
  12. public class MainActivity : Activity
  13. {
  14.  
  15. protected AdView mAdView;
  16. private InterstitialAd interstitialAds = null;
  17.  
  18.  
  19. EditText txtusername;
  20. EditText txtPassword;
  21. Button btncreate;
  22. Button btnsign;
  23. Button btnedit;
  24. protected override void OnCreate(Bundle bundle)
  25. {
  26. base.OnCreate(bundle);
  27. // Set our view from the "main" layout resource
  28. SetContentView(Resource.Layout.Main);
  29. // Get our button from the layout resource,
  30. // and attach an event to it
  31.  
  32. interstitialAds = new InterstitialAd(this);
  33. mAdView = FindViewById<AdView>(Resource.Id.adView);
  34. var adRequest = new AdRequest.Builder().Build();
  35. mAdView.LoadAd(adRequest);
  36. //setting unit id for interstitial ad
  37. interstitialAds.AdUnitId = "ca - app - pub - 3113453000644941 / 8764416112";
  38. //loading test ad using adrequest
  39. interstitialAds.LoadAd(adRequest);
  40.  
  41. interstitialAds.AdListener = new AdListener(this);
  42.  
  43.  
  44.  
  45. btnsign = FindViewById<Button>(Resource.Id.btnlogin);
  46. btncreate = FindViewById<Button>(Resource.Id.btnregister);
  47. btnedit = FindViewById<Button>(Resource.Id.btnforgot);
  48. txtusername = FindViewById<EditText>(Resource.Id.txtusername);
  49. txtPassword = FindViewById<EditText>(Resource.Id.txtpwd);
  50. btnsign.Click += Btnsign_Click;
  51. btncreate.Click += Btncreate_Click;
  52. btnedit.Click += Btnedit_Click;
  53. CreateDB();
  54. }
  55.  
  56.  
  57. class AdListener : Android.Gms.Ads.AdListener
  58. {
  59. MainActivity main;
  60.  
  61. public AdListener(MainActivity innerMain)
  62. {
  63. main = innerMain;
  64. }
  65.  
  66. public override void OnAdLoaded()
  67. {
  68. base.OnAdLoaded();
  69. main.interstitialAds.Show();
  70. }
  71. }
  72.  
  73.  
  74.  
  75. private void Btncreate_Click(object sender, EventArgs e)
  76. {
  77. StartActivity(typeof(RegisterActivity));
  78. }
  79.  
  80. private void Btnedit_Click(object sender, EventArgs e)
  81. {
  82. StartActivity(typeof(ForgotActivity));
  83. }
  84.  
  85. private void Btnsign_Click(object sender, EventArgs e)
  86. {
  87. try
  88. {
  89. string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db3"); //Call Database
  90. var db = new SQLiteConnection(dpPath);
  91. var data = db.Table<LoginTable>(); //Call Table
  92. var data1 = data.Where(x => x.username == txtusername.Text && x.password == txtPassword.Text).FirstOrDefault(); //Linq Query
  93. if (data1 != null)
  94. {
  95. Toast.MakeText(this, "Login Success", ToastLength.Short).Show();
  96. StartActivity(typeof(WelcomeActivity));
  97. }
  98. else
  99. {
  100. Toast.MakeText(this, "Username or Password invalid", ToastLength.Short).Show();
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. Toast.MakeText(this, ex.ToString(), ToastLength.Short).Show();
  106. }
  107. }
  108. public string CreateDB()
  109. {
  110. var output = "";
  111. output += "Creating Database if it doesn't exits";
  112. string dpPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "user.db3"); //Create New Database
  113. var db = new SQLiteConnection(dpPath);
  114. output += "n Database Created.....";
  115. return output;
  116. }
  117. }
  118. }
  119.  
  120. <?xml version="1.0" encoding="utf-8"?>
  121. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  122. xmlns:tools="http://schemas.android.com/tools"
  123. xmlns:ads="http://schemas.android.com/apk/res-auto"
  124. android:orientation="vertical"
  125. android:layout_width="match_parent"
  126. android:layout_height="match_parent"
  127. android:background="@android:color/darker_gray"
  128. android:weightSum="100"
  129. android:minWidth="25px"
  130. android:minHeight="25px">
  131. <TextView
  132. android:text="LOGIN"
  133. android:textAppearance="?android:attr/textAppearanceMedium"
  134. android:textColor="@android:color/black"
  135. android:textSize="25sp"
  136. android:layout_width="match_parent"
  137. android:layout_height="wrap_content"
  138. android:gravity="center"
  139. android:id="@+id/textView1" />
  140. <EditText
  141. android:id="@+id/txtusername"
  142. android:layout_width="fill_parent"
  143. android:textColorHint="@android:color/black"
  144. android:hint="Username"
  145. android:layout_height="wrap_content" />
  146. <EditText
  147. android:id="@+id/txtpwd"
  148. android:layout_width="fill_parent"
  149. android:textColorHint="@android:color/black"
  150. android:hint="Password"
  151. android:inputType="textPassword"
  152. android:layout_height="wrap_content" />
  153. <Button
  154. android:id="@+id/btnlogin"
  155. android:layout_width="match_parent"
  156. android:layout_height="wrap_content"
  157. android:layout_weight="1"
  158. android:background="@drawable/ButtonLogInStyle"
  159. android:textSize="20sp"
  160. android:text="Log In"
  161. android:layout_marginLeft="20dp"
  162. android:layout_marginRight="20dp"
  163. android:layout_marginBottom="20dp" />
  164. <Button
  165. android:id="@+id/btnforgot"
  166. android:layout_width="match_parent"
  167. android:layout_height="wrap_content"
  168. android:layout_weight="1"
  169. android:background="@drawable/ButtonLogInStyle"
  170. android:textSize="15sp"
  171. android:text="Forgot Password?"
  172. android:layout_marginLeft="60dp"
  173. android:layout_marginRight="60dp"
  174. android:layout_marginBottom="20dp" />
  175. <Button
  176. android:id="@+id/btnregister"
  177. android:layout_width="match_parent"
  178. android:layout_height="wrap_content"
  179. android:layout_weight="1"
  180. android:background="@drawable/ButtonSignUpStyle"
  181. android:textSize="20sp"
  182. android:text="Register"
  183. android:layout_marginLeft="20dp"
  184. android:layout_marginRight="20dp"
  185. android:layout_marginBottom="170dp" />
  186. <com.google.android.gms.ads.AdView
  187. android:id="@+id/adView"
  188. android:layout_width="match_parent"
  189. android:layout_height="wrap_content"
  190. ads:adSize="BANNER"
  191. ads:adUnitId="ca-app-pub-3940256099942544/6300978111" />
  192. </LinearLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement