Form1
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace zeljko_nrt_7514
{
public partial class Form1 : Form
{
List<Nalozi> listaNaloga;
string korisnikAvatarTxt;
public Form1()
{
InitializeComponent();
listaNaloga = new List<Nalozi>();
korisnikAvatarTxt = "";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void lblRegister_MouseEnter(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.Red;
}
private void lblRegister_MouseEnter_1(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.Black;
}
private void lblRegister_MouseLeave(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.White;
}
private void btnLogin_Click(object sender, EventArgs e)
{
string putanja = "nalozi.txt";
if (File.Exists(putanja))
{
List<Nalozi> listaDeserialize = new List<Nalozi>();
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.OpenRead(putanja);
listaDeserialize = bf.Deserialize(fs) as List<Nalozi>;
fs.Dispose();
foreach(Nalozi n in listaDeserialize){
if (n.tip.Equals("administrator") && n.username.Equals(txtUsername.Text) && n.password.Equals(txtPassword.Text))
{
Administrator aFrm = new Administrator();
aFrm.Show();
}
else if (n.tip.Equals("korisnik") && n.username.Equals(txtUsername.Text) && n.password.Equals(txtPassword.Text))
{
korisnikAvatarTxt = n.username;
Korisnik kFrm = new Korisnik();
kFrm.Show();
this.Hide();
}
else {
MessageBox.Show("Korisnicko ime ili lozinka nisu validni.");
}
}
}
else {
MessageBox.Show("Datoteka ne postoji!");
}
}
public string avatarText() {
return this.korisnikAvatarTxt;
}
private void lblRegister_Click(object sender, EventArgs e)
{
Registracija rFrm = new Registracija();
rFrm.Show();
this.Hide();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace zeljko_nrt_7514
{
public partial class Form1 : Form
{
List<Nalozi> listaNaloga;
string korisnikAvatarTxt;
public Form1()
{
InitializeComponent();
listaNaloga = new List<Nalozi>();
korisnikAvatarTxt = "";
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void lblRegister_MouseEnter(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.Red;
}
private void lblRegister_MouseEnter_1(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.Black;
}
private void lblRegister_MouseLeave(object sender, EventArgs e)
{
lblRegister.ForeColor = Color.White;
}
private void btnLogin_Click(object sender, EventArgs e)
{
string putanja = "nalozi.txt";
if (File.Exists(putanja))
{
List<Nalozi> listaDeserialize = new List<Nalozi>();
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.OpenRead(putanja);
listaDeserialize = bf.Deserialize(fs) as List<Nalozi>;
fs.Dispose();
foreach(Nalozi n in listaDeserialize){
if (n.tip.Equals("administrator") && n.username.Equals(txtUsername.Text) && n.password.Equals(txtPassword.Text))
{
Administrator aFrm = new Administrator();
aFrm.Show();
}
else if (n.tip.Equals("korisnik") && n.username.Equals(txtUsername.Text) && n.password.Equals(txtPassword.Text))
{
korisnikAvatarTxt = n.username;
Korisnik kFrm = new Korisnik();
kFrm.Show();
this.Hide();
}
else {
MessageBox.Show("Korisnicko ime ili lozinka nisu validni.");
}
}
}
else {
MessageBox.Show("Datoteka ne postoji!");
}
}
public string avatarText() {
return this.korisnikAvatarTxt;
}
private void lblRegister_Click(object sender, EventArgs e)
{
Registracija rFrm = new Registracija();
rFrm.Show();
this.Hide();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
registracija
Code:
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.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace zeljko_nrt_7514
{
public partial class Registracija : Form
{
List<Nalozi> listaNaloga;
public Registracija()
{
InitializeComponent();
listaNaloga = new List<Nalozi>();
}
private void btnRegistrujSe_Click(object sender, EventArgs e)
{
if (txtRegUsername.Text.Trim().Length == 0 || txtRegPassword.Text.Trim().Length == 0)
{
MessageBox.Show("Unesite podatke.");
return;
}
else if (!txtRegPassword.Text.Equals(txtRegRepw.Text))
{
lblPoklapanje.Visible = true;
lblPoklapanje.ForeColor = Color.Red;
return;
}
Nalozi nalog = new Nalozi("korisnik", txtRegUsername.Text, txtRegPassword.Text);
listaNaloga.Add(nalog);
MessageBox.Show("Uspesno ste se registrovali");
string putanja = "nalozi.txt";
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.OpenWrite(putanja);
bf.Serialize(fs, listaNaloga);
fs.Dispose();
Form1 frm1 = new Form1();
frm1.Show();
this.Close();
}
}
}
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.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace zeljko_nrt_7514
{
public partial class Registracija : Form
{
List<Nalozi> listaNaloga;
public Registracija()
{
InitializeComponent();
listaNaloga = new List<Nalozi>();
}
private void btnRegistrujSe_Click(object sender, EventArgs e)
{
if (txtRegUsername.Text.Trim().Length == 0 || txtRegPassword.Text.Trim().Length == 0)
{
MessageBox.Show("Unesite podatke.");
return;
}
else if (!txtRegPassword.Text.Equals(txtRegRepw.Text))
{
lblPoklapanje.Visible = true;
lblPoklapanje.ForeColor = Color.Red;
return;
}
Nalozi nalog = new Nalozi("korisnik", txtRegUsername.Text, txtRegPassword.Text);
listaNaloga.Add(nalog);
MessageBox.Show("Uspesno ste se registrovali");
string putanja = "nalozi.txt";
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.OpenWrite(putanja);
bf.Serialize(fs, listaNaloga);
fs.Dispose();
Form1 frm1 = new Form1();
frm1.Show();
this.Close();
}
}
}
evo i celog projekta:
Projekat