private bool SelectData() { try { var result = _databaza.SpecialSelect(SelectString); if (!Columns.Any()) { foreach (var row in result) { Columns = row.Keys.ToList(); break; } } _result = result; return(true); } catch (Exception e) { ErrorMessage = e.Message; return(false); } finally { OnVystupSpracovany(); } }
public bool SelectPodlaId(object paIdEntity) { string select = $"SELECT cislo FROM s_stlp WHERE id_ulice = {SUlica.IdUlice} ORDER BY poradie"; var rows = Databaza.SpecialSelect(select); foreach (var row in rows) { var stlp = new SStlp(); stlp.SelectPodlaId(int.Parse(row["CISLO"].ToString())); Stlpy.AddLast(stlp); } return(true); }
/// <summary> /// Pocet stĺpov na ktoré je treba generovať generuje sa od 1-2 doplnky /// na stĺpe a ako count sa berie Min(pocet stĺpov, paCount) /// </summary> /// <param name="paCount"></param> public override void Generate(int paCount) { var db = new Databaza(); var reader = db.SpecialSelect("select cislo, to_char(DATUM_INSTALACIE, 'DD.MM.YYYY') as datum from s_stlp where DATUM_INSTALACIE is not null"); var count = 0; const char znacka = 'Z'; const char reklama = 'R'; const char obmedzenie = 'O'; foreach (var row in reader) { var idStlpu = int.Parse(row["CISLO"].ToString()); var datumInstalacieStlpa = DateTime.Parse(row["DATUM"].ToString()); var prvyDatumInstalacieDoplnku = RandomDay(datumInstalacieStlpa, DateTime.Now); var druhyDatumInstalacieDoplnku = RandomDay(prvyDatumInstalacieDoplnku, DateTime.Now); var result = _random.Next() % 2; if (result == 0) { db.VlozDoplnokStlpu(idStlpu, reklama, GenerujReklamu(), prvyDatumInstalacieDoplnku); if (_random.Next() % 2 == 0) { db.VlozDoplnokStlpu(idStlpu, znacka, GenerujZnacku(), druhyDatumInstalacieDoplnku); } } else if (result == 1) { db.VlozDoplnokStlpu(idStlpu, znacka, GenerujZnacku(), prvyDatumInstalacieDoplnku); if (_random.Next() % 2 == 0) { db.VlozDoplnokStlpu(idStlpu, reklama, GenerujReklamu(), druhyDatumInstalacieDoplnku); } } else { db.VlozDoplnokStlpu(idStlpu, obmedzenie, GenerujRychlostneObmedzenie(), prvyDatumInstalacieDoplnku); } if (++count == paCount) { break; } } }
public void PridajDatumyDemontaze() { var db = new Databaza(); var reader = db.SpecialSelect("SELECT cislo , nest.id, nest.typ_doplnku, nest.popis, nest.datum_instalacie FROM s_stlp ss, table(select doplnky from s_stlp c WHERE c.cislo = ss.cislo) nest"); foreach (var row in reader) { if (_random.Next() % 2 == 0) { var idStlpu = int.Parse(row["CISLO"].ToString()); var idDoplnku = int.Parse(row["ID"].ToString()); var typDoplnku = row["TYP_DOPLNKU"].ToString()[0]; var popisDoplnku = row["POPIS"].ToString(); var datumInstalacieDoplnku = DateTime.Parse(row["DATUM_INSTALACIE"].ToString()); var datumDemontazeDoplnku = RandomDay(datumInstalacieDoplnku, DateTime.Now); db.UpdateDoplnokStlpu(idStlpu, idDoplnku, typDoplnku, popisDoplnku, datumInstalacieDoplnku, datumDemontazeDoplnku); } } }
/// <summary> /// entita sa načíta podľa svojho id /// </summary> /// <param name="paIdEntity"></param> /// <returns></returns> public virtual bool SelectPodlaId(object paIdEntity) { var atribut = SqlClassAttribute.ExtractSqlClassAttribute(this); var db = new Databaza(); var stlpce = string.Join(", ", this.GetType().GetProperties() .Where(p => SqlClassAttribute.ExtractSqlClassAttribute(p)?.IsColumn == true && SqlClassAttribute.ExtractSqlClassAttribute(p)?.IsReference == false) .Select(p => SqlClassAttribute.ExtractSqlClassAttribute(p)?.ColumnName)); var iterator = db.SpecialSelect( $"select {stlpce} from {atribut.TableName} where {atribut.TableKey} = {paIdEntity}"); var enumerator = iterator.GetEnumerator(); if (enumerator.MoveNext()) { MapujRiadokSelectu(enumerator.Current, this); return(true); } return(false); }
static void Main(string[] args) { Databaza db = new Databaza(); /* * FileInfo fi = new FileInfo("D:stlp2.jpg"); * FileStream fileStream = fi.OpenRead(); * Image img = new Bitmap(fileStream); * * Vysledok res = db.UpdateInfoStlpu(5,0 ,'I', ImageToByteArray(img)); * if (res.JeChyba) * Console.WriteLine("error"); * * * Console.WriteLine(res.Popis); * * * int c = 0; * DataTable ds = db.GetAllInfo(); * foreach (DataRow row in ds.Rows) * { * if (row["typ"].ToString() == "I") * { * Image i = ByteArrayToImage(row["data"] as byte[]); * i.Save("D:img" + c + ".jpeg", ImageFormat.Jpeg); * c++; * } * * }*/ /* * Dictionary<int, Image> qrCodes = new Dictionary<int, Image>(); * Dictionary<int, Image> pictures = new Dictionary<int, Image>(); * for (int i = 0; i < 699; i++) * { * FileInfo fi = new FileInfo("D:qr/"+i+".jpg"); * FileStream fileStream = fi.OpenRead(); * Image img = new Bitmap(fileStream); * qrCodes.Add(i, img); * } * * for (int i = 0; i < 50; i++) * { * FileInfo fi = new FileInfo("D:stlpy/" + i + ".jpg"); * FileStream fileStream = fi.OpenRead(); * Image img = new Bitmap(fileStream); * pictures.Add(i, img); * } * * Random rand = new Random(); * * for (int i = 0; i < 9775; i++) * { * Image img = pictures[rand.Next(0, pictures.Count)]; * Vysledok res = db.VlozInfoStlpu(i,'I',ImageToByteArray(img)); * * img = qrCodes[rand.Next(0, qrCodes.Count)]; * res = db.VlozInfoStlpu(i, 'Q', ImageToByteArray(img)); * * Console.WriteLine(i); * } */ /* * using (var s = new FileStream("D:import.sql", FileMode.Open)) * { * * }*/ //StringBuilder b = db.Test(); //Console.WriteLine(b.ToString()); //Console.WriteLine("Done"); //var vysledok = new Vysledok(); //var resultProcedurWithoutResult = db.RunProcedureWithOutput("TEST_KOD", null, new ProcedureParameter("parameter1", "integer", 1)); //foreach (var row in resultProcedurWithoutResult) //{ // Console.WriteLine(row[0]); //} //vysledok = new Vysledok(); //var resultProcedureSuccess = db.RunProcedureWithOutput("TEST_KOD", vysledok, new ProcedureParameter("parameter1", "integer", 0)); //foreach (var row in resultProcedureSuccess) //{ // Console.WriteLine(row[0]); //} //Console.WriteLine($"vysledok je chyba:{vysledok.JeChyba}, sprava: {vysledok.Popis}"); //vysledok = new Vysledok(); //var resultProcedureError = db.RunProcedureWithOutput("TEST_KOD", vysledok, new ProcedureParameter("parameter1", "integer", 1)); //foreach (var row in resultProcedureError) //{ // Console.WriteLine(row[0]); //} //Console.WriteLine($"vysledok je chyba:{vysledok.JeChyba}, sprava: {vysledok.Popis}"); //string s = "select cislo, id_sluzby, to_char(datum, 'dd.mm.yyyy'), nvl(popis,''), trvanie, cena from s_obsluha_stlpu join s_sluzba using (id_sluzby) join s_servis using (id_sluzby) order by id_sluzby desc"; //foreach (var rows in db.SpecialSelect(s)) //{ // var a = string.Join(", ", rows.Values); //} var result = db.SpecialSelect("select * from s_stlp"); foreach (var row in result) { Console.WriteLine(String.Join(", ", row)); } Console.WriteLine("Done"); Console.ReadLine(); }
public bool SelectPodlaId(object paIdEntity) { //SStlp.SelectPodlaId(paIdEntity); var select = $"select sd.ID, sd.TYP_DOPLNKU, sd.POPIS, to_char(sd.DATUM_INSTALACIE, 'dd.MM.yyyy') as DATUM_INSTALACIE, to_char(sd.DATUM_DEMONTAZE, 'DD.MM.YYYY') as DATUM_DEMONTAZE from s_stlp s, table(s.doplnky) sd where s.cislo = {SStlp.Cislo}"; var rows = Databaza.SpecialSelect(select); foreach (var row in rows) { var doplnok = new TDoplnok { Id = int.Parse(row["ID"].ToString()), Popis = row["POPIS"].ToString(), DatumDemontaze = row["DATUM_DEMONTAZE"].ToString(), DatumInstalacie = DateTime.Parse(row["DATUM_INSTALACIE"].ToString()),//row["DATUM_INSTALACIE"].ToString(), TypDoplnku = row["TYP_DOPLNKU"].ToString()[0], Cislo = SStlp.Cislo }; Doplnky.AddLast(doplnok); } var selectInfo = $"select * from s_info where cislo = {SStlp.Cislo}"; var informacie = Databaza.SpecialSelect(selectInfo); foreach (var informacia in informacie) { var info = new SInfo { Id = int.Parse(informacia["ID"].ToString()), Cislo = int.Parse(informacia["CISLO"].ToString()), Data = (byte[])informacia["DATA"], Typ = informacia["TYP"].ToString()[0] }; DateTime d; info.Datum = DateTime.TryParse(informacia["DATUM"].ToString(), out d) ? d.ToString("dd.MM.yyyy") : string.Empty; SInformacie.AddLast(info); } var selectLampy = $"select * from s_lampa_na_stlpe where cislo = {SStlp.Cislo} order by datum_demontaze desc"; var lampy = Databaza.SpecialSelect(selectLampy); foreach (var lampaNaStlpe in lampy) { var lampa = new SLampaNaStlpe() { IdLampy = int.Parse(lampaNaStlpe["ID_LAMPY"].ToString()), Cislo = int.Parse(lampaNaStlpe["CISLO"].ToString()), IdTypu = int.Parse(lampaNaStlpe["ID_TYPU"].ToString()), Stav = lampaNaStlpe["STAV"].ToString()[0], DatumInstalacie = DateTime.Parse(lampaNaStlpe["DATUM_INSTALACIE"].ToString())//.ToString("dd.MM.yyyy"), }; DateTime dod; lampa.DatumDemontaze = DateTime.TryParse(lampaNaStlpe["DATUM_DEMONTAZE"].ToString(), out dod) ? dod.ToString("dd.MM.yyyy") : string.Empty; if (lampa.Stav == 'S' && lampa.DatumDemontaze == String.Empty) { var s = $"select svietivost_lampy({lampa.IdLampy}) from dual "; var svietSelect = new VystupSelect(s, "svietivost"); svietSelect.SpustiVystup();; foreach (var row in svietSelect.Rows) { lampa.Svietivost = int.Parse(row[0].ToString()); } } SLampyNaStlpe.AddLast(lampa); } return(true); }