-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dodanie metod webowych do manipulacji danymi Piw.
- Loading branch information
Montwulf
committed
Nov 16, 2014
1 parent
2d77e9f
commit 02b4ba7
Showing
29 changed files
with
211 additions
and
18 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
Browar/Browar/obj/Debug/Browar.csproj.GenerateResource.Cache
Binary file not shown.
Binary file modified
BIN
-818 Bytes
(99%)
Browar/Browar/obj/Debug/Browar.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-1.05 KB
(92%)
Browar/Browar/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file modified
BIN
-339 Bytes
(97%)
Browar/Browar/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file added
BIN
+5.5 KB
Browar/Browar/obj/Release/TempPE/Service References.Serwer.Reference.cs.dll
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Web; | ||
using System.Text; | ||
using System.Data; | ||
using System.Data.SqlClient; | ||
using System.Configuration; | ||
using Serwer.DTO; | ||
|
||
namespace Serwer | ||
{ | ||
public class DatabaseHelper | ||
{ | ||
SqlConnection conn; | ||
string query; | ||
public DatabaseHelper() | ||
{ | ||
this.conn = new SqlConnection(@"Data Source=montwulfpc\Baza;Initial Catalog=BeersDB; User Id=client; Password=test;"); | ||
//string connectionString = ConfigurationManager.ConnectionStrings["Database"].ConnectionString; | ||
} | ||
|
||
public PiwoDetailDTO getBeerWithId(int id) | ||
{ | ||
PiwoDetailDTO beer = new PiwoDetailDTO(); | ||
this.query = string.Format("SELECT id, nazwa FROM dbo.Browar WHERE id = {0}", id); | ||
using(SqlCommand command = new SqlCommand(this.query, this.conn)) | ||
{ | ||
conn.Open(); | ||
|
||
SqlDataReader reader = command.ExecuteReader(); | ||
if(reader.HasRows) | ||
{ | ||
reader.Read(); | ||
beer.Id = int.Parse(reader.GetValue(0).ToString()); | ||
beer.Name = reader.GetValue(1).ToString(); | ||
} | ||
return beer; | ||
} | ||
} | ||
|
||
public List<PiwoDTO> getBeers() | ||
{ | ||
List<PiwoDTO> beers = new List<PiwoDTO>(); | ||
this.query = string.Format("SELECT id, nazwa FROM dbo.Browar"); | ||
using (SqlCommand command = new SqlCommand(this.query, this.conn)) | ||
{ | ||
conn.Open(); | ||
|
||
SqlDataReader reader = command.ExecuteReader(); | ||
while(reader.Read()) | ||
{ | ||
PiwoDTO beer = new PiwoDTO(); | ||
beer.Id = int.Parse(reader.GetValue(0).ToString()); | ||
beer.Name = reader.GetValue(1).ToString(); | ||
beers.Add(beer); | ||
} | ||
|
||
return beers; | ||
} | ||
} | ||
|
||
public bool updateBeer(PiwoDetailDTO beer) | ||
{ | ||
if(this.deleteBeer(beer.Id)) | ||
{ | ||
if(this.updateBeer(beer)) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public bool deleteBeer(int id) | ||
{ | ||
this.query = string.Format("DELETE FROM dbo.Browar WHERE id = {0}", id); | ||
using (SqlCommand command = new SqlCommand(this.query, this.conn)) | ||
{ | ||
conn.Open(); | ||
if (command.ExecuteNonQuery() > 0) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
public bool addBeer(PiwoDetailDTO beer) | ||
{ | ||
this.query = string.Format("INSERT INTO dbo.Browar (id, nazwa) VALUES ({0}, {1})", beer.Id, beer.Name); | ||
using (SqlCommand command = new SqlCommand(this.query, this.conn)) | ||
{ | ||
conn.Open(); | ||
if (command.ExecuteNonQuery() > 0) | ||
{ | ||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
public double getAverageRate(int id) | ||
{ | ||
double averageRate = 0; | ||
this.query = string.Format("SELECT AVG(ocena) FROM dbo.Browar WHERE id = {0}", id); | ||
using (SqlCommand command = new SqlCommand(this.query, this.conn)) | ||
{ | ||
conn.Open(); | ||
averageRate = double.Parse(command.ExecuteScalar().ToString()); | ||
} | ||
return averageRate; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-133 Bytes
(98%)
Browar/Serwer/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
Browar/Serwer/obj/Debug/Serwer.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
-133 Bytes
(98%)
Browar/Serwer/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<sitemanifest> | ||
<IisApp path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" managedRuntimeVersion="v4.0" /> | ||
<setAcl path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" setAclResourceType="Directory" /> | ||
<setAcl path="C:\Users\Dariusz\documents\visual studio 2013\Projects\Browar\Serwer\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" /> | ||
<IisApp path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" managedRuntimeVersion="v4.0" /> | ||
<setAcl path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" setAclResourceType="Directory" /> | ||
<setAcl path="D:\UAM - repozytoria\TAS - repo\TAS\Browar\Serwer\obj\Release\Package\PackageTmp" setAclUser="anonymousAuthenticationUser" setAclResourceType="Directory" /> | ||
</sitemanifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
Browar/Serwer/obj/Release/Serwer.csprojResolveAssemblyReference.cache
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.