Advertisement
csaki

Csabi progtech beadandója

May 21st, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. //az adatbázis miatt kell:
  6. using System.Data;
  7. using System.Data.OleDb;
  8.  
  9. namespace progtechbeadandó
  10. {
  11.  
  12.     //az adatbázis osztály singleton
  13.     //excel alapú adatbázishoz:
  14.     class DatabaseExcel
  15.     {
  16.         private static DatabaseExcel instance;
  17.  
  18.         private DatabaseExcel()
  19.         {
  20.         }
  21.  
  22.         public static DatabaseExcel GetInstance()
  23.         {
  24.             if (instance == null)
  25.             {
  26.                 instance = new DatabaseExcel();
  27.             }
  28.             return instance;
  29.         }
  30.  
  31.         private string GetConnectionString()
  32.         {
  33.             Dictionary<string, string> props = new Dictionary<string, string>();
  34.  
  35.             // XLSX - Excel 2007, 2010, 2012, 2013
  36.             //props["Provider"] = "Microsoft.ACE.OLEDB.12.0;";
  37.             //props["Extended Properties"] = "Excel 12.0 XML";
  38.             //props["Data Source"] = "C:\\Progtechbeadandó\\Database.xlsx";
  39.  
  40.             // XLS - Excel 2003 and Older
  41.             props["Provider"] = "Microsoft.Jet.OLEDB.4.0";
  42.             props["Extended Properties"] = "Excel 8.0";
  43.             props["Data Source"] = "C:\\Progtechbeadandó\\items.xls";
  44.  
  45.             StringBuilder sb = new StringBuilder();
  46.  
  47.             foreach (KeyValuePair<string, string> prop in props)
  48.             {
  49.                 sb.Append(prop.Key);
  50.                 sb.Append('=');
  51.                 sb.Append(prop.Value);
  52.                 sb.Append(';');
  53.             }
  54.  
  55.             return sb.ToString();
  56.         }
  57.  
  58.         public void Write(string command)
  59.         {
  60.             string connectionString = GetConnectionString();
  61.  
  62.             using (OleDbConnection conn = new OleDbConnection(connectionString))
  63.             {
  64.                 conn.Open();
  65.                 OleDbCommand cmd = new OleDbCommand();
  66.                 cmd.Connection = conn;
  67.  
  68.                 //cmd.CommandText = "CREATE TABLE [table1] (id INT, name VARCHAR, datecol DATE );";
  69.                 //cmd.ExecuteNonQuery();
  70.  
  71.                 //cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(1,'AAAA','2014-01-01');";
  72.                 //cmd.ExecuteNonQuery();
  73.  
  74.                 //cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(2, 'BBBB','2014-01-03');";
  75.                 //cmd.ExecuteNonQuery();
  76.  
  77.                 //cmd.CommandText = "INSERT INTO [table1](id,name,datecol) VALUES(3, 'CCCC','2014-01-03');";
  78.                 //cmd.ExecuteNonQuery();
  79.  
  80.                 //cmd.CommandText = "UPDATE [table1] SET name = 'DDDD' WHERE id = 3;";
  81.                 //cmd.ExecuteNonQuery();
  82.  
  83.                 conn.Close();
  84.             }
  85.         }
  86.  
  87.         public DataSet Read(string queryString)
  88.         {
  89.             DataSet results = new DataSet();
  90.  
  91.             string connectionString = GetConnectionString();
  92.  
  93.             using (OleDbConnection conn = new OleDbConnection(connectionString))
  94.             {
  95.                 conn.Open();
  96.                 OleDbCommand cmd = new OleDbCommand();
  97.                 cmd.Connection = conn;
  98.  
  99.                 // Get all Sheets in Excel File
  100.                 DataTable dtSheet = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
  101.  
  102.                 // Loop through all Sheets to get data
  103.                 foreach (DataRow dr in dtSheet.Rows)
  104.                 {
  105.                     // ide jön a lekérdezés
  106.                     cmd.CommandText = queryString;
  107.  
  108.                     DataTable dt = new DataTable();
  109.                     dt.TableName = "results";
  110.  
  111.                     OleDbDataAdapter da = new OleDbDataAdapter(cmd);
  112.                     da.Fill(dt);
  113.  
  114.                     results.Tables.Add(dt);
  115.                 }
  116.  
  117.                 cmd = null;
  118.                 conn.Close();
  119.             }
  120.  
  121.             return results;
  122.         }
  123.  
  124.     } //adatbázis class vége
  125.  
  126.     //.csv (txt) alapú adatbázishoz:
  127.     class Database
  128.     {
  129.         private static Database instance;
  130.         protected static string _filepath = System.IO.Path.Combine(Environment.CurrentDirectory, "items.csv");
  131.         public static string filepath
  132.         {
  133.             get { return _filepath; }
  134.             set { _filepath = value; }
  135.         }
  136.         public static string filenameStatic;
  137.  
  138.         public string filename
  139.         {
  140.             get { return filenameStatic;  }
  141.         }
  142.  
  143.         private Database()
  144.         { }
  145.  
  146.         public static Database GetInstance()
  147.         {
  148.             if (instance == null)
  149.             {
  150.                 instance = new Database();
  151.                 fájlnévbeállítás();
  152.             }
  153.  
  154.             return instance;
  155.         }
  156.  
  157.         private static void fájlnévbeállítás()
  158.         {
  159.             filenameStatic = System.IO.Path.GetFileName(filepath);
  160.         }
  161.  
  162.         private string GetConnectionString()
  163.         {
  164.             Dictionary<string, string> props = new Dictionary<string, string>();
  165.  
  166.             //csv connection string parts
  167.             //props["Provider"] = "Microsoft.Jet.OLEDB.4.0;";
  168.             //props["Extended Properties"] = "'text;HDR=Yes;FMT=Delimited(,)';";
  169.             //props["Extended Properties"] = "text;HDR=Yes;FMT=Delimited";
  170.             //props["Data Source"] = "\"" + file.DirectoryName + "\";";
  171.  
  172.             StringBuilder sb = new StringBuilder();
  173.  
  174.             foreach (KeyValuePair<string, string> prop in props)
  175.             {
  176.                 sb.Append(prop.Key);
  177.                 sb.Append('=');
  178.                 sb.Append(prop.Value);
  179.                 sb.Append(';');
  180.             }
  181.  
  182.             return sb.ToString();
  183.         }
  184.  
  185.         public DataTable Read(string querystring)
  186.         {
  187.             //lekérdezés formátuma:
  188.             //string.Format("SELECT * FROM [{0}]", file.Name),
  189.  
  190.             DataTable eredmeny = new DataTable();
  191.  
  192.  
  193.             string fajl = System.IO.Path.GetFileName(filepath);
  194.             string mappa = System.IO.Path.GetDirectoryName(filepath);
  195.  
  196.             string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
  197.             + "Data Source=\"" + mappa + "\\\";"
  198.             + "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";
  199.             //string lekerdezes = "SELECT * FROM " + fajl;
  200.  
  201.             OleDbDataAdapter Adapter = new OleDbDataAdapter(querystring, connString);
  202.  
  203.             try
  204.             {
  205.                 Adapter.Fill(eredmeny);
  206.             }
  207.             catch (InvalidOperationException /*e*/)
  208.             { }
  209.             Adapter.Dispose();
  210.  
  211.             return eredmeny;
  212.         }
  213.  
  214.     } //DataBaseCsv class vége
  215.  
  216.  
  217.     //az előre definiált kategóriák (amik tulajdonképpen előre megírt különbféle lekérdezések eredményei) stratégia tervezési minta segítségével lettek megvalósítva
  218.     //a 3 kategóriának (notebook-tablet-telefon osztály) van egy lekérdezés mezője, ahová a választástól függően kerül be ezen előre megírt lekérdezés osztályok példánya
  219.     public abstract class BaseQuery
  220.     {
  221.         protected string _name;
  222.         public string name
  223.         {
  224.             get { return _name; }
  225.             set { _name = value; }
  226.         }
  227.  
  228.         public BaseQuery()
  229.         {
  230.         }
  231.  
  232.  
  233.         public abstract DataTable DoQuery();
  234.     }
  235.  
  236.     //ide jönnek majd a BaseQueryből származtatott lekérdezések, amik az előre választható paraméterezési opciók lesznek gyakorlatilag
  237.     //a smartphone kategóriával kapcsolatosak:
  238.     public class AllSmartPhonesQuery : BaseQuery
  239.     {
  240.         public AllSmartPhonesQuery()
  241.         {
  242.             name = "minden okostelefon";
  243.         }
  244.  
  245.         public override DataTable DoQuery()
  246.         {
  247.             DataTable dt = new DataTable();
  248.             Database db = Database.GetInstance();
  249.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE CATEGORY=1");
  250.             return dt;
  251.  
  252.         }
  253.     }
  254.  
  255.     public class CheapestSmartPhoneQuery : BaseQuery
  256.     {
  257.         public CheapestSmartPhoneQuery()
  258.         {
  259.             name = "legolcsóbb okostelefon";
  260.         }
  261.  
  262.         public override DataTable DoQuery()
  263.         {
  264.             DataTable dt = new DataTable();
  265.             Database db = Database.GetInstance();
  266.             dt = db.Read("SELECT MANUFACTURER, MODEL, MIN(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=1");
  267.             return dt;
  268.         }
  269.     }
  270.  
  271.     public class MostExpensiveSmartPhoneQuery : BaseQuery
  272.     {
  273.         public MostExpensiveSmartPhoneQuery()
  274.         {
  275.             name = "legdrágább okostelefon";
  276.         }
  277.  
  278.         public override DataTable DoQuery()
  279.         {
  280.             DataTable dt = new DataTable();
  281.             Database db = Database.GetInstance();
  282.             dt = db.Read("SELECT MANUFACTURER, MODEL, MAX(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=1");
  283.             return dt;
  284.         }
  285.  
  286.     }
  287.  
  288.     public class AllAppleSmartPhonesQuery : BaseQuery
  289.     {
  290.         public AllAppleSmartPhonesQuery()
  291.         {
  292.             name = "Apple okostelefonok";
  293.         }
  294.  
  295.         public override DataTable DoQuery()
  296.         {
  297.             DataTable dt = new DataTable();
  298.             Database db = Database.GetInstance();
  299.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=1) AND (MANUFACTURER LIKE \"Apple\")");
  300.             return dt;
  301.         }
  302.  
  303.     }
  304.  
  305.     public class AllSamsungSmartPhonesQuery : BaseQuery
  306.     {
  307.         public AllSamsungSmartPhonesQuery()
  308.         {
  309.             name = "Samsung okostelefonok";
  310.         }
  311.  
  312.         public override DataTable DoQuery()
  313.         {
  314.             DataTable dt = new DataTable();
  315.             Database db = Database.GetInstance();
  316.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=1) AND (MANUFACTURER LIKE \"Samsung\")");
  317.             return dt;
  318.         }
  319.  
  320.     }
  321.  
  322.     //a tablet kategóriával kapcsolatosak:
  323.     public class AllTabletsQuery : BaseQuery
  324.     {
  325.         public AllTabletsQuery()
  326.         {
  327.             name = "minden tablet";
  328.         }
  329.  
  330.         public override DataTable DoQuery()
  331.         {
  332.             DataTable dt = new DataTable();
  333.             Database db = Database.GetInstance();
  334.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE CATEGORY=2");
  335.             return dt;
  336.  
  337.         }
  338.     }
  339.  
  340.     public class CheapestTabletQuery : BaseQuery
  341.     {
  342.         public CheapestTabletQuery()
  343.         {
  344.             name = "legolcsóbb tablet";
  345.         }
  346.  
  347.         public override DataTable DoQuery()
  348.         {
  349.             DataTable dt = new DataTable();
  350.             Database db = Database.GetInstance();
  351.             dt = db.Read("SELECT MANUFACTURER, MODEL, MIN(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=2");
  352.             return dt;
  353.         }
  354.     }
  355.  
  356.     public class MostExpensiveTabletQuery : BaseQuery
  357.     {
  358.         public MostExpensiveTabletQuery()
  359.         {
  360.             name = "legdrágább tablet";
  361.         }
  362.  
  363.         public override DataTable DoQuery()
  364.         {
  365.             DataTable dt = new DataTable();
  366.             Database db = Database.GetInstance();
  367.             dt = db.Read("SELECT MANUFACTURER, MODEL, MAX(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=2");
  368.             return dt;
  369.         }
  370.  
  371.     }
  372.  
  373.     public class AllAppleTabletsQuery : BaseQuery
  374.     {
  375.         public AllAppleTabletsQuery()
  376.         {
  377.             name = "Apple tabletek";
  378.         }
  379.  
  380.         public override DataTable DoQuery()
  381.         {
  382.             DataTable dt = new DataTable();
  383.             Database db = Database.GetInstance();
  384.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=2) AND (MANUFACTURER LIKE \"Apple\")");
  385.             return dt;
  386.         }
  387.  
  388.     }
  389.  
  390.     public class AllSamsungTabletsQuery : BaseQuery
  391.     {
  392.         public AllSamsungTabletsQuery()
  393.         {
  394.             name = "Samsung tabletek";
  395.         }
  396.  
  397.         public override DataTable DoQuery()
  398.         {
  399.             DataTable dt = new DataTable();
  400.             Database db = Database.GetInstance();
  401.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=2) AND (MANUFACTURER LIKE \"Samsung\")");
  402.             return dt;
  403.         }
  404.  
  405.     }
  406.  
  407.     //a notebook kategóriával kapcsolatosak:
  408.     public class AllNotebooksQuery : BaseQuery
  409.     {
  410.         public AllNotebooksQuery()
  411.         {
  412.             name = "minden notebook";
  413.         }
  414.  
  415.         public override DataTable DoQuery()
  416.         {
  417.             DataTable dt = new DataTable();
  418.             Database db = Database.GetInstance();
  419.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE CATEGORY=3");
  420.             return dt;
  421.  
  422.         }
  423.     }
  424.  
  425.     public class CheapestNotebookQuery : BaseQuery
  426.     {
  427.         public CheapestNotebookQuery()
  428.         {
  429.             name = "legolcsóbb notebook";
  430.         }
  431.  
  432.         public override DataTable DoQuery()
  433.         {
  434.             DataTable dt = new DataTable();
  435.             Database db = Database.GetInstance();
  436.             dt = db.Read("SELECT MANUFACTURER, MODEL, MIN(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=3");
  437.             return dt;
  438.         }
  439.     }
  440.  
  441.     public class MostExpensiveNotebookQuery : BaseQuery
  442.     {
  443.         public MostExpensiveNotebookQuery()
  444.         {
  445.             name = "legdrágább notebook";
  446.         }
  447.  
  448.         public override DataTable DoQuery()
  449.         {
  450.             DataTable dt = new DataTable();
  451.  
  452.             Database db = Database.GetInstance();
  453.             dt = db.Read("SELECT MANUFACTURER, MODEL, MAX(PRICE) AS PRICE FROM " + db.filename + " WHERE CATEGORY=3");
  454.             return dt;
  455.         }
  456.  
  457.     }
  458.  
  459.     public class AllAppleNotebooksQuery : BaseQuery
  460.     {
  461.         public AllAppleNotebooksQuery()
  462.         {
  463.             name = "Apple notebookok";
  464.         }
  465.  
  466.         public override DataTable DoQuery()
  467.         {
  468.             DataTable dt = new DataTable();
  469.             Database db = Database.GetInstance();
  470.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=3) AND (MANUFACTURER LIKE \"Apple\")");
  471.             return dt;
  472.         }
  473.  
  474.     }
  475.  
  476.     public class AllSamsungNotebooksQuery : BaseQuery
  477.     {
  478.         public AllSamsungNotebooksQuery()
  479.         {
  480.             name = "Samsung notebook";
  481.         }
  482.  
  483.         public override DataTable DoQuery()
  484.         {
  485.             DataTable dt = new DataTable();
  486.             Database db = Database.GetInstance();
  487.             dt = db.Read("SELECT MANUFACTURER, MODEL, PRICE FROM " + db.filename + " WHERE (CATEGORY=3) AND (MANUFACTURER LIKE \"Samsung\")");
  488.             return dt;
  489.         }
  490.  
  491.     }
  492.  
  493.  
  494.     //a 3 kategória (notebook-tablet-mobil) template method segítségével lett megvalósítva
  495.     public abstract class Category
  496.     {
  497.         protected List<BaseQuery> _possibilities = new List<BaseQuery>(); //ez reprezentálja a termékszűkítés menüpontjait
  498.         public List<BaseQuery> possibilities
  499.         {
  500.             get { return _possibilities; }
  501.             set { _possibilities = value; }
  502.         }
  503.         protected BaseQuery _currentQuery; //mező a majd végrehajtandó lekérdezésnek (stratégia minta része!)
  504.         public BaseQuery currentQuery
  505.         {
  506.             get { return _currentQuery; }
  507.             set { _currentQuery = value; }
  508.         }
  509.         protected DataTable _result = new DataTable(); //ebbe kerülnek majd a találatok
  510.         public DataTable result
  511.         {
  512.             get { return _result; }
  513.             set { _result = value; }
  514.         }
  515.         protected bool _success;
  516.         public bool success
  517.         {
  518.             get { return _success; }
  519.             set { _success = value; }
  520.         }
  521.  
  522.  
  523.         public void Run() //ez vezérli a programot, az első körben választott kategóriától függően (template method része!)
  524.         {
  525.             ListParameters();
  526.             SelectParameters();
  527.             ExecuteQuery();
  528.             ShowResults();
  529.             success = LastChoice();
  530.         }
  531.  
  532.         protected abstract void ListParameters();
  533.  
  534.         private void SelectParameters()
  535.         {
  536.             bool b = false;
  537.             int x = 0;
  538.             while (!b)
  539.             {
  540.                 Console.WriteLine("Kérlek válassz, mely lehetőség alapján szeretnéd szűkíteni a termékeket:");
  541.                 x = int.Parse(Console.ReadLine());
  542.                 if (x > 0 && x <= possibilities.Count) b = true;
  543.             }
  544.  
  545.             currentQuery = possibilities[x-1];
  546.         }
  547.  
  548.         private void ExecuteQuery()
  549.         {
  550.             try
  551.             {
  552.                 this.result = currentQuery.DoQuery();
  553.             }
  554.             catch (Exception)
  555.             {
  556.                 Console.WriteLine("Hiba történt az adatbázis olvasásakor... bocsi");
  557.             }
  558.  
  559.         }
  560.  
  561.         private void ShowResults()
  562.         {
  563.             Console.WriteLine("A paraméter(ek)nek megfelelő termék(ek):");
  564.  
  565.             for (int curCol = 0; curCol < result.Columns.Count; curCol++)
  566.             {
  567.                 Console.Write(result.Columns[curCol].ColumnName.Trim() + "\t");
  568.             }
  569.             for (int curRow = 0; curRow < result.Rows.Count; curRow++)
  570.             {
  571.                 for (int curCol = 0; curCol < result.Columns.Count; curCol++)
  572.                 {
  573.                     Console.Write(result.Rows[curRow][curCol].ToString().Trim() + "\t");
  574.                 }
  575.                 Console.WriteLine();
  576.             }
  577.  
  578.         }
  579.  
  580.         private bool LastChoice()
  581.         {
  582.             int aaa = -1;
  583.             aaa = result.Rows.Count;
  584.             int beírt = -1;
  585.  
  586.             while (beírt > aaa && beírt < 0)
  587.             {
  588.                 Console.WriteLine("Add meg, hogy melyik terméket szeretnéd megvásárolni (írd be a sorszámát):");
  589.                 Console.WriteLine("A \"0\" beírásával visszajuthatsz a kategória választáshoz!");
  590.                 beírt = int.Parse(Console.ReadLine());
  591.             }
  592.  
  593.             if (beírt == 0) return false;
  594.             else return true;
  595.         }
  596.  
  597.     } //category class vége
  598.  
  599.     public class Notebook : Category
  600.     {
  601.         public Notebook()
  602.         {
  603.             possibilities.Add(new AllNotebooksQuery());
  604.             possibilities.Add(new CheapestNotebookQuery());
  605.             possibilities.Add(new MostExpensiveNotebookQuery());
  606.             possibilities.Add(new AllAppleNotebooksQuery());
  607.             possibilities.Add(new AllSamsungNotebooksQuery());
  608.             currentQuery = null;
  609.             success = false;
  610.         }
  611.  
  612.         protected override void ListParameters()
  613.         {
  614.             Console.WriteLine("Választható paraméterek:");
  615.             for (int i = 0; i < possibilities.Count; i++)
  616.             {
  617.                 Console.WriteLine("{0}. {1}", i + 1, this.possibilities[i].name);
  618.             }
  619.         }
  620.  
  621.     }
  622.  
  623.     public class Tablet : Category
  624.     {
  625.         public Tablet()
  626.         {
  627.             possibilities.Add(new AllTabletsQuery());
  628.             possibilities.Add(new CheapestTabletQuery());
  629.             possibilities.Add(new MostExpensiveTabletQuery());
  630.             possibilities.Add(new AllAppleTabletsQuery());
  631.             possibilities.Add(new AllSamsungTabletsQuery());
  632.             currentQuery = null;
  633.             success = false;
  634.         }
  635.  
  636.         protected override void ListParameters()
  637.         {
  638.             Console.WriteLine("Választható paraméterek:");
  639.             for (int i = 0; i < possibilities.Count; i++)
  640.             {
  641.                 Console.WriteLine("{0}. {1}", i + 1, possibilities[i].name);
  642.             }
  643.         }
  644.  
  645.     }
  646.  
  647.     public class SmartPhone : Category
  648.     {
  649.         public SmartPhone()
  650.         {
  651.             possibilities.Add(new AllSmartPhonesQuery(/*"minden okostelefon"*/));
  652.             possibilities.Add(new CheapestSmartPhoneQuery());
  653.             possibilities.Add(new MostExpensiveSmartPhoneQuery());
  654.             possibilities.Add(new AllAppleSmartPhonesQuery());
  655.             possibilities.Add(new AllSamsungSmartPhonesQuery());
  656.             currentQuery = null;
  657.             success = false;
  658.         }
  659.  
  660.         protected override void ListParameters()
  661.         {
  662.             Console.WriteLine("Választható paraméterek:");
  663.             for (int i = 0; i < possibilities.Count; i++)
  664.             {
  665.                 Console.WriteLine("{0}. {1}", i + 1, possibilities[i].name);
  666.             }
  667.         }
  668.  
  669.     }
  670.  
  671.     class bolt
  672.     {
  673.         protected Category _notipéldány;
  674.         public Category notipéldány
  675.         {
  676.             get { return _notipéldány; }
  677.             set { _notipéldány = value; }
  678.         }
  679.  
  680.         protected Category _táblapéldány;
  681.         public Category táblapéldány
  682.         {
  683.             get { return _táblapéldány; }
  684.             set { _táblapéldány = value; }
  685.         }
  686.  
  687.         protected Category _telópéldány;
  688.         public Category telópéldány
  689.         {
  690.             get { return _telópéldány; }
  691.             set { _telópéldány = value; }
  692.         }
  693.  
  694.         public bolt(Category noti, Category tábla, Category teló)
  695.         {
  696.             notipéldány = noti;
  697.             táblapéldány = tábla;
  698.             telópéldány = teló;
  699.         }
  700.  
  701.         public void start()
  702.         {
  703.             while (notipéldány.success != true || táblapéldány.success != true || telópéldány.success != true)
  704.             {
  705.                 Console.WriteLine("Üdvözöllek az Almádi Electronics Kft. boltjában!");
  706.  
  707.                 int x = 0;
  708.                 while (x != 1 && x != 2 && x != 3)
  709.                 {
  710.                     Console.WriteLine("Kérlek, válassz, hogy milyen terméket szeretnél:");
  711.                     Console.WriteLine("1.Okostelefon | 2.Tablet | 3.Notebook");
  712.                     x = int.Parse(Console.ReadLine());
  713.                 }
  714.  
  715.                 if (x == 1)
  716.                 {
  717.                     telópéldány.Run();
  718.                 }
  719.                 else if (x == 2)
  720.                 {
  721.                     táblapéldány.Run();
  722.                 }
  723.                 else
  724.                 {
  725.                     notipéldány.Run();
  726.                 }
  727.             }
  728.  
  729.             Console.WriteLine("Sikeres vásárlás! Köszönjük!");
  730.         }
  731.  
  732.     }
  733.  
  734.  
  735.     class Program
  736.     {
  737.         static void Main(string[] args)
  738.         {
  739.             bolt shop = new bolt(new Notebook(), new Tablet(), new SmartPhone());
  740.             shop.start();
  741.  
  742.             Console.WriteLine("Nyomj egy tetszőleges gombot a kilépéshez! Viszlát!");
  743.             Console.ReadKey();
  744.         }
  745.     }
  746. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement