Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----
- Form1
- -----
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.Sql;
- using System.Data.SqlClient;
- namespace WindowsFormsApp1
- {
- public partial class Form1 : Form
- {
- // string LCA = "Data Source=localhost;Initial Catalog=LerarenCijferApplicatie;Integrated Security=True";
- public Form1()
- {
- InitializeComponent();
- PasswordTXT.PasswordChar = '*';
- }
- private void button1_Click(object sender, EventArgs e)
- {
- string Username = this.UsernameTXT.Text;
- string Password = this.PasswordTXT.Text;
- try
- {
- string LCAConnection = "Data Source=localhost;Initial Catalog=LerarenCijferApplicatie;Integrated Security=True";
- SqlConnection LCA = new SqlConnection(LCAConnection);
- SqlCommand LCACOM = new SqlCommand("SELECT * FROM LoginData where Username='" + Username + "' and Password='" + Password + "';",LCA);
- SqlDataReader LCAReader;
- LCA.Open();
- LCAReader = LCACOM.ExecuteReader();
- int count = 0;
- while (LCAReader.Read())
- {
- count = count + 1;
- }
- if (count == 1)
- {
- MessageBox.Show("U bent nu ingelogd, " + UsernameTXT.Text);
- this.Visible = false;
- Form2 InvoerForm = new Form2("Welkom, " + UsernameTXT.Text);
- InvoerForm.ShowDialog();
- //this.Hide();
- //From2 f2 = new Form2();
- //f2.ShowDialog();
- }
- else if (count > 1)
- {
- MessageBox.Show("duplicate username and password");
- }
- else
- {
- MessageBox.Show("Gebruikersnaam en/of wachtwoord is incorrect");
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message);
- }
- //this.Visible = false;
- //Form2 P = new Form2();
- //P.ShowDialog();
- }
- }
- }
- -----
- Form2
- -----
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.Sql;
- using System.Data.SqlClient;
- namespace WindowsFormsApp1
- {
- public partial class Form2 : Form
- {
- SqlConnection sc = new SqlConnection();
- //int x = Int32.Parse(CijferBOX.Text);
- public Form2(string Username)
- {
- InitializeComponent();
- UsernameLBL.Text = Username;
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- sc.ConnectionString = ("Data Source=localhost; Initial Catalog = LerarenCijferApplicatie; Integrated Security=True;");
- }
- private void InvoerBTN_Click(object sender, EventArgs e)
- {
- try
- {
- int x = Int32.Parse(CijferBOX.Text);
- SqlCommand Invoer = new SqlCommand();
- sc.Open();
- Invoer.Connection = sc;
- Invoer.CommandText = (@"INSERT INTO ResultaatData (Voornaam, Achternaam, Vak, Cijfer)
- VALUES ('" + VoornaamBOX.Text + "','" + AchternaamBOX.Text + "','" + VakBOX.Text + "','" + x + "');");
- Invoer.ExecuteNonQuery();
- sc.Close();
- VoornaamBOX.Text = "";
- AchternaamBOX.Text = "";
- VakBOX.Text = "";
- CijferBOX.Text = "";
- MessageBox.Show("De gegevens zijn opgeslagen");
- }
- catch { MessageBox.Show("Er is iets fout gegaan bij het versturen"); }
- }
- private void BekijkBTN_Click(object sender, EventArgs e)
- {
- try
- {
- Form3 BekijkApplicatie = new Form3();
- BekijkApplicatie.ShowDialog();
- }
- catch { MessageBox.Show("Er is iets fout gegaan"); }
- }
- }
- }
- -----
- Form3
- -----
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.Data.Sql;
- using System.Data.SqlClient;
- namespace WindowsFormsApp1
- {
- public partial class Form3 : Form
- {
- string connectionstring = @"Data Source=localhost; Initial Catalog=LerarenCijferApplicatie;Integrated Security=True;";
- public Form3()
- {
- InitializeComponent();
- }
- private void Form3_Load(object sender, EventArgs e)
- {
- // ResultaatGridView.DataSource = ResultaatLijst();
- using (SqlConnection sc = new SqlConnection(connectionstring))
- {
- sc.Open();
- SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM ResultaatData", sc);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- ResultaatGridView.DataSource = dt;
- }
- }
- private void AfsluitBTN_Click(object sender, EventArgs e)
- {
- try
- {
- this.Hide();
- }
- catch { MessageBox.Show("Er is iets fout gegaan bij het sluiten van de applicatie"); }
- }
- // private DataTable ResultaatLijst()
- // {
- // DataTable dtResultaatLijst = new DataTable();
- // return dtResultaatLijst;
- //}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement