-
Notifications
You must be signed in to change notification settings - Fork 19
HangszerUzlet - Kurai István AMIA3F #7
base: main
Are you sure you want to change the base?
Changes from all commits
0e17d8e
f5b79fd
d489a89
b86020d
3b56c31
ec1a2d0
036d669
6b236f1
be5044e
cd68312
0a3fb45
954c1c7
60fafe8
213ecea
609ca3e
7a5b259
b097903
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.31702.278 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HangszerUzlet", "HangszerUzlet\HangszerUzlet.csproj", "{FC928961-1A07-4620-8B24-148315E410E7}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{FC928961-1A07-4620-8B24-148315E410E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{FC928961-1A07-4620-8B24-148315E410E7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{FC928961-1A07-4620-8B24-148315E410E7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{FC928961-1A07-4620-8B24-148315E410E7}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {E791081F-31D1-45C4-9111-CB0D7EB80C3A} | ||
EndGlobalSection | ||
EndGlobal |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<configSections> | ||
</configSections> | ||
<connectionStrings> | ||
<add name="HangszerUzlet.Properties.Settings.HangszerUzletConnectionString" | ||
connectionString="Data Source=KURAIISTVAN;Initial Catalog=HangszerUzlet;Integrated Security=True" | ||
providerName="System.Data.SqlClient" /> | ||
</connectionStrings> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||
</startup> | ||
</configuration> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
using HangszerUzlet.Controler; | ||
using HangszerUzlet.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using System.Xml; | ||
using System.Xml.Linq; | ||
using System.Xml.Serialization; | ||
|
||
namespace HangszerUzlet | ||
{ | ||
public class HangszerDbDAO | ||
{ | ||
HangszerDBDataContext context = new HangszerDBDataContext(); | ||
HangszerTipusDAO hangszerTipus = new HangszerTipusDAO(); | ||
|
||
public readonly string readonlyNev = "Szintetizáror"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Readonly helyett célszerűbb konstansokra a const módosítót alkalmazni, főleg ha compile time tudott, hogy mi lesz az érték. |
||
public readonly string readonlyTipus = "Ütős"; | ||
public readonly int readonlyRegiAr = 32500; | ||
public readonly int readonlyAr = 27500; | ||
|
||
public void getHangszerek(DataGridView dataGridView) | ||
{ | ||
var hsz = from h in context.Hangszers select h; | ||
dataGridView.DataSource = hsz; | ||
} | ||
|
||
public void AddNewRowOffline(DataGridView dataGridView) | ||
{ | ||
dataGridView.Rows.Clear(); | ||
DataGridViewRow row = (DataGridViewRow)dataGridView.Rows[0].Clone(); | ||
row.Cells[0].Value = readonlyNev; | ||
row.Cells[1].Value = readonlyTipus; | ||
row.Cells[2].Value = readonlyRegiAr; | ||
row.Cells[3].Value = readonlyAr; | ||
dataGridView.Rows.Add(row); | ||
} | ||
|
||
public async Task InsertHangszer(TextBox nev, ComboBox tipus, TextBox ar, DataGridView dataGridView) | ||
{ | ||
string netto = ar.Text; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha az ár szövege nem szám, akkor a ToInt32() miatt ez szétfog szállni a fenébe. |
||
double brutto = Convert.ToInt32(netto) + (Convert.ToInt32(netto) * 0.27); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Elég lenne egyszer is konvertálni, illetve már kapásból double-be. |
||
|
||
var hsz = new Hangszer | ||
{ | ||
Nev = nev.Text, | ||
Tipus = tipus.SelectedItem.ToString(), | ||
Ar = Convert.ToInt32(brutto) | ||
}; | ||
context.Hangszers.InsertOnSubmit(hsz); | ||
context.SubmitChanges(); | ||
getHangszerek(dataGridView); | ||
await Task.Run(() => | ||
{ | ||
MessageBox.Show("Sikeres Létrehozás"); | ||
}); | ||
} | ||
|
||
public void ModifyHangszer(TextBox id, TextBox nev, ComboBox tipus, TextBox ar, DataGridView dataGridView) | ||
{ | ||
try | ||
{ | ||
string netto = ar.Text; | ||
double brutto = Convert.ToInt32(netto) + (Convert.ToInt32(netto) * 0.27); | ||
|
||
var hsz = (from h in context.Hangszers where h.Id == Convert.ToInt32(id.Text) select h).FirstOrDefault(); | ||
hsz.Nev = nev.Text; | ||
hsz.Tipus = tipus.SelectedItem.ToString(); | ||
hsz.Ar = Convert.ToInt32(brutto); | ||
context.SubmitChanges(); | ||
getHangszerek(dataGridView); | ||
|
||
MessageBox.Show("Sikeres Módosítás"); | ||
} | ||
catch (Exception e) | ||
{ | ||
MessageBox.Show("Sikertelen Módosítás, kérlek tölts ki pontosan minden adatot"); | ||
} | ||
} | ||
|
||
public void DeleteHangszer(TextBox id, DataGridView dataGridView) | ||
{ | ||
var hsz = (from h in context.Hangszers where h.Id == Convert.ToInt32(id.Text) select h).FirstOrDefault(); | ||
context.Hangszers.DeleteOnSubmit(hsz); | ||
context.SubmitChanges(); | ||
getHangszerek(dataGridView); | ||
} | ||
|
||
public void Search(TextBox nev, ComboBox tipus, DataGridView dataGridView) | ||
{ | ||
try | ||
{ | ||
|
||
if (!string.IsNullOrEmpty(nev.Text) && tipus.SelectedItem == null) | ||
{ | ||
var hsz = context.Hangszers.Where(x => x.Nev == nev.Text).ToList(); | ||
dataGridView.DataSource = hsz; | ||
} | ||
|
||
if (tipus.SelectedItem != null && string.IsNullOrEmpty(nev.Text)) | ||
{ | ||
var hsz = context.Hangszers.Where(x => x.Tipus == tipus.SelectedItem.ToString()).ToList(); | ||
dataGridView.DataSource = hsz; | ||
} | ||
|
||
if (tipus.SelectedItem != null && !string.IsNullOrEmpty(nev.Text)) | ||
{ | ||
var hsz = context.Hangszers.Where(x => x.Nev == nev.Text && x.Tipus == tipus.SelectedItem.ToString()).ToList(); | ||
dataGridView.DataSource = hsz; | ||
} | ||
|
||
} | ||
catch (Exception e) | ||
{ | ||
var result = MessageBox.Show(e.ToString(), | ||
"Error", | ||
MessageBoxButtons.AbortRetryIgnore, | ||
MessageBoxIcon.Exclamation); | ||
if (result == DialogResult.Abort) throw; | ||
} | ||
|
||
} | ||
|
||
public void HangszerFiltering(DataGridView dataGridView, TextBox idTextBox, TextBox nameTextBox) | ||
{ | ||
var hsz = from h in context.Hangszers where h.Nev == nameTextBox.Text select h; | ||
dataGridView.DataSource = hsz; | ||
} | ||
|
||
public void SaveToXML(DataGridView dataGridView) | ||
{ | ||
|
||
List<HangszerModel> hangszerList = new List<HangszerModel>(); | ||
XmlSerializer ser = new XmlSerializer(typeof(XElement)); | ||
try | ||
{ | ||
hangszerList = (from h in context.Hangszers | ||
select new HangszerModel | ||
{ | ||
Id = h.Id, | ||
Nev = h.Nev, | ||
Tipus = h.Tipus, | ||
Ar = h.Ar | ||
}).ToList(); | ||
|
||
XElement element = new XElement("Hangszerek", | ||
(from h in hangszerList | ||
select new XElement("Hangszer", | ||
new XElement("Id", h.Id), | ||
new XElement("Name", h.Nev), | ||
new XElement("Type", h.Tipus), | ||
new XElement("Price", h.Ar)))); | ||
|
||
SaveFileDialog saveFileDialog = new SaveFileDialog(); | ||
saveFileDialog.Filter = "XML Files|*.xml"; | ||
|
||
if (saveFileDialog.ShowDialog() == DialogResult.OK) | ||
{ | ||
FileStream fs = new FileStream(saveFileDialog.FileName, FileMode.OpenOrCreate); | ||
ser.Serialize(fs, element); | ||
//element.Save(saveFileDialog.FileName); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
var result = MessageBox.Show(ex.ToString(), | ||
"Error", | ||
MessageBoxButtons.AbortRetryIgnore, | ||
MessageBoxIcon.Exclamation); | ||
if (result == DialogResult.Abort) throw; | ||
} | ||
} | ||
|
||
public void ReadXML() | ||
{ | ||
List<HangszerModel> hangszerList = new List<HangszerModel>(); | ||
hangszerList = (from h in context.Hangszers | ||
select new HangszerModel | ||
{ | ||
Id = h.Id, | ||
Nev = h.Nev, | ||
Tipus = h.Tipus, | ||
Ar = h.Ar | ||
}).ToList(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using HangszerUzlet.Model; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace HangszerUzlet.Controler | ||
{ | ||
class HangszerTipusDAO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Szintén DAO akar lenni, de a UI-al egybe van kötve a típusok miatt. |
||
{ | ||
HangszerDBDataContext context = new HangszerDBDataContext(); | ||
|
||
public List<HangszerTipusModel> FillTipusok(ComboBox comboBox) | ||
{ | ||
List<HangszerTipusModel> hangszerTipusList = new List<HangszerTipusModel>(); | ||
List<HangszerTipusModel> hangszerTipusListResult = new List<HangszerTipusModel>(); | ||
|
||
try | ||
{ | ||
hangszerTipusList = (from ht in context.HangszerTipus | ||
select new HangszerTipusModel | ||
{ | ||
Id = ht.Id, | ||
Nev = ht.Nev | ||
}).ToList(); | ||
|
||
foreach (var item in hangszerTipusList) | ||
{ | ||
HangszerTipusModel hangszerTipus = new HangszerTipusModel() | ||
{ | ||
Nev = item.Nev | ||
}; | ||
|
||
hangszerTipusListResult.Add(hangszerTipus); | ||
} | ||
|
||
FillCombobox(comboBox, hangszerTipusList); | ||
|
||
} | ||
catch (Exception ex) | ||
{ | ||
var result = MessageBox.Show(ex.ToString(), | ||
"Error", | ||
MessageBoxButtons.AbortRetryIgnore, | ||
MessageBoxIcon.Exclamation); | ||
if (result == DialogResult.Abort) throw; | ||
} | ||
|
||
|
||
return hangszerTipusListResult; | ||
} | ||
|
||
|
||
public void FillCombobox(ComboBox comboBox, List<HangszerTipusModel> hangszerTipusList) | ||
{ | ||
foreach (var tipus in hangszerTipusList) | ||
{ | ||
comboBox.Items.Add(tipus.Nev); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mivel ez egy Data acces réteg akar lenni, ezért szerintem semmiképpen nem kéne tudnia a DAO rétegnek Windows forms típusokról, mert így lényegében UI függővé tetted az egészet. Tehát TextBox és Combobox helyett az értékeiket meg tartalmukat kellene beküldeni ennek a rétegnek, vagy legalább egy interféasz szegregációval leválasztani a UI-ról az egészet.