public ElementP(int brojElemenata, int redniBr) { identifikacioniKod = DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + (rand.Next(1000, 9999)).ToString(); redniBroj = redniBr; elementi = new ElementC[brojElemenata]; for (int i = 0; i < brojElemenata; i++) { elementi[i] = new ElementC(); } }
public void ProbaZaCitanje(string s) { List <ElementP> elementPs = new List <ElementP>(); SqlConnection con = new SqlConnection(@"Data Source=VLADICA-PC\SQLEXPRESS;Initial Catalog=NewDatbase;Integrated Security=True;"); try { con.Open(); DateTime dateTime = DateTime.Parse(s); dateTime = new DateTime(2000, 1, 1, dateTime.Hour, dateTime.Minute, dateTime.Second); string sqlP = "SELECT IdentifikacioniKod,RedniBroj,DatumPretrage FROM ElementP"; SqlCommand cmdP = new SqlCommand(sqlP, con); using (SqlDataReader oReader = cmdP.ExecuteReader()) { while (oReader.Read()) { if (dateTime < DateTime.Parse(oReader["DatumPretrage"].ToString())) { ElementP ELP = new ElementP(); ELP.IdentifikacioniKod = oReader["IdentifikacioniKod"].ToString(); ELP.RedniBroj = Int32.Parse(oReader["RedniBroj"].ToString()); elementPs.Add(ELP); Console.WriteLine("Citanje Podataka P"); } } } foreach (var item in elementPs) { List <ElementC> elementCs = new List <ElementC>(); string IDenKod = item.IdentifikacioniKod; string sqlC = "SELECT Grupa,Vrednost FROM ElementC WHERE IDKOD=@IDenKod"; SqlCommand cmdC = new SqlCommand(sqlC, con); cmdC.Parameters.AddWithValue("@IDenKod", IDenKod); using (SqlDataReader oReader = cmdC.ExecuteReader()) { while (oReader.Read()) { ElementC ELC = new ElementC(oReader["Grupa"].ToString().ToCharArray()[0], Int32.Parse(oReader["Vrednost"].ToString())); elementCs.Add(ELC); Console.WriteLine("Citanje Podataka C"); } } item.AddCs(elementCs); } foreach (var item in elementPs) { item.Stampaj(); } } catch (Exception ex) { Console.WriteLine(ex); } finally { con.Close(); } }