Skip to content

Commit

Permalink
Repozitoriji
Browse files Browse the repository at this point in the history
Dodani su repozitoriji i metode
  • Loading branch information
Juric22 committed Jun 12, 2024
1 parent 2a2adc7 commit 216cfef
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 7 deletions.
6 changes: 3 additions & 3 deletions Software/SZUUP/SZUUP/FrmPrijava.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ public FrmPrijava()

private void button1_Click(object sender, EventArgs e)
{
string username = UsernameTxt.Text;
string password = PasswordTxt.Text;
string username = txtUsername.Text;
string password = txtPassword.Text;

// Provjera korisničkih podataka
var zaposlenik = StudentRepository.GetStudent(username);
var zaposlenik = RepozitorijZaposlenik.GetZaposlenik(username);

if (zaposlenik != null && student.Password == password)
{
Expand Down
17 changes: 17 additions & 0 deletions Software/SZUUP/SZUUP/Models/Jelo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SZUUP.Models
{
public class Jelo
{
public int Id_jelo { get; set; }
public int Id_Kategorija { get; set; }
public string Naziv { get; set; }
public float Cijena { get; set; }
public string Detalji { get; set; }
}
}
15 changes: 15 additions & 0 deletions Software/SZUUP/SZUUP/Models/Zaposlenik.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SZUUP.Models
{
internal class Zaposlenik
{
public int Id_zaposlenika { get; set; }
public string Kor_ime { get; set; }
public string Lozinka { get; set; }
}
}
50 changes: 50 additions & 0 deletions Software/SZUUP/SZUUP/Repozitoris/RepozitorijJelo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using DBLayer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SZUUP.Models;

namespace SZUUP.Repozitoris
{
public class RepozitorijJelo
{
public static Jelo GetJelo(int id)
{
Jelo jelo = null;
string sql = $"SELECT * FROM jelo WHERE Id_jelo = {id}";
DB.OpenConnection();
var reader = DB.GetDataReader(sql);
if (reader.HasRows)
{
reader.Read();
jelo = CreateObject(reader);
reader.Close();
}
DB.CloseConnection();
return jelo;
}
public static List<Jelo> GetJelo()
{
List<Jelo> jela = new List<Jelo>();
string sql = "SELECT * FROM jelo";
DB.OpenConnection();
var reader = DB.GetDataReader(sql);
while (reader.Read())
{
Jelo jelo = CreateObject(reader);
Jelo.Add(jelo);
}
reader.Close();
DB.CloseConnection();
return jelo;
}

private static Jelo CreateObject(SqlDataReader reader)
{
throw new NotImplementedException();
}
}
}
54 changes: 54 additions & 0 deletions Software/SZUUP/SZUUP/Repozitoris/RepozitorijZaposlenik.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using DBLayer;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;

namespace SZUUP.Repozitoris
{
public class RepozitorijZaposlenik
{
string sql = $"SELECT * FROM zaposlenik WHERE Kor_ime = '{Kor_ime}'";
return FetchZaposlenik(sql);
}
public static Zaposlenik GetZaposlenik(int id)
{
string sql = $"SELECT * FROM zaposlenik WHERE Id_zaposlenika = {id}";
return FetchTeacher(sql);
}
private static Teacher FetchTeacher(string sql)
{
DB.OpenConnection();
var reader = DB.GetDataReader(sql);
Teacher teacher = null;
if (reader.HasRows == true)
{
reader.Read();
teacher = CreateObject(reader);
reader.Close();
}
DB.CloseConnection();
return teacher;
}
private static Teacher CreateObject(SqlDataReader reader)
{
int id = int.Parse(reader["Id"].ToString());
string firstName = reader["FirstName"].ToString();
string lastName = reader["LastName"].ToString();
string username = reader["Username"].ToString();
string password = reader["Password"].ToString();
var teacher = new Teacher
{
Id = id,
FirstName = firstName,
LastName = lastName,
Username = username,
Password = password
};
return teacher;
}

}
9 changes: 5 additions & 4 deletions Software/SZUUP/SZUUP/SZUUP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@
<Compile Include="FrmUnos.Designer.cs">
<DependentUpon>FrmUnos.cs</DependentUpon>
</Compile>
<Compile Include="Models\Jelo.cs" />
<Compile Include="Models\Zaposlenik.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Repozitoris\RepozitorijJelo.cs" />
<Compile Include="Repozitoris\RepozitorijZaposlenik.cs" />
<EmbeddedResource Include="frmPopisJela.resx">
<DependentUpon>frmPopisJela.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -104,9 +108,6 @@
<ItemGroup>
<Content Include="dlls\DBLayer.dll" />
</ItemGroup>
<ItemGroup>
<Folder Include="Models\" />
<Folder Include="Repozitoris\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

0 comments on commit 216cfef

Please sign in to comment.