Advertisement
Guest User

C#

a guest
Jan 26th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1. -----
  2. Form1
  3. -----
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using System.Data.Sql;
  14. using System.Data.SqlClient;
  15.  
  16. namespace WindowsFormsApp1
  17. {
  18. public partial class Form1 : Form
  19. {
  20. // string LCA = "Data Source=localhost;Initial Catalog=LerarenCijferApplicatie;Integrated Security=True";
  21.  
  22.  
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. PasswordTXT.PasswordChar = '*';
  27.  
  28.  
  29. }
  30.  
  31. private void button1_Click(object sender, EventArgs e)
  32. {
  33. string Username = this.UsernameTXT.Text;
  34. string Password = this.PasswordTXT.Text;
  35. try
  36. {
  37. string LCAConnection = "Data Source=localhost;Initial Catalog=LerarenCijferApplicatie;Integrated Security=True";
  38. SqlConnection LCA = new SqlConnection(LCAConnection);
  39. SqlCommand LCACOM = new SqlCommand("SELECT * FROM LoginData where Username='" + Username + "' and Password='" + Password + "';",LCA);
  40. SqlDataReader LCAReader;
  41.  
  42. LCA.Open();
  43. LCAReader = LCACOM.ExecuteReader();
  44.  
  45. int count = 0;
  46.  
  47. while (LCAReader.Read())
  48. {
  49. count = count + 1;
  50. }
  51.  
  52. if (count == 1)
  53. {
  54. MessageBox.Show("U bent nu ingelogd, " + UsernameTXT.Text);
  55. this.Visible = false;
  56. Form2 InvoerForm = new Form2("Welkom, " + UsernameTXT.Text);
  57. InvoerForm.ShowDialog();
  58. //this.Hide();
  59. //From2 f2 = new Form2();
  60. //f2.ShowDialog();
  61. }
  62. else if (count > 1)
  63. {
  64. MessageBox.Show("duplicate username and password");
  65. }
  66. else
  67. {
  68. MessageBox.Show("Gebruikersnaam en/of wachtwoord is incorrect");
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. MessageBox.Show(ex.Message);
  74. }
  75.  
  76. //this.Visible = false;
  77. //Form2 P = new Form2();
  78. //P.ShowDialog();
  79.  
  80. }
  81. }
  82. }
  83. -----
  84. Form2
  85. -----
  86. using System;
  87. using System.Collections.Generic;
  88. using System.ComponentModel;
  89. using System.Data;
  90. using System.Drawing;
  91. using System.Linq;
  92. using System.Text;
  93. using System.Threading.Tasks;
  94. using System.Windows.Forms;
  95. using System.Data.Sql;
  96. using System.Data.SqlClient;
  97.  
  98. namespace WindowsFormsApp1
  99. {
  100. public partial class Form2 : Form
  101. {
  102. SqlConnection sc = new SqlConnection();
  103. //int x = Int32.Parse(CijferBOX.Text);
  104.  
  105.  
  106. public Form2(string Username)
  107. {
  108. InitializeComponent();
  109. UsernameLBL.Text = Username;
  110.  
  111.  
  112. }
  113.  
  114. private void Form2_Load(object sender, EventArgs e)
  115. {
  116. sc.ConnectionString = ("Data Source=localhost; Initial Catalog = LerarenCijferApplicatie; Integrated Security=True;");
  117. }
  118.  
  119. private void InvoerBTN_Click(object sender, EventArgs e)
  120. {
  121.  
  122. try
  123. {
  124. int x = Int32.Parse(CijferBOX.Text);
  125.  
  126. SqlCommand Invoer = new SqlCommand();
  127. sc.Open();
  128.  
  129. Invoer.Connection = sc;
  130.  
  131. Invoer.CommandText = (@"INSERT INTO ResultaatData (Voornaam, Achternaam, Vak, Cijfer)
  132. VALUES ('" + VoornaamBOX.Text + "','" + AchternaamBOX.Text + "','" + VakBOX.Text + "','" + x + "');");
  133. Invoer.ExecuteNonQuery();
  134.  
  135. sc.Close();
  136.  
  137. VoornaamBOX.Text = "";
  138. AchternaamBOX.Text = "";
  139. VakBOX.Text = "";
  140. CijferBOX.Text = "";
  141.  
  142. MessageBox.Show("De gegevens zijn opgeslagen");
  143. }
  144. catch { MessageBox.Show("Er is iets fout gegaan bij het versturen"); }
  145.  
  146. }
  147.  
  148. private void BekijkBTN_Click(object sender, EventArgs e)
  149. {
  150. try
  151. {
  152. Form3 BekijkApplicatie = new Form3();
  153. BekijkApplicatie.ShowDialog();
  154. }
  155. catch { MessageBox.Show("Er is iets fout gegaan"); }
  156. }
  157. }
  158. }
  159. -----
  160. Form3
  161. -----
  162. using System;
  163. using System.Collections.Generic;
  164. using System.ComponentModel;
  165. using System.Data;
  166. using System.Drawing;
  167. using System.Linq;
  168. using System.Text;
  169. using System.Threading.Tasks;
  170. using System.Windows.Forms;
  171. using System.Data.Sql;
  172. using System.Data.SqlClient;
  173.  
  174. namespace WindowsFormsApp1
  175. {
  176. public partial class Form3 : Form
  177. {
  178.  
  179. string connectionstring = @"Data Source=localhost; Initial Catalog=LerarenCijferApplicatie;Integrated Security=True;";
  180.  
  181. public Form3()
  182. {
  183. InitializeComponent();
  184. }
  185.  
  186. private void Form3_Load(object sender, EventArgs e)
  187. {
  188. // ResultaatGridView.DataSource = ResultaatLijst();
  189.  
  190. using (SqlConnection sc = new SqlConnection(connectionstring))
  191. {
  192. sc.Open();
  193. SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM ResultaatData", sc);
  194. DataTable dt = new DataTable();
  195. sda.Fill(dt);
  196.  
  197. ResultaatGridView.DataSource = dt;
  198. }
  199.  
  200. }
  201.  
  202. private void AfsluitBTN_Click(object sender, EventArgs e)
  203. {
  204. try
  205. {
  206. this.Hide();
  207. }
  208. catch { MessageBox.Show("Er is iets fout gegaan bij het sluiten van de applicatie"); }
  209. }
  210.  
  211. // private DataTable ResultaatLijst()
  212. // {
  213. // DataTable dtResultaatLijst = new DataTable();
  214.  
  215. // return dtResultaatLijst;
  216.  
  217. //}
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement