Beispiel #1
0
 public static KarakterRaktar getInstance()
 {
     if (uniqueInstance == null)
     {
         uniqueInstance = new KarakterRaktar();
     }
     return(uniqueInstance);
 }
        public List <Magus> JatMagusLekerdez()
        {
            KarakterRaktar kar           = KarakterRaktar.getInstance();
            List <string>  karakternevek = new List <string>();
            List <string>  kasztok       = new List <string>();
            List <string>  fegyverek     = new List <string>();
            List <string>  kepek         = new List <string>();

            string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" + "DBQ=" + Environment.CurrentDirectory + @"\Fajlok\DB\jatekosadatbazis.xlsx" + ";ReadOnly=0;";

            string queryString =
                "SELECT * FROM [JatMagus$]";

            using (OdbcConnection connection =
                       new OdbcConnection(connectionString))
            {
                OdbcCommand command = new OdbcCommand(queryString, connection);

                try
                {
                    connection.Open();
                    OdbcDataReader reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        karakternevek.Add((string)reader[0]);
                        kasztok.Add((string)reader[1]);
                        fegyverek.Add((string)reader[2]);
                        kepek.Add((string)reader[3]);
                    }
                    reader.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                for (int i = 0; i < karakternevek.Count; i++)
                {
                    FegyverAdatbazis fa           = FegyverAdatbazis.getInstance();
                    List <MagikusF>  fegyverbazis = fa.MagFegyverLekerdez();
                    Magus            ujmagus      = new Magus();
                    ujmagus.nev        = karakternevek[i];
                    ujmagus.maxeletero = 1000;
                    ujmagus.eletero    = 1000;
                    ujmagus.kep        = kepek[i];
                    for (int j = 0; j < fegyverbazis.Count; j++)
                    {
                        if (fegyverek[i] == fegyverbazis[j].nev)
                        {
                            ujmagus.magusfegyver = fegyverbazis[j];
                        }
                    }
                    kar.JatMagusHozzaad(ujmagus);
                }
                return(kar.jatmagusok);
            }
        }
        public void JatIjaszFeltolt(string nev, string kaszt, string fegyver, string kep)
        {
            KarakterRaktar kar = KarakterRaktar.getInstance();

            string connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" + "DBQ=" + Environment.CurrentDirectory + @"\Fajlok\DB\jatekosadatbazis.xlsx" + ";ReadOnly=0;";

            OdbcConnection con = new OdbcConnection(connectionString);

            con.Open();
            string      query = "insert into [JatIjasz$] (Nev,Kaszt,Fegyver,Kep) values (?,?,?,?)";
            OdbcCommand cmd   = new OdbcCommand(query, con);

            cmd.Parameters.AddWithValue("?", nev);
            cmd.Parameters.AddWithValue("?", kaszt);
            cmd.Parameters.AddWithValue("?", fegyver);
            cmd.Parameters.AddWithValue("?", kep);
            cmd.ExecuteNonQuery();// has error
            con.Close();
        }