Advertisement
Guest User

име

a guest
Apr 27th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. using Android.App;
  2. using Android.Widget;
  3. using Android.OS;
  4. using System.IO;
  5. using SQLite;
  6. using System.Collections;
  7.  
  8. namespace Kursova_xamarin
  9. {
  10. [Activity(Label = "Kursova_xamarin", MainLauncher = true)]
  11. public class MainActivity : Activity
  12. {
  13. Button entry_button;
  14. Button register_button;
  15. EditText username;
  16. EditText password;
  17.  
  18. static string dbPath = Path.Combine(
  19. System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal),
  20. "radostina_shte_kaje_kogato_se_seti.db3");
  21. SQLiteConnection kyso_ime = new SQLiteConnection(dbPath);
  22.  
  23. protected override void OnCreate(Bundle savedInstanceState)
  24. {
  25. base.OnCreate(savedInstanceState);
  26.  
  27. // Set our view from the "main" layout resource
  28. SetContentView(Resource.Layout.Main);
  29. entry_button = FindViewById<Button>(Resource.Id.button1);
  30. entry_button.Click += Entry_button_Click;
  31.  
  32. register_button = FindViewById<Button>(Resource.Id.button2);
  33. register_button.Click += Register_button_Click;
  34.  
  35. username = FindViewById<EditText>(Resource.Id.editText1);
  36. password = FindViewById<EditText>(Resource.Id.editText2);
  37.  
  38. kyso_ime.CreateTable<Users>();
  39. }
  40.  
  41. private void Register_button_Click(object sender, System.EventArgs e)
  42. {
  43. //трябва да се реши тук ще запазва само име и парола или ще отваря нова страница за регистрация, май трябва пак да ми се обясни концепцията
  44.  
  45. var newUser = new Users();
  46.  
  47. newUser.Name = username.Text;
  48. newUser.Password = password.Text;
  49. kyso_ime.Insert(newUser);
  50. //throw new System.NotImplementedException();
  51. }
  52.  
  53. private void Entry_button_Click(object sender, System.EventArgs e)
  54. {
  55. var kyso_ime = new SQLiteConnection(dbPath);
  56.  
  57. var table = kyso_ime.Table<Users>();
  58. foreach (var s in table)
  59. {
  60. if ((s.Name == username.Text) && (s.Password == password.Text))
  61. {
  62. //отваря нова страница и изпраща данни до нея
  63. Toast.MakeText(this, "vhod uspeshen", ToastLength.Short).Show();
  64. }
  65. else
  66. {
  67. //грешка, евентуално, ти си шефа
  68. Toast.MakeText(this, "vhod neuspeshen", ToastLength.Short).Show();
  69. }
  70. }
  71. //throw new System.NotImplementedException();
  72. }
  73.  
  74. [Table("users")]
  75. public class Users
  76. {
  77. [PrimaryKey, AutoIncrement, Column("_id")]
  78. public int Id { get; set; }
  79. [MaxLength(20)]
  80. public string Name { get; set; }
  81. [MaxLength(10)]
  82. public string Password { get; set; }
  83. //базата трябва да има и други данни най-вероятно
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement